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

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

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most TODOs and sync. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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/root_view.h" 9 #include "views/widget/root_view.h"
10 10
11 namespace views { 11 namespace views {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 } 55 }
56 } 56 }
57 } 57 }
58 Checkbox::SetChecked(checked); 58 Checkbox::SetChecked(checked);
59 } 59 }
60 60
61 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
62 // RadioButton, View overrides: 62 // RadioButton, View overrides:
63 63
64 void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) { 64 std::string RadioButton::GetClassName() const {
65 Checkbox::GetAccessibleState(state); 65 return kViewClassName;
66 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
67 } 66 }
68 67
69 View* RadioButton::GetSelectedViewForGroup(int group_id) { 68 View* RadioButton::GetSelectedViewForGroup(int group_id) {
70 std::vector<View*> views; 69 std::vector<View*> views;
71 GetRootView()->GetViewsWithGroup(group_id, &views); 70 GetRootView()->GetViewsWithGroup(group_id, &views);
72 if (views.empty()) 71 if (views.empty())
73 return NULL; 72 return NULL;
74 73
75 for (std::vector<View*>::const_iterator iter = views.begin(); 74 for (std::vector<View*>::const_iterator iter = views.begin();
76 iter != views.end(); ++iter) { 75 iter != views.end(); ++iter) {
77 RadioButton* radio_button = static_cast<RadioButton*>(*iter); 76 RadioButton* radio_button = static_cast<RadioButton*>(*iter);
78 if (radio_button->checked()) 77 if (radio_button->checked())
79 return radio_button; 78 return radio_button;
80 } 79 }
81 return NULL; 80 return NULL;
82 } 81 }
83 82
84 bool RadioButton::IsGroupFocusTraversable() const { 83 bool RadioButton::IsGroupFocusTraversable() const {
85 // When focusing a radio button with tab/shift+tab, only the selected button 84 // When focusing a radio button with tab/shift+tab, only the selected button
86 // from the group should be focused. 85 // from the group should be focused.
87 return false; 86 return false;
88 } 87 }
89 88
90 void RadioButton::OnMouseReleased(const MouseEvent& event, bool canceled) { 89 void RadioButton::OnMouseReleased(const MouseEvent& event) {
91 native_wrapper_->SetPushed(false); 90 native_wrapper_->SetPushed(false);
92 // Set the checked state to true only if we are unchecked, since we can't 91 // Set the checked state to true only if we are unchecked, since we can't
93 // be toggled on and off like a checkbox. 92 // be toggled on and off like a checkbox.
94 if (!checked() && !canceled && HitTestLabel(event)) 93 if (!checked() && HitTestLabel(event))
95 SetChecked(true); 94 SetChecked(true);
96 95
97 ButtonPressed(); 96 ButtonPressed();
98 } 97 }
99 98
100 std::string RadioButton::GetClassName() const { 99 void RadioButton::OnMouseCaptureLost() {
101 return kViewClassName; 100 native_wrapper_->SetPushed(false);
101 ButtonPressed();
102 }
103
104 void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
105 Checkbox::GetAccessibleState(state);
106 state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
102 } 107 }
103 108
104 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
105 // RadioButton, NativeButton overrides: 110 // RadioButton, NativeButton overrides:
106 111
107 NativeButtonWrapper* RadioButton::CreateWrapper() { 112 NativeButtonWrapper* RadioButton::CreateWrapper() {
108 NativeButtonWrapper* native_wrapper = 113 NativeButtonWrapper* native_wrapper =
109 NativeButtonWrapper::CreateRadioButtonWrapper(this); 114 NativeButtonWrapper::CreateRadioButtonWrapper(this);
110 native_wrapper->UpdateLabel(); 115 native_wrapper->UpdateLabel();
111 native_wrapper->UpdateChecked(); 116 native_wrapper->UpdateChecked();
112 return native_wrapper; 117 return native_wrapper;
113 } 118 }
114 119
115 } // namespace views 120 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698