Bug 1343819 - (Part 2) Add line-height-step prop in style system. r?xidorn draft
authorKuoE0 <kuoe0.tw@gmail.com>
Wed, 15 Feb 2017 17:34:25 +0800
changeset 553963 d17554c59df51f9df24280fd57dad4bf29c49d15
parent 553962 04580a4d7ef14bbda47c93f6bf128bdb53e6482d
child 553964 a380df5199df3e0f0973ee8aee5284708b53745e
push id51848
push userbmo:kuoe0@mozilla.com
push dateFri, 31 Mar 2017 05:09:20 +0000
reviewersxidorn
bugs1343819
milestone55.0a1
Bug 1343819 - (Part 2) Add line-height-step prop in style system. r?xidorn MozReview-Commit-ID: LpZzMcPAyNW
devtools/shared/css/generated/properties-db.js
dom/ipc/ContentPrefs.cpp
layout/style/nsCSSPropList.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/devtools/shared/css/generated/properties-db.js
+++ b/devtools/shared/css/generated/properties-db.js
@@ -2930,16 +2930,17 @@ exports.CSS_PROPERTIES = {
       "isolation",
       "justify-content",
       "justify-items",
       "justify-self",
       "left",
       "letter-spacing",
       "lighting-color",
       "line-height",
+      "line-height-step",
       "list-style-image",
       "list-style-position",
       "list-style-type",
       "margin-block-end",
       "margin-block-start",
       "margin-bottom",
       "margin-inline-end",
       "margin-inline-start",
@@ -6821,16 +6822,32 @@ exports.CSS_PROPERTIES = {
       "-moz-block-height",
       "calc",
       "inherit",
       "initial",
       "normal",
       "unset"
     ]
   },
+  "line-height-step": {
+    "isInherited": true,
+    "subproperties": [
+      "line-height-step"
+    ],
+    "supports": [
+      6
+    ],
+    "values": [
+      "calc",
+      "inherit",
+      "initial",
+      "none",
+      "unset"
+    ]
+  },
   "list-style": {
     "isInherited": true,
     "subproperties": [
       "list-style-type",
       "list-style-image",
       "list-style-position"
     ],
     "supports": [
--- a/dom/ipc/ContentPrefs.cpp
+++ b/dom/ipc/ContentPrefs.cpp
@@ -238,9 +238,8 @@ const char** mozilla::dom::ContentPrefs:
   return gInitPrefs;
 }
 
 const char*  mozilla::dom::ContentPrefs::GetContentPref(size_t aIndex)
 {
   MOZ_ASSERT(aIndex < ArrayLength(ContentPrefs::gInitPrefs));
   return gInitPrefs[aIndex];
 }
-
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -2463,16 +2463,30 @@ CSS_PROP_TEXT(
         CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE |
         CSS_PROPERTY_APPLIES_TO_PLACEHOLDER |
         CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH,
     "",
     VARIANT_HLPN | VARIANT_KEYWORD | VARIANT_NORMAL | VARIANT_SYSFONT | VARIANT_CALC,
     kLineHeightKTable,
     offsetof(nsStyleText, mLineHeight),
     eStyleAnimType_Coord)
+CSS_PROP_TEXT(
+    line-height-step,
+    line_height_step,
+    LineHeightStep,
+    CSS_PROPERTY_PARSE_VALUE |
+        CSS_PROPERTY_VALUE_NONNEGATIVE |
+        CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE |
+        CSS_PROPERTY_APPLIES_TO_PLACEHOLDER |
+        CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH,
+    "layout.css.line-height-step.enabled",
+    VARIANT_NONE | VARIANT_HL | VARIANT_CALC,
+    nullptr,
+    CSS_PROP_NO_OFFSET,
+    eStyleAnimType_None)
 CSS_PROP_SHORTHAND(
     list-style,
     list_style,
     ListStyle,
     CSS_PROPERTY_PARSE_FUNCTION,
     "")
 CSS_PROP_LIST(
     list-style-image,
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -4784,16 +4784,38 @@ nsRuleNode::ComputeTextData(void* aStart
         } else {
           lh = minimumFontSize;
         }
       }
       text->mLineHeight.SetCoordValue(lh);
     }
   }
 
