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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h"
7 #import "chrome/browser/ui/cocoa/themed_window.h"
8 #include "ui/gfx/canvas_skia_paint.h"
9 #include "ui/gfx/rect.h"
11 class WrenchIconPainterDelegateMac : public WrenchIconPainter::Delegate {
13 explicit WrenchIconPainterDelegateMac(NSCell* cell) : cell_(cell) {}
14 virtual ~WrenchIconPainterDelegateMac() {}
16 virtual void ScheduleWrenchIconPaint() OVERRIDE {
17 [[cell_ controlView] setNeedsDisplay:YES];
23 DISALLOW_COPY_AND_ASSIGN(WrenchIconPainterDelegateMac);
26 @interface WrenchToolbarButtonCell ()
28 - (WrenchIconPainter::BezelType)currentBezelType;
31 @implementation WrenchToolbarButtonCell
33 - (id)initTextCell:(NSString*)text {
34 if ((self = [super initTextCell:text])) {
40 - (id)initWithCoder:(NSCoder*)decoder {
41 if ((self = [super initWithCoder:decoder])) {
47 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
48 gfx::CanvasSkiaPaint canvas(cellFrame, false);
49 canvas.set_composite_alpha(true);
50 canvas.SaveLayerAlpha(255 *
51 [self imageAlphaForWindowState:[controlView window]]);
52 ui::ThemeProvider* themeProvider = [[controlView window] themeProvider];
54 wrenchIconPainter_->Paint(&canvas,
55 [[controlView window] themeProvider],
56 gfx::Rect(NSRectToCGRect(cellFrame)),
57 [self currentBezelType]);
61 [self drawFocusRingWithFrame:cellFrame inView:controlView];
64 - (void)setSeverity:(WrenchIconPainter::Severity)severity
65 shouldAnimate:(BOOL)shouldAnimate {
66 wrenchIconPainter_->SetSeverity(severity, shouldAnimate);
70 delegate_.reset(new WrenchIconPainterDelegateMac(self));
71 wrenchIconPainter_.reset(new WrenchIconPainter(delegate_.get()));
74 - (WrenchIconPainter::BezelType)currentBezelType {
75 if ([self isHighlighted])
76 return WrenchIconPainter::BEZEL_PRESSED;
77 if ([self isMouseInside])
78 return WrenchIconPainter::BEZEL_HOVER;
79 return WrenchIconPainter::BEZEL_NONE;