Bug 1491731 - [css-text-3] Resolve 'text-indent' using a zero percentage basis in intrinsic sizing. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Mon, 17 Sep 2018 20:14:24 +0200
changeset 436838 0273829e46ea49c8f4c2213c2c7282be99b170c5
parent 436837 b2ac47c5ebf333b38629a2ef590628b3a69c4a24
child 436839 1f67a586878d3580e759db3e704f839db4957d4a
push id34660
push userbtara@mozilla.com
push dateMon, 17 Sep 2018 21:58:52 +0000
treeherdermozilla-central@87a95e1b7ec6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1491731
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1491731 - [css-text-3] Resolve 'text-indent' using a zero percentage basis in intrinsic sizing. r=dholbert Per CSSWG resolution: https://github.com/w3c/csswg-drafts/issues/1597#issuecomment-406001183
layout/generic/nsBlockFrame.cpp
layout/reftests/w3c-css/submitted/values3/calc-text-indent-intrinsic-1-ref.html
testing/web-platform/meta/css/vendor-imports/mozilla/mozilla-central-reftests/values3/calc-text-indent-intrinsic-1.html.ini
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -281,16 +281,22 @@ RecordReflowStatus(bool aChildIsBlock, c
   // Log updates to the status that yield different values
   if (record[index] != newS) {
     record[index] = newS;
     printf("record(%d): %02x %02x\n", index, record[0], record[1]);
   }
 }
 #endif
 
+static nscoord
+ResolveTextIndent(const nsStyleCoord& aStyle, nscoord aPercentageBasis)
+{
+  return nsLayoutUtils::ResolveToLength<false>(aStyle, aPercentageBasis);
+}
+
 NS_DECLARE_FRAME_PROPERTY_WITH_DTOR_NEVER_CALLED(OverflowLinesProperty,
                                                  nsBlockFrame::FrameLines)
 NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OverflowOutOfFlowsProperty)
 NS_DECLARE_FRAME_PROPERTY_FRAMELIST(PushedFloatProperty)
 NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OutsideBulletProperty)
 NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(InsideBulletProperty, nsBulletFrame)
 NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BlockEndEdgeOfChildrenProperty, nscoord)
 
@@ -802,25 +808,18 @@ nsBlockFrame::GetMinISize(gfxContext *aR
       if (line->IsBlock()) {
         data.ForceBreak();
         data.mCurrentLine = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
                         line->mFirstChild, nsLayoutUtils::MIN_ISIZE);
         data.ForceBreak();
       } else {
         if (!curFrame->GetPrevContinuation() &&
             line == curFrame->LinesBegin()) {
-          // Only add text-indent if it has no percentages; using a
-          // percentage basis of 0 unconditionally would give strange
-          // behavior for calc(10%-3px).
-          const nsStyleCoord &indent = StyleText()->mTextIndent;
-          if (indent.ConvertsToLength())
-            data.mCurrentLine += indent.ComputeCoordPercentCalc(0);
+          data.mCurrentLine += ::ResolveTextIndent(StyleText()->mTextIndent, 0);
         }
-        // XXX Bug NNNNNN Should probably handle percentage text-indent.
-
         data.mLine = &line;
         data.SetLineContainer(curFrame);
         nsIFrame *kid = line->mFirstChild;
         for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
              ++i, kid = kid->GetNextSibling()) {
           kid->AddInlineMinISize(aRenderingContext, &data);
         }
       }
@@ -901,30 +900,23 @@ nsBlockFrame::GetPrefISize(gfxContext *a
         }
         data.ForceBreak(breakType);
         data.mCurrentLine = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
                         line->mFirstChild, nsLayoutUtils::PREF_ISIZE);
         data.ForceBreak();
       } else {
         if (!curFrame->GetPrevContinuation() &&
             line == curFrame->LinesBegin()) {
-          // Only add text-indent if it has no percentages; using a
-          // percentage basis of 0 unconditionally would give strange
-          // behavior for calc(10%-3px).
-          const nsStyleCoord &indent = StyleText()->mTextIndent;
-          if (indent.ConvertsToLength()) {
-            nscoord length = indent.ToLength();
-            if (length != 0) {
-              data.mCurrentLine += length;
-              data.mLineIsEmpty = false;
-            }
+          nscoord indent = ::ResolveTextIndent(StyleText()->mTextIndent, 0);
+          data.mCurrentLine += indent;
+          // XXXmats should the test below be indent > 0?
+          if (indent != nscoord(0)) {
+            data.mLineIsEmpty = false;
           }
         }
-        // XXX Bug NNNNNN Should probably handle percentage text-indent.
-
         data.mLine = &line;
         data.SetLineContainer(curFrame);
         nsIFrame *kid = line->mFirstChild;
         for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
              ++i, kid = kid->GetNextSibling()) {
           kid->AddInlinePrefISize(aRenderingContext, &data);
         }
       }
@@ -979,26 +971,18 @@ nsBlockFrame::GetPrefWidthTightBounds(gf
         rv = line->mFirstChild->GetPrefWidthTightBounds(aRenderingContext,
                                                         &childX, &childXMost);
         NS_ENSURE_SUCCESS(rv, rv);
         *aX = std::min(*aX, childX);
         *aXMost = std::max(*aXMost, childXMost);
       } else {
         if (!curFrame->GetPrevContinuation() &&
             line == curFrame->LinesBegin()) {
-          // Only add text-indent if it has no percentages; using a
-          // percentage basis of 0 unconditionally would give strange
-          // behavior for calc(10%-3px).
-          const nsStyleCoord &indent = StyleText()->mTextIndent;
-          if (indent.ConvertsToLength()) {
-            data.mCurrentLine += indent.ComputeCoordPercentCalc(0);
-          }
+          data.mCurrentLine += ::ResolveTextIndent(StyleText()->mTextIndent, 0);
         }
-        // XXX Bug NNNNNN Should probably handle percentage text-indent.
-
         data.mLine = &line;
         data.SetLineContainer(curFrame);
         nsIFrame *kid = line->mFirstChild;
         for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
              ++i, kid = kid->GetNextSibling()) {
           rv = kid->GetPrefWidthTightBounds(aRenderingContext, &childX,
                                             &childXMost);
           NS_ENSURE_SUCCESS(rv, rv);
--- a/layout/reftests/w3c-css/submitted/values3/calc-text-indent-intrinsic-1-ref.html
+++ b/layout/reftests/w3c-css/submitted/values3/calc-text-indent-intrinsic-1-ref.html
@@ -7,16 +7,16 @@
 <style type="text/css">
 
 body > div { margin: 0 0 1px 0; background: blue; color: white; height: 5px }
 
 </style>
 </head>
 <body>
 
-<div style="width: 10px"></div>
+<div style="width: 7px"></div>
 <div style="width: 57px"></div>
-<div style="width: 10px"></div>
+<div style="width: 60px"></div>
 <div style="width: 10px"></div>
 <div style="width: 60px"></div>
 <div style="width: 10px"></div>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/css/vendor-imports/mozilla/mozilla-central-reftests/values3/calc-text-indent-intrinsic-1.html.ini
@@ -0,0 +1,2 @@
+[calc-text-indent-intrinsic-1.html]
+  expected: FAIL