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

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

Issue 2346893002: Share a common alpha value used for displaying disabled state in Harmony (Closed)
Patch Set: compiling is underrated Created 4 years, 3 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/md_text_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 "third_party/skia/include/core/SkDrawLooper.h" 7 #include "third_party/skia/include/core/SkDrawLooper.h"
8 #include "third_party/skia/include/core/SkPaint.h" 8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_palette.h"
10 #include "ui/gfx/color_utils.h" 11 #include "ui/gfx/color_utils.h"
11 #include "ui/views/animation/ink_drop_ripple.h" 12 #include "ui/views/animation/ink_drop_ripple.h"
12 #include "ui/views/border.h" 13 #include "ui/views/border.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 namespace { 17 namespace {
17 18
18 // Constants are measured in dip. 19 // Constants are measured in dip.
19 const int kTrackHeight = 12; 20 const int kTrackHeight = 12;
20 const int kTrackWidth = 28; 21 const int kTrackWidth = 28;
21 // Margins from edge of track to edge of view. 22 // Margins from edge of track to edge of view.
22 const int kTrackVerticalMargin = 5; 23 const int kTrackVerticalMargin = 5;
23 const int kTrackHorizontalMargin = 6; 24 const int kTrackHorizontalMargin = 6;
24 // Margin from edge of thumb to closest edge of view. Note that the thumb 25 // Margin from edge of thumb to closest edge of view. Note that the thumb
25 // margins must be sufficiently large to allow space for the shadow. 26 // margins must be sufficiently large to allow space for the shadow.
26 const int kThumbHorizontalMargin = 4; 27 const int kThumbHorizontalMargin = 4;
27 // Margin from top/bottom edge of thumb to top/bottom edge of view. 28 // Margin from top/bottom edge of thumb to top/bottom edge of view.
28 const int kThumbVerticalMargin = 3; 29 const int kThumbVerticalMargin = 3;
29 30
30 // TODO(estade): get this color from the theme? 31 // TODO(estade): get the base color (black) from the theme?
31 const SkColor kTrackOffColor = SkColorSetA(SK_ColorBLACK, 0x61); 32 const SkColor kTrackOffColor =
33 SkColorSetA(SK_ColorBLACK, gfx::kDisabledControlAlpha);
32 34
33 } // namespace 35 } // namespace
34 36
35 ToggleButton::ToggleButton(ButtonListener* listener) 37 ToggleButton::ToggleButton(ButtonListener* listener)
36 : CustomButton(listener), is_on_(false), slide_animation_(this) { 38 : CustomButton(listener), is_on_(false), slide_animation_(this) {
37 slide_animation_.SetSlideDuration(80 /* ms */); 39 slide_animation_.SetSlideDuration(80 /* ms */);
38 slide_animation_.SetTweenType(gfx::Tween::LINEAR); 40 slide_animation_.SetTweenType(gfx::Tween::LINEAR);
39 SetBorder(Border::CreateEmptyBorder( 41 SetBorder(Border::CreateEmptyBorder(
40 gfx::Insets(kTrackVerticalMargin, kTrackHorizontalMargin))); 42 gfx::Insets(kTrackVerticalMargin, kTrackHorizontalMargin)));
41 SetInkDropMode(InkDropMode::ON); 43 SetInkDropMode(InkDropMode::ON);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 thumb_bounds.set_x(thumb_bounds.x() + 138 thumb_bounds.set_x(thumb_bounds.x() +
137 slide_animation_.GetCurrentValue() * 139 slide_animation_.GetCurrentValue() *
138 (thumb_bounds.width() - thumb_bounds.height())); 140 (thumb_bounds.width() - thumb_bounds.height()));
139 // The thumb is a circle, so the width should match the height. 141 // The thumb is a circle, so the width should match the height.
140 thumb_bounds.set_width(thumb_bounds.height()); 142 thumb_bounds.set_width(thumb_bounds.height());
141 thumb_bounds.set_x(GetMirroredXForRect(thumb_bounds)); 143 thumb_bounds.set_x(GetMirroredXForRect(thumb_bounds));
142 return thumb_bounds; 144 return thumb_bounds;
143 } 145 }
144 146
145 } // namespace views 147 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.cc ('k') | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698