Add CountAllChild to count all the option and optgroup elements so lists

get sized correctly when no rows are specified
r=kmcclusk, bug=4050
This commit is contained in:
rods%netscape.com 1999-11-03 00:07:01 +00:00
Родитель 4dc1d549b0
Коммит 3f9ff89e9b
4 изменённых файлов: 116 добавлений и 8 удалений

Просмотреть файл

@ -178,6 +178,55 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsScrollFrame::QueryInterface(aIID, aInstancePtr);
}
//---------------------------------------------------------
nsresult nsListControlFrame::CountAllChild(nsIDOMNode * aNode, PRInt32& aCount)
{
nsresult status = NS_OK;
nsIDOMNode * child;
aNode->GetFirstChild(&child);
while (child) {
// note: both optgroup and option elements can have DOM child
// option elements have text nodes as COM child, but they don't have too
nsCOMPtr<nsIDOMHTMLOptGroupElement> optGroup;
child->QueryInterface(nsCOMTypeInfo<nsIDOMHTMLOptGroupElement>::GetIID(),(void**) &optGroup);
if (optGroup) {
aCount++;
// check for children
PRBool hasChildren;
status = child->HasChildNodes(&hasChildren);
if (NS_FAILED(status)) {
NS_RELEASE(child);
return status;
}
if (hasChildren) {
status = CountAllChild(child, aCount);
if (NS_FAILED(status)) {
NS_RELEASE(child);
return status;
}
}
} else {
// don't query interface againa if it was an optgroup
nsCOMPtr<nsIDOMHTMLOptionElement> option;
child->QueryInterface(nsCOMTypeInfo<nsIDOMHTMLOptionElement>::GetIID(),(void**) &option);
if (option) {
aCount++;
}
}
nsIDOMNode * tmp = child;
status = child->GetNextSibling(&child);
if (NS_FAILED(status)) {
NS_RELEASE(tmp);
return status;
}
NS_RELEASE(tmp);
}
return status;
}
//---------------------------------------------------------
// Reflow is overriden to constrain the listbox height to the number of rows and columns
// specified.
@ -365,11 +414,15 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
PRInt32 numRows = 1;
GetSizeAttribute(&numRows);
if (numRows == kNoSizeSpecified) {
visibleHeight = aReflowState.mComputedHeight;
visibleHeight -= (border.top + border.bottom + padding.top + padding.bottom);
} else {
visibleHeight = numRows * heightOfARow;
nsIDOMNode* node;
nsresult rv = mContent->QueryInterface(nsCOMTypeInfo<nsIDOMNode>::GetIID(),(void**) &node);
if (node && NS_SUCCEEDED(rv)) {
numRows = 0;
CountAllChild(node, numRows);
NS_RELEASE(node);
}
}
visibleHeight = numRows * heightOfARow;
}
}

Просмотреть файл

@ -160,6 +160,7 @@ public:
protected:
NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM
NS_IMETHOD IsTargetOptionDisabled(PRBool &aIsDisabled);
nsresult CountAllChild(nsIDOMNode * aNode, PRInt32& aCount);
nsListControlFrame();
virtual ~nsListControlFrame();

Просмотреть файл

@ -178,6 +178,55 @@ nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsScrollFrame::QueryInterface(aIID, aInstancePtr);
}
//---------------------------------------------------------
nsresult nsListControlFrame::CountAllChild(nsIDOMNode * aNode, PRInt32& aCount)
{
nsresult status = NS_OK;
nsIDOMNode * child;
aNode->GetFirstChild(&child);
while (child) {
// note: both optgroup and option elements can have DOM child
// option elements have text nodes as COM child, but they don't have too
nsCOMPtr<nsIDOMHTMLOptGroupElement> optGroup;
child->QueryInterface(nsCOMTypeInfo<nsIDOMHTMLOptGroupElement>::GetIID(),(void**) &optGroup);
if (optGroup) {
aCount++;
// check for children
PRBool hasChildren;
status = child->HasChildNodes(&hasChildren);
if (NS_FAILED(status)) {
NS_RELEASE(child);
return status;
}
if (hasChildren) {
status = CountAllChild(child, aCount);
if (NS_FAILED(status)) {
NS_RELEASE(child);
return status;
}
}
} else {
// don't query interface againa if it was an optgroup
nsCOMPtr<nsIDOMHTMLOptionElement> option;
child->QueryInterface(nsCOMTypeInfo<nsIDOMHTMLOptionElement>::GetIID(),(void**) &option);
if (option) {
aCount++;
}
}
nsIDOMNode * tmp = child;
status = child->GetNextSibling(&child);
if (NS_FAILED(status)) {
NS_RELEASE(tmp);
return status;
}
NS_RELEASE(tmp);
}
return status;
}
//---------------------------------------------------------
// Reflow is overriden to constrain the listbox height to the number of rows and columns
// specified.
@ -365,11 +414,15 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
PRInt32 numRows = 1;
GetSizeAttribute(&numRows);
if (numRows == kNoSizeSpecified) {
visibleHeight = aReflowState.mComputedHeight;
visibleHeight -= (border.top + border.bottom + padding.top + padding.bottom);
} else {
visibleHeight = numRows * heightOfARow;
nsIDOMNode* node;
nsresult rv = mContent->QueryInterface(nsCOMTypeInfo<nsIDOMNode>::GetIID(),(void**) &node);
if (node && NS_SUCCEEDED(rv)) {
numRows = 0;
CountAllChild(node, numRows);
NS_RELEASE(node);
}
}
visibleHeight = numRows * heightOfARow;
}
}

Просмотреть файл

@ -160,6 +160,7 @@ public:
protected:
NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM
NS_IMETHOD IsTargetOptionDisabled(PRBool &aIsDisabled);
nsresult CountAllChild(nsIDOMNode * aNode, PRInt32& aCount);
nsListControlFrame();
virtual ~nsListControlFrame();