Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/app_toolbar_button_cell.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #import "chrome/browser/ui/cocoa/themed_window.h" | 8 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 9 #include "ui/gfx/canvas_skia_paint.h" | 9 #include "ui/gfx/canvas_skia_paint.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 | 11 |
| 12 class AppMenuIconPainterDelegateMac : public AppMenuIconPainter::Delegate { | |
| 13 public: | |
| 14 explicit AppMenuIconPainterDelegateMac(NSCell* cell) : cell_(cell) {} | |
| 15 ~AppMenuIconPainterDelegateMac() override {} | |
| 16 | |
| 17 void ScheduleAppMenuIconPaint() override { | |
| 18 [[cell_ controlView] setNeedsDisplay:YES]; | |
| 19 } | |
| 20 | |
| 21 private: | |
| 22 NSCell* cell_; | |
| 23 | |
| 24 DISALLOW_COPY_AND_ASSIGN(AppMenuIconPainterDelegateMac); | |
| 25 }; | |
| 26 | |
| 27 @interface AppToolbarButtonCell () | 12 @interface AppToolbarButtonCell () |
| 28 - (void)commonInit; | 13 - (void)commonInit; |
| 29 - (AppMenuIconPainter::BezelType)currentBezelType; | |
| 30 @end | 14 @end |
| 31 | 15 |
| 32 @implementation AppToolbarButtonCell | 16 @implementation AppToolbarButtonCell |
| 33 | 17 |
| 34 - (id)initTextCell:(NSString*)text { | 18 - (id)initTextCell:(NSString*)text { |
| 35 if ((self = [super initTextCell:text])) { | 19 if ((self = [super initTextCell:text])) { |
| 36 [self commonInit]; | 20 [self commonInit]; |
| 37 } | 21 } |
| 38 return self; | 22 return self; |
| 39 } | 23 } |
| 40 | 24 |
| 41 - (id)initWithCoder:(NSCoder*)decoder { | 25 - (id)initWithCoder:(NSCoder*)decoder { |
| 42 if ((self = [super initWithCoder:decoder])) { | 26 if ((self = [super initWithCoder:decoder])) { |
| 43 [self commonInit]; | 27 [self commonInit]; |
| 44 } | 28 } |
| 45 return self; | 29 return self; |
| 46 } | 30 } |
| 47 | 31 |
| 48 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 32 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 49 gfx::CanvasSkiaPaint canvas(cellFrame, false); | 33 gfx::CanvasSkiaPaint canvas(cellFrame, false); |
| 50 canvas.set_composite_alpha(true); | 34 canvas.set_composite_alpha(true); |
|
Elly Fong-Jones
2016/09/30 11:09:59
The overall effect of this method is now to apply
Evan Stade
2016/09/30 17:20:06
I don't think AppToolbarButtonCell is used or need
| |
| 51 canvas.SaveLayerAlpha(255 * | 35 canvas.SaveLayerAlpha(255 * |
| 52 [self imageAlphaForWindowState:[controlView window]]); | 36 [self imageAlphaForWindowState:[controlView window]]); |
| 53 const ui::ThemeProvider* themeProvider = [[controlView window] themeProvider]; | 37 |
| 54 if (themeProvider) { | |
| 55 iconPainter_->Paint(&canvas, [[controlView window] themeProvider], | |
| 56 gfx::Rect(NSRectToCGRect(cellFrame)), | |
| 57 [self currentBezelType]); | |
| 58 } | |
| 59 canvas.Restore(); | 38 canvas.Restore(); |
| 60 } | 39 } |
| 61 | 40 |
| 62 - (void)setSeverity:(AppMenuIconPainter::Severity)severity | |
| 63 shouldAnimate:(BOOL)shouldAnimate { | |
| 64 iconPainter_->SetSeverity(severity, shouldAnimate); | |
| 65 } | |
| 66 | |
| 67 - (void)commonInit { | 41 - (void)commonInit { |
| 68 delegate_.reset(new AppMenuIconPainterDelegateMac(self)); | |
| 69 iconPainter_.reset(new AppMenuIconPainter(delegate_.get())); | |
| 70 } | |
| 71 | |
| 72 - (AppMenuIconPainter::BezelType)currentBezelType { | |
| 73 if ([self isHighlighted]) | |
| 74 return AppMenuIconPainter::BEZEL_PRESSED; | |
| 75 if ([self isMouseInside]) | |
| 76 return AppMenuIconPainter::BEZEL_HOVER; | |
| 77 return AppMenuIconPainter::BEZEL_NONE; | |
| 78 } | 42 } |
| 79 | 43 |
| 80 @end | 44 @end |
| OLD | NEW |