OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/progress_bar.h" | 5 #include "views/controls/progress_bar.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 13 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
14 #include "third_party/skia/include/effects/SkGradientShader.h" | 14 #include "third_party/skia/include/effects/SkGradientShader.h" |
15 #include "ui/base/accessibility/accessible_view_state.h" | 15 #include "ui/base/accessibility/accessible_view_state.h" |
16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
18 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
19 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
20 #include "views/background.h" | 20 #include "views/background.h" |
21 #include "views/border.h" | 21 #include "views/border.h" |
22 #include "views/painter.h" | 22 #include "views/painter.h" |
23 | 23 |
24 using std::max; | |
25 using std::min; | |
26 | |
27 namespace { | 24 namespace { |
28 | 25 |
29 // Corner radius for the progress bar's border. | 26 // Corner radius for the progress bar's border. |
30 const int kCornerRadius = 3; | 27 const int kCornerRadius = 3; |
31 | 28 |
32 // Progress bar's border width | 29 // Progress bar's border width |
33 const int kBorderWidth = 1; | 30 const int kBorderWidth = 1; |
34 | 31 |
35 void AddRoundRectPathWithPadding(int x, int y, | 32 void AddRoundRectPathWithPadding(int x, int y, |
36 int w, int h, | 33 int w, int h, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 133 |
137 ProgressBar::ProgressBar() | 134 ProgressBar::ProgressBar() |
138 : min_display_value_(0.0), | 135 : min_display_value_(0.0), |
139 max_display_value_(1.0), | 136 max_display_value_(1.0), |
140 current_value_(0.0) { | 137 current_value_(0.0) { |
141 } | 138 } |
142 | 139 |
143 ProgressBar::~ProgressBar() { | 140 ProgressBar::~ProgressBar() { |
144 } | 141 } |
145 | 142 |
146 gfx::Size ProgressBar::GetPreferredSize() { | 143 void ProgressBar::SetDisplayRange(double min_display_value, |
147 return gfx::Size(100, 16); | 144 double max_display_value) { |
| 145 if (min_display_value != min_display_value_ || |
| 146 max_display_value != max_display_value_) { |
| 147 DCHECK(min_display_value < max_display_value); |
| 148 min_display_value_ = min_display_value; |
| 149 max_display_value_ = max_display_value; |
| 150 SchedulePaint(); |
| 151 } |
148 } | 152 } |
149 | 153 |
150 std::string ProgressBar::GetClassName() const { | 154 void ProgressBar::SetValue(double value) { |
151 return kViewClassName; | 155 if (value != current_value_) { |
| 156 current_value_ = value; |
| 157 SchedulePaint(); |
| 158 } |
| 159 } |
| 160 |
| 161 void ProgressBar::SetTooltipText(const string16& tooltip_text) { |
| 162 tooltip_text_ = tooltip_text; |
| 163 } |
| 164 |
| 165 bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) const { |
| 166 DCHECK(tooltip); |
| 167 if (tooltip == NULL) |
| 168 return false; |
| 169 tooltip->assign(tooltip_text_); |
| 170 return !tooltip_text_.empty(); |
152 } | 171 } |
153 | 172 |
154 void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) { | 173 void ProgressBar::GetAccessibleState(ui::AccessibleViewState* state) { |
155 state->role = ui::AccessibilityTypes::ROLE_PROGRESSBAR; | 174 state->role = ui::AccessibilityTypes::ROLE_PROGRESSBAR; |
156 state->state = ui::AccessibilityTypes::STATE_READONLY; | 175 state->state = ui::AccessibilityTypes::STATE_READONLY; |
157 } | 176 } |
158 | 177 |
| 178 gfx::Size ProgressBar::GetPreferredSize() { |
| 179 return gfx::Size(100, 16); |
| 180 } |
| 181 |
| 182 std::string ProgressBar::GetClassName() const { |
| 183 return kViewClassName; |
| 184 } |
| 185 |
159 void ProgressBar::OnPaint(gfx::Canvas* canvas) { | 186 void ProgressBar::OnPaint(gfx::Canvas* canvas) { |
160 const double capped_value = | 187 const double capped_value = std::min( |
161 min(max(current_value_, min_display_value_), max_display_value_); | 188 std::max(current_value_, min_display_value_), max_display_value_); |
162 const double capped_fraction = | 189 const double capped_fraction = |
163 (capped_value - min_display_value_) / | 190 (capped_value - min_display_value_) / |
164 (max_display_value_ - min_display_value_); | 191 (max_display_value_ - min_display_value_); |
165 const int progress_width = static_cast<int>(width() * capped_fraction + 0.5); | 192 const int progress_width = static_cast<int>(width() * capped_fraction + 0.5); |
166 | 193 |
167 #if defined(OS_CHROMEOS) | 194 #if defined(OS_CHROMEOS) |
168 const SkColor background_colors[] = { | 195 const SkColor background_colors[] = { |
169 SkColorSetRGB(0xBB, 0xBB, 0xBB), | 196 SkColorSetRGB(0xBB, 0xBB, 0xBB), |
170 SkColorSetRGB(0xE7, 0xE7, 0xE7), | 197 SkColorSetRGB(0xE7, 0xE7, 0xE7), |
171 SkColorSetRGB(0xFE, 0xFE, 0xFE) | 198 SkColorSetRGB(0xFE, 0xFE, 0xFE) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 309 } |
283 StrokeRoundRect(canvas, | 310 StrokeRoundRect(canvas, |
284 0, 0, | 311 0, 0, |
285 width(), height(), | 312 width(), height(), |
286 kCornerRadius, | 313 kCornerRadius, |
287 border_color, | 314 border_color, |
288 kBorderWidth); | 315 kBorderWidth); |
289 #endif | 316 #endif |
290 } | 317 } |
291 | 318 |
292 bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) const { | |
293 DCHECK(tooltip); | |
294 if (tooltip == NULL) | |
295 return false; | |
296 tooltip->assign(tooltip_text_); | |
297 return !tooltip_text_.empty(); | |
298 } | |
299 | |
300 void ProgressBar::SetDisplayRange(double min_display_value, | |
301 double max_display_value) { | |
302 if (min_display_value != min_display_value_ || | |
303 max_display_value != max_display_value_) { | |
304 DCHECK(min_display_value < max_display_value); | |
305 min_display_value_ = min_display_value; | |
306 max_display_value_ = max_display_value; | |
307 SchedulePaint(); | |
308 } | |
309 } | |
310 | |
311 void ProgressBar::SetValue(double value) { | |
312 if (value != current_value_) { | |
313 current_value_ = value; | |
314 SchedulePaint(); | |
315 } | |
316 } | |
317 | |
318 void ProgressBar::SetTooltipText(const string16& tooltip_text) { | |
319 tooltip_text_ = tooltip_text; | |
320 } | |
321 | |
322 } // namespace views | 319 } // namespace views |
OLD | NEW |