Bug 1261754 - Part 5: Move text-rendering from nsStyleSVG to nsStyleText. r=dholbert draft
authorCameron McCormack <cam@mcc.id.au>
Tue, 12 Apr 2016 11:35:26 +1000
changeset 349674 f692f29d3362fd2f0df760bbc86e8fd90fa3e98d
parent 349673 9fd976f0cc659230ba8bd7f669d20a7dc07bb727
child 349675 ca1013da198f56a46c6d3beccdcc7a4f3a08f404
push id15154
push usercmccormack@mozilla.com
push dateTue, 12 Apr 2016 01:46:39 +0000
reviewersdholbert
bugs1261754
milestone48.0a1
Bug 1261754 - Part 5: Move text-rendering from nsStyleSVG to nsStyleText. r=dholbert MozReview-Commit-ID: 7DbhcNtfxu
layout/base/nsLayoutUtils.cpp
layout/style/nsCSSPropList.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/svg/SVGTextFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -6974,17 +6974,17 @@ nsLayoutUtils::GetTextRunFlagsForStyle(n
 {
   uint32_t result = 0;
   if (aLetterSpacing != 0) {
     result |= gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES;
   }
   if (aStyleText->mControlCharacterVisibility == NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN) {
     result |= gfxTextRunFactory::TEXT_HIDE_CONTROL_CHARACTERS;
   }
-  switch (aStyleContext->StyleSVG()->mTextRendering) {
+  switch (aStyleContext->StyleText()->mTextRendering) {
   case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
     result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
     break;
   case NS_STYLE_TEXT_RENDERING_AUTO:
     if (aStyleFont->mFont.size <
         aStyleContext->PresContext()->GetAutoQualityMinFontSize()) {
       result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
     }
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -4340,25 +4340,25 @@ CSS_PROP_SVG(
     text_anchor,
     TextAnchor,
     CSS_PROPERTY_PARSE_VALUE,
     "",
     VARIANT_HK,
     kTextAnchorKTable,
     offsetof(nsStyleSVG, mTextAnchor),
     eStyleAnimType_EnumU8)
-CSS_PROP_SVG(
+CSS_PROP_TEXT(
     text-rendering,
     text_rendering,
     TextRendering,
     CSS_PROPERTY_PARSE_VALUE,
     "",
     VARIANT_HK,
     kTextRenderingKTable,
-    offsetof(nsStyleSVG, mTextRendering),
+    offsetof(nsStyleText, mTextRendering),
     eStyleAnimType_EnumU8)
 CSS_PROP_SVGRESET(
     vector-effect,
     vector_effect,
     VectorEffect,
     CSS_PROPERTY_PARSE_VALUE,
     "",
     VARIANT_HK,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -5746,17 +5746,17 @@ nsComputedDOMStyle::DoGetShapeRendering(
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetTextRendering()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   val->SetIdent(
-    nsCSSProps::ValueToKeywordEnum(StyleSVG()->mTextRendering,
+    nsCSSProps::ValueToKeywordEnum(StyleText()->mTextRendering,
                                    nsCSSProps::kTextRenderingKTable));
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetFloodColor()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -4672,16 +4672,23 @@ nsRuleNode::ComputeTextData(void* aStart
       TruncateStringToSingleGrapheme(strValue);
       text->mTextEmphasisStyleString = strValue;
       break;
     }
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown value unit type");
   }
 
+  // text-rendering: enum, inherit, initial
+  SetDiscrete(*aRuleData->ValueForTextRendering(),
+              text->mTextRendering, conditions,
+              SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
+              parentText->mTextRendering,
+              NS_STYLE_TEXT_RENDERING_AUTO, 0, 0, 0, 0);
+
   // -webkit-text-fill-color: color, string, inherit, initial
   const nsCSSValue*
     webkitTextFillColorValue = aRuleData->ValueForWebkitTextFillColor();
   if (webkitTextFillColorValue->GetUnit() == eCSSUnit_Null) {
     // We don't want to change anything in this case.
   } else if (webkitTextFillColorValue->GetUnit() == eCSSUnit_Inherit ||
              webkitTextFillColorValue->GetUnit() == eCSSUnit_Unset) {
     conditions.SetUncacheable();
@@ -9444,23 +9451,16 @@ nsRuleNode::ComputeSVGData(void* aStartS
 
   // text-anchor: enum, inherit, initial
   SetDiscrete(*aRuleData->ValueForTextAnchor(),
               svg->mTextAnchor, conditions,
               SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
               parentSVG->mTextAnchor,
               NS_STYLE_TEXT_ANCHOR_START, 0, 0, 0, 0);
 
-  // text-rendering: enum, inherit, initial
-  SetDiscrete(*aRuleData->ValueForTextRendering(),
-              svg->mTextRendering, conditions,
-              SETDSC_ENUMERATED | SETDSC_UNSET_INHERIT,
-              parentSVG->mTextRendering,
-              NS_STYLE_TEXT_RENDERING_AUTO, 0, 0, 0, 0);
-
   COMPUTE_END_INHERITED(SVG, svg)
 }
 
 void
 nsRuleNode::SetStyleClipPathToCSSValue(nsStyleClipPath* aStyleClipPath,
                                        const nsCSSValue* aValue,
                                        nsStyleContext* aStyleContext,
                                        nsPresContext* aPresContext,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -929,17 +929,16 @@ nsStyleSVG::nsStyleSVG(StyleStructContex
   mColorInterpolation      = NS_STYLE_COLOR_INTERPOLATION_SRGB;
   mColorInterpolationFilters = NS_STYLE_COLOR_INTERPOLATION_LINEARRGB;
   mFillRule                = NS_STYLE_FILL_RULE_NONZERO;
   mPaintOrder              = NS_STYLE_PAINT_ORDER_NORMAL;
   mShapeRendering          = NS_STYLE_SHAPE_RENDERING_AUTO;
   mStrokeLinecap           = NS_STYLE_STROKE_LINECAP_BUTT;
   mStrokeLinejoin          = NS_STYLE_STROKE_LINEJOIN_MITER;
   mTextAnchor              = NS_STYLE_TEXT_ANCHOR_START;
-  mTextRendering           = NS_STYLE_TEXT_RENDERING_AUTO;
   mFillOpacitySource       = eStyleSVGOpacitySource_Normal;
   mStrokeOpacitySource     = eStyleSVGOpacitySource_Normal;
   mStrokeDasharrayFromObject = false;
   mStrokeDashoffsetFromObject = false;
   mStrokeWidthFromObject   = false;
 } 
 nsStyleSVG::~nsStyleSVG()
 {
@@ -982,17 +981,16 @@ nsStyleSVG::nsStyleSVG(const nsStyleSVG&
   mColorInterpolation = aSource.mColorInterpolation;
   mColorInterpolationFilters = aSource.mColorInterpolationFilters;
   mFillRule = aSource.mFillRule;
   mPaintOrder = aSource.mPaintOrder;
   mShapeRendering = aSource.mShapeRendering;
   mStrokeLinecap = aSource.mStrokeLinecap;
   mStrokeLinejoin = aSource.mStrokeLinejoin;
   mTextAnchor = aSource.mTextAnchor;
-  mTextRendering = aSource.mTextRendering;
   mFillOpacitySource = aSource.mFillOpacitySource;
   mStrokeOpacitySource = aSource.mStrokeOpacitySource;
   mStrokeDasharrayFromObject = aSource.mStrokeDasharrayFromObject;
   mStrokeDashoffsetFromObject = aSource.mStrokeDashoffsetFromObject;
   mStrokeWidthFromObject = aSource.mStrokeWidthFromObject;
 }
 
 static bool PaintURIChanged(const nsStyleSVGPaint& aPaint1,
@@ -1044,24 +1042,22 @@ nsChangeHint nsStyleSVG::CalcDifference(
       NS_UpdateHint(hint, nsChangeHint_UpdateEffects);
     }
   }
 
   // Stroke currently contributes to nsSVGPathGeometryFrame::mRect, so
   // we need a reflow here. No intrinsic sizes need to change, so
   // nsChangeHint_NeedReflow is sufficient.
   // Note that stroke-dashoffset does not affect nsSVGPathGeometryFrame::mRect.
-  // text-anchor and text-rendering changes also require a reflow since they
-  // change frames' rects.
+  // text-anchor changes also require a reflow since it changes frames' rects.
   if (mStrokeWidth           != aOther.mStrokeWidth           ||
       mStrokeMiterlimit      != aOther.mStrokeMiterlimit      ||
       mStrokeLinecap         != aOther.mStrokeLinecap         ||
       mStrokeLinejoin        != aOther.mStrokeLinejoin        ||
-      mTextAnchor            != aOther.mTextAnchor            ||
-      mTextRendering         != aOther.mTextRendering) {
+      mTextAnchor            != aOther.mTextAnchor) {
     NS_UpdateHint(hint, nsChangeHint_NeedReflow);
     NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
     NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
     return hint;
   }
 
   if (hint & nsChangeHint_RepaintFrame) {
     return hint; // we don't add anything else below
@@ -3659,16 +3655,17 @@ nsStyleText::nsStyleText(StyleStructCont
   mWordBreak = NS_STYLE_WORDBREAK_NORMAL;
   mWordWrap = NS_STYLE_WORDWRAP_NORMAL;
   mHyphens = NS_STYLE_HYPHENS_MANUAL;
   mRubyAlign = NS_STYLE_RUBY_ALIGN_SPACE_AROUND;
   mRubyPosition = NS_STYLE_RUBY_POSITION_OVER;
   mTextSizeAdjust = NS_STYLE_TEXT_SIZE_ADJUST_AUTO;
   mTextCombineUpright = NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE;
   mTextEmphasisStyle = NS_STYLE_TEXT_EMPHASIS_STYLE_NONE;
+  mTextRendering = NS_STYLE_TEXT_RENDERING_AUTO;
   nsCOMPtr<nsIAtom> language = aContext.GetContentLanguage();
   mTextEmphasisPosition = language &&
     nsStyleUtil::MatchesLanguagePrefix(language, MOZ_UTF16("zh")) ?
     NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH :
     NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT;
   mTextEmphasisColor = aContext.DefaultColor();
   mWebkitTextFillColor = aContext.DefaultColor();
   mControlCharacterVisibility = nsCSSParser::ControlCharVisibilityDefault();
@@ -3696,16 +3693,17 @@ nsStyleText::nsStyleText(const nsStyleTe
     mHyphens(aSource.mHyphens),
     mRubyAlign(aSource.mRubyAlign),
     mRubyPosition(aSource.mRubyPosition),
     mTextSizeAdjust(aSource.mTextSizeAdjust),
     mTextCombineUpright(aSource.mTextCombineUpright),
     mControlCharacterVisibility(aSource.mControlCharacterVisibility),
     mTextEmphasisPosition(aSource.mTextEmphasisPosition),
     mTextEmphasisStyle(aSource.mTextEmphasisStyle),
+    mTextRendering(aSource.mTextRendering),
     mTabSize(aSource.mTabSize),
     mTextEmphasisColor(aSource.mTextEmphasisColor),
     mWebkitTextFillColor(aSource.mWebkitTextFillColor),
     mWordSpacing(aSource.mWordSpacing),
     mLetterSpacing(aSource.mLetterSpacing),
     mLineHeight(aSource.mLineHeight),
     mTextIndent(aSource.mTextIndent),
     mTextShadow(aSource.mTextShadow),
@@ -3754,35 +3752,52 @@ nsChangeHint nsStyleText::CalcDifference
   if (HasTextEmphasis() != aOther.HasTextEmphasis() ||
       (HasTextEmphasis() &&
        mTextEmphasisPosition != aOther.mTextEmphasisPosition)) {
     // Text emphasis position change could affect line height calculation.
     return nsChangeHint_AllReflowHints |
            nsChangeHint_RepaintFrame;
   }
 
+  nsChangeHint hint = nsChangeHint(0);
+
+  // text-rendering changes require a reflow since they change SVG
+  // frames' rects.
+  if (mTextRendering != aOther.mTextRendering) {
+    hint |= nsChangeHint_NeedReflow |
+            nsChangeHint_NeedDirtyReflow | // XXX remove me: bug 876085
+            nsChangeHint_RepaintFrame;
+  }
+
   if (!AreShadowArraysEqual(mTextShadow, aOther.mTextShadow) ||
       mTextEmphasisStyle != aOther.mTextEmphasisStyle ||
       mTextEmphasisStyleString != aOther.mTextEmphasisStyleString) {
-    return nsChangeHint_UpdateSubtreeOverflow |
-           nsChangeHint_SchedulePaint |
-           nsChangeHint_RepaintFrame;
+    hint |= nsChangeHint_UpdateSubtreeOverflow |
+            nsChangeHint_SchedulePaint |
+            nsChangeHint_RepaintFrame;
+
+    // We don't add any other hints below.
+    return hint;
   }
 
   MOZ_ASSERT(!mTextEmphasisColorForeground ||
              !aOther.mTextEmphasisColorForeground ||
              mTextEmphasisColor == aOther.mTextEmphasisColor,
              "If the text-emphasis-color are both foreground color, "
              "mTextEmphasisColor should also be identical");
   if (mTextEmphasisColorForeground != aOther.mTextEmphasisColorForeground ||
       mTextEmphasisColor != aOther.mTextEmphasisColor ||
       mWebkitTextFillColorForeground != aOther.mWebkitTextFillColorForeground ||
       mWebkitTextFillColor != aOther.mWebkitTextFillColor) {
-    return nsChangeHint_SchedulePaint |
-           nsChangeHint_RepaintFrame;
+    NS_UpdateHint(hint, nsChangeHint_SchedulePaint);
+    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
+  }
+
+  if (hint) {
+    return hint;
   }
 
   if (mTextEmphasisPosition != aOther.mTextEmphasisPosition) {
     return nsChangeHint_NeutralChange;
   }
 
   return NS_STYLE_HINT_NONE;
 }
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1976,16 +1976,17 @@ struct nsStyleText
   uint8_t mHyphens;                     // [inherited] see nsStyleConsts.h
   uint8_t mRubyAlign;                   // [inherited] see nsStyleConsts.h
   uint8_t mRubyPosition;                // [inherited] see nsStyleConsts.h
   uint8_t mTextSizeAdjust;              // [inherited] see nsStyleConsts.h
   uint8_t mTextCombineUpright;          // [inherited] see nsStyleConsts.h
   uint8_t mControlCharacterVisibility;  // [inherited] see nsStyleConsts.h
   uint8_t mTextEmphasisPosition;        // [inherited] see nsStyleConsts.h
   uint8_t mTextEmphasisStyle;           // [inherited] see nsStyleConsts.h
+  uint8_t mTextRendering;               // [inherited] see nsStyleConsts.h
   int32_t mTabSize;                     // [inherited] see nsStyleConsts.h
   nscolor mTextEmphasisColor;           // [inherited]
   nscolor mWebkitTextFillColor;         // [inherited]
 
   nsStyleCoord mWordSpacing;            // [inherited] coord, percent, calc
   nsStyleCoord mLetterSpacing;          // [inherited] coord, normal
   nsStyleCoord mLineHeight;             // [inherited] coord, factor, normal
   nsStyleCoord mTextIndent;             // [inherited] coord, percent, calc
@@ -3241,17 +3242,16 @@ struct nsStyleSVG
   uint8_t          mColorInterpolation; // [inherited] see nsStyleConsts.h
   uint8_t          mColorInterpolationFilters; // [inherited] see nsStyleConsts.h
   uint8_t          mFillRule;         // [inherited] see nsStyleConsts.h
   uint8_t          mPaintOrder;       // [inherited] see nsStyleConsts.h
   uint8_t          mShapeRendering;   // [inherited] see nsStyleConsts.h
   uint8_t          mStrokeLinecap;    // [inherited] see nsStyleConsts.h
   uint8_t          mStrokeLinejoin;   // [inherited] see nsStyleConsts.h
   uint8_t          mTextAnchor;       // [inherited] see nsStyleConsts.h
-  uint8_t          mTextRendering;    // [inherited] see nsStyleConsts.h
 
   // In SVG glyphs, whether we inherit fill or stroke opacity from the outer
   // text object.
   // Use 3 bits to avoid signedness problems in MSVC.
   nsStyleSVGOpacitySource mFillOpacitySource    : 3;
   nsStyleSVGOpacitySource mStrokeOpacitySource  : 3;
 
   // SVG glyph outer object inheritance for other properties
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -2855,17 +2855,17 @@ SVGTextDrawPathCallbacks::NotifyAfterTex
   gfx->Restore();
 }
 
 void
 SVGTextDrawPathCallbacks::PaintDecorationLine(Rect aPath, nscolor aColor)
 {
   mColor = aColor;
   AntialiasMode aaMode =
-    nsSVGUtils::ToAntialiasMode(mFrame->StyleSVG()->mTextRendering);
+    nsSVGUtils::ToAntialiasMode(mFrame->StyleText()->mTextRendering);
 
   gfx->Save();
   gfx->NewPath();
   gfx->SetAntialiasMode(aaMode);
   gfx->Rectangle(ThebesRect(aPath));
   HandleTextGeometry();
   gfx->NewPath();
   gfx->Restore();
@@ -2892,17 +2892,17 @@ SVGTextDrawPathCallbacks::PaintSelection
 void
 SVGTextDrawPathCallbacks::SetupContext()
 {
   gfx->Save();
 
   // XXX This is copied from nsSVGGlyphFrame::Render, but cairo doesn't actually
   // seem to do anything with the antialias mode.  So we can perhaps remove it,
   // or make SetAntialiasMode set cairo text antialiasing too.
-  switch (mFrame->StyleSVG()->mTextRendering) {
+  switch (mFrame->StyleText()->mTextRendering) {
   case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
     gfx->SetAntialiasMode(AntialiasMode::NONE);
     break;
   default:
     gfx->SetAntialiasMode(AntialiasMode::SUBPIXEL);
     break;
   }
 }
@@ -3018,17 +3018,17 @@ SVGTextDrawPathCallbacks::StrokeGeometry
 
         RefPtr<Path> path = gfx->GetPath();
         SVGContentUtils::AutoStrokeOptions strokeOptions;
         SVGContentUtils::GetStrokeOptions(&strokeOptions, svgOwner,
                                           mFrame->StyleContext(),
                                           /*aContextPaint*/ nullptr);
         DrawOptions drawOptions;
         drawOptions.mAntialiasMode =
-          nsSVGUtils::ToAntialiasMode(mFrame->StyleSVG()->mTextRendering);
+          nsSVGUtils::ToAntialiasMode(mFrame->StyleText()->mTextRendering);
         gfx->GetDrawTarget()->Stroke(path, strokePattern, strokeOptions);
       }
     }
   }
 }
 
 //----------------------------------------------------------------------
 // SVGTextContextPaint methods:
@@ -5421,17 +5421,17 @@ SVGTextFrame::UpdateFontSizeScaleFactor(
   // Find the minimum and maximum font sizes used over all the
   // nsTextFrames.
   TextFrameIterator it(this);
   nsTextFrame* f = it.Current();
   while (f) {
     if (!geometricPrecision) {
       // Unfortunately we can't treat text-rendering:geometricPrecision
       // separately for each text frame.
-      geometricPrecision = f->StyleSVG()->mTextRendering ==
+      geometricPrecision = f->StyleText()->mTextRendering ==
                              NS_STYLE_TEXT_RENDERING_GEOMETRICPRECISION;
     }
     nscoord size = f->StyleFont()->mFont.size;
     if (size) {
       min = std::min(min, size);
       max = std::max(max, size);
     }
     f = it.Next();