From d2b33df467e7fda0935cfcb5d923966c4bb7891f Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 3 May 2012 20:04:30 -0400 Subject: [PATCH] Make effect of form controls on font size inflation text threshold not depend on user changes to their value. (Bug 747857) r=roc --HG-- extra : transplant_source : %1F%7B%3Fk%A6%F1%2C%EAZ%920%FB%FD%FB%3D%8E%9C%C9y%19 --- layout/forms/nsListControlFrame.h | 2 + layout/generic/nsFontInflationData.cpp | 60 ++++++++++++++++++- layout/reftests/font-inflation/reftest.list | 17 ++++++ ...hreshold-input-text-contents-at-1-ref.html | 19 ++++++ .../threshold-input-text-contents-at-1.html | 19 ++++++ ...hreshold-input-text-contents-at-2-ref.html | 19 ++++++ .../threshold-input-text-contents-at-2.html | 19 ++++++ ...threshold-input-text-contents-under-1.html | 19 ++++++ ...threshold-input-text-contents-under-2.html | 19 ++++++ ...old-select-combobox-contents-at-1-ref.html | 23 +++++++ ...reshold-select-combobox-contents-at-1.html | 23 +++++++ ...old-select-combobox-contents-at-2-ref.html | 23 +++++++ ...reshold-select-combobox-contents-at-2.html | 23 +++++++ ...hold-select-combobox-contents-under-1.html | 23 +++++++ ...hold-select-combobox-contents-under-2.html | 23 +++++++ ...hold-select-listbox-contents-at-1-ref.html | 23 +++++++ ...hreshold-select-listbox-contents-at-1.html | 23 +++++++ ...hold-select-listbox-contents-at-2-ref.html | 23 +++++++ ...hreshold-select-listbox-contents-at-2.html | 23 +++++++ ...shold-select-listbox-contents-under-1.html | 23 +++++++ ...shold-select-listbox-contents-under-2.html | 23 +++++++ .../threshold-textarea-contents-at-1-ref.html | 21 +++++++ .../threshold-textarea-contents-at-1.html | 21 +++++++ .../threshold-textarea-contents-at-2-ref.html | 21 +++++++ .../threshold-textarea-contents-at-2.html | 21 +++++++ .../threshold-textarea-contents-under-1.html | 21 +++++++ .../threshold-textarea-contents-under-2.html | 21 +++++++ 27 files changed, 594 insertions(+), 1 deletion(-) create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-at-1-ref.html create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-at-1.html create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-at-2-ref.html create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-at-2.html create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-under-1.html create mode 100644 layout/reftests/font-inflation/threshold-input-text-contents-under-2.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-at-1-ref.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-at-1.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-at-2-ref.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-at-2.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-under-1.html create mode 100644 layout/reftests/font-inflation/threshold-select-combobox-contents-under-2.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-at-1-ref.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-at-1.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-at-2-ref.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-at-2.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-under-1.html create mode 100644 layout/reftests/font-inflation/threshold-select-listbox-contents-under-2.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-at-1-ref.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-at-1.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-at-2-ref.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-at-2.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-under-1.html create mode 100644 layout/reftests/font-inflation/threshold-textarea-contents-under-2.html diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index 9598edbae7b..3042d0ff426 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -411,10 +411,12 @@ protected: bool HandleListSelection(nsIDOMEvent * aDOMEvent, PRInt32 selectedIndex); void InitSelectionRange(PRInt32 aClickedIndex); +public: nsSelectsAreaFrame* GetOptionsContainer() const { return static_cast(GetScrolledFrame()); } +protected: nscoord HeightOfARow() { return GetOptionsContainer()->HeightOfARow(); } diff --git a/layout/generic/nsFontInflationData.cpp b/layout/generic/nsFontInflationData.cpp index 8862acd79de..f036ead83dd 100644 --- a/layout/generic/nsFontInflationData.cpp +++ b/layout/generic/nsFontInflationData.cpp @@ -41,6 +41,9 @@ #include "FramePropertyTable.h" #include "nsTextFragment.h" #include "nsIFormControlFrame.h" +#include "nsTextControlFrame.h" +#include "nsListControlFrame.h" +#include "nsComboboxControlFrame.h" #include "nsHTMLReflowState.h" #include "nsTextFrameUtils.h" @@ -298,6 +301,41 @@ nsFontInflationData::ScanText() mInflationEnabled = mTextAmount >= mTextThreshold; } +static PRUint32 +DoCharCountOfLargestOption(nsIFrame *aContainer) +{ + PRUint32 result = 0; + for (nsIFrame* option = aContainer->GetFirstPrincipalChild(); + option; option = option->GetNextSibling()) { + PRUint32 optionResult; + if (option->GetContent()->IsHTML(nsGkAtoms::optgroup)) { + optionResult = DoCharCountOfLargestOption(option); + } else { + // REVIEW: Check the frame structure for this! + optionResult = 0; + for (nsIFrame *optionChild = option->GetFirstPrincipalChild(); + optionChild; optionChild = optionChild->GetNextSibling()) { + if (optionChild->GetType() == nsGkAtoms::textFrame) { + optionResult += nsTextFrameUtils:: + ComputeApproximateLengthWithWhitespaceCompression( + optionChild->GetContent(), optionChild->GetStyleText()); + } + } + } + if (optionResult > result) { + result = optionResult; + } + } + return result; +} + +static PRUint32 +CharCountOfLargestOption(nsIFrame *aListControlFrame) +{ + return DoCharCountOfLargestOption( + static_cast(aListControlFrame)->GetOptionsContainer()); +} + void nsFontInflationData::ScanTextIn(nsIFrame *aFrame) { @@ -316,7 +354,8 @@ nsFontInflationData::ScanTextIn(nsIFrame *aFrame) continue; } - if (kid->GetType() == nsGkAtoms::textFrame) { + nsIAtom *fType = kid->GetType(); + if (fType == nsGkAtoms::textFrame) { nsIContent *content = kid->GetContent(); if (content && kid == content->GetPrimaryFrame()) { PRUint32 len = nsTextFrameUtils:: @@ -329,6 +368,25 @@ nsFontInflationData::ScanTextIn(nsIFrame *aFrame) } } } + } else if (fType == nsGkAtoms::textInputFrame) { + // We don't want changes to the amount of text in a text input + // to change what we count towards inflation. + nscoord fontSize = kid->GetStyleFont()->mFont.size; + PRInt32 charCount = static_cast(kid)->GetCols(); + mTextAmount += charCount * fontSize; + } else if (fType == nsGkAtoms::comboboxControlFrame) { + // See textInputFrame above (with s/amount of text/selected option/). + // Don't just recurse down to the list control inside, since we + // need to exclude the display frame. + nscoord fontSize = kid->GetStyleFont()->mFont.size; + PRInt32 charCount = CharCountOfLargestOption( + static_cast(kid)->GetDropDown()); + mTextAmount += charCount * fontSize; + } else if (fType == nsGkAtoms::listControlFrame) { + // See textInputFrame above (with s/amount of text/selected option/). + nscoord fontSize = kid->GetStyleFont()->mFont.size; + PRInt32 charCount = CharCountOfLargestOption(kid); + mTextAmount += charCount * fontSize; } else { // recursive step ScanTextIn(kid); diff --git a/layout/reftests/font-inflation/reftest.list b/layout/reftests/font-inflation/reftest.list index c3b4bb34137..74c00fd82eb 100644 --- a/layout/reftests/font-inflation/reftest.list +++ b/layout/reftests/font-inflation/reftest.list @@ -67,3 +67,20 @@ test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineTh test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-scope-cell-1.html threshold-scope-cell-1-ref.html test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-scope-cell-2.html threshold-scope-cell-2-ref.html test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-scope-cell-3.html threshold-scope-cell-3-ref.html + +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-textarea-contents-under-1.html threshold-textarea-contents-under-1.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-textarea-contents-under-2.html threshold-textarea-contents-under-2.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-textarea-contents-at-1.html threshold-textarea-contents-at-1-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-textarea-contents-at-2.html threshold-textarea-contents-at-2-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-input-text-contents-under-1.html threshold-input-text-contents-under-1.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-input-text-contents-under-2.html threshold-input-text-contents-under-2.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-input-text-contents-at-1.html threshold-input-text-contents-at-1-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-input-text-contents-at-2.html threshold-input-text-contents-at-2-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-listbox-contents-under-1.html threshold-select-listbox-contents-under-1.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-listbox-contents-under-2.html threshold-select-listbox-contents-under-2.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-listbox-contents-at-1.html threshold-select-listbox-contents-at-1-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-listbox-contents-at-2.html threshold-select-listbox-contents-at-2-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-under-1.html threshold-select-combobox-contents-under-1.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-under-2.html threshold-select-combobox-contents-under-2.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-at-1.html threshold-select-combobox-contents-at-1-ref.html +test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-at-2.html threshold-select-combobox-contents-at-2-ref.html diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-at-1-ref.html b/layout/reftests/font-inflation/threshold-input-text-contents-at-1-ref.html new file mode 100644 index 00000000000..472ccc62bc1 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-at-1-ref.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-at-1.html b/layout/reftests/font-inflation/threshold-input-text-contents-at-1.html new file mode 100644 index 00000000000..b277c6556cb --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-at-1.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-at-2-ref.html b/layout/reftests/font-inflation/threshold-input-text-contents-at-2-ref.html new file mode 100644 index 00000000000..639d05e8b92 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-at-2-ref.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-at-2.html b/layout/reftests/font-inflation/threshold-input-text-contents-at-2.html new file mode 100644 index 00000000000..a26f0e92eaf --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-at-2.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-under-1.html b/layout/reftests/font-inflation/threshold-input-text-contents-under-1.html new file mode 100644 index 00000000000..d464c66ab03 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-under-1.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-input-text-contents-under-2.html b/layout/reftests/font-inflation/threshold-input-text-contents-under-2.html new file mode 100644 index 00000000000..adf81cb9e40 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-input-text-contents-under-2.html @@ -0,0 +1,19 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1-ref.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1-ref.html new file mode 100644 index 00000000000..9e585c4bc90 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1-ref.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1.html new file mode 100644 index 00000000000..8e24ea46bab --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-1.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2-ref.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2-ref.html new file mode 100644 index 00000000000..7ccb43a52c4 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2-ref.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2.html new file mode 100644 index 00000000000..87f5f3cedc8 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-at-2.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-under-1.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-under-1.html new file mode 100644 index 00000000000..a29001f9e2a --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-under-1.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-combobox-contents-under-2.html b/layout/reftests/font-inflation/threshold-select-combobox-contents-under-2.html new file mode 100644 index 00000000000..de5e82b558f --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-combobox-contents-under-2.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1-ref.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1-ref.html new file mode 100644 index 00000000000..df3ce974255 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1-ref.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1.html new file mode 100644 index 00000000000..b43e209d5b1 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-1.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2-ref.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2-ref.html new file mode 100644 index 00000000000..7b79a99882f --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2-ref.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2.html new file mode 100644 index 00000000000..8b7374e6922 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-at-2.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-under-1.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-under-1.html new file mode 100644 index 00000000000..777ac09f3a0 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-under-1.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-select-listbox-contents-under-2.html b/layout/reftests/font-inflation/threshold-select-listbox-contents-under-2.html new file mode 100644 index 00000000000..abfada7e36c --- /dev/null +++ b/layout/reftests/font-inflation/threshold-select-listbox-contents-under-2.html @@ -0,0 +1,23 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-at-1-ref.html b/layout/reftests/font-inflation/threshold-textarea-contents-at-1-ref.html new file mode 100644 index 00000000000..5728bb0fdff --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-at-1-ref.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-at-1.html b/layout/reftests/font-inflation/threshold-textarea-contents-at-1.html new file mode 100644 index 00000000000..d527e070f42 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-at-1.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-at-2-ref.html b/layout/reftests/font-inflation/threshold-textarea-contents-at-2-ref.html new file mode 100644 index 00000000000..27dd261461e --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-at-2-ref.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-at-2.html b/layout/reftests/font-inflation/threshold-textarea-contents-at-2.html new file mode 100644 index 00000000000..02989efe10a --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-at-2.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-under-1.html b/layout/reftests/font-inflation/threshold-textarea-contents-under-1.html new file mode 100644 index 00000000000..7b8b6232169 --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-under-1.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890

diff --git a/layout/reftests/font-inflation/threshold-textarea-contents-under-2.html b/layout/reftests/font-inflation/threshold-textarea-contents-under-2.html new file mode 100644 index 00000000000..82c8faf0faa --- /dev/null +++ b/layout/reftests/font-inflation/threshold-textarea-contents-under-2.html @@ -0,0 +1,21 @@ + +font.size.inflation.lineThreshold test + + +

123456789 +123456789 + +123456789 +1234567890