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

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

Issue 2032683003: Add ripples to md checkboxes/radio buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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/checkbox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/button/checkbox.h" 5 #include "ui/views/controls/button/checkbox.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/material_design/material_design_controller.h" 12 #include "ui/base/material_design/material_design_controller.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/paint_vector_icon.h" 15 #include "ui/gfx/paint_vector_icon.h"
16 #include "ui/gfx/vector_icons_public.h" 16 #include "ui/gfx/vector_icons_public.h"
17 #include "ui/resources/grit/ui_resources.h" 17 #include "ui/resources/grit/ui_resources.h"
18 #include "ui/views/animation/ink_drop_highlight.h"
19 #include "ui/views/animation/ink_drop_ripple.h"
18 #include "ui/views/controls/button/label_button_border.h" 20 #include "ui/views/controls/button/label_button_border.h"
19 #include "ui/views/painter.h" 21 #include "ui/views/painter.h"
20 #include "ui/views/resources/grit/views_resources.h" 22 #include "ui/views/resources/grit/views_resources.h"
21 23
22 namespace views { 24 namespace views {
23 25
24 // static 26 // static
25 const char Checkbox::kViewClassName[] = "Checkbox"; 27 const char Checkbox::kViewClassName[] = "Checkbox";
26 28
27 Checkbox::Checkbox(const base::string16& label) 29 Checkbox::Checkbox(const base::string16& label)
28 : LabelButton(NULL, label), 30 : LabelButton(NULL, label),
29 checked_(false) { 31 checked_(false) {
30 SetHorizontalAlignment(gfx::ALIGN_LEFT); 32 SetHorizontalAlignment(gfx::ALIGN_LEFT);
31 SetFocusForPlatform(); 33 SetFocusForPlatform();
32 34
33 if (UseMd()) { 35 if (UseMd()) {
34 set_request_focus_on_press(false); 36 set_request_focus_on_press(false);
37 SetInkDropMode(InkDropMode::ON);
38 set_has_ink_drop_action_on_click(true);
39 // The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp.
40 set_ink_drop_size(gfx::Size(21, 21));
35 } else { 41 } else {
36 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder()); 42 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder());
37 // Inset the trailing side by a couple pixels for the focus border. 43 // Inset the trailing side by a couple pixels for the focus border.
38 button_border->set_insets(gfx::Insets(0, 0, 0, 2)); 44 button_border->set_insets(gfx::Insets(0, 0, 0, 2));
39 SetBorder(std::move(button_border)); 45 SetBorder(std::move(button_border));
40 set_request_focus_on_press(true); 46 set_request_focus_on_press(true);
41 47
42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
43 49
44 // Unchecked/Unfocused images. 50 // Unchecked/Unfocused images.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (!UseMd()) 151 if (!UseMd())
146 UpdateImage(); 152 UpdateImage();
147 } 153 }
148 154
149 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { 155 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) {
150 LabelButton::OnNativeThemeChanged(theme); 156 LabelButton::OnNativeThemeChanged(theme);
151 if (UseMd()) 157 if (UseMd())
152 UpdateImage(); 158 UpdateImage();
153 } 159 }
154 160
161 std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const {
162 return CreateDefaultInkDropRipple(image()->bounds().CenterPoint());
163 }
164
165 std::unique_ptr<InkDropHighlight> Checkbox::CreateInkDropHighlight() const {
166 return nullptr;
167 }
168
169 SkColor Checkbox::GetInkDropBaseColor() const {
170 return GetNativeTheme()->GetSystemColor(
171 ui::NativeTheme::kColorId_UnfocusedBorderColor);
172 }
173
155 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { 174 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const {
156 if (UseMd()) { 175 if (UseMd()) {
157 return gfx::CreateVectorIcon( 176 return gfx::CreateVectorIcon(
158 checked_ ? gfx::VectorIconId::CHECKBOX_ACTIVE 177 checked_ ? gfx::VectorIconId::CHECKBOX_ACTIVE
159 : gfx::VectorIconId::CHECKBOX_NORMAL, 178 : gfx::VectorIconId::CHECKBOX_NORMAL,
160 16, GetNativeTheme()->GetSystemColor( 179 16, GetNativeTheme()->GetSystemColor(
161 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor 180 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor
162 : ui::NativeTheme::kColorId_UnfocusedBorderColor)); 181 : ui::NativeTheme::kColorId_UnfocusedBorderColor));
163 } 182 }
164 183
(...skipping 29 matching lines...) Expand all
194 ui::NativeTheme::Part Checkbox::GetThemePart() const { 213 ui::NativeTheme::Part Checkbox::GetThemePart() const {
195 return ui::NativeTheme::kCheckbox; 214 return ui::NativeTheme::kCheckbox;
196 } 215 }
197 216
198 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 217 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
199 LabelButton::GetExtraParams(params); 218 LabelButton::GetExtraParams(params);
200 params->button.checked = checked_; 219 params->button.checked = checked_;
201 } 220 }
202 221
203 } // namespace views 222 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/checkbox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698