Don't do arithmetic with unconstrained widths when reflowing comboboxes. Bug 363858, r+sr=dbaron

This commit is contained in:
bzbarsky@mit.edu 2007-12-02 22:41:38 -08:00
Родитель 004ba2ffc2
Коммит 365fb40b8c
18 изменённых файлов: 427 добавлений и 21 удалений

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

@ -562,19 +562,8 @@ static void printSize(char * aDesc, nscoord aSize)
//-------------------------------------------------------------------
nscoord
nsComboboxControlFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
{
// We want to size to our pref width
nscoord result;
DISPLAY_MIN_WIDTH(this, result);
result = GetPrefWidth(aRenderingContext);
return result;
}
nscoord
nsComboboxControlFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
nsComboboxControlFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
nsLayoutUtils::IntrinsicWidthType aType)
{
// get the scrollbar width, we'll use this later
nscoord scrollbarWidth = 0;
@ -587,23 +576,50 @@ nsComboboxControlFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
scrollbarWidth = scrollable->GetDesiredScrollbarSizes(&bls).LeftRight();
}
nscoord displayPrefWidth = 0;
DISPLAY_PREF_WIDTH(this, displayPrefWidth);
nscoord displayWidth = 0;
if (NS_LIKELY(mDisplayFrame)) {
displayPrefWidth = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mDisplayFrame,
nsLayoutUtils::PREF_WIDTH);
displayWidth = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
mDisplayFrame,
aType);
}
if (mDropdownFrame) {
nscoord dropdownContentWidth = mDropdownFrame->GetPrefWidth(aRenderingContext) - scrollbarWidth;
displayPrefWidth = PR_MAX(dropdownContentWidth, displayPrefWidth);
nscoord dropdownContentWidth;
if (aType == nsLayoutUtils::MIN_WIDTH) {
dropdownContentWidth = mDropdownFrame->GetMinWidth(aRenderingContext);
} else {
NS_ASSERTION(aType == nsLayoutUtils::PREF_WIDTH, "Unexpected type");
dropdownContentWidth = mDropdownFrame->GetPrefWidth(aRenderingContext);
}
dropdownContentWidth -= scrollbarWidth;
displayWidth = PR_MAX(dropdownContentWidth, displayWidth);
}
// add room for the dropmarker button if there is one
if (!IsThemed() || presContext->GetTheme()->ThemeNeedsComboboxDropmarker())
displayPrefWidth += scrollbarWidth;
displayWidth += scrollbarWidth;
return displayPrefWidth;
return displayWidth;
}
nscoord
nsComboboxControlFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
{
nscoord minWidth;
DISPLAY_MIN_WIDTH(this, minWidth);
minWidth = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH);
return minWidth;
}
nscoord
nsComboboxControlFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
{
nscoord prefWidth;
DISPLAY_PREF_WIDTH(this, prefWidth);
prefWidth = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH);
return prefWidth;
}
NS_IMETHODIMP

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

@ -224,6 +224,9 @@ protected:
nsresult ReflowDropdown(nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState);
// Helper for GetMinWidth/GetPrefWidth
nscoord GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
nsLayoutUtils::IntrinsicWidthType aType);
protected:
class RedisplayTextEvent;
friend class RedisplayTextEvent;

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

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<style>
div { width: 0 }
option { white-space: normal }
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<style>
* { -moz-appearance: none }
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<style>
div { width: 0 }
option { white-space: normal }
* { -moz-appearance: none }
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div>
<select>
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
</div>
<div>
<select size="3">
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<style>
div { width: 0 }
option { white-space: normal }
optgroup { white-space: normal }
</style>
</head>
<body>
<div>
<select>
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
</div>
<div>
<select size="3">
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<style>
* { -moz-appearance: none }
</style>
</head>
<body>
<div>
<select>
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
</div>
<div>
<select size="3">
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<style>
div { width: 0 }
option { white-space: normal }
optgroup { white-space: normal }
* { -moz-appearance: none }
</style>
</head>
<body>
<div>
<select>
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
</div>
<div>
<select size="3">
<optgroup>
<option>This is option one</option>
<option>This is option two</option>
<option>This is option three which is long</option>
<option>This is option four</option>
</optgroup>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
select { width: 100%; -moz-box-sizing: border-box }
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option style="visibility: hidden">This is option one</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<style>
option { padding-left: 100%; }
</style>
</head>
<body>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<style>
select { width: -moz-fill; }
</style>
</head>
<body>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option style="visibility: hidden">This is option one</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<style>
select { width: 100%; -moz-box-sizing: border-box }
* { -moz-appearance: none; }
</style>
</head>
<body>
<div>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option style="visibility: hidden">This is option one</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
option { padding-left: 100%; }
* { -moz-appearance: none; }
</style>
</head>
<body>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option>This is option one</option>
</select>
<div>
</body>
</html>

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

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
select { width: -moz-fill; }
* { -moz-appearance: none; }
</style>
</head>
<body>
<select>
<option>This is option one</option>
</select>
</div>
<div>
<select size="3">
<option style="visibility: hidden">This is option one</option>
</select>
<div>
</body>
</html>

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

@ -244,6 +244,14 @@ fails == 352980-1h.html 352980-1-ref.html
== 363329-2.html 363329-2-ref.html
== 363370-1.html 363370-1-ref.html
== 363637-1.html 363637-1-ref.html
== 363858-1.html 363858-1-ref.html
== 363858-2.html 363858-2-ref.html
== 363858-3.html 363858-3-ref.html
== 363858-4.html 363858-4-ref.html
== 363858-5a.html 363858-5-ref.html
== 363858-5b.html 363858-5-ref.html
== 363858-6a.html 363858-6-ref.html
== 363858-6b.html 363858-6-ref.html
== 363874.html 363874-ref.html
== 363874-max-width.html 363874-max-width-ref.html
== 364066-1.html 364066-1-ref.html

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

@ -240,6 +240,7 @@ option {
line-height: normal !important;
-moz-user-select: none;
text-indent: 0;
white-space: nowrap !important;
}
select > option {
@ -265,6 +266,7 @@ optgroup {
font-size: inherit;
-moz-user-select: none;
text-indent: 0;
white-space: nowrap !important;
}
optgroup > option {