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

Side by Side Diff: ui/views/controls/progress_bar.cc

Issue 2942143002: Add progress notification support to new-style notification. (Closed)
Patch Set: Resolve review comments. Created 3 years, 6 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
« no previous file with comments | « ui/views/controls/progress_bar.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/progress_bar.h" 5 #include "ui/views/controls/progress_bar.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 10
(...skipping 10 matching lines...) Expand all
21 21
22 namespace views { 22 namespace views {
23 23
24 namespace { 24 namespace {
25 25
26 // In DP, the amount to round the corners of the progress bar (both bg and 26 // In DP, the amount to round the corners of the progress bar (both bg and
27 // fg, aka slice). 27 // fg, aka slice).
28 const int kCornerRadius = 3; 28 const int kCornerRadius = 3;
29 29
30 // Adds a rectangle to the path. The corners will be rounded if there is room. 30 // Adds a rectangle to the path. The corners will be rounded if there is room.
31 void AddPossiblyRoundRectToPath(const gfx::Rect& rectangle, SkPath* path) { 31 void AddPossiblyRoundRectToPath(const gfx::Rect& rectangle,
32 if (rectangle.height() < kCornerRadius) { 32 bool allow_round_corner,
33 SkPath* path) {
34 if (!allow_round_corner || rectangle.height() < kCornerRadius) {
33 path->addRect(gfx::RectToSkRect(rectangle)); 35 path->addRect(gfx::RectToSkRect(rectangle));
34 } else { 36 } else {
35 path->addRoundRect(gfx::RectToSkRect(rectangle), kCornerRadius, 37 path->addRoundRect(gfx::RectToSkRect(rectangle), kCornerRadius,
36 kCornerRadius); 38 kCornerRadius);
37 } 39 }
38 } 40 }
39 41
40 } // namespace 42 } // namespace
41 43
42 // static 44 // static
43 const char ProgressBar::kViewClassName[] = "ProgressBar"; 45 const char ProgressBar::kViewClassName[] = "ProgressBar";
44 46
45 ProgressBar::ProgressBar(int preferred_height) 47 ProgressBar::ProgressBar(int preferred_height, bool allow_round_corner)
46 : preferred_height_(preferred_height) { 48 : preferred_height_(preferred_height),
49 allow_round_corner_(allow_round_corner) {
47 EnableCanvasFlippingForRTLUI(true); 50 EnableCanvasFlippingForRTLUI(true);
48 } 51 }
49 52
50 ProgressBar::~ProgressBar() { 53 ProgressBar::~ProgressBar() {
51 } 54 }
52 55
53 void ProgressBar::GetAccessibleNodeData(ui::AXNodeData* node_data) { 56 void ProgressBar::GetAccessibleNodeData(ui::AXNodeData* node_data) {
54 node_data->role = ui::AX_ROLE_PROGRESS_INDICATOR; 57 node_data->role = ui::AX_ROLE_PROGRESS_INDICATOR;
55 node_data->AddState(ui::AX_STATE_READ_ONLY); 58 node_data->AddState(ui::AX_STATE_READ_ONLY);
56 } 59 }
(...skipping 11 matching lines...) Expand all
68 } 71 }
69 72
70 void ProgressBar::OnPaint(gfx::Canvas* canvas) { 73 void ProgressBar::OnPaint(gfx::Canvas* canvas) {
71 if (IsIndeterminate()) 74 if (IsIndeterminate())
72 return OnPaintIndeterminate(canvas); 75 return OnPaintIndeterminate(canvas);
73 76
74 gfx::Rect content_bounds = GetContentsBounds(); 77 gfx::Rect content_bounds = GetContentsBounds();
75 78
76 // Draw background. 79 // Draw background.
77 SkPath background_path; 80 SkPath background_path;
78 AddPossiblyRoundRectToPath(content_bounds, &background_path); 81 AddPossiblyRoundRectToPath(content_bounds, allow_round_corner_,
82 &background_path);
79 cc::PaintFlags background_flags; 83 cc::PaintFlags background_flags;
80 background_flags.setStyle(cc::PaintFlags::kFill_Style); 84 background_flags.setStyle(cc::PaintFlags::kFill_Style);
81 background_flags.setAntiAlias(true); 85 background_flags.setAntiAlias(true);
82 background_flags.setColor(GetBackgroundColor()); 86 background_flags.setColor(GetBackgroundColor());
83 canvas->DrawPath(background_path, background_flags); 87 canvas->DrawPath(background_path, background_flags);
84 88
85 // Draw slice. 89 // Draw slice.
86 SkPath slice_path; 90 SkPath slice_path;
87 const int slice_width = static_cast<int>( 91 const int slice_width = static_cast<int>(
88 content_bounds.width() * std::min(current_value_, 1.0) + 0.5); 92 content_bounds.width() * std::min(current_value_, 1.0) + 0.5);
89 if (slice_width < 1) 93 if (slice_width < 1)
90 return; 94 return;
91 95
92 gfx::Rect slice_bounds = content_bounds; 96 gfx::Rect slice_bounds = content_bounds;
93 slice_bounds.set_width(slice_width); 97 slice_bounds.set_width(slice_width);
94 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 98 AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
95 99
96 cc::PaintFlags slice_flags; 100 cc::PaintFlags slice_flags;
97 slice_flags.setStyle(cc::PaintFlags::kFill_Style); 101 slice_flags.setStyle(cc::PaintFlags::kFill_Style);
98 slice_flags.setAntiAlias(true); 102 slice_flags.setAntiAlias(true);
99 slice_flags.setColor(GetForegroundColor()); 103 slice_flags.setColor(GetForegroundColor());
100 canvas->DrawPath(slice_path, slice_flags); 104 canvas->DrawPath(slice_path, slice_flags);
101 } 105 }
102 106
103 void ProgressBar::SetValue(double value) { 107 void ProgressBar::SetValue(double value) {
104 double adjusted_value = (value < 0.0 || value > 1.0) ? -1.0 : value; 108 double adjusted_value = (value < 0.0 || value > 1.0) ? -1.0 : value;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 147
144 bool ProgressBar::IsIndeterminate() { 148 bool ProgressBar::IsIndeterminate() {
145 return current_value_ < 0.0; 149 return current_value_ < 0.0;
146 } 150 }
147 151
148 void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) { 152 void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) {
149 gfx::Rect content_bounds = GetContentsBounds(); 153 gfx::Rect content_bounds = GetContentsBounds();
150 154
151 // Draw background. 155 // Draw background.
152 SkPath background_path; 156 SkPath background_path;
153 AddPossiblyRoundRectToPath(content_bounds, &background_path); 157 AddPossiblyRoundRectToPath(content_bounds, allow_round_corner_,
158 &background_path);
154 cc::PaintFlags background_flags; 159 cc::PaintFlags background_flags;
155 background_flags.setStyle(cc::PaintFlags::kFill_Style); 160 background_flags.setStyle(cc::PaintFlags::kFill_Style);
156 background_flags.setAntiAlias(true); 161 background_flags.setAntiAlias(true);
157 background_flags.setColor(GetBackgroundColor()); 162 background_flags.setColor(GetBackgroundColor());
158 canvas->DrawPath(background_path, background_flags); 163 canvas->DrawPath(background_path, background_flags);
159 164
160 // Draw slice. 165 // Draw slice.
161 SkPath slice_path; 166 SkPath slice_path;
162 double time = indeterminate_bar_animation_->GetCurrentValue(); 167 double time = indeterminate_bar_animation_->GetCurrentValue();
163 168
(...skipping 23 matching lines...) Expand all
187 int bar1_start_x = std::round(content_bounds.width() * bar1_left); 192 int bar1_start_x = std::round(content_bounds.width() * bar1_left);
188 int bar1_end_x = std::round( 193 int bar1_end_x = std::round(
189 content_bounds.width() * std::min(1.0, bar1_left + bar1_width)); 194 content_bounds.width() * std::min(1.0, bar1_left + bar1_width));
190 int bar2_start_x = std::round(content_bounds.width() * bar2_left); 195 int bar2_start_x = std::round(content_bounds.width() * bar2_left);
191 int bar2_end_x = std::round( 196 int bar2_end_x = std::round(
192 content_bounds.width() * std::min(1.0, bar2_left + bar2_width)); 197 content_bounds.width() * std::min(1.0, bar2_left + bar2_width));
193 198
194 gfx::Rect slice_bounds = content_bounds; 199 gfx::Rect slice_bounds = content_bounds;
195 slice_bounds.set_x(content_bounds.x() + bar1_start_x); 200 slice_bounds.set_x(content_bounds.x() + bar1_start_x);
196 slice_bounds.set_width(bar1_end_x - bar1_start_x); 201 slice_bounds.set_width(bar1_end_x - bar1_start_x);
197 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 202 AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
198 slice_bounds.set_x(content_bounds.x() + bar2_start_x); 203 slice_bounds.set_x(content_bounds.x() + bar2_start_x);
199 slice_bounds.set_width(bar2_end_x - bar2_start_x); 204 slice_bounds.set_width(bar2_end_x - bar2_start_x);
200 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 205 AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
201 206
202 cc::PaintFlags slice_flags; 207 cc::PaintFlags slice_flags;
203 slice_flags.setStyle(cc::PaintFlags::kFill_Style); 208 slice_flags.setStyle(cc::PaintFlags::kFill_Style);
204 slice_flags.setAntiAlias(true); 209 slice_flags.setAntiAlias(true);
205 slice_flags.setColor(GetForegroundColor()); 210 slice_flags.setColor(GetForegroundColor());
206 canvas->DrawPath(slice_path, slice_flags); 211 canvas->DrawPath(slice_path, slice_flags);
207 } 212 }
208 213
209 } // namespace views 214 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/progress_bar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698