• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/global_error/global_error.h"
12 #include "chrome/browser/upgrade_detector.h"
13 #include "ui/gfx/animation/animation_delegate.h"
14 #include "ui/gfx/image/image_skia.h"
15 
16 namespace gfx {
17 class Canvas;
18 class MultiAnimation;
19 class Rect;
20 }
21 namespace ui {
22 class ThemeProvider;
23 }
24 
25 // This class is used to draw the wrench icon. It can signify severity levels
26 // by changing the wrench icon to different colors.
27 class WrenchIconPainter : gfx::AnimationDelegate {
28  public:
29   enum BezelType {
30     BEZEL_NONE,
31     BEZEL_HOVER,
32     BEZEL_PRESSED,
33   };
34 
35   enum Severity {
36     SEVERITY_NONE,
37     SEVERITY_LOW,
38     SEVERITY_MEDIUM,
39     SEVERITY_HIGH,
40   };
41 
42   class Delegate {
43    public:
44     virtual void ScheduleWrenchIconPaint() = 0;
45    protected:
~Delegate()46     virtual ~Delegate() {}
47   };
48 
49   // Map an upgrade level to a severity level.
50   static Severity SeverityFromUpgradeLevel(
51       UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);
52 
53   // Checks if the wrench icon should be animated for the given upgrade level.
54   static bool ShouldAnimateUpgradeLevel(
55       UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);
56 
57   // Get the severity level for global errors.
58   static Severity GlobalErrorSeverity();
59 
60   explicit WrenchIconPainter(Delegate* delegate);
61   virtual ~WrenchIconPainter();
62 
63   // If |severity| is not |SEVERITY_NONE| then the wrench icon is colored to
64   // match the severity level.
65   void SetSeverity(Severity severity, bool animate);
66 
67   // A badge drawn on the top left.
set_badge(const gfx::ImageSkia & badge)68   void set_badge(const gfx::ImageSkia& badge) { badge_ = badge; }
69 
70   void Paint(gfx::Canvas* canvas,
71              ui::ThemeProvider* theme_provider,
72              const gfx::Rect& rect,
73              BezelType bezel_type);
74 
75  private:
76   FRIEND_TEST_ALL_PREFIXES(WrenchIconPainterTest, PaintCallback);
77 
78   // AnimationDelegate:
79   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
80 
81   // Gets the image ID used to draw bars for the current severity level.
82   int GetCurrentSeverityImageID() const;
83 
84   Delegate* delegate_;
85   Severity severity_;
86   gfx::ImageSkia badge_;
87   scoped_ptr<gfx::MultiAnimation> animation_;
88 
89   DISALLOW_COPY_AND_ASSIGN(WrenchIconPainter);
90 };
91 
92 #endif  // CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
93