Avoid discontinuity when options drop to height:0 by using CalcFallbackRowHeight only when GetNumberOfOptions() == 0, thus eliminating the last caller of CalcFallbackRowHeight passing a non-zero option count. (Bug 467084) sr=roc r=bzbarsky a=blocking1.9.1+

This commit is contained in:
L. David Baron 2008-12-04 08:09:53 -08:00
parent 2dccf4784c
commit 4260a65399
7 changed files with 70 additions and 25 deletions

View File

@ -344,7 +344,7 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsPoint aPt)
} else {
fRect.x = fRect.y = 0;
fRect.width = GetScrollPortSize().width;
fRect.height = CalcFallbackRowHeight(0);
fRect.height = CalcFallbackRowHeight();
fRect.MoveBy(containerFrame->GetOffsetTo(this));
}
fRect += aPt;
@ -380,7 +380,7 @@ nsListControlFrame::InvalidateFocus()
// is drawn.
// The origin of the scrollport is the origin of containerFrame.
nsRect invalidateArea = containerFrame->GetOverflowRect();
nsRect emptyFallbackArea(0, 0, GetScrollPortSize().width, CalcFallbackRowHeight(0));
nsRect emptyFallbackArea(0, 0, GetScrollPortSize().width, CalcFallbackRowHeight());
invalidateArea.UnionRect(invalidateArea, emptyFallbackArea);
containerFrame->Invalidate(invalidateArea);
}
@ -509,9 +509,10 @@ nsListControlFrame::CalcHeightOfARow()
// invisible, may use different fonts, etc.
PRInt32 heightOfARow = GetMaxOptionHeight(GetOptionsContainer());
// Check to see if we have zero items
if (heightOfARow == 0) {
heightOfARow = CalcFallbackRowHeight(GetNumberOfOptions());
// Check to see if we have zero items (and optimize by checking
// heightOfARow first)
if (heightOfARow == 0 && GetNumberOfOptions() == 0) {
heightOfARow = CalcFallbackRowHeight();
}
return heightOfARow;
@ -1875,27 +1876,12 @@ nsListControlFrame::IsLeftButton(nsIDOMEvent* aMouseEvent)
}
nscoord
nsListControlFrame::CalcFallbackRowHeight(PRInt32 aNumOptions)
nsListControlFrame::CalcFallbackRowHeight()
{
nsIFrame *fontFrame = nsnull;
if (aNumOptions > 0) {
// Try the first option
nsCOMPtr<nsIContent> option = GetOptionContent(0);
if (option) {
fontFrame = PresContext()->PresShell()->GetPrimaryFrameFor(option);
}
}
if (!fontFrame) {
// Fall back to our own font
fontFrame = this;
}
nscoord rowHeight = 0;
nsCOMPtr<nsIFontMetrics> fontMet;
nsLayoutUtils::GetFontMetricsForFrame(fontFrame, getter_AddRefs(fontMet));
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
if (fontMet) {
fontMet->GetHeight(rowHeight);
}

View File

@ -373,9 +373,8 @@ protected:
PRInt32 GetIndexFromContent(nsIContent *aContent);
PRBool IsLeftButton(nsIDOMEvent* aMouseEvent);
// aNumOptions is the number of options we have; if we have none,
// we'll just guess at a row height based on our own style.
nscoord CalcFallbackRowHeight(PRInt32 aNumOptions);
// guess at a row height based on our own style.
nscoord CalcFallbackRowHeight();
// CalcIntrinsicHeight computes our intrinsic height (taking the "size"
// attribute into account). This should only be called in non-dropdown mode.

View File

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<title>Testcase for side issue in bug 467084</title>
<style type="text/css">
div { background: yellow; }
select {
margin: 2em 0; /* be bigger than the line-height */
visibility: hidden;
}
option { height: 1px; min-height: 0; }
</style>
<div>
<select size="3">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>

View File

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<title>Testcase for side issue in bug 467084</title>
<style type="text/css">
div { background: yellow; padding-bottom: 3px; }
select {
margin: 2em 0; /* be bigger than the line-height */
visibility: hidden;
}
option { height: 0; min-height: 0; }
</style>
<div>
<select size="3">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>

View File

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<title>Testcase for side issue in bug 467084</title>
<style type="text/css">
select { font-size: 50px; }
</style>
<select size="3">
<option></option>
</select>

View File

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<title>Testcase for side issue in bug 467084</title>
<style type="text/css">
option { font-size: 50px; }
</style>
<select size="3">
<option></option>
</select>

View File

@ -982,3 +982,5 @@ fails == 461512-1.html 461512-1-ref.html # Bug 461512
== 464811-1.html 464811-1-ref.html
== 466395-1.html 466395-1-ref.html
== 466395-2.html 466395-2-ref.html
== 467084-1.html 467084-1-ref.html
== 467084-2.html 467084-2-ref.html