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 #ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
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/base/animation/animation_delegate.h"
14 #include "ui/gfx/image/image_skia.h"
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
: ui::AnimationDelegate
{
44 virtual void ScheduleWrenchIconPaint() = 0;
46 virtual ~Delegate() {}
49 // Map an upgrade level to a severity level.
50 static Severity
SeverityFromUpgradeLevel(
51 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level
);
53 // Checks if the wrench icon should be animated for the given upgrade level.
54 static bool ShouldAnimateUpgradeLevel(
55 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level
);
57 // Get the severity level for global errors.
58 static Severity
GlobalErrorSeverity();
60 explicit WrenchIconPainter(Delegate
* delegate
);
61 virtual ~WrenchIconPainter();
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
);
67 // A badge drawn on the top left.
68 void set_badge(const gfx::ImageSkia
& badge
) { badge_
= badge
; }
70 void Paint(gfx::Canvas
* canvas
,
71 ui::ThemeProvider
* theme_provider
,
72 const gfx::Rect
& rect
,
73 BezelType bezel_type
);
76 FRIEND_TEST_ALL_PREFIXES(WrenchIconPainterTest
, PaintCallback
);
79 virtual void AnimationProgressed(const ui::Animation
* animation
) OVERRIDE
;
81 // Gets the image ID used to draw bars for the current severity level.
82 int GetCurrentSeverityImageID() const;
86 gfx::ImageSkia badge_
;
87 scoped_ptr
<ui::MultiAnimation
> animation_
;
89 DISALLOW_COPY_AND_ASSIGN(WrenchIconPainter
);
92 #endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_