Bug 1484565 - Implement scrollbar-width: thin support for cocoa widget. r=spohl
authorXidorn Quan <me@upsuper.org>
Mon, 20 Aug 2018 04:57:58 +0000
changeset 487403 eaf6867923b99cd189d501cd3dd131f73c0e533c
parent 487402 93d0e291f45883765df384c070e56e4e0517db4b
child 487404 4e0960a6ffb6c283f29d75ba5bc2585df4c3caf0
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1484565
milestone63.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 1484565 - Implement scrollbar-width: thin support for cocoa widget. r=spohl It also converts nsNativeThemeCocoa::GetParentScrollbarFrame into a local static function rather than a member function, since it doesn't seem to be necessary that way. Differential Revision: https://phabricator.services.mozilla.com/D3737
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -530,17 +530,16 @@ protected:
   void DrawScrollCorner(CGContextRef cgContext, const CGRect& inBoxRect,
                         ScrollbarParams aParams);
   void DrawMultilineTextField(CGContextRef cgContext, const CGRect& inBoxRect,
                               bool aIsFocused);
   void DrawSourceList(CGContextRef cgContext, const CGRect& inBoxRect,
                       bool aIsActive);
 
   // Scrollbars
-  nsIFrame* GetParentScrollbarFrame(nsIFrame *aFrame);
   bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
 
   void RenderWidget(const WidgetInfo& aWidgetInfo,
                     mozilla::gfx::DrawTarget& aDrawTarget,
                     const mozilla::gfx::Rect& aWidgetRect,
                     const mozilla::gfx::Rect& aDirtyRect,
                     float aScale);
 
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2538,18 +2538,18 @@ nsNativeThemeCocoa::DrawSegment(CGContex
     @"size": CUIControlSizeForCocoaSize(controlSize),
     @"is.flipped": [NSNumber numberWithBool:YES],
     @"direction": @"up"
   };
 
   RenderWithCoreUI(drawRect, cgContext, dict);
 }
 
