[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / toolbar / wrench_toolbar_button_cell.mm
blob8425bff094b5a31986150c050c51aebfa61fcc5b
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 {
12  public:
13   explicit WrenchIconPainterDelegateMac(NSCell* cell) : cell_(cell) {}
14   virtual ~WrenchIconPainterDelegateMac() {}
16   virtual void ScheduleWrenchIconPaint() OVERRIDE {
17     [[cell_ controlView] setNeedsDisplay:YES];
18   }
20  private:
21   NSCell* cell_;
23   DISALLOW_COPY_AND_ASSIGN(WrenchIconPainterDelegateMac);
26 @interface WrenchToolbarButtonCell ()
27 - (void)commonInit;
28 - (WrenchIconPainter::BezelType)currentBezelType;
29 @end
31 @implementation WrenchToolbarButtonCell
33 - (id)initTextCell:(NSString*)text {
34   if ((self = [super initTextCell:text])) {
35     [self commonInit];
36   }
37   return self;
40 - (id)initWithCoder:(NSCoder*)decoder {
41   if ((self = [super initWithCoder:decoder])) {
42     [self commonInit];
43   }
44   return self;
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];
53   if (themeProvider) {
54     wrenchIconPainter_->Paint(&canvas,
55                               [[controlView window] themeProvider],
56                               gfx::Rect(NSRectToCGRect(cellFrame)),
57                               [self currentBezelType]);
58   }
59   canvas.Restore();
61   [self drawFocusRingWithFrame:cellFrame inView:controlView];
64 - (void)setSeverity:(WrenchIconPainter::Severity)severity
65       shouldAnimate:(BOOL)shouldAnimate {
66   wrenchIconPainter_->SetSeverity(severity, shouldAnimate);
69 - (void)commonInit {
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;
82 @end