Break out scrollbar track drawing into a method. draft
authorMarkus Stange <mstange@themasta.com>
Fri, 17 Nov 2017 18:43:23 -0500
changeset 700302 2a4e973f13a3ee33f152b2add4535ee4e0768a04
parent 700301 6a4f3276bba99f46307010b357c2ad1f81976a18
child 700303 579725b1f81a24181fa7aa8dcb30c8a660c5cddb
push id89787
push userbmo:mstange@themasta.com
push dateSun, 19 Nov 2017 21:49:28 +0000
milestone59.0a1
Break out scrollbar track drawing into a method.
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -283,16 +283,18 @@ protected:
                       bool aIsDisabled, bool aIsInActiveWindow);
   void DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inBoxRect,
                           float aUnifiedHeight, bool aIsMain);
   void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
                      bool aIsMain);
   void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame);
   void DrawScrollbarThumb(CGContextRef cgContext, const CGRect& inBoxRect,
                           ScrollbarParams aParams);
+  void DrawScrollbarTrack(CGContextRef cgContext, const CGRect& inBoxRect,
+                          ScrollbarParams aParams);
 
   // Scrollbars
   void GetScrollbarPressStates(nsIFrame *aFrame,
                                mozilla::EventStates aButtonStates[]);
   nsIFrame* GetParentScrollbarFrame(nsIFrame *aFrame);
   bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
 
 private:
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2492,16 +2492,39 @@ nsNativeThemeCocoa::DrawScrollbarThumb(C
     [NSNumber numberWithBool:YES], @"is.flipped",
     nil];
   if (aParams.rolledOver) {
     [options setObject:@"rollover" forKey:@"state"];
   }
   RenderWithCoreUI(drawRect, cgContext, options, true);
 }
 
+void
+nsNativeThemeCocoa::DrawScrollbarTrack(CGContextRef cgContext,
+                                       const CGRect& inBoxRect,
+                                       ScrollbarParams aParams)
+{
+  if (aParams.overlay && !aParams.rolledOver) {
+    // Non-hovered overlay scrollbars don't have a track. Draw nothing.
+    return;
+  }
+
+  RenderWithCoreUI(inBoxRect, cgContext,
+          [NSDictionary dictionaryWithObjectsAndKeys:
+            (aParams.overlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
+            (aParams.small ? @"small" : @"regular"), @"size",
+            (aParams.horizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
+            (aParams.onDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
+            [NSNumber numberWithBool:YES], @"noindicator",
+            [NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
+            [NSNumber numberWithBool:YES], @"is.flipped",
+            nil],
+          true);
+}
+
 static bool
 IsHiDPIContext(nsDeviceContext* aContext)
 {
   return nsPresContext::AppUnitsPerCSSPixel() >=
     2 * aContext->AppUnitsPerDevPixelAtUnitFullZoom();
 }
 
 static void
@@ -3052,36 +3075,19 @@ nsNativeThemeCocoa::DrawWidgetBackground
     case NS_THEME_SCROLLBARBUTTON_DOWN:
     case NS_THEME_SCROLLBARBUTTON_RIGHT:
 #if SCROLLBARS_VISUAL_DEBUG
       CGContextSetRGBFillColor(cgContext, 0, 1.0, 0, 0.6);
       CGContextFillRect(cgContext, macRect);
 #endif
     break;
     case NS_THEME_SCROLLBARTRACK_HORIZONTAL:
-    case NS_THEME_SCROLLBARTRACK_VERTICAL: {
-      BOOL isOverlay = nsLookAndFeel::UseOverlayScrollbars();
-      if (!isOverlay || IsParentScrollbarRolledOver(aFrame)) {
-        BOOL isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTRACK_HORIZONTAL);
-        nsIFrame* scrollbarFrame = GetParentScrollbarFrame(aFrame);
-        bool isSmall = (scrollbarFrame && scrollbarFrame->StyleDisplay()->mAppearance == NS_THEME_SCROLLBAR_SMALL);
-        const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
-        RenderWithCoreUI(macRect, cgContext,
-                [NSDictionary dictionaryWithObjectsAndKeys:
-                  (isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
-                  (isSmall ? @"small" : @"regular"), @"size",
-                  (isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
-                  (isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
-                  [NSNumber numberWithBool:YES], @"noindicator",
-                  [NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
-                  [NSNumber numberWithBool:YES], @"is.flipped",
-                  nil],
-                true);
-      }
-    }
+    case NS_THEME_SCROLLBARTRACK_VERTICAL:
+      DrawScrollbarTrack(cgContext, macRect,
+                         ComputeScrollbarParams(aFrame, aWidgetType == NS_THEME_SCROLLBARTRACK_HORIZONTAL));
       break;
 
     case NS_THEME_TEXTFIELD_MULTILINE: {
       // we have to draw this by hand because there is no HITheme value for it
       CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
 
       CGContextFillRect(cgContext, macRect);