| Index: chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
|
| index 72315e8dc924ab3fff8e29d13f1913f587522420..e0726749932e1ff59d7655f05cf9be3780182e1e 100644
|
| --- a/chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
|
| +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
|
| @@ -7,7 +7,6 @@
|
| #include "base/mac/foundation_util.h"
|
| #include "base/mac/sdk_forward_declarations.h"
|
| #import "chrome/browser/ui/cocoa/image_button_cell.h"
|
| -#import "chrome/browser/ui/cocoa/themed_window.h"
|
| #import "chrome/browser/ui/cocoa/view_id_util.h"
|
| #include "skia/ext/skia_utils_mac.h"
|
| #import "ui/base/cocoa/nsview_additions.h"
|
| @@ -105,9 +104,9 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
| [fillColor set];
|
| [roundedRectPath fill];
|
|
|
| - // Compute the icon's location and draw it there.
|
| - CGFloat iconInset =
|
| - (kMDButtonBounds.size.width - kMDButtonIconSize.width) / 2;
|
| + // Center the icon within the button.
|
| + NSSize iconSize = [imageRep.icon size];
|
| + CGFloat iconInset = (kMDButtonBounds.size.width - iconSize.width) / 2;
|
| NSRect iconDestRect = NSInsetRect(kMDButtonBounds, iconInset, iconInset);
|
| [imageRep.icon drawInRect:iconDestRect
|
| fromRect:NSZeroRect
|
| @@ -125,9 +124,6 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
| // background.
|
| - (NSImage*)imageForIcon:(NSImage*)iconImage
|
| withBackgroundStyle:(ToolbarButtonImageBackgroundStyle)style;
|
| -// Creates and assigns images for the button's various states (pressed, hover,
|
| -// etc.).
|
| -- (void)setImagesFromIconId:(gfx::VectorIconId)iconId;
|
| // Implemented to set the button's icon when added to the browser window. We
|
| // can't set the image before this because its appearance depends upon the
|
| // browser window's theme.
|
| @@ -140,6 +136,14 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
|
|
| @synthesize handleMiddleClick = handleMiddleClick_;
|
|
|
| ++ (NSSize)toolbarButtonSize {
|
| + if (!ui::MaterialDesignController::IsModeMaterial()) {
|
| + return NSMakeSize(29, 29);
|
| + }
|
| +
|
| + return kMDButtonBounds.size;
|
| +}
|
| +
|
| - (void)otherMouseDown:(NSEvent*)theEvent {
|
| if (![self shouldHandleEvent:theEvent]) {
|
| [super otherMouseDown:theEvent];
|
| @@ -187,7 +191,24 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
| yRadius:2] fill];
|
| }
|
|
|
| -- (SkColor)iconColor:(BOOL)themeIsDark {
|
| +- (gfx::VectorIconId)vectorIconId {
|
| + switch ([self viewID]) {
|
| + case VIEW_ID_BACK_BUTTON:
|
| + return gfx::VectorIconId::NAVIGATE_BACK;
|
| + case VIEW_ID_FORWARD_BUTTON:
|
| + return gfx::VectorIconId::NAVIGATE_FORWARD;
|
| + case VIEW_ID_HOME_BUTTON:
|
| + return gfx::VectorIconId::NAVIGATE_HOME;
|
| + case VIEW_ID_APP_MENU:
|
| + return gfx::VectorIconId::BROWSER_TOOLS;
|
| + default:
|
| + break;
|
| + }
|
| +
|
| + return gfx::VectorIconId::VECTOR_ICON_NONE;
|
| +}
|
| +
|
| +- (SkColor)vectorIconColor:(BOOL)themeIsDark {
|
| return themeIsDark ? SK_ColorWHITE : SkColorSetRGB(0x5A, 0x5A, 0x5A);
|
| }
|
|
|
| @@ -229,26 +250,51 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
| return image;
|
| }
|
|
|
| -- (void)setImagesFromIconId:(gfx::VectorIconId)iconId {
|
| - // Compute the normal and disabled icon colors.
|
| - BOOL isDarkTheme = [[self window] hasDarkTheme];
|
| - const SkColor iconColor = [self iconColor:isDarkTheme];
|
| - CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF;
|
| - const SkColor normalColor = SkColorSetA(iconColor, normalAlpha);
|
| - const SkColor disabledColor = SkColorSetA(iconColor, 0x33);
|
| +- (void)setImage:(NSImage*)anImage {
|
| + [super setImage:anImage];
|
| + if (ui::MaterialDesignController::IsModeMaterial()) {
|
| + [self resetButtonStateImages];
|
| + }
|
| +}
|
| +
|
| +- (void)resetButtonStateImages {
|
| + DCHECK(ui::MaterialDesignController::IsModeMaterial());
|
|
|
| - // Create the normal and disabled state icons. These icons are
|
| - // always the same shape, but use a different color.
|
| NSImage* normalIcon = nil;
|
| NSImage* disabledIcon = nil;
|
| - if (iconId == gfx::VectorIconId::BROWSER_TOOLS) {
|
| - normalIcon = [self browserToolsIconForFillColor:normalColor];
|
| - disabledIcon = [self browserToolsIconForFillColor:disabledColor];
|
| +
|
| + gfx::VectorIconId iconId = [self vectorIconId];
|
| + if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) {
|
| + // If the button does not have a vector icon id (e.g. it's an extension
|
| + // button), use its image.
|
| + normalIcon = disabledIcon = [self image];
|
| } else {
|
| - normalIcon = NSImageFromImageSkia(
|
| - gfx::CreateVectorIcon(iconId, kMDButtonIconSize.width, normalColor));
|
| - disabledIcon = NSImageFromImageSkia(
|
| - gfx::CreateVectorIcon(iconId, kMDButtonIconSize.width, disabledColor));
|
| + // Compute the normal and disabled vector icon colors.
|
| + BOOL isDarkTheme = [[self window] hasDarkTheme];
|
| + const SkColor vectorIconColor = [self vectorIconColor:isDarkTheme];
|
| + CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF;
|
| + const SkColor normalColor = SkColorSetA(vectorIconColor, normalAlpha);
|
| + const SkColor disabledColor = SkColorSetA(vectorIconColor, 0x33);
|
| +
|
| + // Create the normal and disabled state icons. These icons are always the
|
| + // same shape but use a different color.
|
| + if (iconId == gfx::VectorIconId::BROWSER_TOOLS) {
|
| + normalIcon = [self browserToolsIconForFillColor:normalColor];
|
| + disabledIcon = [self browserToolsIconForFillColor:disabledColor];
|
| + } else {
|
| + normalIcon = NSImageFromImageSkia(
|
| + gfx::CreateVectorIcon(iconId,
|
| + kMDButtonIconSize.width,
|
| + normalColor));
|
| +
|
| + // The home button has no icon for its disabled state.
|
| + if (iconId != gfx::VectorIconId::NAVIGATE_RELOAD) {
|
| + disabledIcon = NSImageFromImageSkia(
|
| + gfx::CreateVectorIcon(iconId,
|
| + kMDButtonIconSize.width,
|
| + disabledColor));
|
| + }
|
| + }
|
| }
|
|
|
| ImageButtonCell* theCell = base::mac::ObjCCast<ImageButtonCell>([self cell]);
|
| @@ -257,68 +303,37 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
|
|
| // Determine the appropriate image background style for the hover and pressed
|
| // states.
|
| - ToolbarButtonImageBackgroundStyle hoverStyle;
|
| - ToolbarButtonImageBackgroundStyle pressedStyle;
|
| + ToolbarButtonImageBackgroundStyle hoverStyle =
|
| + ToolbarButtonImageBackgroundStyle::HOVER;
|
| + ToolbarButtonImageBackgroundStyle pressedStyle =
|
| + ToolbarButtonImageBackgroundStyle::PRESSED;
|
| +
|
| + // Use the themed style for custom themes and Incognito mode.
|
| const ui::ThemeProvider* themeProvider = [[self window] themeProvider];
|
| - bool isNonIncognitoSystemTheme = themeProvider &&
|
| - !themeProvider->InIncognitoMode() && themeProvider->UsingSystemTheme();
|
| - // Use the regular style only when using the system (i.e. non-custom) theme
|
| - // and not in Incognito mode.
|
| - if (isNonIncognitoSystemTheme) {
|
| - hoverStyle = ToolbarButtonImageBackgroundStyle::HOVER;
|
| - pressedStyle = ToolbarButtonImageBackgroundStyle::PRESSED;
|
| - } else {
|
| + bool incongitoMode = themeProvider && themeProvider->InIncognitoMode();
|
| + bool usingACustomTheme = themeProvider && !themeProvider->UsingSystemTheme();
|
| + if (usingACustomTheme || incongitoMode) {
|
| hoverStyle = ToolbarButtonImageBackgroundStyle::HOVER_THEMED;
|
| pressedStyle = ToolbarButtonImageBackgroundStyle::PRESSED_THEMED;
|
| }
|
|
|
| - // Create and set the image for the hover state.
|
| + // Create and set the hover state image.
|
| NSImage* hoverImage =
|
| [self imageForIcon:normalIcon withBackgroundStyle:hoverStyle];
|
| [theCell setImage:hoverImage
|
| forButtonState:image_button_cell::kHoverState];
|
|
|
| - // Create and set the image for the pressed state.
|
| + // Create and set the pressed state image.
|
| NSImage* pressedImage =
|
| [self imageForIcon:normalIcon withBackgroundStyle:pressedStyle];
|
| [theCell setImage:pressedImage
|
| forButtonState:image_button_cell::kPressedState];
|
|
|
| - // Set the image for the disabled state, which is just the disabled icon,
|
| - // except if this is the home button.
|
| - if (iconId == gfx::VectorIconId::NAVIGATE_RELOAD) {
|
| - [theCell setImage:nil forButtonState:image_button_cell::kDisabledState];
|
| - } else {
|
| - [theCell setImage:disabledIcon
|
| - forButtonState:image_button_cell::kDisabledState];
|
| - }
|
| - [self setNeedsDisplay:YES];
|
| -}
|
| -
|
| -- (void)resetIcons {
|
| - // Compute the button's icon.
|
| - gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE;
|
| - switch ([self viewID]) {
|
| - case VIEW_ID_BACK_BUTTON:
|
| - icon_id = gfx::VectorIconId::NAVIGATE_BACK;
|
| - break;
|
| - case VIEW_ID_FORWARD_BUTTON:
|
| - icon_id = gfx::VectorIconId::NAVIGATE_FORWARD;
|
| - break;
|
| - case VIEW_ID_HOME_BUTTON:
|
| - icon_id = gfx::VectorIconId::NAVIGATE_HOME;
|
| - break;
|
| - case VIEW_ID_APP_MENU:
|
| - icon_id = gfx::VectorIconId::BROWSER_TOOLS;
|
| - break;
|
| - default:
|
| - break;
|
| - }
|
| + // Set the disabled state image.
|
| + [theCell setImage:disabledIcon
|
| + forButtonState:image_button_cell::kDisabledState];
|
|
|
| - // Set it.
|
| - if (icon_id != gfx::VectorIconId::VECTOR_ICON_NONE) {
|
| - [self setImagesFromIconId:icon_id];
|
| - }
|
| + [self setNeedsDisplay:YES];
|
| }
|
|
|
| - (void)viewDidMoveToWindow {
|
| @@ -326,14 +341,17 @@ const NSSize kMDButtonIconSize = NSMakeSize(16, 16);
|
| // window so that we can configure its appearance based on the window's
|
| // theme.
|
| if ([self window] && ui::MaterialDesignController::IsModeMaterial()) {
|
| - [self resetIcons];
|
| + [self resetButtonStateImages];
|
| }
|
| }
|
|
|
| // ThemedWindowDrawing implementation.
|
|
|
| - (void)windowDidChangeTheme {
|
| - [self resetIcons];
|
| + // Update the hover and pressed image backgrounds to match the current theme.
|
| + if (ui::MaterialDesignController::IsModeMaterial()) {
|
| + [self resetButtonStateImages];
|
| + }
|
| }
|
|
|
| - (void)windowDidChangeActive {
|
|
|