Bug 1414147 - Move fontSmoothingBackgroundColor from nsStyleUserInterface to nsStyleFont / nsFont. r?dbaron draft
authorMarkus Stange <mstange@themasta.com>
Thu, 02 Nov 2017 17:48:44 -0400
changeset 693233 83c92fb35a9fa0dcd42c4592293aee36d3383728
parent 693219 ab10dee6754602dc43038618032c2a6b06396661
child 693234 238fe13c37df6b9052bba601e3db1d7605ee98f3
push id87731
push userbmo:mstange@themasta.com
push dateSat, 04 Nov 2017 16:30:03 +0000
reviewersdbaron
bugs1414147
milestone58.0a1
Bug 1414147 - Move fontSmoothingBackgroundColor from nsStyleUserInterface to nsStyleFont / nsFont. r?dbaron MozReview-Commit-ID: 7i0Sy50Badm
gfx/src/nsFont.cpp
gfx/src/nsFont.h
layout/generic/nsTextFrame.cpp
layout/style/nsCSSPropList.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/xul/nsTextBoxFrame.cpp
layout/xul/tree/nsTreeBodyFrame.cpp
--- a/gfx/src/nsFont.cpp
+++ b/gfx/src/nsFont.cpp
@@ -58,17 +58,18 @@ bool nsFont::Equals(const nsFont& aOther
       (variantCaps == aOther.variantCaps) &&
       (variantEastAsian == aOther.variantEastAsian) &&
       (variantLigatures == aOther.variantLigatures) &&
       (variantNumeric == aOther.variantNumeric) &&
       (variantPosition == aOther.variantPosition) &&
       (variantWidth == aOther.variantWidth) &&
       (alternateValues == aOther.alternateValues) &&
       (featureValueLookup == aOther.featureValueLookup) &&
-      (smoothing == aOther.smoothing)) {
+      (smoothing == aOther.smoothing) &&
+      (fontSmoothingBackgroundColor == aOther.fontSmoothingBackgroundColor)) {
     return true;
   }
   return false;
 }
 
 nsFont& nsFont::operator=(const nsFont& aOther) = default;
 
 void
--- a/gfx/src/nsFont.h
+++ b/gfx/src/nsFont.h
@@ -9,16 +9,17 @@
 
 #include <stdint.h>                     // for uint8_t, uint16_t
 #include <sys/types.h>                  // for int16_t
 #include "gfxFontFamilyList.h"
 #include "gfxFontConstants.h"           // for NS_FONT_KERNING_AUTO, etc
 #include "gfxFontFeatures.h"
 #include "gfxFontVariations.h"
 #include "mozilla/RefPtr.h"             // for RefPtr
+#include "nsColor.h"                    // for nsColor and NS_RGBA
 #include "nsCoord.h"                    // for nscoord
 #include "nsStringFwd.h"                // for nsAString
 #include "nsString.h"               // for nsString
 #include "nsTArray.h"                   // for nsTArray
 
 struct gfxFontStyle;
 
 // XXX we need a method to enumerate all of the possible fonts on the
