Bug 1501418 - Have scrollbar-color: auto resolved to auto rather than two colors. r=emilio
authorXidorn Quan <me@upsuper.org>
Wed, 24 Oct 2018 11:52:46 +0000
changeset 442757 da3fbfd892b2f91495f9c018b0ea9677631664ba
parent 442756 a0509a9b9a06e3402cf519280b01c1f94aefea7a
child 442758 35c3b881583a46085ce6164efcc24448ced3adf6
push id34922
push usershindli@mozilla.com
push dateWed, 24 Oct 2018 16:46:21 +0000
treeherdermozilla-central@45632b51fa05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1501418
milestone65.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 1501418 - Have scrollbar-color: auto resolved to auto rather than two colors. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D9640
gfx/src/nsITheme.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/test/test_transitions_per_property.html
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
widget/windows/nsNativeThemeWin.cpp
widget/windows/nsNativeThemeWin.h
--- a/gfx/src/nsITheme.h
+++ b/gfx/src/nsITheme.h
@@ -70,24 +70,16 @@ public:
    */
   NS_IMETHOD DrawWidgetBackground(gfxContext* aContext,
                                   nsIFrame* aFrame,
                                   WidgetType aWidgetType,
                                   const nsRect& aRect,
                                   const nsRect& aDirtyRect) = 0;
 
   /**
-   * Get the used color of the given widget when it's specified as auto.
-   * It's currently only used for scrollbar-*-color properties.
-   */
-  virtual nscolor GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
-                                     WidgetType aWidgetType)
-  { return NS_RGB(0, 0, 0); }
-
-  /**
    * Create WebRender commands for the theme background.
    * @return true if the theme knows how to create WebRender commands for the
    *         given widget type, false if DrawWidgetBackground need sto be called
    *         instead.
    */
   virtual bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
                                                 mozilla::wr::IpcResourceUpdateQueue& aResources,
                                                 const mozilla::layers::StackingContextHelper& aSc,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -1145,42 +1145,16 @@ nsComputedDOMStyle::SetToRGBAColor(nsROC
 
 void
 nsComputedDOMStyle::SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
                                              const StyleComplexColor& aColor)
 {
   SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
 }
 
-void
-nsComputedDOMStyle::SetValueForWidgetColor(nsROCSSPrimitiveValue* aValue,
-                                           const StyleComplexColor& aColor,
-                                           StyleAppearance aWidgetType)
-{
-  if (!aColor.IsAuto()) {
-    SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
-    return;
-  }
-  nsPresContext* presContext = mPresShell->GetPresContext();
-  MOZ_ASSERT(presContext);
-  if (nsContentUtils::ShouldResistFingerprinting(presContext->GetDocShell())) {
-    // Return transparent when resisting fingerprinting.
-    SetToRGBAColor(aValue, NS_RGBA(0, 0, 0, 0));
-    return;
-  }
-  if (nsITheme* theme = presContext->GetTheme()) {
-    nscolor color = theme->GetWidgetAutoColor(mComputedStyle, aWidgetType);
-    SetToRGBAColor(aValue, color);
-  } else {
-    // If we don't have theme, we don't know what value it should be,
-    // just give it a transparent fallback.
-    SetToRGBAColor(aValue, NS_RGBA(0, 0, 0, 0));
-  }
-}
-
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetColor()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   SetToRGBAColor(val, StyleColor()->mColor);
   return val.forget();
 }
 
@@ -2481,25 +2455,34 @@ nsComputedDOMStyle::DoGetScrollSnapCoord
     return valueList.forget();
   }
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetScrollbarColor()
 {
   const nsStyleUI* ui = StyleUI();
+  MOZ_ASSERT(ui->mScrollbarFaceColor.IsAuto() ==
+             ui->mScrollbarTrackColor.IsAuto(),
+             "Whether the two colors are auto should be identical");
+
+  if (ui->mScrollbarFaceColor.IsAuto()) {
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
+    val->SetIdent(eCSSKeyword_auto);
+    return val.forget();
+  }
+
   RefPtr<nsDOMCSSValueList> list = GetROCSSValueList(false);
-  auto put = [this, &list](const StyleComplexColor& color,
-                           StyleAppearance type) {
+  auto put = [this, &list](const StyleComplexColor& color) {
     RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
-    SetValueForWidgetColor(val, color, type);
+    SetValueFromComplexColor(val, color);
     list->AppendCSSValue(val.forget());
   };
-  put(ui->mScrollbarFaceColor, StyleAppearance::ScrollbarthumbVertical);
-  put(ui->mScrollbarTrackColor, StyleAppearance::ScrollbarVertical);
+  put(ui->mScrollbarFaceColor);
+  put(ui->mScrollbarTrackColor);
   return list.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetOutlineWidth()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -454,19 +454,16 @@ private:
   // For working around a MSVC bug. See related comment in
   // GenerateComputedDOMStyleGenerated.py.
   already_AddRefed<CSSValue> DummyGetter();
 
   /* Helper functions */
   void SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor);
   void SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
                                 const mozilla::StyleComplexColor& aColor);
