Bug 1498216 - Properly support alpha channel on custom scrollbars. r=spohl
authorXidorn Quan <me@upsuper.org>
Mon, 22 Oct 2018 16:05:05 +0000
changeset 490800 0087557ee59e71e9756c44ef25ba23a22f08dc5a
parent 490799 d38eafa9429c39224016bf74f67e13b9a9c1ba08
child 490801 2eda4a5dffcca83112096781c7ff8cca39308e42
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersspohl
bugs1498216, 1464722
milestone65.0a1
Bug 1498216 - Properly support alpha channel on custom scrollbars. r=spohl This also includes implementation of nsNativeThemeCocoa::GetWidgetAutoColor which should have been done in bug 1464722 actually. Differential Revision: https://phabricator.services.mozilla.com/D8629
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -375,16 +375,18 @@ 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
@@ -2716,31 +2716,16 @@ nsNativeThemeCocoa::DrawResizer(CGContex
   drawInfo.size = kHIThemeGrowBoxSizeNormal;
 
   RenderTransformedHIThemeControl(cgContext, aRect, RenderResizer, &drawInfo,
                                   aIsRTL);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-static nscolor
-GetAutoScrollbarTrackColor(ComputedStyle* aStyle)
-{
-  // Use the default scrollbar color. XXX Can we get it from the system?
-  return NS_RGB(0xFA, 0xFA, 0xFA);
-}
-
-static nscolor
-GetAutoScrollbarFaceColor(ComputedStyle* aStyle)
-{
-  // Use the default scrollbar color. We may want to derive from track
-  // color at some point.
-  return NS_RGB(0xC1, 0xC1, 0xC1);
-}
-
 static bool
 IsSmallScrollbar(nsIFrame* aFrame)
 {
   ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
   if (style->StyleUIReset()->mScrollbarWidth == StyleScrollbarWidth::Thin) {
     return true;
   }
   nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
@@ -2761,22 +2746,21 @@ nsNativeThemeCocoa::ComputeScrollbarPara
   params.small = IsSmallScrollbar(aFrame);
   params.rtl = IsFrameRTL(aFrame);
   params.horizontal = aIsHorizontal;
   params.onDarkBackground = IsDarkBackground(aFrame);
   // Don't use custom scrollbars for overlay scrollbars since they are
   // generally good enough for use cases of custom scrollbars.
   if (!params.overlay) {
     ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
-    if (style->StyleUI()->HasCustomScrollbars()) {
+    const nsStyleUI* ui = style->StyleUI();
+    if (ui->HasCustomScrollbars()) {
       params.custom = true;
-      params.trackColor =
-        GetScrollbarTrackColor(style, &GetAutoScrollbarTrackColor);
-      params.faceColor =
-        GetScrollbarFaceColor(style, &GetAutoScrollbarFaceColor);
+      params.trackColor = ui->mScrollbarTrackColor.CalcColor(style);
+      params.faceColor = ui->mScrollbarFaceColor.CalcColor(style);
     }
   }
   return params;
 }
 
 void
 nsNativeThemeCocoa::DrawScrollbarThumb(CGContextRef cgContext,
                                        const CGRect& inBoxRect,
@@ -4005,16 +3989,41 @@ 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();
@@ -4957,18 +4966,24 @@ nsNativeThemeCocoa::GetWidgetTransparenc
   case StyleAppearance::Tooltip:
     return eTransparent;
 
   case StyleAppearance::Dialog:
     return IsWindowSheet(aFrame) ? eTransparent : eOpaque;
 
   case StyleAppearance::ScrollbarSmall:
   case StyleAppearance::Scrollbar:
-  case StyleAppearance::Scrollcorner:
+  case StyleAppearance::Scrollcorner: {
+    const nsStyleUI* ui = nsLayoutUtils::StyleForScrollbar(aFrame)->StyleUI();
+    StyleComplexColor trackColor = ui->mScrollbarTrackColor;
+    if (!trackColor.IsAuto()) {
+      return trackColor.MaybeTransparent() ? eTransparent : eOpaque;
+    }
     return nsLookAndFeel::UseOverlayScrollbars() ? eTransparent : eOpaque;
+  }
 
   case StyleAppearance::Statusbar:
     // Knowing that scrollbars and statusbars are opaque improves
     // performance, because we create layers for them.
     return eOpaque;
 
   case StyleAppearance::Toolbar:
     return eOpaque;