Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(922)

Side by Side Diff: chrome/browser/ui/toolbar/wrench_icon_painter.cc

Issue 395193003: Create a cross-platform helper class for badging the wrench menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/toolbar/wrench_icon_painter.h" 5 #include "chrome/browser/ui/toolbar/wrench_icon_painter.h"
6 6
7 #include <algorithm>
8
7 #include "grit/theme_resources.h" 9 #include "grit/theme_resources.h"
8 #include "ui/base/theme_provider.h" 10 #include "ui/base/theme_provider.h"
9 #include "ui/gfx/animation/multi_animation.h" 11 #include "ui/gfx/animation/multi_animation.h"
10 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
13 15
14 namespace { 16 namespace {
15 17
16 // The wrench icon is made up of this many bars stacked vertically. 18 // The wrench icon is made up of this many bars stacked vertically.
17 const int kBarCount = 3; 19 const int kBarCount = 3;
18 20
19 // |value| is the animation progress from 0 to 1. |index| is the index of the 21 // |value| is the animation progress from 0 to 1. |index| is the index of the
20 // bar being drawn. This function returns a new progress value (from 0 to 1) 22 // bar being drawn. This function returns a new progress value (from 0 to 1)
21 // such that bars appear staggered. 23 // such that bars appear staggered.
22 double GetStaggeredValue(double value, int index) { 24 double GetStaggeredValue(double value, int index) {
23 // When animating the wrench icon's bars the bars are staggered by this 25 // When animating the wrench icon's bars the bars are staggered by this
24 // factor. 26 // factor.
25 const double kStaggerFactor = 0.15; 27 const double kStaggerFactor = 0.15;
26 double maxStaggeredValue = 1.0 - (kBarCount - 1) * kStaggerFactor; 28 double maxStaggeredValue = 1.0 - (kBarCount - 1) * kStaggerFactor;
27 double staggeredValue = (value - kStaggerFactor * index) / maxStaggeredValue; 29 double staggeredValue = (value - kStaggerFactor * index) / maxStaggeredValue;
28 return std::min(1.0, std::max(0.0, staggeredValue)); 30 return std::min(1.0, std::max(0.0, staggeredValue));
29 } 31 }
30 32
31 } // namespace 33 } // namespace
32 34
33 // static
34 WrenchIconPainter::Severity WrenchIconPainter::SeverityFromUpgradeLevel(
35 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
36 switch (level) {
37 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
38 return SEVERITY_NONE;
39 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
40 return SEVERITY_LOW;
41 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
42 return SEVERITY_MEDIUM;
43 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
44 return SEVERITY_HIGH;
45 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
46 return SEVERITY_HIGH;
47 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
48 return SEVERITY_HIGH;
49 }
50 NOTREACHED();
51 return SEVERITY_NONE;
52 }
53
54 // static
55 bool WrenchIconPainter::ShouldAnimateUpgradeLevel(
56 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
57 bool should_animate = true;
58 if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) {
59 // Only animate low severity upgrades once.
60 static bool should_animate_low_severity = true;
61 should_animate = should_animate_low_severity;
62 should_animate_low_severity = false;
63 }
64 return should_animate;
65 }
66
67 // static
68 WrenchIconPainter::Severity WrenchIconPainter::GlobalErrorSeverity() {
69 // If you change this make sure to also change the menu icon and the bubble
70 // icon.
71 return SEVERITY_MEDIUM;
72 }
73
74 WrenchIconPainter::WrenchIconPainter(Delegate* delegate) 35 WrenchIconPainter::WrenchIconPainter(Delegate* delegate)
75 : delegate_(delegate), 36 : delegate_(delegate),
76 severity_(SEVERITY_NONE) { 37 severity_(SEVERITY_NONE) {
77 } 38 }
78 39
79 WrenchIconPainter::~WrenchIconPainter() {} 40 WrenchIconPainter::~WrenchIconPainter() {}
80 41
81 void WrenchIconPainter::SetSeverity(Severity severity, bool animate) { 42 void WrenchIconPainter::SetSeverity(Severity severity, bool animate) {
82 if (severity_ == severity) 43 if (severity_ == severity)
83 return; 44 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 case SEVERITY_LOW: 139 case SEVERITY_LOW:
179 return IDR_TOOLS_BAR_LOW; 140 return IDR_TOOLS_BAR_LOW;
180 case SEVERITY_MEDIUM: 141 case SEVERITY_MEDIUM:
181 return IDR_TOOLS_BAR_MEDIUM; 142 return IDR_TOOLS_BAR_MEDIUM;
182 case SEVERITY_HIGH: 143 case SEVERITY_HIGH:
183 return IDR_TOOLS_BAR_HIGH; 144 return IDR_TOOLS_BAR_HIGH;
184 } 145 }
185 NOTREACHED(); 146 NOTREACHED();
186 return 0; 147 return 0;
187 } 148 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/wrench_icon_painter.h ('k') | chrome/browser/ui/toolbar/wrench_menu_badge_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698