| 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/new_tab_button.h" | 5 #import "chrome/browser/ui/cocoa/new_tab_button.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 #include "chrome/browser/ui/cocoa/l10n_util.h" | 10 #include "chrome/browser/ui/cocoa/l10n_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 const NSSize newTabButtonImageSize = { 34, 18 }; | 28 const NSSize newTabButtonImageSize = { 34, 18 }; |
| 29 | 29 |
| 30 const CGFloat k7PercentAlpha = 0.07; | 30 const CGFloat k7PercentAlpha = 0.07; |
| 31 const CGFloat k8PercentAlpha = 0.08; | 31 const CGFloat k8PercentAlpha = 0.08; |
| 32 const CGFloat k10PercentAlpha = 0.1; | 32 const CGFloat k10PercentAlpha = 0.1; |
| 33 const CGFloat k20PercentAlpha = 0.2; | 33 const CGFloat k20PercentAlpha = 0.2; |
| 34 const CGFloat k25PercentAlpha = 0.25; | 34 const CGFloat k25PercentAlpha = 0.25; |
| 35 | 35 |
| 36 NSImage* GetMaskImageFromCell(NewTabButtonCell* aCell) { | 36 NSImage* GetMaskImageFromCell(NewTabButtonCell* aCell) { |
| 37 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 38 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 39 return bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); | |
| 40 } | |
| 41 return [aCell imageForState:image_button_cell::kDefaultState view:nil]; | 37 return [aCell imageForState:image_button_cell::kDefaultState view:nil]; |
| 42 } | 38 } |
| 43 | 39 |
| 44 // Creates an NSImage with size |size| and bitmap image representations for both | 40 // Creates an NSImage with size |size| and bitmap image representations for both |
| 45 // 1x and 2x scale factors. |drawingHandler| is called once for every scale | 41 // 1x and 2x scale factors. |drawingHandler| is called once for every scale |
| 46 // factor. This is similar to -[NSImage imageWithSize:flipped:drawingHandler:], | 42 // factor. This is similar to -[NSImage imageWithSize:flipped:drawingHandler:], |
| 47 // but this function always evaluates drawingHandler eagerly, and it works on | 43 // but this function always evaluates drawingHandler eagerly, and it works on |
| 48 // 10.6 and 10.7. | 44 // 10.6 and 10.7. |
| 49 NSImage* CreateImageWithSize(NSSize size, | 45 NSImage* CreateImageWithSize(NSSize size, |
| 50 void (^drawingHandler)(NSSize)) { | 46 void (^drawingHandler)(NSSize)) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 [self setImages]; | 242 [self setImages]; |
| 247 } | 243 } |
| 248 } | 244 } |
| 249 | 245 |
| 250 - (void)setImages { | 246 - (void)setImages { |
| 251 const ui::ThemeProvider* theme = [[self window] themeProvider]; | 247 const ui::ThemeProvider* theme = [[self window] themeProvider]; |
| 252 if (!theme) { | 248 if (!theme) { |
| 253 return; | 249 return; |
| 254 } | 250 } |
| 255 | 251 |
| 256 // The old way of doing things. | |
| 257 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 258 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 259 NSImage* mask = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); | |
| 260 NSImage* normal = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON).ToNSImage(); | |
| 261 NSImage* hover = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_H).ToNSImage(); | |
| 262 NSImage* pressed = rb.GetNativeImageNamed(IDR_NEWTAB_BUTTON_P).ToNSImage(); | |
| 263 | |
| 264 NSImage* foreground = ApplyMask( | |
| 265 theme->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND), mask); | |
| 266 | |
| 267 [[self cell] setImage:Overlay(foreground, normal, 1.0) | |
| 268 forButtonState:image_button_cell::kDefaultState]; | |
| 269 [[self cell] setImage:Overlay(foreground, hover, 1.0) | |
| 270 forButtonState:image_button_cell::kHoverState]; | |
| 271 [[self cell] setImage:Overlay(foreground, pressed, 1.0) | |
| 272 forButtonState:image_button_cell::kPressedState]; | |
| 273 | |
| 274 // IDR_THEME_TAB_BACKGROUND_INACTIVE is only used with the default theme. | |
| 275 if (theme->UsingSystemTheme()) { | |
| 276 const CGFloat alpha = tabs::kImageNoFocusAlpha; | |
| 277 NSImage* background = ApplyMask( | |
| 278 theme->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE), mask); | |
| 279 [[self cell] setImage:Overlay(background, normal, alpha) | |
| 280 forButtonState: | |
| 281 image_button_cell::kDefaultStateBackground]; | |
| 282 [[self cell] setImage:Overlay(background, hover, alpha) | |
| 283 forButtonState:image_button_cell::kHoverStateBackground]; | |
| 284 } else { | |
| 285 [[self cell] setImage:nil | |
| 286 forButtonState: | |
| 287 image_button_cell::kDefaultStateBackground]; | |
| 288 [[self cell] setImage:nil | |
| 289 forButtonState:image_button_cell::kHoverStateBackground]; | |
| 290 } | |
| 291 return; | |
| 292 } | |
| 293 | |
| 294 NSImage* mask = [self imageWithFillColor:[NSColor whiteColor]]; | 252 NSImage* mask = [self imageWithFillColor:[NSColor whiteColor]]; |
| 295 NSImage* normal = | 253 NSImage* normal = |
| 296 [self imageForState:image_button_cell::kDefaultState theme:theme]; | 254 [self imageForState:image_button_cell::kDefaultState theme:theme]; |
| 297 NSImage* hover = | 255 NSImage* hover = |
| 298 [self imageForState:image_button_cell::kHoverState theme:theme]; | 256 [self imageForState:image_button_cell::kHoverState theme:theme]; |
| 299 NSImage* pressed = | 257 NSImage* pressed = |
| 300 [self imageForState:image_button_cell::kPressedState theme:theme]; | 258 [self imageForState:image_button_cell::kPressedState theme:theme]; |
| 301 NSImage* normalBackground = nil; | 259 NSImage* normalBackground = nil; |
| 302 NSImage* hoverBackground = nil; | 260 NSImage* hoverBackground = nil; |
| 303 | 261 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 [fillColor set]; | 493 [fillColor set]; |
| 536 CGContextRef context = static_cast<CGContextRef>( | 494 CGContextRef context = static_cast<CGContextRef>( |
| 537 [[NSGraphicsContext currentContext] graphicsPort]); | 495 [[NSGraphicsContext currentContext] graphicsPort]); |
| 538 CGFloat lineWidth = LineWidthFromContext(context); | 496 CGFloat lineWidth = LineWidthFromContext(context); |
| 539 [[NewTabButton newTabButtonBezierPathWithLineWidth:lineWidth] fill]; | 497 [[NewTabButton newTabButtonBezierPathWithLineWidth:lineWidth] fill]; |
| 540 [image unlockFocus]; | 498 [image unlockFocus]; |
| 541 return image; | 499 return image; |
| 542 } | 500 } |
| 543 | 501 |
| 544 @end | 502 @end |
| OLD | NEW |