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 "ui/gfx/animation/animation_delegate.h"
12#include "ui/gfx/image/image_skia.h"
13
14namespace gfx {
15class Canvas;
16class MultiAnimation;
17class Rect;
18}
19namespace ui {
20class ThemeProvider;
21}
22
23// This class is used to draw the wrench icon. It can signify severity levels
24// by changing the wrench icon to different colors.
25class WrenchIconPainter : gfx::AnimationDelegate {
26 public:
27  enum BezelType {
28    BEZEL_NONE,
29    BEZEL_HOVER,
30    BEZEL_PRESSED,
31  };
32
33  enum Severity {
34    SEVERITY_NONE,
35    SEVERITY_LOW,
36    SEVERITY_MEDIUM,
37    SEVERITY_HIGH,
38  };
39
40  class Delegate {
41   public:
42    virtual void ScheduleWrenchIconPaint() = 0;
43   protected:
44    virtual ~Delegate() {}
45  };
46
47  explicit WrenchIconPainter(Delegate* delegate);
48  virtual ~WrenchIconPainter();
49
50  // If |severity| is not |SEVERITY_NONE| then the wrench icon is colored to
51  // match the severity level.
52  void SetSeverity(Severity severity, bool animate);
53
54  // A badge drawn on the top left.
55  void set_badge(const gfx::ImageSkia& badge) { badge_ = badge; }
56
57  void Paint(gfx::Canvas* canvas,
58             ui::ThemeProvider* theme_provider,
59             const gfx::Rect& rect,
60             BezelType bezel_type);
61
62 private:
63  FRIEND_TEST_ALL_PREFIXES(WrenchIconPainterTest, PaintCallback);
64
65  // AnimationDelegate:
66  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
67
68  // Gets the image ID used to draw bars for the current severity level.
69  int GetCurrentSeverityImageID() const;
70
71  Delegate* delegate_;
72  Severity severity_;
73  gfx::ImageSkia badge_;
74  scoped_ptr<gfx::MultiAnimation> animation_;
75
76  DISALLOW_COPY_AND_ASSIGN(WrenchIconPainter);
77};
78
79#endif  // CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
80