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

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

Issue 2734273002: Remove dashed focus rect from Views checkboxes. (Closed)
Patch Set: review Created 3 years, 9 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
(...skipping 15 matching lines...) Expand all
26 namespace views { 26 namespace views {
27 27
28 // static 28 // static
29 const char Checkbox::kViewClassName[] = "Checkbox"; 29 const char Checkbox::kViewClassName[] = "Checkbox";
30 30
31 Checkbox::Checkbox(const base::string16& label) 31 Checkbox::Checkbox(const base::string16& label)
32 : LabelButton(NULL, label), 32 : LabelButton(NULL, label),
33 checked_(false) { 33 checked_(false) {
34 SetHorizontalAlignment(gfx::ALIGN_LEFT); 34 SetHorizontalAlignment(gfx::ALIGN_LEFT);
35 SetFocusForPlatform(); 35 SetFocusForPlatform();
36 SetFocusPainter(nullptr);
36 37
37 if (UseMd()) { 38 if (UseMd()) {
38 set_request_focus_on_press(false); 39 set_request_focus_on_press(false);
39 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON 40 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON
40 : InkDropMode::OFF); 41 : InkDropMode::OFF);
41 set_has_ink_drop_action_on_click(true); 42 set_has_ink_drop_action_on_click(true);
42 SetFocusPainter(nullptr);
43 } else { 43 } else {
44 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder()); 44 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder());
45 // Inset the trailing side by a couple pixels for the focus border. 45 // Inset the trailing side by a couple pixels for the focus border.
46 button_border->set_insets(gfx::Insets(0, 0, 0, 2)); 46 button_border->set_insets(gfx::Insets(0, 0, 0, 2));
47 SetBorder(std::move(button_border)); 47 SetBorder(std::move(button_border));
48 set_request_focus_on_press(true); 48 set_request_focus_on_press(true);
49 49
50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
51 51
52 // Unchecked/Unfocused images. 52 // Unchecked/Unfocused images.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void Checkbox::SetChecked(bool checked) { 97 void Checkbox::SetChecked(bool checked) {
98 checked_ = checked; 98 checked_ = checked;
99 UpdateImage(); 99 UpdateImage();
100 } 100 }
101 101
102 // static 102 // static
103 bool Checkbox::UseMd() { 103 bool Checkbox::UseMd() {
104 return ui::MaterialDesignController::IsSecondaryUiMaterial(); 104 return ui::MaterialDesignController::IsSecondaryUiMaterial();
105 } 105 }
106 106
107 void Checkbox::Layout() {
108 LabelButton::Layout();
109
110 if (!UseMd()) {
111 // Construct a focus painter that only surrounds the label area.
112 gfx::Rect rect = label()->GetMirroredBounds();
113 rect.Inset(-2, 3);
114 SetFocusPainter(Painter::CreateDashedFocusPainterWithInsets(gfx::Insets(
115 rect.y(), rect.x(), height() - rect.bottom(), width() - rect.right())));
116 }
117 }
118
119 const char* Checkbox::GetClassName() const { 107 const char* Checkbox::GetClassName() const {
120 return kViewClassName; 108 return kViewClassName;
121 } 109 }
122 110
123 void Checkbox::GetAccessibleNodeData(ui::AXNodeData* node_data) { 111 void Checkbox::GetAccessibleNodeData(ui::AXNodeData* node_data) {
124 LabelButton::GetAccessibleNodeData(node_data); 112 LabelButton::GetAccessibleNodeData(node_data);
125 node_data->role = ui::AX_ROLE_CHECK_BOX; 113 node_data->role = ui::AX_ROLE_CHECK_BOX;
126 if (checked()) 114 if (checked())
127 node_data->AddStateFlag(ui::AX_STATE_CHECKED); 115 node_data->AddStateFlag(ui::AX_STATE_CHECKED);
128 if (enabled()) { 116 if (enabled()) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ui::NativeTheme::Part Checkbox::GetThemePart() const { 220 ui::NativeTheme::Part Checkbox::GetThemePart() const {
233 return ui::NativeTheme::kCheckbox; 221 return ui::NativeTheme::kCheckbox;
234 } 222 }
235 223
236 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 224 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
237 LabelButton::GetExtraParams(params); 225 LabelButton::GetExtraParams(params);
238 params->button.checked = checked_; 226 params->button.checked = checked_;
239 } 227 }
240 228
241 } // namespace views 229 } // 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