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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: DrawingDisplayItem Created 3 years, 10 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
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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "third_party/skia/include/core/SkPaint.h" 13 #include "cc/paint/paint_flags.h"
14 #include "third_party/skia/include/core/SkPath.h" 14 #include "third_party/skia/include/core/SkPath.h"
15 #include "third_party/skia/include/effects/SkGradientShader.h" 15 #include "third_party/skia/include/effects/SkGradientShader.h"
16 #include "ui/accessibility/ax_node_data.h" 16 #include "ui/accessibility/ax_node_data.h"
17 #include "ui/gfx/animation/linear_animation.h" 17 #include "ui/gfx/animation/linear_animation.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_utils.h" 19 #include "ui/gfx/color_utils.h"
20 #include "ui/native_theme/native_theme.h" 20 #include "ui/native_theme/native_theme.h"
21 21
22 namespace views { 22 namespace views {
23 23
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 void ProgressBar::OnPaint(gfx::Canvas* canvas) { 70 void ProgressBar::OnPaint(gfx::Canvas* canvas) {
71 if (IsIndeterminate()) 71 if (IsIndeterminate())
72 return OnPaintIndeterminate(canvas); 72 return OnPaintIndeterminate(canvas);
73 73
74 gfx::Rect content_bounds = GetContentsBounds(); 74 gfx::Rect content_bounds = GetContentsBounds();
75 75
76 // Draw background. 76 // Draw background.
77 SkPath background_path; 77 SkPath background_path;
78 AddPossiblyRoundRectToPath(content_bounds, &background_path); 78 AddPossiblyRoundRectToPath(content_bounds, &background_path);
79 SkPaint background_paint; 79 cc::PaintFlags background_paint;
80 background_paint.setStyle(SkPaint::kFill_Style); 80 background_paint.setStyle(cc::PaintFlags::kFill_Style);
81 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 81 background_paint.setAntiAlias(true);
82 background_paint.setColor(GetBackgroundColor()); 82 background_paint.setColor(GetBackgroundColor());
83 canvas->DrawPath(background_path, background_paint); 83 canvas->DrawPath(background_path, background_paint);
84 84
85 // Draw slice. 85 // Draw slice.
86 SkPath slice_path; 86 SkPath slice_path;
87 const int slice_width = static_cast<int>( 87 const int slice_width = static_cast<int>(
88 content_bounds.width() * std::min(current_value_, 1.0) + 0.5); 88 content_bounds.width() * std::min(current_value_, 1.0) + 0.5);
89 if (slice_width < 1) 89 if (slice_width < 1)
90 return; 90 return;
91 91
92 gfx::Rect slice_bounds = content_bounds; 92 gfx::Rect slice_bounds = content_bounds;
93 slice_bounds.set_width(slice_width); 93 slice_bounds.set_width(slice_width);
94 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 94 AddPossiblyRoundRectToPath(slice_bounds, &slice_path);
95 95
96 SkPaint slice_paint; 96 cc::PaintFlags slice_paint;
97 slice_paint.setStyle(SkPaint::kFill_Style); 97 slice_paint.setStyle(cc::PaintFlags::kFill_Style);
98 slice_paint.setFlags(SkPaint::kAntiAlias_Flag); 98 slice_paint.setAntiAlias(true);
99 slice_paint.setColor(GetForegroundColor()); 99 slice_paint.setColor(GetForegroundColor());
100 canvas->DrawPath(slice_path, slice_paint); 100 canvas->DrawPath(slice_path, slice_paint);
101 } 101 }
102 102
103 void ProgressBar::SetValue(double value) { 103 void ProgressBar::SetValue(double value) {
104 double adjusted_value = (value < 0.0 || value > 1.0) ? -1.0 : value; 104 double adjusted_value = (value < 0.0 || value > 1.0) ? -1.0 : value;
105 105
106 if (adjusted_value == current_value_) 106 if (adjusted_value == current_value_)
107 return; 107 return;
108 108
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 bool ProgressBar::IsIndeterminate() { 144 bool ProgressBar::IsIndeterminate() {
145 return current_value_ < 0.0; 145 return current_value_ < 0.0;
146 } 146 }
147 147
148 void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) { 148 void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) {
149 gfx::Rect content_bounds = GetContentsBounds(); 149 gfx::Rect content_bounds = GetContentsBounds();
150 150
151 // Draw background. 151 // Draw background.
152 SkPath background_path; 152 SkPath background_path;
153 AddPossiblyRoundRectToPath(content_bounds, &background_path); 153 AddPossiblyRoundRectToPath(content_bounds, &background_path);
154 SkPaint background_paint; 154 cc::PaintFlags background_paint;
155 background_paint.setStyle(SkPaint::kFill_Style); 155 background_paint.setStyle(cc::PaintFlags::kFill_Style);
156 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 156 background_paint.setAntiAlias(true);
157 background_paint.setColor(GetBackgroundColor()); 157 background_paint.setColor(GetBackgroundColor());
158 canvas->DrawPath(background_path, background_paint); 158 canvas->DrawPath(background_path, background_paint);
159 159
160 // Draw slice. 160 // Draw slice.
161 SkPath slice_path; 161 SkPath slice_path;
162 double time = indeterminate_bar_animation_->GetCurrentValue(); 162 double time = indeterminate_bar_animation_->GetCurrentValue();
163 163
164 // The animation spec corresponds to the material design lite's parameter. 164 // The animation spec corresponds to the material design lite's parameter.
165 // (cf. https://github.com/google/material-design-lite/) 165 // (cf. https://github.com/google/material-design-lite/)
166 double bar1_left; 166 double bar1_left;
(...skipping 25 matching lines...) Expand all
192 content_bounds.width() * std::min(1.0, bar2_left + bar2_width)); 192 content_bounds.width() * std::min(1.0, bar2_left + bar2_width));
193 193
194 gfx::Rect slice_bounds = content_bounds; 194 gfx::Rect slice_bounds = content_bounds;
195 slice_bounds.set_x(content_bounds.x() + bar1_start_x); 195 slice_bounds.set_x(content_bounds.x() + bar1_start_x);
196 slice_bounds.set_width(bar1_end_x - bar1_start_x); 196 slice_bounds.set_width(bar1_end_x - bar1_start_x);
197 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 197 AddPossiblyRoundRectToPath(slice_bounds, &slice_path);
198 slice_bounds.set_x(content_bounds.x() + bar2_start_x); 198 slice_bounds.set_x(content_bounds.x() + bar2_start_x);
199 slice_bounds.set_width(bar2_end_x - bar2_start_x); 199 slice_bounds.set_width(bar2_end_x - bar2_start_x);
200 AddPossiblyRoundRectToPath(slice_bounds, &slice_path); 200 AddPossiblyRoundRectToPath(slice_bounds, &slice_path);
201 201
202 SkPaint slice_paint; 202 cc::PaintFlags slice_paint;
203 slice_paint.setStyle(SkPaint::kFill_Style); 203 slice_paint.setStyle(cc::PaintFlags::kFill_Style);
204 slice_paint.setFlags(SkPaint::kAntiAlias_Flag); 204 slice_paint.setAntiAlias(true);
205 slice_paint.setColor(GetForegroundColor()); 205 slice_paint.setColor(GetForegroundColor());
206 canvas->DrawPath(slice_path, slice_paint); 206 canvas->DrawPath(slice_path, slice_paint);
207 } 207 }
208 208
209 } // namespace views 209 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_scroll_view_container.cc ('k') | ui/views/controls/scrollbar/cocoa_scroll_bar.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698