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

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

Issue 2026833003: MD - update checkbox and radio buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky review Created 4 years, 6 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.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/radio_button.h" 5 #include "ui/views/controls/button/radio_button.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/events/event_utils.h" 10 #include "ui/events/event_utils.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/paint_vector_icon.h"
13 #include "ui/gfx/vector_icons_public.h"
11 #include "ui/resources/grit/ui_resources.h" 14 #include "ui/resources/grit/ui_resources.h"
12 #include "ui/views/resources/grit/views_resources.h" 15 #include "ui/views/resources/grit/views_resources.h"
13 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
14 17
15 namespace views { 18 namespace views {
16 19
17 // static 20 // static
18 const char RadioButton::kViewClassName[] = "RadioButton"; 21 const char RadioButton::kViewClassName[] = "RadioButton";
19 22
20 RadioButton::RadioButton(const base::string16& label, int group_id) 23 RadioButton::RadioButton(const base::string16& label, int group_id)
21 : Checkbox(label) { 24 : Checkbox(label) {
22 SetGroup(group_id); 25 SetGroup(group_id);
23 26
24 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 27 if (!UseMd()) {
28 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
29 // Unchecked/Unfocused images.
30 SetCustomImage(false, false, STATE_NORMAL,
31 *rb.GetImageSkiaNamed(IDR_RADIO));
32 SetCustomImage(false, false, STATE_HOVERED,
33 *rb.GetImageSkiaNamed(IDR_RADIO_HOVER));
34 SetCustomImage(false, false, STATE_PRESSED,
35 *rb.GetImageSkiaNamed(IDR_RADIO_PRESSED));
36 SetCustomImage(false, false, STATE_DISABLED,
37 *rb.GetImageSkiaNamed(IDR_RADIO_DISABLED));
25 38
26 // Unchecked/Unfocused images. 39 // Checked/Unfocused images.
27 SetCustomImage(false, false, STATE_NORMAL, 40 SetCustomImage(true, false, STATE_NORMAL,
28 *rb.GetImageSkiaNamed(IDR_RADIO)); 41 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED));
29 SetCustomImage(false, false, STATE_HOVERED, 42 SetCustomImage(true, false, STATE_HOVERED,
30 *rb.GetImageSkiaNamed(IDR_RADIO_HOVER)); 43 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_HOVER));
31 SetCustomImage(false, false, STATE_PRESSED, 44 SetCustomImage(true, false, STATE_PRESSED,
32 *rb.GetImageSkiaNamed(IDR_RADIO_PRESSED)); 45 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_PRESSED));
33 SetCustomImage(false, false, STATE_DISABLED, 46 SetCustomImage(true, false, STATE_DISABLED,
34 *rb.GetImageSkiaNamed(IDR_RADIO_DISABLED)); 47 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_DISABLED));
35 48
36 // Checked/Unfocused images. 49 // Unchecked/Focused images.
37 SetCustomImage(true, false, STATE_NORMAL, 50 SetCustomImage(false, true, STATE_NORMAL,
38 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED)); 51 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED));
39 SetCustomImage(true, false, STATE_HOVERED, 52 SetCustomImage(false, true, STATE_HOVERED,
40 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_HOVER)); 53 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_HOVER));
41 SetCustomImage(true, false, STATE_PRESSED, 54 SetCustomImage(false, true, STATE_PRESSED,
42 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_PRESSED)); 55 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_PRESSED));
43 SetCustomImage(true, false, STATE_DISABLED,
44 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_DISABLED));
45 56
46 // Unchecked/Focused images. 57 // Checked/Focused images.
47 SetCustomImage(false, true, STATE_NORMAL, 58 SetCustomImage(true, true, STATE_NORMAL,
48 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED)); 59 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED));
49 SetCustomImage(false, true, STATE_HOVERED, 60 SetCustomImage(true, true, STATE_HOVERED,
50 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_HOVER)); 61 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER));
51 SetCustomImage(false, true, STATE_PRESSED, 62 SetCustomImage(true, true, STATE_PRESSED,
52 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_PRESSED)); 63 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED));
53 64 }
54 // Checked/Focused images.
55 SetCustomImage(true, true, STATE_NORMAL,
56 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED));
57 SetCustomImage(true, true, STATE_HOVERED,
58 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER));
59 SetCustomImage(true, true, STATE_PRESSED,
60 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED));
61 } 65 }
62 66
63 RadioButton::~RadioButton() { 67 RadioButton::~RadioButton() {
64 } 68 }
65 69
66 void RadioButton::SetChecked(bool checked) { 70 void RadioButton::SetChecked(bool checked) {
67 if (checked == RadioButton::checked()) 71 if (checked == RadioButton::checked())
68 return; 72 return;
69 if (checked) { 73 if (checked) {
70 // We can't just get the root view here because sometimes the radio 74 // We can't just get the root view here because sometimes the radio
(...skipping 14 matching lines...) Expand all
85 } 89 }
86 RadioButton* peer = static_cast<RadioButton*>(*i); 90 RadioButton* peer = static_cast<RadioButton*>(*i);
87 peer->SetChecked(false); 91 peer->SetChecked(false);
88 } 92 }
89 } 93 }
90 } 94 }
91 } 95 }
92 Checkbox::SetChecked(checked); 96 Checkbox::SetChecked(checked);
93 } 97 }
94 98
99 void RadioButton::PaintFocusRing(gfx::Canvas* canvas, const SkPaint& paint) {
100 canvas->DrawCircle(gfx::PointF(image()->bounds().CenterPoint()),
101 image()->width() / 2 + .5f, paint);
102 }
103
95 const char* RadioButton::GetClassName() const { 104 const char* RadioButton::GetClassName() const {
96 return kViewClassName; 105 return kViewClassName;
97 } 106 }
98 107
99 void RadioButton::GetAccessibleState(ui::AXViewState* state) { 108 void RadioButton::GetAccessibleState(ui::AXViewState* state) {
100 Checkbox::GetAccessibleState(state); 109 Checkbox::GetAccessibleState(state);
101 state->role = ui::AX_ROLE_RADIO_BUTTON; 110 state->role = ui::AX_ROLE_RADIO_BUTTON;
102 } 111 }
103 112
104 View* RadioButton::GetSelectedViewForGroup(int group) { 113 View* RadioButton::GetSelectedViewForGroup(int group) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (!checked()) 145 if (!checked())
137 SetChecked(true); 146 SetChecked(true);
138 RequestFocus(); 147 RequestFocus();
139 LabelButton::NotifyClick(event); 148 LabelButton::NotifyClick(event);
140 } 149 }
141 150
142 ui::NativeTheme::Part RadioButton::GetThemePart() const { 151 ui::NativeTheme::Part RadioButton::GetThemePart() const {
143 return ui::NativeTheme::kRadio; 152 return ui::NativeTheme::kRadio;
144 } 153 }
145 154
155 gfx::ImageSkia RadioButton::GetImage(ButtonState for_state) const {
156 if (!UseMd())
157 return Checkbox::GetImage(for_state);
158
159 return gfx::CreateVectorIcon(
160 checked() ? gfx::VectorIconId::RADIO_BUTTON_ACTIVE
161 : gfx::VectorIconId::RADIO_BUTTON_NORMAL,
162 16, GetNativeTheme()->GetSystemColor(
163 checked() ? ui::NativeTheme::kColorId_FocusedBorderColor
164 : ui::NativeTheme::kColorId_UnfocusedBorderColor));
165 }
166
146 } // namespace views 167 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/radio_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698