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

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

Issue 2680943002: ui: Clean up naming of paint-related identifiers (Closed)
Patch Set: 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
« no previous file with comments | « ui/views/controls/button/radio_button.cc ('k') | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "cc/paint/paint_flags.h"
8 #include "third_party/skia/include/core/SkDrawLooper.h" 8 #include "third_party/skia/include/core/SkDrawLooper.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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 void OnPaint(gfx::Canvas* canvas) override { 72 void OnPaint(gfx::Canvas* canvas) override {
73 const float dsf = canvas->UndoDeviceScaleFactor(); 73 const float dsf = canvas->UndoDeviceScaleFactor();
74 std::vector<gfx::ShadowValue> shadows; 74 std::vector<gfx::ShadowValue> shadows;
75 gfx::ShadowValue shadow( 75 gfx::ShadowValue shadow(
76 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur, 76 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur,
77 SkColorSetA(GetNativeTheme()->GetSystemColor( 77 SkColorSetA(GetNativeTheme()->GetSystemColor(
78 ui::NativeTheme::kColorId_LabelEnabledColor), 78 ui::NativeTheme::kColorId_LabelEnabledColor),
79 0x99)); 79 0x99));
80 shadows.push_back(shadow.Scale(dsf)); 80 shadows.push_back(shadow.Scale(dsf));
81 cc::PaintFlags thumb_paint; 81 cc::PaintFlags thumb_flags;
82 thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); 82 thumb_flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows));
83 thumb_paint.setAntiAlias(true); 83 thumb_flags.setAntiAlias(true);
84 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( 84 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor(
85 ui::NativeTheme::kColorId_ProminentButtonColor); 85 ui::NativeTheme::kColorId_ProminentButtonColor);
86 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor( 86 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor(
87 ui::NativeTheme::kColorId_DialogBackground); 87 ui::NativeTheme::kColorId_DialogBackground);
88 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_); 88 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_);
89 thumb_paint.setColor( 89 thumb_flags.setColor(
90 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); 90 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend));
91 91
92 // We want the circle to have an integer pixel diameter and to be aligned 92 // We want the circle to have an integer pixel diameter and to be aligned
93 // with pixel boundaries, so we scale dip bounds to pixel bounds and round. 93 // with pixel boundaries, so we scale dip bounds to pixel bounds and round.
94 gfx::RectF thumb_bounds(GetLocalBounds()); 94 gfx::RectF thumb_bounds(GetLocalBounds());
95 thumb_bounds.Inset(-GetShadowOutsets()); 95 thumb_bounds.Inset(-GetShadowOutsets());
96 thumb_bounds.Inset(gfx::InsetsF(0.5f)); 96 thumb_bounds.Inset(gfx::InsetsF(0.5f));
97 thumb_bounds.Scale(dsf); 97 thumb_bounds.Scale(dsf);
98 thumb_bounds = gfx::RectF(gfx::ToEnclosingRect(thumb_bounds)); 98 thumb_bounds = gfx::RectF(gfx::ToEnclosingRect(thumb_bounds));
99 canvas->DrawCircle(thumb_bounds.CenterPoint(), thumb_bounds.height() / 2.f, 99 canvas->DrawCircle(thumb_bounds.CenterPoint(), thumb_bounds.height() / 2.f,
100 thumb_paint); 100 thumb_flags);
101 } 101 }
102 102
103 // Color ratio between 0 and 1 that controls the thumb color. 103 // Color ratio between 0 and 1 that controls the thumb color.
104 double color_ratio_; 104 double color_ratio_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(ThumbView); 106 DISALLOW_COPY_AND_ASSIGN(ThumbView);
107 }; 107 };
108 108
109 // static 109 // static
110 const char ToggleButton::kViewClassName[] = "ToggleButton"; 110 const char ToggleButton::kViewClassName[] = "ToggleButton";
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 void ToggleButton::OnPaint(gfx::Canvas* canvas) { 192 void ToggleButton::OnPaint(gfx::Canvas* canvas) {
193 // Paint the toggle track. To look sharp even at fractional scale factors, 193 // Paint the toggle track. To look sharp even at fractional scale factors,
194 // round up to pixel boundaries. 194 // round up to pixel boundaries.
195 canvas->Save(); 195 canvas->Save();
196 float dsf = canvas->UndoDeviceScaleFactor(); 196 float dsf = canvas->UndoDeviceScaleFactor();
197 gfx::RectF track_rect(GetTrackBounds()); 197 gfx::RectF track_rect(GetTrackBounds());
198 track_rect.Scale(dsf); 198 track_rect.Scale(dsf);
199 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect)); 199 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect));
200 cc::PaintFlags track_paint; 200 cc::PaintFlags track_flags;
201 track_paint.setAntiAlias(true); 201 track_flags.setAntiAlias(true);
202 const double color_ratio = slide_animation_.GetCurrentValue(); 202 const double color_ratio = slide_animation_.GetCurrentValue();
203 track_paint.setColor(color_utils::AlphaBlend( 203 track_flags.setColor(color_utils::AlphaBlend(
204 GetTrackColor(true), GetTrackColor(false), 204 GetTrackColor(true), GetTrackColor(false),
205 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio))); 205 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio)));
206 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint); 206 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_flags);
207 canvas->Restore(); 207 canvas->Restore();
208 208
209 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 209 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
210 } 210 }
211 211
212 void ToggleButton::OnFocus() { 212 void ToggleButton::OnFocus() {
213 CustomButton::OnFocus(); 213 CustomButton::OnFocus();
214 if (focus_painter_) 214 if (focus_painter_)
215 SchedulePaint(); 215 SchedulePaint();
216 } 216 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // TODO(varkha, estade): The thumb is using its own view. Investigate if 272 // TODO(varkha, estade): The thumb is using its own view. Investigate if
273 // repainting in every animation step to update colors could be avoided. 273 // repainting in every animation step to update colors could be avoided.
274 UpdateThumb(); 274 UpdateThumb();
275 SchedulePaint(); 275 SchedulePaint();
276 return; 276 return;
277 } 277 }
278 CustomButton::AnimationProgressed(animation); 278 CustomButton::AnimationProgressed(animation);
279 } 279 }
280 280
281 } // namespace views 281 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/radio_button.cc ('k') | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698