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