+  // line-height-step: none, length, calc
+  const nsCSSValue* lineHeightStepValue = aRuleData->ValueForLineHeightStep();
+  if (eCSSUnit_Null == lineHeightStepValue->GetUnit()) {
+    // do nothing
+  } else if (eCSSUnit_None == lineHeightStepValue->GetUnit() ||
+             eCSSUnit_Initial == lineHeightStepValue->GetUnit()) {
+    text->mLineHeightStep.SetCoordValue(0);
+  } else if (eCSSUnit_Inherit == lineHeightStepValue->GetUnit() ||
+             eCSSUnit_Unset == lineHeightStepValue->GetUnit()) {
+    text->mLineHeightStep = parentText->mLineHeightStep;
+  } else if (eCSSUnit_Calc == lineHeightStepValue->GetUnit()) {
+    SetLineHeightCalcOps ops(aContext, mPresContext, conditions);
+    LengthNumberCalcObj obj = css::ComputeCalc(*lineHeightStepValue, ops);
+    text->mLineHeightStep.SetCoordValue(NSToCoordRoundWithClamp(obj.mValue));
+  } else if (lineHeightStepValue->IsLengthUnit()) {
+    nscoord len = CalcLength(*lineHeightStepValue, aContext, mPresContext,
+                             conditions);
+    conditions.SetUncacheable();
+    text->mLineHeightStep.SetCoordValue(len);
+  } else {
+    MOZ_ASSERT_UNREACHABLE("unexpected unit");
+  }
 
   // text-align: enum, string, pair(enum|string), inherit, initial
   // NOTE: string is not implemented yet.
   const nsCSSValue* textAlignValue = aRuleData->ValueForTextAlign();
   text->mTextAlignTrue = false;
   if (eCSSUnit_String == textAlignValue->GetUnit()) {
     NS_NOTYETIMPLEMENTED("align string");
   } else if (eCSSUnit_Enumerated == textAlignValue->GetUnit() &&
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3920,16 +3920,17 @@ nsStyleText::nsStyleText(const nsPresCon
   , mTextRendering(NS_STYLE_TEXT_RENDERING_AUTO)
   , mTextEmphasisColor(StyleComplexColor::CurrentColor())
   , mWebkitTextFillColor(StyleComplexColor::CurrentColor())
   , mWebkitTextStrokeColor(StyleComplexColor::CurrentColor())
   , mTabSize(float(NS_STYLE_TABSIZE_INITIAL), eStyleUnit_Factor)
   , mWordSpacing(0, nsStyleCoord::CoordConstructor)
   , mLetterSpacing(eStyleUnit_Normal)
   , mLineHeight(eStyleUnit_Normal)
+  , mLineHeightStep(0, nsStyleCoord::CoordConstructor)
   , mTextIndent(0, nsStyleCoord::CoordConstructor)
   , mWebkitTextStrokeWidth(0)
   , mTextShadow(nullptr)
 {
   MOZ_COUNT_CTOR(nsStyleText);
   nsCOMPtr<nsIAtom> language = aContext->GetContentLanguage();
   mTextEmphasisPosition = language &&
     nsStyleUtil::MatchesLanguagePrefix(language, u"zh") ?
@@ -3958,16 +3959,17 @@ nsStyleText::nsStyleText(const nsStyleTe
   , mTextRendering(aSource.mTextRendering)
   , mTextEmphasisColor(aSource.mTextEmphasisColor)
   , mWebkitTextFillColor(aSource.mWebkitTextFillColor)
   , mWebkitTextStrokeColor(aSource.mWebkitTextStrokeColor)
   , mTabSize(aSource.mTabSize)
   , mWordSpacing(aSource.mWordSpacing)
   , mLetterSpacing(aSource.mLetterSpacing)
   , mLineHeight(aSource.mLineHeight)
+  , mLineHeightStep(aSource.mLineHeightStep)
   , mTextIndent(aSource.mTextIndent)
   , mWebkitTextStrokeWidth(aSource.mWebkitTextStrokeWidth)
   , mTextShadow(aSource.mTextShadow)
   , mTextEmphasisStyleString(aSource.mTextEmphasisStyleString)
 {
   MOZ_COUNT_CTOR(nsStyleText);
 }
 
@@ -3999,16 +4001,17 @@ nsStyleText::CalcDifference(const nsStyl
       (mWordBreak != aNewData.mWordBreak) ||
       (mOverflowWrap != aNewData.mOverflowWrap) ||
       (mHyphens != aNewData.mHyphens) ||
       (mRubyAlign != aNewData.mRubyAlign) ||
       (mRubyPosition != aNewData.mRubyPosition) ||
       (mTextSizeAdjust != aNewData.mTextSizeAdjust) ||
       (mLetterSpacing != aNewData.mLetterSpacing) ||
       (mLineHeight != aNewData.mLineHeight) ||
+      (mLineHeightStep != aNewData.mLineHeightStep) ||
       (mTextIndent != aNewData.mTextIndent) ||
       (mTextJustify != aNewData.mTextJustify) ||
       (mWordSpacing != aNewData.mWordSpacing) ||
       (mTabSize != aNewData.mTabSize)) {
     return NS_STYLE_HINT_REFLOW;
   }
 
   if (HasTextEmphasis() != aNewData.HasTextEmphasis() ||
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1936,16 +1936,17 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   mozilla::StyleComplexColor mTextEmphasisColor;      // [inherited]
   mozilla::StyleComplexColor mWebkitTextFillColor;    // [inherited]
   mozilla::StyleComplexColor mWebkitTextStrokeColor;  // [inherited]
 
   nsStyleCoord mTabSize;                // [inherited] coord, factor, calc
   nsStyleCoord mWordSpacing;            // [inherited] coord, percent, calc
   nsStyleCoord mLetterSpacing;          // [inherited] coord, normal
   nsStyleCoord mLineHeight;             // [inherited] coord, factor, normal
+  nsStyleCoord mLineHeightStep;         // [inherited] none, coord, calc
   nsStyleCoord mTextIndent;             // [inherited] coord, percent, calc
   nscoord mWebkitTextStrokeWidth;       // [inherited] coord
 
   RefPtr<nsCSSShadowArray> mTextShadow; // [inherited] nullptr in case of a zero-length
 
   nsString mTextEmphasisStyleString;    // [inherited]
 
   bool WhiteSpaceIsSignificant() const {