-nsIFrame*
-nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame)
+static nsIFrame*
+GetParentScrollbarFrame(nsIFrame *aFrame)
 {
   // Walk our parents to find a scrollbar frame
   nsIFrame* scrollbarFrame = aFrame;
   do {
     if (scrollbarFrame->IsScrollbarFrame()) break;
   } while ((scrollbarFrame = scrollbarFrame->GetParent()));
 
   // We return null if we can't find a parent scrollbar frame
@@ -2726,26 +2726,39 @@ GetAutoScrollbarTrackColor(ComputedStyle
 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);
+  if (scrollbarFrame &&
+      scrollbarFrame->StyleDisplay()->mAppearance ==
+        StyleAppearance::ScrollbarSmall) {
+    return true;
+  }
+  return false;
+}
+
 nsNativeThemeCocoa::ScrollbarParams
 nsNativeThemeCocoa::ComputeScrollbarParams(nsIFrame* aFrame, bool aIsHorizontal)
 {
   ScrollbarParams params;
   params.overlay = nsLookAndFeel::UseOverlayScrollbars();
   params.rolledOver = IsParentScrollbarRolledOver(aFrame);
-  nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
-  params.small =
-    (scrollbarFrame &&
-     scrollbarFrame->StyleDisplay()->mAppearance == StyleAppearance::ScrollbarSmall);
+  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()) {
@@ -4431,75 +4444,58 @@ nsNativeThemeCocoa::GetMinimumWidgetSize
       aResult->SizeTo(scaleWidth, scaleWidth);
       *aIsOverridable = false;
       break;
     }
 
     case StyleAppearance::ScrollbarthumbHorizontal:
     case StyleAppearance::ScrollbarthumbVertical:
     {
-      // Find our parent scrollbar frame in order to find out whether we're in
-      // a small or a large scrollbar.
-      nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
-      if (!scrollbarFrame)
-        return NS_ERROR_FAILURE;
-
-      bool isSmall = (scrollbarFrame->StyleDisplay()->mAppearance == StyleAppearance::ScrollbarSmall);
+      bool isSmall = IsSmallScrollbar(aFrame);
       bool isHorizontal = (aWidgetType == StyleAppearance::ScrollbarthumbHorizontal);
       int32_t& minSize = isHorizontal ? aResult->width : aResult->height;
       minSize = isSmall ? kSmallScrollbarThumbMinSize : kRegularScrollbarThumbMinSize;
       break;
     }
 
     case StyleAppearance::Scrollbar:
     case StyleAppearance::ScrollbarSmall:
     case StyleAppearance::ScrollbartrackVertical:
     case StyleAppearance::ScrollbartrackHorizontal:
     {
       *aIsOverridable = false;
 
       if (nsLookAndFeel::UseOverlayScrollbars()) {
-        nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
-        if (scrollbarFrame &&
-            scrollbarFrame->StyleDisplay()->mAppearance ==
-              StyleAppearance::ScrollbarSmall) {
+        if (IsSmallScrollbar(aFrame)) {
           aResult->SizeTo(14, 14);
-        }
-        else {
+        } else {
           aResult->SizeTo(16, 16);
         }
         break;
       }
 
       // yeah, i know i'm cheating a little here, but i figure that it
       // really doesn't matter if the scrollbar is vertical or horizontal
       // and the width metric is a really good metric for every piece
       // of the scrollbar.
 
-      nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
-      if (!scrollbarFrame) return NS_ERROR_FAILURE;
-
-      int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == StyleAppearance::ScrollbarSmall) ?
-                            kThemeMetricSmallScrollBarWidth :
-                            kThemeMetricScrollBarWidth;
+      int32_t themeMetric = IsSmallScrollbar(aFrame)
+        ? kThemeMetricSmallScrollBarWidth : kThemeMetricScrollBarWidth;
       SInt32 scrollbarWidth = 0;
       ::GetThemeMetric(themeMetric, &scrollbarWidth);
       aResult->SizeTo(scrollbarWidth, scrollbarWidth);
       break;
     }
 
     case StyleAppearance::ScrollbarNonDisappearing:
     {
       int32_t themeMetric = kThemeMetricScrollBarWidth;
 
       if (aFrame) {
-        nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
-        if (scrollbarFrame &&
-            scrollbarFrame->StyleDisplay()->mAppearance ==
-            StyleAppearance::ScrollbarSmall) {
+        if (IsSmallScrollbar(aFrame)) {
           // XXX We're interested in the width of non-disappearing scrollbars
           // to leave enough space for a dropmarker in non-native styled
           // comboboxes (bug 869314). It isn't clear to me if comboboxes can
           // ever have small scrollbars.
           themeMetric = kThemeMetricSmallScrollBarWidth;
         }
       }
 
@@ -4509,23 +4505,18 @@ nsNativeThemeCocoa::GetMinimumWidgetSize
       break;
     }
 
     case StyleAppearance::ScrollbarbuttonUp:
     case StyleAppearance::ScrollbarbuttonDown:
     case StyleAppearance::ScrollbarbuttonLeft:
     case StyleAppearance::ScrollbarbuttonRight:
     {
-      nsIFrame *scrollbarFrame = GetParentScrollbarFrame(aFrame);
-      if (!scrollbarFrame) return NS_ERROR_FAILURE;
-
-      // Since there is no StyleAppearance::ScrollbarbuttonUpSmall we need to ask the parent what appearance style it has.
-      int32_t themeMetric = (scrollbarFrame->StyleDisplay()->mAppearance == StyleAppearance::ScrollbarSmall) ?
-                            kThemeMetricSmallScrollBarWidth :
-                            kThemeMetricScrollBarWidth;
+      int32_t themeMetric = IsSmallScrollbar(aFrame)
+        ? kThemeMetricSmallScrollBarWidth : kThemeMetricScrollBarWidth;
       SInt32 scrollbarWidth = 0;
       ::GetThemeMetric(themeMetric, &scrollbarWidth);
 
       // It seems that for both sizes of scrollbar, the buttons are one pixel "longer".
       if (aWidgetType == StyleAppearance::ScrollbarbuttonLeft || aWidgetType == StyleAppearance::ScrollbarbuttonRight)
         aResult->SizeTo(scrollbarWidth+1, scrollbarWidth);
       else
         aResult->SizeTo(scrollbarWidth, scrollbarWidth+1);