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

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

Issue 7057014: Variety of tweaks to View API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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
« no previous file with comments | « views/controls/button/native_button.cc ('k') | 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/controls/button/radio_button.h" 5 #include "views/controls/button/radio_button.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "views/widget/widget.h" 9 #include "views/widget/widget.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 // static 13 // static
14 const char RadioButton::kViewClassName[] = "views/RadioButton"; 14 const char RadioButton::kViewClassName[] = "views/RadioButton";
15 15
16 // static 16 // static
17 const char RadioButtonNt::kViewClassName[] = "views/RadioButtonNt"; 17 const char RadioButtonNt::kViewClassName[] = "views/RadioButtonNt";
18 18
19 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
20 // RadioButton, public: 20 // RadioButton, public:
21 21
22 RadioButton::RadioButton(const std::wstring& label, int group_id) 22 RadioButton::RadioButton(const std::wstring& label, int group_id)
23 : Checkbox(label) { 23 : Checkbox(label) {
24 SetGroup(group_id); 24 set_group(group_id);
25 } 25 }
26 26
27 RadioButton::~RadioButton() { 27 RadioButton::~RadioButton() {
28 } 28 }
29 29
30 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
31 // RadioButton, Checkbox overrides: 31 // RadioButton, Checkbox overrides:
32 32
33 void RadioButton::SetChecked(bool checked) { 33 void RadioButton::SetChecked(bool checked) {
34 if (checked == RadioButton::checked()) 34 if (checked == RadioButton::checked())
35 return; 35 return;
36 if (native_wrapper_ && 36 if (native_wrapper_ &&
37 !native_wrapper_->UsesNativeRadioButtonGroup() && checked) { 37 !native_wrapper_->UsesNativeRadioButtonGroup() && checked) {
38 // We can't just get the root view here because sometimes the radio 38 // We can't just get the root view here because sometimes the radio
39 // button isn't attached to a root view (e.g., if it's part of a tab page 39 // button isn't attached to a root view (e.g., if it's part of a tab page
40 // that is currently not active). 40 // that is currently not active).
41 View* container = parent(); 41 View* container = parent();
42 while (container && container->parent()) 42 while (container && container->parent())
43 container = container->parent(); 43 container = container->parent();
44 if (container) { 44 if (container) {
45 std::vector<View*> other; 45 std::vector<View*> other;
46 container->GetViewsWithGroup(GetGroup(), &other); 46 container->GetViewsInGroup(group(), &other);
47 std::vector<View*>::iterator i; 47 std::vector<View*>::iterator i;
48 for (i = other.begin(); i != other.end(); ++i) { 48 for (i = other.begin(); i != other.end(); ++i) {
49 if (*i != this) { 49 if (*i != this) {
50 if ((*i)->GetClassName() != kViewClassName) { 50 if ((*i)->GetClassName() != kViewClassName) {
51 NOTREACHED() << "radio-button has same group as other non " 51 NOTREACHED() << "radio-button has same group as other non "
52 "radio-button views."; 52 "radio-button views.";
53 continue; 53 continue;
54 } 54 }
55 RadioButton* peer = static_cast<RadioButton*>(*i); 55 RadioButton* peer = static_cast<RadioButton*>(*i);
56 peer->SetChecked(false); 56 peer->SetChecked(false);
57 } 57 }
58 } 58 }
59 } 59 }
60 } 60 }
61 Checkbox::SetChecked(checked); 61 Checkbox::SetChecked(checked);
62 } 62 }
63 63
64 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
65 // RadioButton, View overrides: 65 // RadioButton, View overrides:
66 66
67 void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) { 67 void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
68 Checkbox::GetAccessibleState(state); 68 Checkbox::GetAccessibleState(state);
69 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON; 69 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
70 } 70 }
71 71
72 View* RadioButton::GetSelectedViewForGroup(int group_id) { 72 View* RadioButton::GetSelectedViewForGroup(int group_id) {
73 std::vector<View*> views; 73 std::vector<View*> views;
74 GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views); 74 GetWidget()->GetRootView()->GetViewsInGroup(group_id, &views);
75 if (views.empty()) 75 if (views.empty())
76 return NULL; 76 return NULL;
77 77
78 for (std::vector<View*>::const_iterator iter = views.begin(); 78 for (std::vector<View*>::const_iterator iter = views.begin();
79 iter != views.end(); ++iter) { 79 iter != views.end(); ++iter) {
80 RadioButton* radio_button = static_cast<RadioButton*>(*iter); 80 RadioButton* radio_button = static_cast<RadioButton*>(*iter);
81 if (radio_button->checked()) 81 if (radio_button->checked())
82 return radio_button; 82 return radio_button;
83 } 83 }
84 return NULL; 84 return NULL;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
119 // 119 //
120 // RadioButtonNt 120 // RadioButtonNt
121 // 121 //
122 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
123 123
124 RadioButtonNt::RadioButtonNt(const std::wstring& label, int group_id) 124 RadioButtonNt::RadioButtonNt(const std::wstring& label, int group_id)
125 : CheckboxNt(label) { 125 : CheckboxNt(label) {
126 SetGroup(group_id); 126 set_group(group_id);
127 } 127 }
128 128
129 RadioButtonNt::~RadioButtonNt() { 129 RadioButtonNt::~RadioButtonNt() {
130 } 130 }
131 131
132 void RadioButtonNt::SetChecked(bool checked) { 132 void RadioButtonNt::SetChecked(bool checked) {
133 if (checked == RadioButtonNt::checked()) 133 if (checked == RadioButtonNt::checked())
134 return; 134 return;
135 if (checked) { 135 if (checked) {
136 // We can't just get the root view here because sometimes the radio 136 // We can't just get the root view here because sometimes the radio
137 // button isn't attached to a root view (e.g., if it's part of a tab page 137 // button isn't attached to a root view (e.g., if it's part of a tab page
138 // that is currently not active). 138 // that is currently not active).
139 View* container = parent(); 139 View* container = parent();
140 while (container && container->parent()) 140 while (container && container->parent())
141 container = container->parent(); 141 container = container->parent();
142 if (container) { 142 if (container) {
143 std::vector<View*> other; 143 std::vector<View*> other;
144 container->GetViewsWithGroup(GetGroup(), &other); 144 container->GetViewsInGroup(group(), &other);
145 std::vector<View*>::iterator i; 145 std::vector<View*>::iterator i;
146 for (i = other.begin(); i != other.end(); ++i) { 146 for (i = other.begin(); i != other.end(); ++i) {
147 if (*i != this) { 147 if (*i != this) {
148 if ((*i)->GetClassName() != kViewClassName) { 148 if ((*i)->GetClassName() != kViewClassName) {
149 NOTREACHED() << "radio-button-nt has same group as other non " 149 NOTREACHED() << "radio-button-nt has same group as other non "
150 "radio-button-nt views."; 150 "radio-button-nt views.";
151 continue; 151 continue;
152 } 152 }
153 RadioButtonNt* peer = static_cast<RadioButtonNt*>(*i); 153 RadioButtonNt* peer = static_cast<RadioButtonNt*>(*i);
154 peer->SetChecked(false); 154 peer->SetChecked(false);
155 } 155 }
156 } 156 }
157 } 157 }
158 } 158 }
159 CheckboxNt::SetChecked(checked); 159 CheckboxNt::SetChecked(checked);
160 } 160 }
161 161
162 std::string RadioButtonNt::GetClassName() const { 162 std::string RadioButtonNt::GetClassName() const {
163 return kViewClassName; 163 return kViewClassName;
164 } 164 }
165 165
166 void RadioButtonNt::GetAccessibleState(ui::AccessibleViewState* state) { 166 void RadioButtonNt::GetAccessibleState(ui::AccessibleViewState* state) {
167 CheckboxNt::GetAccessibleState(state); 167 CheckboxNt::GetAccessibleState(state);
168 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON; 168 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
169 } 169 }
170 170
171 View* RadioButtonNt::GetSelectedViewForGroup(int group_id) { 171 View* RadioButtonNt::GetSelectedViewForGroup(int group_id) {
172 std::vector<View*> views; 172 std::vector<View*> views;
173 GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views); 173 GetWidget()->GetRootView()->GetViewsInGroup(group_id, &views);
174 if (views.empty()) 174 if (views.empty())
175 return NULL; 175 return NULL;
176 176
177 for (std::vector<View*>::const_iterator iter = views.begin(); 177 for (std::vector<View*>::const_iterator iter = views.begin();
178 iter != views.end(); ++iter) { 178 iter != views.end(); ++iter) {
179 // REVIEW: why don't we check the runtime type like is done above? 179 // REVIEW: why don't we check the runtime type like is done above?
180 RadioButtonNt* radio_button = static_cast<RadioButtonNt*>(*iter); 180 RadioButtonNt* radio_button = static_cast<RadioButtonNt*>(*iter);
181 if (radio_button->checked()) 181 if (radio_button->checked())
182 return radio_button; 182 return radio_button;
183 } 183 }
(...skipping 12 matching lines...) Expand all
196 if (!checked()) 196 if (!checked())
197 SetChecked(true); 197 SetChecked(true);
198 RequestFocus(); 198 RequestFocus();
199 } 199 }
200 200
201 gfx::NativeTheme::Part RadioButtonNt::GetThemePart() const { 201 gfx::NativeTheme::Part RadioButtonNt::GetThemePart() const {
202 return gfx::NativeTheme::kRadio; 202 return gfx::NativeTheme::kRadio;
203 } 203 }
204 204
205 } // namespace views 205 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/native_button.cc ('k') | views/controls/combobox/combobox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698