| 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 #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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 - (void)viewDidMoveToWindow; | 146 - (void)viewDidMoveToWindow; |
| 147 | 147 |
| 148 @end | 148 @end |
| 149 | 149 |
| 150 | 150 |
| 151 @implementation ToolbarButton | 151 @implementation ToolbarButton |
| 152 | 152 |
| 153 @synthesize handleMiddleClick = handleMiddleClick_; | 153 @synthesize handleMiddleClick = handleMiddleClick_; |
| 154 | 154 |
| 155 + (NSSize)toolbarButtonSize { | 155 + (NSSize)toolbarButtonSize { |
| 156 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 157 return NSMakeSize(29, 29); | |
| 158 } | |
| 159 | |
| 160 return kMDButtonBounds.size; | 156 return kMDButtonBounds.size; |
| 161 } | 157 } |
| 162 | 158 |
| 163 - (void)otherMouseDown:(NSEvent*)theEvent { | 159 - (void)otherMouseDown:(NSEvent*)theEvent { |
| 164 if (![self shouldHandleEvent:theEvent]) { | 160 if (![self shouldHandleEvent:theEvent]) { |
| 165 [super otherMouseDown:theEvent]; | 161 [super otherMouseDown:theEvent]; |
| 166 return; | 162 return; |
| 167 } | 163 } |
| 168 | 164 |
| 169 NSEvent* nextEvent = theEvent; | 165 NSEvent* nextEvent = theEvent; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return themeIsDark ? SK_ColorWHITE : SkColorSetRGB(0x5A, 0x5A, 0x5A); | 224 return themeIsDark ? SK_ColorWHITE : SkColorSetRGB(0x5A, 0x5A, 0x5A); |
| 229 } | 225 } |
| 230 | 226 |
| 231 - (NSImage*)browserToolsIconForFillColor:(SkColor)fillColor { | 227 - (NSImage*)browserToolsIconForFillColor:(SkColor)fillColor { |
| 232 // Create a |BrowserToolsImageRep| to draw the browser tools icon using | 228 // Create a |BrowserToolsImageRep| to draw the browser tools icon using |
| 233 // the provided fill color. | 229 // the provided fill color. |
| 234 base::scoped_nsobject<BrowserToolsImageRep> imageRep( | 230 base::scoped_nsobject<BrowserToolsImageRep> imageRep( |
| 235 [[BrowserToolsImageRep alloc] | 231 [[BrowserToolsImageRep alloc] |
| 236 initWithDrawSelector:@selector(drawBrowserToolsIcon:) | 232 initWithDrawSelector:@selector(drawBrowserToolsIcon:) |
| 237 delegate:[BrowserToolsImageRep class]]); | 233 delegate:[BrowserToolsImageRep class]]); |
| 238 if (!ui::MaterialDesignController::IsModeMaterial()) { | 234 [imageRep setFillColor:skia::SkColorToSRGBNSColor(fillColor)]; |
| 239 [imageRep setFillColor:skia::SkColorToCalibratedNSColor(fillColor)]; | |
| 240 } else { | |
| 241 [imageRep setFillColor:skia::SkColorToSRGBNSColor(fillColor)]; | |
| 242 } | |
| 243 | 235 |
| 244 // Create the image from the image rep. | 236 // Create the image from the image rep. |
| 245 NSImage* browserToolsIcon = | 237 NSImage* browserToolsIcon = |
| 246 [[[NSImage alloc] initWithSize:kMDButtonIconSize] autorelease]; | 238 [[[NSImage alloc] initWithSize:kMDButtonIconSize] autorelease]; |
| 247 [browserToolsIcon setCacheMode:NSImageCacheAlways]; | 239 [browserToolsIcon setCacheMode:NSImageCacheAlways]; |
| 248 [browserToolsIcon addRepresentation:imageRep]; | 240 [browserToolsIcon addRepresentation:imageRep]; |
| 249 | 241 |
| 250 return browserToolsIcon; | 242 return browserToolsIcon; |
| 251 } | 243 } |
| 252 | 244 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 // Create the image from the image rep. | 256 // Create the image from the image rep. |
| 265 NSImage* image = | 257 NSImage* image = |
| 266 [[[NSImage alloc] initWithSize:kMDButtonBounds.size] autorelease]; | 258 [[[NSImage alloc] initWithSize:kMDButtonBounds.size] autorelease]; |
| 267 [image setCacheMode:NSImageCacheAlways]; | 259 [image setCacheMode:NSImageCacheAlways]; |
| 268 [image addRepresentation:imageRep]; | 260 [image addRepresentation:imageRep]; |
| 269 | 261 |
| 270 return image; | 262 return image; |
| 271 } | 263 } |
| 272 | 264 |
| 273 - (NSImage*)image { | 265 - (NSImage*)image { |
| 274 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 275 return [super image]; | |
| 276 } | |
| 277 // setImage: stores the image in an ivar. | 266 // setImage: stores the image in an ivar. |
| 278 return image_.get(); | 267 return image_.get(); |
| 279 } | 268 } |
| 280 | 269 |
| 281 - (void)setImage:(NSImage*)anImage { | 270 - (void)setImage:(NSImage*)anImage { |
| 282 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 283 [super setImage:anImage]; | |
| 284 return; | |
| 285 } | |
| 286 | |
| 287 // We want to set the default image as the image for kDefaultState. Setting it | 271 // We want to set the default image as the image for kDefaultState. Setting it |
| 288 // as the default image (via setImage:) can cause ghosting from the two | 272 // as the default image (via setImage:) can cause ghosting from the two |
| 289 // default images being drawn over each other. However we also need to keep | 273 // default images being drawn over each other. However we also need to keep |
| 290 // the default image around for resetButtonStateImages, so stick it in an | 274 // the default image around for resetButtonStateImages, so stick it in an |
| 291 // ivar. | 275 // ivar. |
| 292 image_.reset([anImage retain]); | 276 image_.reset([anImage retain]); |
| 293 [self resetButtonStateImages]; | 277 [self resetButtonStateImages]; |
| 294 } | 278 } |
| 295 | 279 |
| 296 - (void)resetButtonStateImages { | 280 - (void)resetButtonStateImages { |
| 297 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | |
| 298 | |
| 299 NSImage* normalIcon = nil; | 281 NSImage* normalIcon = nil; |
| 300 NSImage* disabledIcon = nil; | 282 NSImage* disabledIcon = nil; |
| 301 BOOL isDarkTheme = NO; | 283 BOOL isDarkTheme = NO; |
| 302 | 284 |
| 303 gfx::VectorIconId iconId = [self vectorIconId]; | 285 gfx::VectorIconId iconId = [self vectorIconId]; |
| 304 if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) { | 286 if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) { |
| 305 // If the button does not have a vector icon id (e.g. it's an extension | 287 // If the button does not have a vector icon id (e.g. it's an extension |
| 306 // button), use its image. The hover, etc. images will be created using | 288 // button), use its image. The hover, etc. images will be created using |
| 307 // imageForIcon:withBackgroundStyle: so do the same for the default image. | 289 // imageForIcon:withBackgroundStyle: so do the same for the default image. |
| 308 // If we don't do this, the icon may not appear in the same place as in the | 290 // If we don't do this, the icon may not appear in the same place as in the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 [theCell setImage:disabledIcon | 358 [theCell setImage:disabledIcon |
| 377 forButtonState:image_button_cell::kDisabledState]; | 359 forButtonState:image_button_cell::kDisabledState]; |
| 378 | 360 |
| 379 [self setNeedsDisplay:YES]; | 361 [self setNeedsDisplay:YES]; |
| 380 } | 362 } |
| 381 | 363 |
| 382 - (void)viewDidMoveToWindow { | 364 - (void)viewDidMoveToWindow { |
| 383 // In Material Design we want to catch when the button is attached to its | 365 // In Material Design we want to catch when the button is attached to its |
| 384 // window so that we can configure its appearance based on the window's | 366 // window so that we can configure its appearance based on the window's |
| 385 // theme. | 367 // theme. |
| 386 if ([self window] && ui::MaterialDesignController::IsModeMaterial()) { | 368 if ([self window]) { |
| 387 [self resetButtonStateImages]; | 369 [self resetButtonStateImages]; |
| 388 } | 370 } |
| 389 } | 371 } |
| 390 | 372 |
| 391 // ThemedWindowDrawing implementation. | 373 // ThemedWindowDrawing implementation. |
| 392 | 374 |
| 393 - (void)windowDidChangeTheme { | 375 - (void)windowDidChangeTheme { |
| 394 // Update the hover and pressed image backgrounds to match the current theme. | 376 // Update the hover and pressed image backgrounds to match the current theme. |
| 395 if (ui::MaterialDesignController::IsModeMaterial()) { | 377 [self resetButtonStateImages]; |
| 396 [self resetButtonStateImages]; | |
| 397 } | |
| 398 } | 378 } |
| 399 | 379 |
| 400 - (void)windowDidChangeActive { | 380 - (void)windowDidChangeActive { |
| 401 } | 381 } |
| 402 | 382 |
| 403 @end | 383 @end |
| OLD | NEW |