--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -894,26 +894,16 @@ static void DrawCellWithSnapping(NSCell
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@interface NSWindow(CoreUIRendererPrivate)
+ (CUIRendererRef)coreUIRenderer;
@end
-static void
-RenderWithCoreUILegacy(CGRect aRect, CGContextRef cgContext, NSDictionary* aOptions, bool aSkipAreaCheck)
-{
- if (aSkipAreaCheck || (aRect.size.width * aRect.size.height <= BITMAP_MAX_AREA)) {
- CUIRendererRef renderer = [NSWindow respondsToSelector:@selector(coreUIRenderer)]
- ? [NSWindow coreUIRenderer] : nil;
- CUIDraw(renderer, aRect, cgContext, (CFDictionaryRef)aOptions, NULL);
- }
-}
-
static id
GetAquaAppearance()
{
// We only need NSAppearance on 10.10 and up.
if (nsCocoaFeatures::OnYosemiteOrLater()) {
Class NSAppearanceClass = NSClassFromString(@"NSAppearance");
if (NSAppearanceClass &&
[NSAppearanceClass respondsToSelector:@selector(appearanceNamed:)]) {
@@ -924,33 +914,35 @@ GetAquaAppearance()
return nil;
}
@interface NSObject(NSAppearanceCoreUIRendering)
- (void)_drawInRect:(CGRect)rect context:(CGContextRef)cgContext options:(id)options;
@end
static void
-RenderWithCoreUI(CGRect aRect, CGContextRef cgContext, NSDictionary* aOptions)
+RenderWithCoreUI(CGRect aRect, CGContextRef cgContext, NSDictionary* aOptions, bool aSkipAreaCheck = false)
{
id appearance = GetAquaAppearance();
- if (aRect.size.width * aRect.size.height > BITMAP_MAX_AREA) {
+ if (!aSkipAreaCheck && aRect.size.width * aRect.size.height > BITMAP_MAX_AREA) {
return;
}
if (appearance && [appearance respondsToSelector:@selector(_drawInRect:context:options:)]) {
// Render through NSAppearance on Mac OS 10.10 and up. This will call
// CUIDraw with a CoreUI renderer that will give us the correct 10.10
// style. Calling CUIDraw directly with [NSWindow coreUIRenderer] still
// renders 10.9-style widgets on 10.10.
[appearance _drawInRect:aRect context:cgContext options:aOptions];
} else {
// 10.9 and below
- RenderWithCoreUILegacy(aRect, cgContext, aOptions, false);
+ CUIRendererRef renderer = [NSWindow respondsToSelector:@selector(coreUIRenderer)]
+ ? [NSWindow coreUIRenderer] : nil;
+ CUIDraw(renderer, aRect, cgContext, (CFDictionaryRef)aOptions, NULL);
}
}
static float VerticalAlignFactor(nsIFrame *aFrame)
{
if (!aFrame)
return 0.5f; // default: center
@@ -2751,30 +2743,29 @@ nsNativeThemeCocoa::DrawWidgetBackground
if (aFrame->StyleVisibility()->mDirection !=
NS_STYLE_DIRECTION_RTL) {
macRect.origin.x += 4;
}
macRect.size.width -= 4;
}
}
const BOOL isOnTopOfDarkBackground = IsDarkBackground(aFrame);
- // Scrollbar thumbs have a too high minimum width when rendered through
- // NSAppearance on 10.10, so we call RenderWithCoreUILegacy here.
- RenderWithCoreUILegacy(macRect, cgContext,
- [NSDictionary dictionaryWithObjectsAndKeys:
- (isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
- (isSmall ? @"small" : @"regular"), @"size",
- (isRolledOver ? @"rollover" : @"normal"), @"state",
- (isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
- (isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
- [NSNumber numberWithBool:YES], @"indiconly",
- [NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
- [NSNumber numberWithBool:YES], @"is.flipped",
- nil],
- true);
+ NSMutableDictionary* options = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ (isOverlay ? @"kCUIWidgetOverlayScrollBar" : @"scrollbar"), @"widget",
+ (isSmall ? @"small" : @"regular"), @"size",
+ (isHorizontal ? @"kCUIOrientHorizontal" : @"kCUIOrientVertical"), @"kCUIOrientationKey",
+ (isOnTopOfDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
+ [NSNumber numberWithBool:YES], @"indiconly",
+ [NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
+ [NSNumber numberWithBool:YES], @"is.flipped",
+ nil];
+ if (isRolledOver) {
+ [options setObject:@"rollover" forKey:@"state"];
+ }
+ RenderWithCoreUI(macRect, cgContext, options, true);
}
break;
case NS_THEME_SCROLLBARBUTTON_UP:
case NS_THEME_SCROLLBARBUTTON_LEFT:
#if SCROLLBARS_VISUAL_DEBUG
CGContextSetRGBFillColor(cgContext, 1.0, 0, 0, 0.6);
CGContextFillRect(cgContext, macRect);
@@ -2790,17 +2781,17 @@ nsNativeThemeCocoa::DrawWidgetBackground
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);
- RenderWithCoreUILegacy(macRect, cgContext,
+ 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",
@@ -3007,20 +2998,35 @@ nsNativeThemeCocoa::GetWidgetBorder(nsDe
break;
}
case NS_THEME_SCROLLBARTRACK_HORIZONTAL:
case NS_THEME_SCROLLBARTRACK_VERTICAL:
{
bool isHorizontal = (aWidgetType == NS_THEME_SCROLLBARTRACK_HORIZONTAL);
if (nsLookAndFeel::UseOverlayScrollbars()) {
+ if (!nsCocoaFeatures::OnYosemiteOrLater()) {
+ // Pre-10.10, we have to center the thumb rect in the middle of the
+ // scrollbar. Starting with 10.10, the expected rect for thumb
+ // rendering is the full width of the scrollbar.
+ if (isHorizontal) {
+ aResult->top = 2;
+ aResult->bottom = 1;
+ } else {
+ aResult->left = 2;
+ aResult->right = 1;
+ }
+ }
+ // Leave a bit of space at the start and the end on all OS X versions.
if (isHorizontal) {
- aResult->SizeTo(2, 1, 1, 1);
+ aResult->left = 1;
+ aResult->right = 1;
} else {
- aResult->SizeTo(1, 1, 1, 2);
+ aResult->top = 1;
+ aResult->bottom = 1;
}
}
break;
}
case NS_THEME_STATUSBAR:
aResult->SizeTo(1, 0, 0, 0);