Bug 1387594 - Add a chrome-only CSS property called -moz-font-smoothing-background-color. r?dbaron draft
authorMarkus Stange <mstange@themasta.com>
Wed, 16 Aug 2017 17:06:12 -0400
changeset 664802 4078991d65e1898c3b5e27bc31e05907a107d8ff
parent 661321 50857982881ae7803ceb438fee90650a282f7f05
child 664803 cd540549eb0aa213c5208b339f456950ddbded14
push id79812
push userbmo:mstange@themasta.com
push dateThu, 14 Sep 2017 12:15:40 +0000
reviewersdbaron
bugs1387594
milestone57.0a1
Bug 1387594 - Add a chrome-only CSS property called -moz-font-smoothing-background-color. r?dbaron This property accepts a color. It's inherited and defaults to transparent. Its value is respected on macOS when rendering text into transparent pixels. This property should be used for text that is placed on top of "vibrant" -moz-appearances, in order to achieve high quality text rendering for such text. In most cases, the property should be set to a named system color; an upcoming patch in this patch series will add one such color for each vibrant -moz-appearance value. However, in some cases it can also be useful to use a custom color: If text is rendered into an intermediate surface, for example because a mask is applied to it, and the background color behind that intermediate surface is known, then this property can be set to that background color in order to achieve subpixel AA for the text inside the mask effect. In that case, the font smoothing background color is respected because text is rendered into transparent pixels *inside the intermediate surface*. At the moment, the only example of that use case is the text of the active tab in the state where the text is overflowing. MozReview-Commit-ID: D98qQnxoFaq
devtools/shared/css/generated/properties-db.js
layout/style/nsCSSPropList.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsComputedDOMStylePropertyList.h
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/style/test/ListCSSProperties.cpp
layout/style/test/property_database.js
--- a/devtools/shared/css/generated/properties-db.js
+++ b/devtools/shared/css/generated/properties-db.js
@@ -3008,16 +3008,17 @@ exports.CSS_PROPERTIES = {
       "flood-color",
       "flood-opacity",
       "font-family",
       "font-feature-settings",
       "font-kerning",
       "font-language-override",
       "font-size",
       "font-size-adjust",
+      "-moz-font-smoothing-background-color",
       "font-stretch",
       "font-style",
       "font-synthesis",
       "font-variant-alternates",
       "font-variant-caps",
       "font-variant-east-asian",
       "font-variant-ligatures",
       "font-variant-numeric",
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -1946,16 +1946,30 @@ CSS_PROP_FONT(
         CSS_PROPERTY_VALUE_NONNEGATIVE |
         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(
+    -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),
+    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 |
         CSS_PROPERTY_APPLIES_TO_PLACEHOLDER,
     "",
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -1762,16 +1762,24 @@ nsComputedDOMStyle::DoGetOsxFontSmoothin
 
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.smoothing,
                                                nsCSSProps::kFontSmoothingKTable));
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
+nsComputedDOMStyle::DoGetFontSmoothingBackgroundColor()
+{
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
+  SetToRGBAColor(val, StyleUserInterface()->mFontSmoothingBackgroundColor);
+  return val.forget();
+}
+
+already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetFontStretch()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
   val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.stretch,
                                                nsCSSProps::kFontStretchKTable));
 
   return val.forget();
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -291,16 +291,17 @@ private:
   already_AddRefed<CSSValue> DoGetFontFamily();
   already_AddRefed<CSSValue> DoGetFontFeatureSettings();
   already_AddRefed<CSSValue> DoGetFontVariationSettings();
   already_AddRefed<CSSValue> DoGetFontKerning();
   already_AddRefed<CSSValue> DoGetFontLanguageOverride();
   already_AddRefed<CSSValue> DoGetFontSize();
   already_AddRefed<CSSValue> DoGetFontSizeAdjust();
   already_AddRefed<CSSValue> DoGetOsxFontSmoothing();
+  already_AddRefed<CSSValue> DoGetFontSmoothingBackgroundColor();
   already_AddRefed<CSSValue> DoGetFontStretch();
   already_AddRefed<CSSValue> DoGetFontStyle();
   already_AddRefed<CSSValue> DoGetFontSynthesis();
   already_AddRefed<CSSValue> DoGetFontVariant();
   already_AddRefed<CSSValue> DoGetFontVariantAlternates();
   already_AddRefed<CSSValue> DoGetFontVariantCaps();
   already_AddRefed<CSSValue> DoGetFontVariantEastAsian();
   already_AddRefed<CSSValue> DoGetFontVariantLigatures();
