Fix sizing regression for selects with optgroups. b=188426 r+sr=bzbarsky

This commit is contained in:
dbaron%dbaron.org 2003-01-10 00:30:50 +00:00
parent 0cf9f72e1b
commit 849440045e
2 changed files with 54 additions and 18 deletions

View File

@ -778,6 +778,31 @@ static void printSize(char * aDesc, nscoord aSize)
} }
#endif #endif
static nscoord
GetMaxOptionHeight(nsIPresContext *aPresContext, nsIFrame *aContainer)
{
nscoord result = 0;
nsIFrame *option;
for (aContainer->FirstChild(aPresContext, nsnull, &option);
option; option->GetNextSibling(&option)) {
nscoord optionHeight;
nsCOMPtr<nsIContent> content;
option->GetContent(getter_AddRefs(content));
if (nsCOMPtr<nsIDOMHTMLOptGroupElement>(do_QueryInterface(content))) {
// an optgroup
optionHeight = GetMaxOptionHeight(aPresContext, option);
} else {
// an option
nsSize size;
option->GetSize(size);
optionHeight = size.height;
}
if (result < optionHeight)
result = optionHeight;
}
return result;
}
//----------------------------------------------------------------- //-----------------------------------------------------------------
// Main Reflow for ListBox/Dropdown // Main Reflow for ListBox/Dropdown
//----------------------------------------------------------------- //-----------------------------------------------------------------
@ -1047,16 +1072,9 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext,
// list by using the tallest of the grandchildren, since there may be // list by using the tallest of the grandchildren, since there may be
// option groups in addition to option elements, either of which may // option groups in addition to option elements, either of which may
// be visible or invisible. // be visible or invisible.
PRInt32 heightOfARow = 0; nsIFrame *optionsContainer;
nsIFrame *optionsContainer, *option;
GetOptionsContainer(aPresContext, &optionsContainer); GetOptionsContainer(aPresContext, &optionsContainer);
for (optionsContainer->FirstChild(aPresContext, nsnull, &option); PRInt32 heightOfARow = GetMaxOptionHeight(aPresContext, optionsContainer);
option; option->GetNextSibling(&option)) {
nsSize size;
option->GetSize(size);
if (heightOfARow < size.height)
heightOfARow = size.height;
}
// Check to see if we have zero items // Check to see if we have zero items
PRInt32 length = 0; PRInt32 length = 0;

View File

@ -778,6 +778,31 @@ static void printSize(char * aDesc, nscoord aSize)
} }
#endif #endif
static nscoord
GetMaxOptionHeight(nsIPresContext *aPresContext, nsIFrame *aContainer)
{
nscoord result = 0;
nsIFrame *option;
for (aContainer->FirstChild(aPresContext, nsnull, &option);
option; option->GetNextSibling(&option)) {
nscoord optionHeight;
nsCOMPtr<nsIContent> content;
option->GetContent(getter_AddRefs(content));
if (nsCOMPtr<nsIDOMHTMLOptGroupElement>(do_QueryInterface(content))) {
// an optgroup
optionHeight = GetMaxOptionHeight(aPresContext, option);
} else {
// an option
nsSize size;
option->GetSize(size);
optionHeight = size.height;
}
if (result < optionHeight)
result = optionHeight;
}
return result;
}
//----------------------------------------------------------------- //-----------------------------------------------------------------
// Main Reflow for ListBox/Dropdown // Main Reflow for ListBox/Dropdown
//----------------------------------------------------------------- //-----------------------------------------------------------------
@ -1047,16 +1072,9 @@ nsListControlFrame::Reflow(nsIPresContext* aPresContext,
// list by using the tallest of the grandchildren, since there may be // list by using the tallest of the grandchildren, since there may be
// option groups in addition to option elements, either of which may // option groups in addition to option elements, either of which may
// be visible or invisible. // be visible or invisible.
PRInt32 heightOfARow = 0; nsIFrame *optionsContainer;
nsIFrame *optionsContainer, *option;
GetOptionsContainer(aPresContext, &optionsContainer); GetOptionsContainer(aPresContext, &optionsContainer);
for (optionsContainer->FirstChild(aPresContext, nsnull, &option); PRInt32 heightOfARow = GetMaxOptionHeight(aPresContext, optionsContainer);
option; option->GetNextSibling(&option)) {
nsSize size;
option->GetSize(size);
if (heightOfARow < size.height)
heightOfARow = size.height;
}
// Check to see if we have zero items // Check to see if we have zero items
PRInt32 length = 0; PRInt32 length = 0;