summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/toolbar/wrench_icon_painter.h
blob: 77b5e5477f8508ae7a8c152d4b3a91eb3ce547d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_
#define CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_

#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/upgrade_detector.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/image/image_skia.h"

namespace gfx {
class Canvas;
class MultiAnimation;
class Rect;
}
namespace ui {
class ThemeProvider;
}

// This class is used to draw the wrench icon. It can signify severity levels
// by changing the wrench icon to different colors.
class WrenchIconPainter : gfx::AnimationDelegate {
 public:
  enum BezelType {
    BEZEL_NONE,
    BEZEL_HOVER,
    BEZEL_PRESSED,
  };

  enum Severity {
    SEVERITY_NONE,
    SEVERITY_LOW,
    SEVERITY_MEDIUM,
    SEVERITY_HIGH,
  };

  class Delegate {
   public:
    virtual void ScheduleWrenchIconPaint() = 0;
   protected:
    virtual ~Delegate() {}
  };

  // Map an upgrade level to a severity level.
  static Severity SeverityFromUpgradeLevel(
      UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);

  // Checks if the wrench icon should be animated for the given upgrade level.
  static bool ShouldAnimateUpgradeLevel(
      UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);

  // Get the severity level for global errors.
  static Severity GlobalErrorSeverity();

  explicit WrenchIconPainter(Delegate* delegate);
  virtual ~WrenchIconPainter();

  // If |severity| is not |SEVERITY_NONE| then the wrench icon is colored to
  // match the severity level.
  void SetSeverity(Severity severity, bool animate);

  // A badge drawn on the top left.
  void set_badge(const gfx::ImageSkia& badge) { badge_ = badge; }

  void Paint(gfx::Canvas* canvas,
             ui::ThemeProvider* theme_provider,
             const gfx::Rect& rect,
             BezelType bezel_type);

 private:
  FRIEND_TEST_ALL_PREFIXES(WrenchIconPainterTest, PaintCallback);

  // AnimationDelegate:
  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;

  // Gets the image ID used to draw bars for the current severity level.
  int GetCurrentSeverityImageID() const;

  Delegate* delegate_;
  Severity severity_;
  gfx::ImageSkia badge_;
  scoped_ptr<gfx::MultiAnimation> animation_;

  DISALLOW_COPY_AND_ASSIGN(WrenchIconPainter);
};

#endif  // CHROME_BROWSER_UI_TOOLBAR_WRENCH_ICON_PAINTER_H_