Bug 746966: Conditionally set NS_FRAME_IN_CONSTRAINED_HEIGHT for font inflation on percentage-based height so fonts with room to inflate can do so. [r=dbaron][a=johnath]
authorScott Johnson <sjohnson@mozilla.com>
Tue, 08 May 2012 15:31:48 -0500
changeset 95668 3f16abb633ee1055f3bacbd467509b7298313267
parent 95667 c035ee184c13abf82b589e8f71f7a9367353229d
child 95669 317262a2c3b7b8745854c54e0f99d525beaf7bed
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron, johnath
bugs746966
milestone14.0a2
Bug 746966: Conditionally set NS_FRAME_IN_CONSTRAINED_HEIGHT for font inflation on percentage-based height so fonts with room to inflate can do so. [r=dbaron][a=johnath]
layout/generic/nsHTMLReflowState.cpp
layout/reftests/font-inflation/height-constraint-percent-1-ref.html
layout/reftests/font-inflation/height-constraint-percent-1.html
layout/reftests/font-inflation/height-constraint-percent-2-ref.html
layout/reftests/font-inflation/height-constraint-percent-2.html
layout/reftests/font-inflation/height-constraint-percent-3-ref.html
layout/reftests/font-inflation/height-constraint-percent-3.html
layout/reftests/font-inflation/height-constraint-percent-4-ref.html
layout/reftests/font-inflation/height-constraint-percent-4.html
layout/reftests/font-inflation/height-constraint-percent-5-ref.html
layout/reftests/font-inflation/height-constraint-percent-5.html
layout/reftests/font-inflation/height-constraint-percent-6-ref.html
layout/reftests/font-inflation/height-constraint-percent-6.html
layout/reftests/font-inflation/height-constraint-percent-7-ref.html
layout/reftests/font-inflation/height-constraint-percent-7.html
layout/reftests/font-inflation/height-constraint-percent-8-ref.html
layout/reftests/font-inflation/height-constraint-percent-8.html
layout/reftests/font-inflation/reftest.list
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -298,17 +298,46 @@ nsHTMLReflowState::Init(nsPresContext* a
     frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
   } else if ((mStylePosition->mHeight.GetUnit() != eStyleUnit_Auto ||
               mStylePosition->mMaxHeight.GetUnit() != eStyleUnit_None) &&
               // Don't set NS_FRAME_IN_CONSTRAINED_HEIGHT on body or html
               // elements.
              (frame->GetContent() &&
             !(frame->GetContent()->IsHTML(nsGkAtoms::body) ||
               frame->GetContent()->IsHTML(nsGkAtoms::html)))) {
-    frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
+
+    // If our height was specified as a percentage, then this could
+    // actually resolve to 'auto', based on:
+    // http://www.w3.org/TR/CSS21/visudet.html#the-height-property
+    nsIFrame* containingBlk = frame;
+    while (containingBlk) {
+      const nsStylePosition* stylePos = containingBlk->GetStylePosition();
+      if ((stylePos->mHeight.IsCoordPercentCalcUnit() &&
+           !stylePos->mHeight.HasPercent()) ||
+          (stylePos->mMaxHeight.IsCoordPercentCalcUnit() &&
+           !stylePos->mMaxHeight.HasPercent())) {
+        frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
+        break;
+      } else if ((stylePos->mHeight.IsCoordPercentCalcUnit() &&
+                  stylePos->mHeight.HasPercent()) ||
+                 (stylePos->mMaxHeight.IsCoordPercentCalcUnit() &&
+                  stylePos->mMaxHeight.HasPercent())) {
+        if (!(containingBlk = containingBlk->GetContainingBlock())) {
+          // If we've reached the top of the tree, then we don't have
+          // a constrained height.
+          frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
+          break;
+        }
+
+        continue;
+      } else {
+        frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
+        break;
+      }
+    }
   } else {
     frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
   }
 
   NS_WARN_IF_FALSE((mFrameType == NS_CSS_FRAME_TYPE_INLINE &&
                     !frame->IsFrameOfType(nsIFrame::eReplaced)) ||
                    type == nsGkAtoms::textFrame ||
                    mComputedWidth != NS_UNCONSTRAINEDSIZE,
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-1-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { font-size: 34px; width: 450px }
+#center-block { height: 80%;}
+#center-col { background: yellow; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-2-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { font-size: 34px; width: 450px }
+#center-block { max-height: 80%;}
+#center-col { background: yellow; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-2.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { max-height: 80%; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-3-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { font-size: 34px; width: 450px }
+#center-block { height: -moz-calc(80% + 5%); }
+#center-col { background: yellow; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-3.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: -moz-calc(80% + 5%); }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-4-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#center-col { background: yellow }
+#containing-block { height: 800px; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height of the containing block is constrained, the percent height should also
+be constrained, resulting in font inflation being disabled.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-4.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#center-col { background: yellow }
+#containing-block { height: 800px; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height of the containing block is constrained, the percent height should also
+be constrained, resulting in font inflation being disabled.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-5-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#center-col { background: yellow }
+#containing-block { height: -moz-calc(400px + 20px); }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height of the containing block is constrained, the percent height should also
+be constrained, resulting in font inflation being disabled.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-5.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#center-col { background: yellow }
+#containing-block { height: -moz-calc(400px + 20px); }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height of the containing block is constrained, the percent height should also
+be constrained, resulting in font inflation being disabled.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-6-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<style>
+div { font-size: 12px; width: 450px }
+#center-block { height: 400px; }
+#center-col { background: yellow; }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height is constrained, this should not be inflated.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-6.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 400px; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the height is constrained, this should not be inflated.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-7-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { max-height: 400px; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the max height is constrained, this should not be inflated.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-7.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { max-height: 400px; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+Because the max height is constrained, this should not be inflated.
+-->
+<div id="center-block">
+<div id="center-col">
+    <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-8-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 34px; width: 450px }
+#center-block { height: 80%; }
+#containing-block { height: 80%; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-inflation/height-constraint-percent-8.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<style>
+div { margin-top: 0; font-size: 12px; width: 450px }
+#center-block { height: 80%; }
+#containing-block { height: 80%; }
+#center-col { background: yellow }
+p { margin-top: 0px; }
+
+</style>
+<!--
+In a 450px container, the minimum font size at 15em per line is 30px.
+This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
+-->
+<div id="containing-block">
+  <div id="center-block">
+    <div id="center-col">
+      <p>Life and death, dreaming and wakefulness: stations for the perplexed soul. It traverses them by stage, taking signs and hints from things, groping about in the sea of darkness, clinging stubbornly to a hope that smilingly and mysteriously renews itself. Traveler, what are you searching for? What emotions rage in your heart?</p>
+    </div>
+  </div>
+</div>
--- a/layout/reftests/font-inflation/reftest.list
+++ b/layout/reftests/font-inflation/reftest.list
@@ -4,16 +4,24 @@
 # them compatibly without having to rewrite all of them, we run them
 # with the lineThreshold preference explicitly set to zero.  However,
 # newer tests should probably focus more on testing nonzero values of
 # that preference.
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-1.html text-1-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-2.html text-2-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-3.html text-3-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-4.html text-4-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-1.html height-constraint-percent-1-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-2.html height-constraint-percent-2-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-3.html height-constraint-percent-3-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-4.html height-constraint-percent-4-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-5.html height-constraint-percent-5-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-6.html height-constraint-percent-6-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-7.html height-constraint-percent-7-ref.html
+test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == height-constraint-percent-8.html height-constraint-percent-8-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == decoration-1.html decoration-1-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == bullet-1.html bullet-1-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == bullet-2.html bullet-2-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == input-text-1-height.html input-text-1-height-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == input-text-1-noheight.html input-text-1-noheight-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == input-text-2-height.html input-text-2-height-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == input-text-2-noheight.html input-text-2-noheight-ref.html
 test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == input-text-3-height.html input-text-3-height-ref.html