--- a/layout/style/nsComputedDOMStylePropertyList.h
+++ b/layout/style/nsComputedDOMStylePropertyList.h
@@ -283,16 +283,17 @@ COMPUTED_STYLE_PROP(_moz_border_top_colo
 COMPUTED_STYLE_PROP(_moz_box_align,                BoxAlign)
 COMPUTED_STYLE_PROP(_moz_box_direction,            BoxDirection)
 COMPUTED_STYLE_PROP(_moz_box_flex,                 BoxFlex)
 COMPUTED_STYLE_PROP(_moz_box_ordinal_group,        BoxOrdinalGroup)
 COMPUTED_STYLE_PROP(_moz_box_orient,               BoxOrient)
 COMPUTED_STYLE_PROP(_moz_box_pack,                 BoxPack)
 COMPUTED_STYLE_PROP(_moz_context_properties,       ContextProperties)
 COMPUTED_STYLE_PROP(_moz_float_edge,               FloatEdge)
+COMPUTED_STYLE_PROP(_moz_font_smoothing_background_color, FontSmoothingBackgroundColor)
 COMPUTED_STYLE_PROP(_moz_force_broken_image_icon,  ForceBrokenImageIcon)
 COMPUTED_STYLE_PROP(_moz_image_region,             ImageRegion)
 COMPUTED_STYLE_PROP(_moz_orient,                   Orient)
 COMPUTED_STYLE_PROP(_moz_osx_font_smoothing,       OsxFontSmoothing)
 COMPUTED_STYLE_PROP(_moz_outline_radius_bottomleft, OutlineRadiusBottomLeft)
 COMPUTED_STYLE_PROP(_moz_outline_radius_bottomright,OutlineRadiusBottomRight)
 COMPUTED_STYLE_PROP(_moz_outline_radius_topleft,    OutlineRadiusTopLeft)
 COMPUTED_STYLE_PROP(_moz_outline_radius_topright,   OutlineRadiusTopRight)
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -5321,16 +5321,28 @@ 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
@@ -4320,28 +4320,30 @@ 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);
 }
@@ -4393,17 +4395,18 @@ nsStyleUserInterface::CalcDifference(con
       hint |= nsChangeHint_NeutralChange;
     }
   }
 
   if (mUserFocus != aNewData.mUserFocus) {
     hint |= nsChangeHint_NeutralChange;
   }
 
-  if (mCaretColor != aNewData.mCaretColor) {
+  if (mCaretColor != aNewData.mCaretColor ||
+      mFontSmoothingBackgroundColor != aNewData.mFontSmoothingBackgroundColor) {
     hint |= nsChangeHint_RepaintFrame;
   }
 
   return hint;
 }
 
 //-----------------------
 // nsStyleUIReset
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3314,16 +3314,17 @@ 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/style/test/ListCSSProperties.cpp
+++ b/layout/style/test/ListCSSProperties.cpp
@@ -110,16 +110,17 @@ const char *gInaccessibleProperties[] = 
     "-moz-control-character-visibility",
     "-moz-script-level", // parsed by UA sheets only
     "-moz-script-size-multiplier",
     "-moz-script-min-size",
     "-moz-math-variant",
     "-moz-math-display", // parsed by UA sheets only
     "-moz-top-layer", // parsed by UA sheets only
     "-moz-min-font-size-ratio", // parsed by UA sheets only
+    "-moz-font-smoothing-background-color", // chrome-only internal properties
     "-moz-window-opacity", // chrome-only internal properties
     "-moz-window-transform", // chrome-only internal properties
     "-moz-window-transform-origin", // chrome-only internal properties
     "-moz-window-shadow" // chrome-only internal properties
 };
 
 inline int
 is_inaccessible(const char* aPropName)
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -8288,9 +8288,18 @@ if (false) {
   gCSSProperties["-moz-context-properties"] = {
     //domProp: "MozContextProperties",
     inherited: true,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "none" ],
     other_values: [ "fill", "stroke", "fill, stroke", "fill, stroke, fill", "fill, foo", "foo" ],
     invalid_values: [ "default", "fill, auto", "all, stroke", "none, fill", "fill, none", "fill, default", "2px" ]
   };
+
+  gCSSProperties["-moz-font-smoothing-background-color"] = {
+    // domProp: "MozFontSmoothingBackgroundColor",
+    inherited: true,
+    type: CSS_TYPE_LONGHAND,
+    initial_values: [ "transparent" ],
+    other_values: [ "green", "#fc3" ],
+    invalid_values: [ "000000", "ff00ff" ]
+  };
 }