| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #include "chrome/app/vector_icons/vector_icons.h" |
| 9 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 10 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/l10n_util.h" | 11 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 11 #import "chrome/browser/ui/cocoa/view_id_util.h" | 12 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 12 #include "skia/ext/skia_utils_mac.h" | 13 #include "skia/ext/skia_utils_mac.h" |
| 13 #import "ui/base/cocoa/nsview_additions.h" | 14 #import "ui/base/cocoa/nsview_additions.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
| 15 #include "ui/base/theme_provider.h" | 16 #include "ui/base/theme_provider.h" |
| 16 #include "ui/gfx/image/image_skia_util_mac.h" | 17 #include "ui/gfx/image/image_skia_util_mac.h" |
| 17 #include "ui/gfx/paint_vector_icon.h" | 18 #include "ui/gfx/paint_vector_icon.h" |
| 18 | 19 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return handleMiddleClick_ && [theEvent buttonNumber] == 2; | 198 return handleMiddleClick_ && [theEvent buttonNumber] == 2; |
| 198 } | 199 } |
| 199 | 200 |
| 200 - (void)drawFocusRingMask { | 201 - (void)drawFocusRingMask { |
| 201 // Match the hover image's bezel. | 202 // Match the hover image's bezel. |
| 202 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect([self bounds], 2, 2) | 203 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect([self bounds], 2, 2) |
| 203 xRadius:2 | 204 xRadius:2 |
| 204 yRadius:2] fill]; | 205 yRadius:2] fill]; |
| 205 } | 206 } |
| 206 | 207 |
| 207 - (gfx::VectorIconId)vectorIconId { | 208 - (const gfx::VectorIcon*)vectorIcon { |
| 208 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 209 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
| 209 switch ([self viewID]) { | 210 switch ([self viewID]) { |
| 210 case VIEW_ID_BACK_BUTTON: | 211 case VIEW_ID_BACK_BUTTON: |
| 211 return isRTL ? gfx::VectorIconId::NAVIGATE_FORWARD | 212 return isRTL ? &kNavigateForwardIcon : &kNavigateBackIcon; |
| 212 : gfx::VectorIconId::NAVIGATE_BACK; | |
| 213 case VIEW_ID_FORWARD_BUTTON: | 213 case VIEW_ID_FORWARD_BUTTON: |
| 214 return isRTL ? gfx::VectorIconId::NAVIGATE_BACK | 214 return isRTL ? &kNavigateBackIcon : &kNavigateForwardIcon; |
| 215 : gfx::VectorIconId::NAVIGATE_FORWARD; | |
| 216 case VIEW_ID_HOME_BUTTON: | 215 case VIEW_ID_HOME_BUTTON: |
| 217 return gfx::VectorIconId::NAVIGATE_HOME; | 216 return &kNavigateHomeIcon; |
| 218 case VIEW_ID_APP_MENU: | 217 case VIEW_ID_APP_MENU: |
| 219 return gfx::VectorIconId::BROWSER_TOOLS; | 218 return &kBrowserToolsIcon; |
| 220 default: | 219 default: |
| 221 break; | 220 break; |
| 222 } | 221 } |
| 223 | 222 |
| 224 return gfx::VectorIconId::VECTOR_ICON_NONE; | 223 return nullptr; |
| 225 } | 224 } |
| 226 | 225 |
| 227 - (SkColor)vectorIconColor:(BOOL)themeIsDark { | 226 - (SkColor)vectorIconColor:(BOOL)themeIsDark { |
| 228 return themeIsDark ? SK_ColorWHITE : SkColorSetRGB(0x5A, 0x5A, 0x5A); | 227 return themeIsDark ? SK_ColorWHITE : SkColorSetRGB(0x5A, 0x5A, 0x5A); |
| 229 } | 228 } |
| 230 | 229 |
| 231 - (NSImage*)browserToolsIconForFillColor:(SkColor)fillColor { | 230 - (NSImage*)browserToolsIconForFillColor:(SkColor)fillColor { |
| 232 // Create a |BrowserToolsImageRep| to draw the browser tools icon using | 231 // Create a |BrowserToolsImageRep| to draw the browser tools icon using |
| 233 // the provided fill color. | 232 // the provided fill color. |
| 234 base::scoped_nsobject<BrowserToolsImageRep> imageRep( | 233 base::scoped_nsobject<BrowserToolsImageRep> imageRep( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // ivar. | 278 // ivar. |
| 280 image_.reset([anImage retain]); | 279 image_.reset([anImage retain]); |
| 281 [self resetButtonStateImages]; | 280 [self resetButtonStateImages]; |
| 282 } | 281 } |
| 283 | 282 |
| 284 - (void)resetButtonStateImages { | 283 - (void)resetButtonStateImages { |
| 285 NSImage* normalIcon = nil; | 284 NSImage* normalIcon = nil; |
| 286 NSImage* disabledIcon = nil; | 285 NSImage* disabledIcon = nil; |
| 287 BOOL isDarkTheme = NO; | 286 BOOL isDarkTheme = NO; |
| 288 | 287 |
| 289 gfx::VectorIconId iconId = [self vectorIconId]; | 288 const gfx::VectorIcon* icon = [self vectorIcon]; |
| 290 if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) { | 289 if (!icon) { |
| 291 // If the button does not have a vector icon id (e.g. it's an extension | 290 // If the button does not have a vector icon (e.g. it's an extension |
| 292 // button), use its image. The hover, etc. images will be created using | 291 // button), use its image. The hover, etc. images will be created using |
| 293 // imageForIcon:withBackgroundStyle: so do the same for the default image. | 292 // imageForIcon:withBackgroundStyle: so do the same for the default image. |
| 294 // If we don't do this, the icon may not appear in the same place as in the | 293 // If we don't do this, the icon may not appear in the same place as in the |
| 295 // other states, causing the icon to appear to shift as you mouse over the | 294 // other states, causing the icon to appear to shift as you mouse over the |
| 296 // button. | 295 // button. |
| 297 NSImage* defaultImage = | 296 NSImage* defaultImage = |
| 298 [self imageForIcon:[self image] | 297 [self imageForIcon:[self image] |
| 299 withBackgroundStyle:ToolbarButtonImageBackgroundStyle::DEFAULT]; | 298 withBackgroundStyle:ToolbarButtonImageBackgroundStyle::DEFAULT]; |
| 300 normalIcon = disabledIcon = defaultImage; | 299 normalIcon = disabledIcon = defaultImage; |
| 301 } else { | 300 } else { |
| 302 // Compute the normal and disabled vector icon colors. | 301 // Compute the normal and disabled vector icon colors. |
| 303 isDarkTheme = [[self window] hasDarkTheme]; | 302 isDarkTheme = [[self window] hasDarkTheme]; |
| 304 const SkColor vectorIconColor = [self vectorIconColor:isDarkTheme]; | 303 const SkColor vectorIconColor = [self vectorIconColor:isDarkTheme]; |
| 305 CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF; | 304 CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF; |
| 306 const SkColor normalColor = SkColorSetA(vectorIconColor, normalAlpha); | 305 const SkColor normalColor = SkColorSetA(vectorIconColor, normalAlpha); |
| 307 const SkColor disabledColor = SkColorSetA(vectorIconColor, 0x33); | 306 const SkColor disabledColor = SkColorSetA(vectorIconColor, 0x33); |
| 308 | 307 |
| 309 // Create the normal and disabled state icons. These icons are always the | 308 // Create the normal and disabled state icons. These icons are always the |
| 310 // same shape but use a different color. | 309 // same shape but use a different color. |
| 311 if (iconId == gfx::VectorIconId::BROWSER_TOOLS) { | 310 if (icon == &kBrowserToolsIcon) { |
| 312 normalIcon = [self browserToolsIconForFillColor:normalColor]; | 311 normalIcon = [self browserToolsIconForFillColor:normalColor]; |
| 313 disabledIcon = [self browserToolsIconForFillColor:disabledColor]; | 312 disabledIcon = [self browserToolsIconForFillColor:disabledColor]; |
| 314 } else { | 313 } else { |
| 315 normalIcon = NSImageFromImageSkia( | 314 normalIcon = NSImageFromImageSkia( |
| 316 gfx::CreateVectorIcon(iconId, | 315 gfx::CreateVectorIcon(*icon, |
| 317 kMDButtonIconSize.width, | 316 kMDButtonIconSize.width, |
| 318 normalColor)); | 317 normalColor)); |
| 319 | 318 |
| 320 // The home button has no icon for its disabled state. | 319 // The home button has no icon for its disabled state. |
| 321 if (iconId != gfx::VectorIconId::NAVIGATE_RELOAD) { | 320 if (icon != &kNavigateReloadIcon) { |
| 322 disabledIcon = NSImageFromImageSkia( | 321 disabledIcon = NSImageFromImageSkia( |
| 323 gfx::CreateVectorIcon(iconId, | 322 gfx::CreateVectorIcon(*icon, |
| 324 kMDButtonIconSize.width, | 323 kMDButtonIconSize.width, |
| 325 disabledColor)); | 324 disabledColor)); |
| 326 } | 325 } |
| 327 } | 326 } |
| 328 } | 327 } |
| 329 | 328 |
| 330 ImageButtonCell* theCell = base::mac::ObjCCast<ImageButtonCell>([self cell]); | 329 ImageButtonCell* theCell = base::mac::ObjCCast<ImageButtonCell>([self cell]); |
| 331 // Set the image for the default state, which is just the icon. | 330 // Set the image for the default state, which is just the icon. |
| 332 [theCell setImage:normalIcon forButtonState:image_button_cell::kDefaultState]; | 331 [theCell setImage:normalIcon forButtonState:image_button_cell::kDefaultState]; |
| 333 | 332 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 377 |
| 379 - (void)windowDidChangeTheme { | 378 - (void)windowDidChangeTheme { |
| 380 // Update the hover and pressed image backgrounds to match the current theme. | 379 // Update the hover and pressed image backgrounds to match the current theme. |
| 381 [self resetButtonStateImages]; | 380 [self resetButtonStateImages]; |
| 382 } | 381 } |
| 383 | 382 |
| 384 - (void)windowDidChangeActive { | 383 - (void)windowDidChangeActive { |
| 385 } | 384 } |
| 386 | 385 |
| 387 @end | 386 @end |
| OLD | NEW |