Commit bebbcf9b authored by L. David Baron's avatar L. David Baron
Browse files

Make effect of form controls on font size inflation text threshold not depend...

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 : %82%DCX%81%B2%AAM%A3%A1%A1-%87%10%B3%B6%10kw%F4%FB
parent b6363403
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -411,10 +411,12 @@ protected:
  bool     HandleListSelection(nsIDOMEvent * aDOMEvent, PRInt32 selectedIndex);
  void     InitSelectionRange(PRInt32 aClickedIndex);

public:
  nsSelectsAreaFrame* GetOptionsContainer() const {
    return static_cast<nsSelectsAreaFrame*>(GetScrolledFrame());
  }

protected:
  nscoord HeightOfARow() {
    return GetOptionsContainer()->HeightOfARow();
  }
+59 −1
Original line number Diff line number Diff line
@@ -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<nsListControlFrame*>(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<nsTextControlFrame*>(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<nsComboboxControlFrame*>(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);
+17 −0
Original line number Diff line number Diff line
@@ -75,3 +75,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

fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,10) 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
fuzzy-if(gtk2Widget,1,8) 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
fuzzy-if(gtk2Widget,1,8) 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
fuzzy-if(gtk2Widget,1,8) 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
fuzzy-if(gtk2Widget,1,8) 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
+19 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<title>font.size.inflation.lineThreshold test</title>
<style>
body { width: 600px; }
body, input { font-size: 44px }
p { margin: 0 }
</style>
<!--
In a 600px container, the minimum font size at 15em per line is 40px.
This means we map 0px-60px into 40px-60px, so 12px gets mapped to 44px.

Further, with a lineThreshold of 100, we need 50 characters of 12px
text to meet the line threshold.
-->
<p>123456789
123456789
<input size="10" value="hi">
123456789
1234567890</p>
+19 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<title>font.size.inflation.lineThreshold test</title>
<style>
body { width: 600px; }
body, input { font-size: 12px }
p { margin: 0 }
</style>
<!--
In a 600px container, the minimum font size at 15em per line is 40px.
This means we map 0px-60px into 40px-60px, so 12px gets mapped to 44px.

Further, with a lineThreshold of 100, we need 50 characters of 12px
text to meet the line threshold.
-->
<p>123456789
123456789
<input size="10" value="hi">
123456789
1234567890</p>
Loading