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