-  void SetValueForWidgetColor(nsROCSSPrimitiveValue* aValue,
-                              const mozilla::StyleComplexColor& aColor,
-                              mozilla::StyleAppearance aWidgetType);
   void SetValueToPositionCoord(const mozilla::Position::Coord& aCoord,
                                nsROCSSPrimitiveValue* aValue);
   void SetValueToPosition(const mozilla::Position& aPosition,
                           nsDOMCSSValueList* aValueList);
   void SetValueToURLValue(const mozilla::css::URLValue* aURL,
                           nsROCSSPrimitiveValue* aValue);
 
   /**
--- a/layout/style/test/test_transitions_per_property.html
+++ b/layout/style/test/test_transitions_per_property.html
@@ -1585,19 +1585,24 @@ function test_currentcolor_transition(pr
 
 function test_auto_color_transition(prop, options={}) {
   let { get_color, set_color } = get_color_options(options);
 
   const msg_prefix = `color-valued property ${prop}: `;
   const test_color = "rgb(51, 102, 153)";
   div.style.setProperty("transition-property", "none", "");
   div.style.setProperty(prop, "auto", "");
-  let used_value_of_auto = get_color(cs.getPropertyValue(prop));
-  isnot(used_value_of_auto, test_color,
-        msg_prefix + "ensure used auto value is different than our test color");
+  if (prop == "scrollbar-color") {
+    is(cs.getPropertyValue(prop), "auto",
+       msg_prefix + "auto should not be resolved to rgb color");
+  } else {
+    let used_value_of_auto = get_color(cs.getPropertyValue(prop));
+    isnot(used_value_of_auto, test_color,
+          msg_prefix + "ensure used auto value is different than our test color");
+  }
 
   div.style.setProperty("transition-property", prop, "");
   div.style.setProperty(prop, set_color(test_color), "");
   is(get_color(cs.getPropertyValue(prop)), test_color,
      msg_prefix + "not interpolatable between auto and rgb color");
 }
 
 function get_color_from_shorthand_value(value) {
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -375,18 +375,16 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // The nsITheme interface.
   NS_IMETHOD DrawWidgetBackground(gfxContext* aContext,
                                   nsIFrame* aFrame,
                                   WidgetType aWidgetType,
                                   const nsRect& aRect,
                                   const nsRect& aDirtyRect) override;
-  nscolor GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
-                             WidgetType aWidgetType) override;
   bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
                                         mozilla::wr::IpcResourceUpdateQueue& aResources,
                                         const mozilla::layers::StackingContextHelper& aSc,
                                         mozilla::layers::WebRenderLayerManager* aManager,
                                         nsIFrame* aFrame,
                                         WidgetType aWidgetType,
                                         const nsRect& aRect) override;
   MOZ_MUST_USE LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -3989,41 +3989,16 @@ nsNativeThemeCocoa::CreateWebRenderComma
     case StyleAppearance::Resizer:
       return false;
 
     default:
       return true;
   }
 }
 
-
-nscolor
-nsNativeThemeCocoa::GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
-                                       WidgetType aWidgetType)
-{
-  switch (aWidgetType) {
-    case StyleAppearance::Scrollbar:
-    case StyleAppearance::ScrollbarSmall:
-    case StyleAppearance::ScrollbarVertical:
-    case StyleAppearance::ScrollbarHorizontal:
-    case StyleAppearance::ScrollbarbuttonUp:
-    case StyleAppearance::ScrollbarbuttonDown:
-    case StyleAppearance::ScrollbarbuttonLeft:
-    case StyleAppearance::ScrollbarbuttonRight:
-      return NS_RGB(0xFA, 0xFA, 0xFA);
-
-    case StyleAppearance::ScrollbarthumbVertical:
-    case StyleAppearance::ScrollbarthumbHorizontal:
-      return NS_RGB(0xC1, 0xC1, 0xC1);
-
-    default:
-      return nsITheme::GetWidgetAutoColor(aStyle, aWidgetType);
-  }
-}
-
 LayoutDeviceIntMargin
 nsNativeThemeCocoa::DirectionAwareMargin(const LayoutDeviceIntMargin& aMargin,
                                          nsIFrame* aFrame)
 {
   // Assuming aMargin was originally specified for a horizontal LTR context,
   // reinterpret the values as logical, and then map to physical coords
   // according to aFrame's actual writing mode.
   WritingMode wm = aFrame->GetWritingMode();
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -1984,51 +1984,16 @@ RENDER_AGAIN:
   if (nativeDrawing.ShouldRenderAgain())
     goto RENDER_AGAIN;
 
   nativeDrawing.PaintToContext();
 
   return NS_OK;
 }
 
-static nscolor
-GetScrollbarFaceColorForAuto(ComputedStyle* aStyle)
-{
-  return NS_RGB(205, 205, 205);
-}
-
-static nscolor
-GetScrollbarTrackColorForAuto(ComputedStyle* aStyle)
-{
-  return NS_RGB(240, 240, 240);
-}
-
-nscolor
-nsNativeThemeWin::GetWidgetAutoColor(ComputedStyle* aStyle, WidgetType aWidgetType)
-{
-  switch (aWidgetType) {
-    case StyleAppearance::Scrollbar:
-    case StyleAppearance::ScrollbarSmall:
-    case StyleAppearance::ScrollbarVertical:
-    case StyleAppearance::ScrollbarHorizontal:
-    case StyleAppearance::ScrollbarbuttonUp:
-    case StyleAppearance::ScrollbarbuttonDown:
-    case StyleAppearance::ScrollbarbuttonLeft:
-    case StyleAppearance::ScrollbarbuttonRight:
-      return GetScrollbarTrackColorForAuto(aStyle);
-
-    case StyleAppearance::ScrollbarthumbVertical:
-    case StyleAppearance::ScrollbarthumbHorizontal:
-      return GetScrollbarFaceColorForAuto(aStyle);
-
-    default:
-      return nsITheme::GetWidgetAutoColor(aStyle, aWidgetType);
-  }
-}
-
 static void
 ScaleForFrameDPI(LayoutDeviceIntMargin* aMargin, nsIFrame* aFrame)
 {
   double themeScale = GetThemeDpiScaleFactor(aFrame);
   if (themeScale != 1.0) {
     aMargin->top = NSToIntRound(aMargin->top * themeScale);
     aMargin->left = NSToIntRound(aMargin->left * themeScale);
     aMargin->bottom = NSToIntRound(aMargin->bottom * themeScale);
@@ -4345,17 +4310,17 @@ nsNativeThemeWin::DrawCustomScrollbarPar
   gfxRect clipRect =
     ThebesRect(LayoutDevicePixel::FromAppUnits(aClipRect, p2a).ToUnknownRect());
   ctx->Clip(clipRect);
   gfxRect rect =
     ThebesRect(LayoutDevicePixel::FromAppUnits(aRect, p2a).ToUnknownRect());
 
   const nsStyleUI* ui = aStyle->StyleUI();
   nscolor trackColor = ui->mScrollbarTrackColor.IsAuto()
-    ? GetScrollbarTrackColorForAuto(aStyle)
+    ? NS_RGB(240, 240, 240)
     : ui->mScrollbarTrackColor.CalcColor(aStyle);
   switch (aWidgetType) {
     case StyleAppearance::ScrollbarHorizontal:
     case StyleAppearance::ScrollbarVertical:
     case StyleAppearance::Scrollcorner: {
       ctx->SetColor(Color::FromABGR(trackColor));
       ctx->Rectangle(rect);
       ctx->Fill();
@@ -4382,17 +4347,17 @@ nsNativeThemeWin::DrawCustomScrollbarPar
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown widget type");
   }
 
   switch (aWidgetType) {
     case StyleAppearance::ScrollbarthumbVertical:
     case StyleAppearance::ScrollbarthumbHorizontal: {
       nscolor faceColor = ui->mScrollbarFaceColor.IsAuto()
-        ? GetScrollbarFaceColorForAuto(aStyle)
+        ? NS_RGB(205, 205, 205)
         : ui->mScrollbarFaceColor.CalcColor(aStyle);
       faceColor = AdjustScrollbarFaceColor(faceColor, eventStates);
       ctx->SetColor(Color::FromABGR(faceColor));
       ctx->Rectangle(bgRect);
       ctx->Fill();
       break;
     }
     case StyleAppearance::ScrollbarbuttonUp:
--- a/widget/windows/nsNativeThemeWin.h
+++ b/widget/windows/nsNativeThemeWin.h
@@ -32,19 +32,16 @@ public:
 
   // The nsITheme interface.
   NS_IMETHOD DrawWidgetBackground(gfxContext* aContext,
                                   nsIFrame* aFrame,
                                   WidgetType aWidgetType,
                                   const nsRect& aRect,
                                   const nsRect& aDirtyRect) override;
 
-  nscolor GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
-                             WidgetType aWidgetType) override;
-
   MOZ_MUST_USE LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
                                                      nsIFrame* aFrame,
                                                      WidgetType aWidgetType) override;
 
   bool GetWidgetPadding(nsDeviceContext* aContext,
                         nsIFrame* aFrame,
                         WidgetType aWidgetType,
                         LayoutDeviceIntMargin* aResult) override;