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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 p[1].set(SkIntToScalar(x + w), SkIntToScalar(y)); | 78 p[1].set(SkIntToScalar(x + w), SkIntToScalar(y)); |
79 } else { | 79 } else { |
80 p[1].set(SkIntToScalar(x), SkIntToScalar(y + h)); | 80 p[1].set(SkIntToScalar(x), SkIntToScalar(y + h)); |
81 } | 81 } |
82 SkShader* s = SkGradientShader::CreateLinear( | 82 SkShader* s = SkGradientShader::CreateLinear( |
83 p, colors, points, count, SkShader::kClamp_TileMode, NULL); | 83 p, colors, points, count, SkShader::kClamp_TileMode, NULL); |
84 paint.setShader(s); | 84 paint.setShader(s); |
85 // Need to unref shader, otherwise never deleted. | 85 // Need to unref shader, otherwise never deleted. |
86 s->unref(); | 86 s->unref(); |
87 | 87 |
88 canvas->AsCanvasSkia()->drawPath(path, paint); | 88 canvas->GetSkCanvas()->drawPath(path, paint); |
89 } | 89 } |
90 | 90 |
91 void FillRoundRect(gfx::Canvas* canvas, | 91 void FillRoundRect(gfx::Canvas* canvas, |
92 int x, int y, | 92 int x, int y, |
93 int w, int h, | 93 int w, int h, |
94 int corner_radius, | 94 int corner_radius, |
95 SkColor gradient_start_color, | 95 SkColor gradient_start_color, |
96 SkColor gradient_end_color, | 96 SkColor gradient_end_color, |
97 bool gradient_horizontal) { | 97 bool gradient_horizontal) { |
98 if (gradient_start_color != gradient_end_color) { | 98 if (gradient_start_color != gradient_end_color) { |
99 SkColor colors[2] = { gradient_start_color, gradient_end_color }; | 99 SkColor colors[2] = { gradient_start_color, gradient_end_color }; |
100 FillRoundRect(canvas, x, y, w, h, corner_radius, | 100 FillRoundRect(canvas, x, y, w, h, corner_radius, |
101 colors, NULL, 2, gradient_horizontal); | 101 colors, NULL, 2, gradient_horizontal); |
102 } else { | 102 } else { |
103 SkPath path; | 103 SkPath path; |
104 AddRoundRectPath(x, y, w, h, corner_radius, &path); | 104 AddRoundRectPath(x, y, w, h, corner_radius, &path); |
105 SkPaint paint; | 105 SkPaint paint; |
106 paint.setStyle(SkPaint::kFill_Style); | 106 paint.setStyle(SkPaint::kFill_Style); |
107 paint.setFlags(SkPaint::kAntiAlias_Flag); | 107 paint.setFlags(SkPaint::kAntiAlias_Flag); |
108 paint.setColor(gradient_start_color); | 108 paint.setColor(gradient_start_color); |
109 canvas->AsCanvasSkia()->drawPath(path, paint); | 109 canvas->GetSkCanvas()->drawPath(path, paint); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void StrokeRoundRect(gfx::Canvas* canvas, | 113 void StrokeRoundRect(gfx::Canvas* canvas, |
114 int x, int y, | 114 int x, int y, |
115 int w, int h, | 115 int w, int h, |
116 int corner_radius, | 116 int corner_radius, |
117 SkColor stroke_color, | 117 SkColor stroke_color, |
118 int stroke_width) { | 118 int stroke_width) { |
119 SkPath path; | 119 SkPath path; |
120 AddRoundRectPath(x, y, w, h, corner_radius, &path); | 120 AddRoundRectPath(x, y, w, h, corner_radius, &path); |
121 SkPaint paint; | 121 SkPaint paint; |
122 paint.setShader(NULL); | 122 paint.setShader(NULL); |
123 paint.setColor(stroke_color); | 123 paint.setColor(stroke_color); |
124 paint.setStyle(SkPaint::kStroke_Style); | 124 paint.setStyle(SkPaint::kStroke_Style); |
125 paint.setFlags(SkPaint::kAntiAlias_Flag); | 125 paint.setFlags(SkPaint::kAntiAlias_Flag); |
126 paint.setStrokeWidth(SkIntToScalar(stroke_width)); | 126 paint.setStrokeWidth(SkIntToScalar(stroke_width)); |
127 canvas->AsCanvasSkia()->drawPath(path, paint); | 127 canvas->GetSkCanvas()->drawPath(path, paint); |
128 } | 128 } |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 namespace views { | 132 namespace views { |
133 | 133 |
134 // static | 134 // static |
135 const char ProgressBar::kViewClassName[] = "views/ProgressBar"; | 135 const char ProgressBar::kViewClassName[] = "views/ProgressBar"; |
136 | 136 |
137 ProgressBar::ProgressBar() | 137 ProgressBar::ProgressBar() |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // Draw bar background | 215 // Draw bar background |
216 FillRoundRect(canvas, | 216 FillRoundRect(canvas, |
217 0, 0, progress_width, height(), | 217 0, 0, progress_width, height(), |
218 kCornerRadius, | 218 kCornerRadius, |
219 bar_color_start, | 219 bar_color_start, |
220 bar_color_end, | 220 bar_color_end, |
221 false); | 221 false); |
222 | 222 |
223 // Draw inner stroke and shadow if wide enough. | 223 // Draw inner stroke and shadow if wide enough. |
224 if (progress_width > 2 * kBorderWidth) { | 224 if (progress_width > 2 * kBorderWidth) { |
225 canvas->AsCanvasSkia()->save(); | 225 canvas->GetSkCanvas()->save(); |
226 | 226 |
227 SkPath inner_path; | 227 SkPath inner_path; |
228 AddRoundRectPathWithPadding( | 228 AddRoundRectPathWithPadding( |
229 0, 0, progress_width, height(), | 229 0, 0, progress_width, height(), |
230 kCornerRadius, | 230 kCornerRadius, |
231 SkIntToScalar(kBorderWidth), | 231 SkIntToScalar(kBorderWidth), |
232 &inner_path); | 232 &inner_path); |
233 canvas->AsCanvasSkia()->clipPath(inner_path); | 233 canvas->GetSkCanvas()->clipPath(inner_path); |
234 | 234 |
235 // Draw bar inner stroke | 235 // Draw bar inner stroke |
236 StrokeRoundRect(canvas, | 236 StrokeRoundRect(canvas, |
237 kBorderWidth, kBorderWidth, | 237 kBorderWidth, kBorderWidth, |
238 progress_width - 2 * kBorderWidth, | 238 progress_width - 2 * kBorderWidth, |
239 height() - 2 * kBorderWidth, | 239 height() - 2 * kBorderWidth, |
240 kCornerRadius - kBorderWidth, | 240 kCornerRadius - kBorderWidth, |
241 bar_inner_border_color, | 241 bar_inner_border_color, |
242 kBorderWidth); | 242 kBorderWidth); |
243 | 243 |
244 // Draw bar inner shadow | 244 // Draw bar inner shadow |
245 StrokeRoundRect(canvas, | 245 StrokeRoundRect(canvas, |
246 0, kBorderWidth, progress_width, height(), | 246 0, kBorderWidth, progress_width, height(), |
247 kCornerRadius, | 247 kCornerRadius, |
248 bar_inner_shadow_color, | 248 bar_inner_shadow_color, |
249 kBorderWidth); | 249 kBorderWidth); |
250 | 250 |
251 canvas->AsCanvasSkia()->restore(); | 251 canvas->GetSkCanvas()->restore(); |
252 } | 252 } |
253 | 253 |
254 // Draw bar stroke | 254 // Draw bar stroke |
255 StrokeRoundRect(canvas, | 255 StrokeRoundRect(canvas, |
256 0, 0, progress_width, height(), | 256 0, 0, progress_width, height(), |
257 kCornerRadius, | 257 kCornerRadius, |
258 bar_outer_color, | 258 bar_outer_color, |
259 kBorderWidth); | 259 kBorderWidth); |
260 } | 260 } |
261 #else | 261 #else |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 current_value_ = value; | 313 current_value_ = value; |
314 SchedulePaint(); | 314 SchedulePaint(); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 void ProgressBar::SetTooltipText(const string16& tooltip_text) { | 318 void ProgressBar::SetTooltipText(const string16& tooltip_text) { |
319 tooltip_text_ = tooltip_text; | 319 tooltip_text_ = tooltip_text; |
320 } | 320 } |
321 | 321 |
322 } // namespace views | 322 } // namespace views |
OLD | NEW |