Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tabs/tab_view.mm |
| diff --git a/chrome/browser/ui/cocoa/tabs/tab_view.mm b/chrome/browser/ui/cocoa/tabs/tab_view.mm |
| index ea826ff8b463931d0e02afe74c6a1c385d8b300a..84b48cf1e16275d3310bfb532101decec531b6da 100644 |
| --- a/chrome/browser/ui/cocoa/tabs/tab_view.mm |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_view.mm |
| @@ -6,6 +6,7 @@ |
| #include "base/i18n/rtl.h" |
| #include "base/logging.h" |
| +#include "base/mac/mac_util.h" |
| #include "base/mac/sdk_forward_declarations.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "chrome/browser/themes/theme_properties.h" |
| @@ -45,12 +46,20 @@ const NSTimeInterval kGlowUpdateInterval = 0.025; |
| // has moved less than the threshold, we want to close the tab. |
| const CGFloat kRapidCloseDist = 2.5; |
| -@interface TabView(MaterialDesign) |
| +// This class contains the logic for drawing Material Design tab images. The |
| +// |setTabEdgeStrokeColor| method is overridden by |TabHeavyImageMaker| to draw |
| +// high-contrast tabs. |
| +@interface TabImageMaker : NSObject |
| + (void)drawTabLeftMaskImage; |
| + (void)drawTabRightMaskImage; |
| + (void)drawTabLeftEdgeImage; |
| + (void)drawTabMiddleEdgeImage; |
| + (void)drawTabRightEdgeImage; |
| ++ (void)setTabEdgeStrokeColor; |
| +@end |
| + |
| +@interface TabHeavyImageMaker : TabImageMaker |
| ++ (void)setTabEdgeStrokeColor; |
| @end |
| @interface TabController(Private) |
| @@ -58,9 +67,11 @@ const CGFloat kRapidCloseDist = 2.5; |
| - (HoverCloseButton*)closeButton; |
| @end |
| +extern NSString* const _Nonnull NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification; |
|
Mark Mentovai
2016/06/21 19:58:54
Wrap the long name to a hanging-indent line of its
Elly Fong-Jones
2016/06/21 20:25:36
Done.
|
| + |
| namespace { |
| -NSImage* imageForResourceID(int resource_id) { |
| +NSImage* imageForResourceID(int resource_id, bool heavy_stroke) { |
| if (!ui::MaterialDesignController::IsModeMaterial()) { |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| return [rb.GetNativeImageNamed(resource_id).CopyNSImage() autorelease]; |
| @@ -91,9 +102,11 @@ NSImage* imageForResourceID(int resource_id) { |
| } |
| DCHECK(theSelector); |
| + Class makerClass = |
| + heavy_stroke ? [TabHeavyImageMaker class] : [TabImageMaker class]; |
| base::scoped_nsobject<NSCustomImageRep> imageRep([[NSCustomImageRep alloc] |
| initWithDrawSelector:theSelector |
| - delegate:[TabView class]]); |
| + delegate:makerClass]); |
| NSImage* newTabButtonImage = |
| [[[NSImage alloc] initWithSize:NSMakeSize(imageWidth, 29)] autorelease]; |
| @@ -104,29 +117,32 @@ NSImage* imageForResourceID(int resource_id) { |
| } |
| ui::ThreePartImage& GetMaskImage() { |
| - CR_DEFINE_STATIC_LOCAL(ui::ThreePartImage, mask, |
| - (imageForResourceID(IDR_TAB_ALPHA_LEFT), nullptr, |
| - imageForResourceID(IDR_TAB_ALPHA_RIGHT))); |
| + CR_DEFINE_STATIC_LOCAL( |
| + ui::ThreePartImage, mask, |
| + (imageForResourceID(IDR_TAB_ALPHA_LEFT, false), nullptr, |
| + imageForResourceID(IDR_TAB_ALPHA_RIGHT, false))); |
| return mask; |
| } |
| -ui::ThreePartImage& GetStrokeImage(bool active) { |
| +ui::ThreePartImage& GetStrokeImage(bool active, bool increase_contrast) { |
| if (!ui::MaterialDesignController::IsModeMaterial() && !active) { |
| - CR_DEFINE_STATIC_LOCAL( |
| - ui::ThreePartImage, inactiveStroke, |
| - (imageForResourceID(IDR_TAB_INACTIVE_LEFT), |
| - imageForResourceID(IDR_TAB_INACTIVE_CENTER), |
| - imageForResourceID(IDR_TAB_INACTIVE_RIGHT))); |
| + CR_DEFINE_STATIC_LOCAL(ui::ThreePartImage, inactiveStroke, |
| + (imageForResourceID(IDR_TAB_INACTIVE_LEFT, false), |
| + imageForResourceID(IDR_TAB_INACTIVE_CENTER, false), |
| + imageForResourceID(IDR_TAB_INACTIVE_RIGHT, false))); |
| return inactiveStroke; |
| } |
| - CR_DEFINE_STATIC_LOCAL( |
| - ui::ThreePartImage, stroke, |
| - (imageForResourceID(IDR_TAB_ACTIVE_LEFT), |
| - imageForResourceID(IDR_TAB_ACTIVE_CENTER), |
| - imageForResourceID(IDR_TAB_ACTIVE_RIGHT))); |
| + CR_DEFINE_STATIC_LOCAL(ui::ThreePartImage, stroke, |
| + (imageForResourceID(IDR_TAB_ACTIVE_LEFT, false), |
| + imageForResourceID(IDR_TAB_ACTIVE_CENTER, false), |
| + imageForResourceID(IDR_TAB_ACTIVE_RIGHT, false))); |
| + CR_DEFINE_STATIC_LOCAL(ui::ThreePartImage, heavyStroke, |
| + (imageForResourceID(IDR_TAB_ACTIVE_LEFT, true), |
| + imageForResourceID(IDR_TAB_ACTIVE_CENTER, true), |
| + imageForResourceID(IDR_TAB_ACTIVE_RIGHT, true))); |
| - return stroke; |
| + return increase_contrast ? heavyStroke : stroke; |
| } |
| CGFloat LineWidthFromContext(CGContextRef context) { |
| @@ -178,11 +194,21 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| if (!ui::MaterialDesignController::IsModeMaterial()) { |
| fontSize = [NSFont systemFontSizeForControlSize:NSSmallControlSize]; |
| } |
| - [labelCell setFont:[NSFont systemFontOfSize:fontSize]]; |
| [titleView_ setCell:labelCell]; |
| titleViewCell_ = labelCell; |
| [self setWantsLayer:YES]; // -drawFill: needs a layer. |
| + |
| + if (base::mac::IsOSYosemiteOrLater()) { |
|
Mark Mentovai
2016/06/21 19:58:54
Here (and in -dealloc) too, would it be more our s
Elly Fong-Jones
2016/06/21 20:25:36
Done.
|
| + NSNotificationCenter* center = |
| + [[NSWorkspace sharedWorkspace] notificationCenter]; |
| + [center |
| + addObserver:self |
| + selector:@selector(accessibilityOptionsDidChange:) |
| + name: |
| + NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification |
| + object:nil]; |
| + } |
| } |
| return self; |
| } |
| @@ -190,6 +216,11 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| - (void)dealloc { |
| // Cancel any delayed requests that may still be pending (drags or hover). |
| [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
| + if (base::mac::IsOSYosemiteOrLater()) { |
| + NSNotificationCenter* center = |
| + [[NSWorkspace sharedWorkspace] notificationCenter]; |
| + [center removeObserver:self]; |
| + } |
| [super dealloc]; |
| } |
| @@ -489,7 +520,8 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| // In MD, the tab stroke is always opaque. |
| alpha = 1; |
| } |
| - GetStrokeImage(state_ == NSOnState) |
| + GetStrokeImage(state_ == NSOnState, |
| + [[self window] themeProvider]->ShouldIncreaseContrast()) |
| .DrawInRect(bounds, NSCompositeSourceOver, alpha); |
| } |
| @@ -598,10 +630,26 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| return [[controller_ closeButton] iconColor]; |
| } |
| +- (void)accessibilityOptionsDidChange:(id)ignored { |
| + [self updateLabelFont]; |
| + [self setNeedsDisplay:YES]; |
| +} |
| + |
| +- (void)updateLabelFont { |
| + CGFloat fontSize = [titleViewCell_ font].pointSize; |
| + if ([[self window] themeProvider]->ShouldIncreaseContrast() && |
| + state_ == NSOnState) { |
| + [titleViewCell_ setFont:[NSFont boldSystemFontOfSize:fontSize]]; |
| + } else { |
| + [titleViewCell_ setFont:[NSFont systemFontOfSize:fontSize]]; |
| + } |
| +} |
| + |
| - (void)setState:(NSCellStateValue)state { |
| if (state_ == state) |
| return; |
| state_ = state; |
| + [self updateLabelFont]; |
| [self setNeedsDisplay:YES]; |
| } |
| @@ -821,8 +869,7 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| @end // @implementation TabView(Private) |
| - |
| -@implementation TabView(MaterialDesign) |
| +@implementation TabImageMaker |
| + (NSBezierPath*)tabLeftEdgeBezierPathForContext:(CGContextRef)context { |
| NSBezierPath* bezierPath = [NSBezierPath bezierPath]; |
| @@ -874,7 +921,7 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| CGContextRef context = static_cast<CGContextRef>( |
| [[NSGraphicsContext currentContext] graphicsPort]); |
| - [TabView setTabEdgeStrokeColor]; |
| + [self setTabEdgeStrokeColor]; |
| [[self tabLeftEdgeBezierPathForContext:context] stroke]; |
| } |
| @@ -896,7 +943,7 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| [translationTransform translateXBy:0 yBy:-1 + lineWidth / 2.]; |
| [middleEdgePath transformUsingAffineTransform:translationTransform]; |
| - [TabView setTabEdgeStrokeColor]; |
| + [self setTabEdgeStrokeColor]; |
| [middleEdgePath stroke]; |
| } |
| @@ -912,7 +959,7 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| [transform translateXBy:-18 yBy:0]; |
| [leftEdgePath transformUsingAffineTransform:transform]; |
| - [TabView setTabEdgeStrokeColor]; |
| + [self setTabEdgeStrokeColor]; |
| [leftEdgePath stroke]; |
| } |
| @@ -951,4 +998,16 @@ CGFloat LineWidthFromContext(CGContextRef context) { |
| [bezierPath fill]; |
| } |
| -@end // @implementation TabView(MaterialDesign) |
| +@end |
| + |
| +@implementation TabHeavyImageMaker |
| + |
| +// For "Increase Contrast" mode, use flat black instead of semitransparent black |
| +// for the tab edge stroke. |
| ++ (void)setTabEdgeStrokeColor { |
| + static NSColor* heavyStrokeColor = |
| + [skia::SkColorToSRGBNSColor(SK_ColorBLACK) retain]; |
| + [heavyStrokeColor set]; |
| +} |
| + |
| +@end |