Bug 806364 - Calculate dropdown height based on number of child frames for <option>s and <optgroup>s with non-empty label, instead of GetNumberOfOptions() which only includes <option> nodes. r=roc

This commit is contained in:
Mats Palmgren 2012-10-31 23:00:36 +01:00
parent 80dae24d12
commit f2df7bcbe6
2 changed files with 41 additions and 3 deletions

View File

@ -403,7 +403,7 @@ nsListControlFrame::Reflow(nsPresContext* aPresContext,
(NS_SUBTREE_DIRTY(this) || aReflowState.ShouldReflowAllKids());
nsHTMLReflowState state(aReflowState);
int32_t length = GetNumberOfOptions();
int32_t length = GetNumberOfRows();
nscoord oldHeightOfARow = HeightOfARow();
@ -565,7 +565,7 @@ nsListControlFrame::ReflowAsDropdown(nsPresContext* aPresContext,
if (above <= 0 && below <= 0) {
state.SetComputedHeight(heightOfARow);
mNumDisplayRows = 1;
mDropdownCanGrow = GetNumberOfOptions() > 1;
mDropdownCanGrow = GetNumberOfRows() > 1;
} else {
nscoord bp = aReflowState.mComputedBorderPadding.TopBottom();
nscoord availableHeight = NS_MAX(above, below) - bp;
@ -573,7 +573,7 @@ nsListControlFrame::ReflowAsDropdown(nsPresContext* aPresContext,
uint32_t rows;
if (visibleHeight <= availableHeight) {
// The dropdown fits in the available height.
rows = GetNumberOfOptions();
rows = GetNumberOfRows();
mNumDisplayRows = clamped<uint32_t>(rows, 1, kMaxDropDownRows);
if (mNumDisplayRows == rows) {
newHeight = visibleHeight; // use the exact height
@ -749,6 +749,39 @@ nsListControlFrame::InitSelectionRange(int32_t aClickedIndex)
}
}
static uint32_t
CountOptionsAndOptgroups(nsIFrame* aFrame)
{
uint32_t count = 0;
nsFrameList::Enumerator e(aFrame->PrincipalChildList());
for (; !e.AtEnd(); e.Next()) {
nsIFrame* child = e.get();
nsIContent* content = child->GetContent();
if (content) {
if (content->IsHTML(nsGkAtoms::option)) {
++count;
} else {
nsCOMPtr<nsIDOMHTMLOptGroupElement> optgroup = do_QueryInterface(content);
if (optgroup) {
nsAutoString label;
optgroup->GetLabel(label);
if (label.Length() > 0) {
++count;
}
count += CountOptionsAndOptgroups(child);
}
}
}
}
return count;
}
uint32_t
nsListControlFrame::GetNumberOfRows()
{
return ::CountOptionsAndOptgroups(GetContentInsertionFrame());
}
//---------------------------------------------------------
bool
nsListControlFrame::PerformSelection(int32_t aClickedIndex,

View File

@ -389,6 +389,11 @@ protected:
nscoord HeightOfARow() {
return GetOptionsContainer()->HeightOfARow();
}
/**
* @return how many displayable options/optgroups this frame has.
*/
uint32_t GetNumberOfRows();
// Data Members
int32_t mStartSelectionIndex;