Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm

Issue 1987053005: [Mac][Material Design] Fix toolbar icon hover bg for custom themes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "chrome/browser/ui/cocoa/image_button_cell.h" 9 #import "chrome/browser/ui/cocoa/image_button_cell.h"
10 #import "chrome/browser/ui/cocoa/view_id_util.h" 10 #import "chrome/browser/ui/cocoa/view_id_util.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // ivar. 287 // ivar.
288 image_.reset([anImage retain]); 288 image_.reset([anImage retain]);
289 [self resetButtonStateImages]; 289 [self resetButtonStateImages];
290 } 290 }
291 291
292 - (void)resetButtonStateImages { 292 - (void)resetButtonStateImages {
293 DCHECK(ui::MaterialDesignController::IsModeMaterial()); 293 DCHECK(ui::MaterialDesignController::IsModeMaterial());
294 294
295 NSImage* normalIcon = nil; 295 NSImage* normalIcon = nil;
296 NSImage* disabledIcon = nil; 296 NSImage* disabledIcon = nil;
297 BOOL isDarkTheme = NO;
297 298
298 gfx::VectorIconId iconId = [self vectorIconId]; 299 gfx::VectorIconId iconId = [self vectorIconId];
299 if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) { 300 if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) {
300 // If the button does not have a vector icon id (e.g. it's an extension 301 // If the button does not have a vector icon id (e.g. it's an extension
301 // button), use its image. The hover, etc. images will be created using 302 // button), use its image. The hover, etc. images will be created using
302 // imageForIcon:withBackgroundStyle: so do the same for the default image. 303 // imageForIcon:withBackgroundStyle: so do the same for the default image.
303 // If we don't do this, the icon may not appear in the same place as in the 304 // If we don't do this, the icon may not appear in the same place as in the
304 // other states, causing the icon to appear to shift as you mouse over the 305 // other states, causing the icon to appear to shift as you mouse over the
305 // button. 306 // button.
306 NSImage* defaultImage = 307 NSImage* defaultImage =
307 [self imageForIcon:[self image] 308 [self imageForIcon:[self image]
308 withBackgroundStyle:ToolbarButtonImageBackgroundStyle::DEFAULT]; 309 withBackgroundStyle:ToolbarButtonImageBackgroundStyle::DEFAULT];
309 normalIcon = disabledIcon = defaultImage; 310 normalIcon = disabledIcon = defaultImage;
310 } else { 311 } else {
311 // Compute the normal and disabled vector icon colors. 312 // Compute the normal and disabled vector icon colors.
312 BOOL isDarkTheme = [[self window] hasDarkTheme]; 313 isDarkTheme = [[self window] hasDarkTheme];
313 const SkColor vectorIconColor = [self vectorIconColor:isDarkTheme]; 314 const SkColor vectorIconColor = [self vectorIconColor:isDarkTheme];
314 CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF; 315 CGFloat normalAlpha = isDarkTheme ? 0xCC : 0xFF;
315 const SkColor normalColor = SkColorSetA(vectorIconColor, normalAlpha); 316 const SkColor normalColor = SkColorSetA(vectorIconColor, normalAlpha);
316 const SkColor disabledColor = SkColorSetA(vectorIconColor, 0x33); 317 const SkColor disabledColor = SkColorSetA(vectorIconColor, 0x33);
317 318
318 // Create the normal and disabled state icons. These icons are always the 319 // Create the normal and disabled state icons. These icons are always the
319 // same shape but use a different color. 320 // same shape but use a different color.
320 if (iconId == gfx::VectorIconId::BROWSER_TOOLS) { 321 if (iconId == gfx::VectorIconId::BROWSER_TOOLS) {
321 normalIcon = [self browserToolsIconForFillColor:normalColor]; 322 normalIcon = [self browserToolsIconForFillColor:normalColor];
322 disabledIcon = [self browserToolsIconForFillColor:disabledColor]; 323 disabledIcon = [self browserToolsIconForFillColor:disabledColor];
(...skipping 20 matching lines...) Expand all
343 // Determine the appropriate image background style for the hover and pressed 344 // Determine the appropriate image background style for the hover and pressed
344 // states. 345 // states.
345 ToolbarButtonImageBackgroundStyle hoverStyle = 346 ToolbarButtonImageBackgroundStyle hoverStyle =
346 ToolbarButtonImageBackgroundStyle::HOVER; 347 ToolbarButtonImageBackgroundStyle::HOVER;
347 ToolbarButtonImageBackgroundStyle pressedStyle = 348 ToolbarButtonImageBackgroundStyle pressedStyle =
348 ToolbarButtonImageBackgroundStyle::PRESSED; 349 ToolbarButtonImageBackgroundStyle::PRESSED;
349 350
350 // Use the themed style for custom themes and Incognito mode. 351 // Use the themed style for custom themes and Incognito mode.
351 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; 352 const ui::ThemeProvider* themeProvider = [[self window] themeProvider];
352 bool incongitoMode = themeProvider && themeProvider->InIncognitoMode(); 353 bool incongitoMode = themeProvider && themeProvider->InIncognitoMode();
353 bool usingACustomTheme = themeProvider && !themeProvider->UsingSystemTheme(); 354 if (isDarkTheme || incongitoMode) {
354 if (usingACustomTheme || incongitoMode) {
355 hoverStyle = ToolbarButtonImageBackgroundStyle::HOVER_THEMED; 355 hoverStyle = ToolbarButtonImageBackgroundStyle::HOVER_THEMED;
356 pressedStyle = ToolbarButtonImageBackgroundStyle::PRESSED_THEMED; 356 pressedStyle = ToolbarButtonImageBackgroundStyle::PRESSED_THEMED;
357 } 357 }
358 358
359 // Create and set the hover state image. 359 // Create and set the hover state image.
360 NSImage* hoverImage = 360 NSImage* hoverImage =
361 [self imageForIcon:normalIcon withBackgroundStyle:hoverStyle]; 361 [self imageForIcon:normalIcon withBackgroundStyle:hoverStyle];
362 [theCell setImage:hoverImage 362 [theCell setImage:hoverImage
363 forButtonState:image_button_cell::kHoverState]; 363 forButtonState:image_button_cell::kHoverState];
364 364
(...skipping 25 matching lines...) Expand all
390 // Update the hover and pressed image backgrounds to match the current theme. 390 // Update the hover and pressed image backgrounds to match the current theme.
391 if (ui::MaterialDesignController::IsModeMaterial()) { 391 if (ui::MaterialDesignController::IsModeMaterial()) {
392 [self resetButtonStateImages]; 392 [self resetButtonStateImages];
393 } 393 }
394 } 394 }
395 395
396 - (void)windowDidChangeActive { 396 - (void)windowDidChangeActive {
397 } 397 }
398 398
399 @end 399 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698