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

Side by Side Diff: ui/views/controls/button/toggle_button.cc

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/button/toggle_button.h" 5 #include "ui/views/controls/button/toggle_button.h"
6 6
7 #include "cc/paint/paint_flags.h"
7 #include "third_party/skia/include/core/SkDrawLooper.h" 8 #include "third_party/skia/include/core/SkDrawLooper.h"
8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "ui/accessibility/ax_node_data.h" 9 #include "ui/accessibility/ax_node_data.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/color_palette.h" 11 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
13 #include "ui/gfx/geometry/rect_conversions.h" 13 #include "ui/gfx/geometry/rect_conversions.h"
14 #include "ui/gfx/shadow_value.h" 14 #include "ui/gfx/shadow_value.h"
15 #include "ui/views/animation/ink_drop_impl.h" 15 #include "ui/views/animation/ink_drop_impl.h"
16 #include "ui/views/animation/ink_drop_ripple.h" 16 #include "ui/views/animation/ink_drop_ripple.h"
17 #include "ui/views/border.h" 17 #include "ui/views/border.h"
18 #include "ui/views/painter.h" 18 #include "ui/views/painter.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 void OnPaint(gfx::Canvas* canvas) override { 71 void OnPaint(gfx::Canvas* canvas) override {
72 const float dsf = canvas->UndoDeviceScaleFactor(); 72 const float dsf = canvas->UndoDeviceScaleFactor();
73 std::vector<gfx::ShadowValue> shadows; 73 std::vector<gfx::ShadowValue> shadows;
74 gfx::ShadowValue shadow( 74 gfx::ShadowValue shadow(
75 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur, 75 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur,
76 SkColorSetA(GetNativeTheme()->GetSystemColor( 76 SkColorSetA(GetNativeTheme()->GetSystemColor(
77 ui::NativeTheme::kColorId_LabelEnabledColor), 77 ui::NativeTheme::kColorId_LabelEnabledColor),
78 0x99)); 78 0x99));
79 shadows.push_back(shadow.Scale(dsf)); 79 shadows.push_back(shadow.Scale(dsf));
80 SkPaint thumb_paint; 80 cc::PaintFlags thumb_paint;
81 thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); 81 thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows));
82 thumb_paint.setAntiAlias(true); 82 thumb_paint.setAntiAlias(true);
83 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( 83 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor(
84 ui::NativeTheme::kColorId_ProminentButtonColor); 84 ui::NativeTheme::kColorId_ProminentButtonColor);
85 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor( 85 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor(
86 ui::NativeTheme::kColorId_DialogBackground); 86 ui::NativeTheme::kColorId_DialogBackground);
87 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_); 87 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_);
88 thumb_paint.setColor( 88 thumb_paint.setColor(
89 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); 89 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend));
90 90
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 void ToggleButton::OnPaint(gfx::Canvas* canvas) { 191 void ToggleButton::OnPaint(gfx::Canvas* canvas) {
192 // Paint the toggle track. To look sharp even at fractional scale factors, 192 // Paint the toggle track. To look sharp even at fractional scale factors,
193 // round up to pixel boundaries. 193 // round up to pixel boundaries.
194 canvas->Save(); 194 canvas->Save();
195 float dsf = canvas->UndoDeviceScaleFactor(); 195 float dsf = canvas->UndoDeviceScaleFactor();
196 gfx::RectF track_rect(GetTrackBounds()); 196 gfx::RectF track_rect(GetTrackBounds());
197 track_rect.Scale(dsf); 197 track_rect.Scale(dsf);
198 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect)); 198 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect));
199 SkPaint track_paint; 199 cc::PaintFlags track_paint;
200 track_paint.setAntiAlias(true); 200 track_paint.setAntiAlias(true);
201 const double color_ratio = slide_animation_.GetCurrentValue(); 201 const double color_ratio = slide_animation_.GetCurrentValue();
202 track_paint.setColor(color_utils::AlphaBlend( 202 track_paint.setColor(color_utils::AlphaBlend(
203 GetTrackColor(true), GetTrackColor(false), 203 GetTrackColor(true), GetTrackColor(false),
204 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio))); 204 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio)));
205 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint); 205 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint);
206 canvas->Restore(); 206 canvas->Restore();
207 207
208 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 208 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
209 } 209 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // TODO(varkha, estade): The thumb is using its own view. Investigate if 271 // TODO(varkha, estade): The thumb is using its own view. Investigate if
272 // repainting in every animation step to update colors could be avoided. 272 // repainting in every animation step to update colors could be avoided.
273 UpdateThumb(); 273 UpdateThumb();
274 SchedulePaint(); 274 SchedulePaint();
275 return; 275 return;
276 } 276 }
277 CustomButton::AnimationProgressed(animation); 277 CustomButton::AnimationProgressed(animation);
278 } 278 }
279 279
280 } // namespace views 280 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698