@@ -68,16 +69,20 @@ struct nsFont {
   // These are resolved *after* font matching occurs.
 
   // -- bitmask for both enumerated and functional propvals
   uint16_t variantAlternates = NS_FONT_VARIANT_ALTERNATES_NORMAL;
 
   // Smoothing - controls subpixel-antialiasing (currently OSX only)
   uint8_t smoothing = NS_FONT_SMOOTHING_AUTO;
 
+  // The estimated background color behind the text. Enables a special
+  // rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome.
+  nscolor fontSmoothingBackgroundColor = NS_RGBA(0,0,0,0);
+
   // The weight of the font; see gfxFontConstants.h.
   uint16_t weight = NS_FONT_WEIGHT_NORMAL;
 
   // The stretch of the font (the sum of various NS_FONT_STRETCH_*
   // constants; see gfxFontConstants.h).
   int16_t stretch = NS_FONT_STRETCH_NORMAL;
 
   // Kerning
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -7088,17 +7088,17 @@ nsTextFrame::PaintText(const PaintTextPa
   params.textColor = foregroundColor;
   params.textStrokeColor = textStrokeColor;
   params.textStrokeWidth = textPaintStyle.GetWebkitTextStrokeWidth();
   params.clipEdges = &clipEdges;
   params.drawSoftHyphen = (GetStateBits() & TEXT_HYPHEN_BREAK) != 0;
   params.contextPaint = aParams.contextPaint;
   params.callbacks = aParams.callbacks;
   aParams.context->SetFontSmoothingBackgroundColor(
-    Color::FromABGR(StyleUserInterface()->mFontSmoothingBackgroundColor));
+    Color::FromABGR(StyleFont()->mFont.fontSmoothingBackgroundColor));
   DrawText(range, textBaselinePt, params);
   aParams.context->SetFontSmoothingBackgroundColor(Color());
 }
 
 static void
 DrawTextRun(const gfxTextRun* aTextRun,
             const gfx::Point& aTextBaselinePt,
             gfxTextRun::Range aRange,
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -1948,27 +1948,27 @@ CSS_PROP_FONT(
         CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE |
         CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
     "",
     VARIANT_HON | VARIANT_SYSFONT,
     nullptr,
     offsetof(nsStyleFont, mFont.sizeAdjust),
     eStyleAnimType_float)
 #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL
-CSS_PROP_USERINTERFACE(
+CSS_PROP_FONT(
     -moz-font-smoothing-background-color,
     _moz_font_smoothing_background_color,
     CSS_PROP_DOMPROP_PREFIXED(FontSmoothingBackgroundColor),
     CSS_PROPERTY_INTERNAL |
         CSS_PROPERTY_PARSE_VALUE |
         CSS_PROPERTY_ENABLED_IN_UA_SHEETS_AND_CHROME,
     "",
     VARIANT_HC,
     nullptr,
-    offsetof(nsStyleUserInterface, mFontSmoothingBackgroundColor),
+    offsetof(nsStyleFont, mFont.fontSmoothingBackgroundColor),
     eStyleAnimType_Color)
 #endif // CSS_PROP_LIST_EXCLUDE_INTERNAL
 CSS_PROP_FONT(
     font-stretch,
     font_stretch,
     FontStretch,
     CSS_PROPERTY_PARSE_VALUE |
         CSS_PROPERTY_APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE |
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -1896,17 +1896,17 @@ nsComputedDOMStyle::DoGetOsxFontSmoothin
                                                nsCSSProps::kFontSmoothingKTable));
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetFontSmoothingBackgroundColor()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
-  SetToRGBAColor(val, StyleUserInterface()->mFontSmoothingBackgroundColor);
+  SetToRGBAColor(val, StyleFont()->mFont.fontSmoothingBackgroundColor);
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetFontStretch()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -3755,23 +3755,39 @@ nsRuleNode::SetFont(nsPresContext* aPres
            aParentFont->mMathVariant, NS_MATHML_MATHVARIANT_NONE);
 
   // -moz-math-display: enum, inherit, initial
   SetValue(*aRuleData->ValueForMathDisplay(), aFont->mMathDisplay,
            aConditions,
            SETVAL_ENUMERATED | SETVAL_UNSET_INHERIT,
            aParentFont->mMathDisplay, NS_MATHML_DISPLAYSTYLE_INLINE);
 
-  // font-smoothing: enum, inherit, initial
+  // -moz-osx-font-smoothing: enum, inherit, initial
   SetValue(*aRuleData->ValueForOsxFontSmoothing(),
            aFont->mFont.smoothing, aConditions,
            SETVAL_ENUMERATED | SETVAL_UNSET_INHERIT,
            aParentFont->mFont.smoothing,
            defaultVariableFont->smoothing);
 
+  // -moz-font-smoothing-background-color: color, inherit, initial
+  const nsCSSValue* fsbColorValue =
+    aRuleData->ValueForFontSmoothingBackgroundColor();
+  if (eCSSUnit_Initial == fsbColorValue->GetUnit()) {
+    aFont->mFont.fontSmoothingBackgroundColor = NS_RGBA(0, 0, 0, 0);
+  } else if (eCSSUnit_Inherit == fsbColorValue->GetUnit() ||
+             eCSSUnit_Unset == fsbColorValue->GetUnit()) {
+    aConditions.SetUncacheable();
+    aFont->mFont.fontSmoothingBackgroundColor =
+      aParentFont->mFont.fontSmoothingBackgroundColor;
+  } else {
+    SetColor(*fsbColorValue, aParentFont->mFont.fontSmoothingBackgroundColor,
+             aPresContext, aContext, aFont->mFont.fontSmoothingBackgroundColor,
+             aConditions);
+  }
+
   // font-style: enum, inherit, initial, -moz-system-font
   if (aFont->mMathVariant != NS_MATHML_MATHVARIANT_NONE) {
     // -moz-math-variant overrides font-style
     aFont->mFont.style = NS_FONT_STYLE_NORMAL;
   } else {
     SetValue(*aRuleData->ValueForFontStyle(),
              aFont->mFont.style, aConditions,
              SETVAL_ENUMERATED | SETVAL_UNSET_INHERIT,
@@ -5321,28 +5337,16 @@ nsRuleNode::ComputeUserInterfaceData(voi
   // caret-color: auto, color, inherit
   const nsCSSValue* caretColorValue = aRuleData->ValueForCaretColor();
   SetComplexColor<eUnsetInherit>(*caretColorValue,
                                  parentUI->mCaretColor,
                                  StyleComplexColor::Auto(),
                                  mPresContext,
                                  ui->mCaretColor, conditions);
 
-  // -moz-font-smoothing-background-color:
-  const nsCSSValue* fsbColorValue =
-    aRuleData->ValueForFontSmoothingBackgroundColor();
-  if (eCSSUnit_Initial == fsbColorValue->GetUnit() ||
-      eCSSUnit_Unset == fsbColorValue->GetUnit()) {
-    ui->mFontSmoothingBackgroundColor = NS_RGBA(0, 0, 0, 0);
-  } else {
-    SetColor(*fsbColorValue, parentUI->mFontSmoothingBackgroundColor,
-             mPresContext, aContext, ui->mFontSmoothingBackgroundColor,
-             conditions);
-  }
-
   COMPUTE_END_INHERITED(UserInterface, ui)
 }
 
 const void*
 nsRuleNode::ComputeUIResetData(void* aStartStruct,
                                const nsRuleData* aRuleData,
                                GeckoStyleContext* aContext,
                                nsRuleNode* aHighestNode,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -200,16 +200,19 @@ nsStyleFont::CalcDifference(const nsStyl
              "expected mAllowZoom to be the same on both nsStyleFonts");
   if (mSize != aNewData.mSize ||
       mFont != aNewData.mFont ||
       mLanguage != aNewData.mLanguage ||
       mExplicitLanguage != aNewData.mExplicitLanguage ||
       mMathVariant != aNewData.mMathVariant ||
       mMathDisplay != aNewData.mMathDisplay ||
       mMinFontSizeRatio != aNewData.mMinFontSizeRatio) {
+    // If only mFont.fontSmoothingBackgroundColor changes, we really only need
+    // a repaint hint rather than a reflow+repaint hint, but it's not worth
+    // worth optimizing.
     return NS_STYLE_HINT_REFLOW;
   }
 
   // XXX Should any of these cause a non-nsChangeHint_NeutralChange change?
   if (mGenericID != aNewData.mGenericID ||
       mScriptLevel != aNewData.mScriptLevel ||
       mScriptUnconstrainedSize != aNewData.mScriptUnconstrainedSize ||
       mScriptMinSize != aNewData.mScriptMinSize ||
@@ -4386,30 +4389,28 @@ nsCursorImage::operator==(const nsCursor
 
 nsStyleUserInterface::nsStyleUserInterface(const nsPresContext* aContext)
   : mUserInput(StyleUserInput::Auto)
   , mUserModify(StyleUserModify::ReadOnly)
   , mUserFocus(StyleUserFocus::None)
   , mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO)
   , mCursor(NS_STYLE_CURSOR_AUTO)
   , mCaretColor(StyleComplexColor::Auto())
-  , mFontSmoothingBackgroundColor(NS_RGBA(0, 0, 0, 0))
 {
   MOZ_COUNT_CTOR(nsStyleUserInterface);
 }
 
 nsStyleUserInterface::nsStyleUserInterface(const nsStyleUserInterface& aSource)
   : mUserInput(aSource.mUserInput)
   , mUserModify(aSource.mUserModify)
   , mUserFocus(aSource.mUserFocus)
   , mPointerEvents(aSource.mPointerEvents)
   , mCursor(aSource.mCursor)
   , mCursorImages(aSource.mCursorImages)
   , mCaretColor(aSource.mCaretColor)
-  , mFontSmoothingBackgroundColor(aSource.mFontSmoothingBackgroundColor)
 {
   MOZ_COUNT_CTOR(nsStyleUserInterface);
 }
 
 nsStyleUserInterface::~nsStyleUserInterface()
 {
   MOZ_COUNT_DTOR(nsStyleUserInterface);
 }
@@ -4461,18 +4462,17 @@ nsStyleUserInterface::CalcDifference(con
       hint |= nsChangeHint_NeutralChange;
     }
   }
 
   if (mUserFocus != aNewData.mUserFocus) {
     hint |= nsChangeHint_NeutralChange;
   }
 
-  if (mCaretColor != aNewData.mCaretColor ||
-      mFontSmoothingBackgroundColor != aNewData.mFontSmoothingBackgroundColor) {
+  if (mCaretColor != aNewData.mCaretColor) {
     hint |= nsChangeHint_RepaintFrame;
   }
 
   return hint;
 }
 
 //-----------------------
 // nsStyleUIReset
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3171,17 +3171,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   mozilla::StyleUserInput   mUserInput;       // [inherited]
   mozilla::StyleUserModify  mUserModify;      // [inherited] (modify-content)
   mozilla::StyleUserFocus   mUserFocus;       // [inherited] (auto-select)
   uint8_t                   mPointerEvents;   // [inherited] see nsStyleConsts.h
 
   uint8_t mCursor;                            // [inherited] See nsStyleConsts.h
   nsTArray<nsCursorImage> mCursorImages;      // [inherited] images and coords
   mozilla::StyleComplexColor mCaretColor;     // [inherited]
-  nscolor                   mFontSmoothingBackgroundColor; // [inherited]
 
   inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const;
 };
 
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL
 {
   explicit nsStyleXUL(const nsPresContext* aContext);
   nsStyleXUL(const nsStyleXUL& aSource);
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -522,17 +522,17 @@ nsTextBoxFrame::DrawText(gfxContext&    
     DrawTarget* refDrawTarget = refContext->GetDrawTarget();
 
     CalculateUnderline(refDrawTarget, *fontMet);
 
     nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor;
     ColorPattern color(ToDeviceColor(c));
     aRenderingContext.SetColor(Color::FromABGR(c));
     aRenderingContext.SetFontSmoothingBackgroundColor(
-        Color::FromABGR(StyleUserInterface()->mFontSmoothingBackgroundColor));
+        Color::FromABGR(StyleFont()->mFont.fontSmoothingBackgroundColor));
 
     nsresult rv = NS_ERROR_FAILURE;
 
     if (mState & NS_FRAME_IS_BIDI) {
       presContext->SetBidiEnabled();
       nsBidiLevel level = nsBidiPresUtils::BidiLevelFromStyle(StyleContext());
       if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
           // We let the RenderText function calculate the mnemonic's
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -3059,17 +3059,17 @@ nsTreeBodyFrame::PaintRow(int32_t       
   auto appearance = rowContext->StyleDisplay()->mAppearance;
   if (appearance) {
     theme = aPresContext->GetTheme();
   }
 
   // Save the current font smoothing background color in case we change it.
   Color originalColor(aRenderingContext.GetFontSmoothingBackgroundColor());
   aRenderingContext.SetFontSmoothingBackgroundColor(
-    ToDeviceColor(rowContext->StyleUserInterface()->mFontSmoothingBackgroundColor));
+    ToDeviceColor(rowContext->StyleFont()->mFont.fontSmoothingBackgroundColor));
   if (theme && theme->ThemeSupportsWidget(aPresContext, nullptr, appearance)) {
     nsRect dirty;
     dirty.IntersectRect(rowRect, aDirtyRect);
     theme->DrawWidgetBackground(&aRenderingContext, this, appearance, rowRect,
                                 dirty);
   } else {
     result &= PaintBackgroundLayer(rowContext, aPresContext, aRenderingContext,
                                    rowRect, aDirtyRect);