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

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

Issue 15061006: views: Switch Checkbox over to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disabled images Created 7 years, 7 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 | Annotate | Revision Log
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 "grit/ui_resources.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 9 #include "ui/base/accessibility/accessible_view_state.h"
10 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
10 12
11 namespace views { 13 namespace views {
12 14
13 // static 15 // static
14 const char RadioButton::kViewClassName[] = "views/RadioButton"; 16 const char RadioButton::kViewClassName[] = "views/RadioButton";
15 17
16 RadioButton::RadioButton(const string16& label, int group_id) 18 RadioButton::RadioButton(const string16& label, int group_id)
17 : Checkbox(label) { 19 : Checkbox(label) {
18 SetGroup(group_id); 20 SetGroup(group_id);
19 set_focusable(true); 21 set_focusable(true);
22
23 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
24
25 // Disabled image.
26 SetCustomImage(false, false, STATE_DISABLED,
27 *rb.GetImageSkiaNamed(IDR_RADIO_DISABLED));
28
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
37 // Checked/Unfocused images.
38 SetCustomImage(true, false, STATE_NORMAL,
39 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED));
40 SetCustomImage(true, false, STATE_HOVERED,
41 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_HOVER));
42 SetCustomImage(true, false, STATE_PRESSED,
43 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_PRESSED));
44
45 // Unchecked/Focused images.
46 SetCustomImage(false, true, STATE_NORMAL,
47 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED));
48 SetCustomImage(false, true, STATE_HOVERED,
49 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_HOVER));
50 SetCustomImage(false, true, STATE_PRESSED,
51 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_PRESSED));
52
53 // Checked/Focused images.
54 SetCustomImage(true, true, STATE_NORMAL,
55 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED));
56 SetCustomImage(true, true, STATE_HOVERED,
57 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER));
58 SetCustomImage(true, true, STATE_PRESSED,
59 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED));
20 } 60 }
21 61
22 RadioButton::~RadioButton() { 62 RadioButton::~RadioButton() {
23 } 63 }
24 64
25 void RadioButton::SetChecked(bool checked) { 65 void RadioButton::SetChecked(bool checked) {
26 if (checked == RadioButton::checked()) 66 if (checked == RadioButton::checked())
27 return; 67 return;
28 if (checked) { 68 if (checked) {
29 // We can't just get the root view here because sometimes the radio 69 // We can't just get the root view here because sometimes the radio
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 bool RadioButton::IsGroupFocusTraversable() const { 118 bool RadioButton::IsGroupFocusTraversable() const {
79 // When focusing a radio button with tab/shift+tab, only the selected button 119 // When focusing a radio button with tab/shift+tab, only the selected button
80 // from the group should be focused. 120 // from the group should be focused.
81 return false; 121 return false;
82 } 122 }
83 123
84 void RadioButton::OnFocus() { 124 void RadioButton::OnFocus() {
85 Checkbox::OnFocus(); 125 Checkbox::OnFocus();
86 SetChecked(true); 126 SetChecked(true);
87 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); 127 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0);
88 TextButtonBase::NotifyClick(event); 128 LabelButton::NotifyClick(event);
89 } 129 }
90 130
91 void RadioButton::NotifyClick(const ui::Event& event) { 131 void RadioButton::NotifyClick(const ui::Event& event) {
92 // Set the checked state to true only if we are unchecked, since we can't 132 // Set the checked state to true only if we are unchecked, since we can't
93 // be toggled on and off like a checkbox. 133 // be toggled on and off like a checkbox.
94 if (!checked()) 134 if (!checked())
95 SetChecked(true); 135 SetChecked(true);
96 RequestFocus(); 136 RequestFocus();
97 TextButtonBase::NotifyClick(event); 137 LabelButton::NotifyClick(event);
98 } 138 }
99 139
100 ui::NativeTheme::Part RadioButton::GetThemePart() const { 140 ui::NativeTheme::Part RadioButton::GetThemePart() const {
101 return ui::NativeTheme::kRadio; 141 return ui::NativeTheme::kRadio;
102 } 142 }
103 143
104 } // namespace views 144 } // namespace views
OLDNEW
« ui/views/controls/button/checkbox.cc ('K') | « ui/views/controls/button/label_button_border.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698