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

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

Issue 2240603002: Harmony checkbox/radio tweaks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 4 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"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 SetCustomImage(true, true, STATE_HOVERED, 60 SetCustomImage(true, true, STATE_HOVERED,
61 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER)); 61 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER));
62 SetCustomImage(true, true, STATE_PRESSED, 62 SetCustomImage(true, true, STATE_PRESSED,
63 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED)); 63 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED));
64 } 64 }
65 } 65 }
66 66
67 RadioButton::~RadioButton() { 67 RadioButton::~RadioButton() {
68 } 68 }
69 69
70 void RadioButton::SetChecked(bool checked) {
71 if (checked == RadioButton::checked())
72 return;
73 if (checked) {
74 // We can't just get the root view here because sometimes the radio
75 // button isn't attached to a root view (e.g., if it's part of a tab page
76 // that is currently not active).
77 View* container = parent();
78 while (container && container->parent())
79 container = container->parent();
80 if (container) {
81 Views other;
82 container->GetViewsInGroup(GetGroup(), &other);
83 for (Views::iterator i(other.begin()); i != other.end(); ++i) {
84 if (*i != this) {
85 if (strcmp((*i)->GetClassName(), kViewClassName)) {
86 NOTREACHED() << "radio-button-nt has same group as other non "
87 "radio-button-nt views.";
88 continue;
89 }
90 RadioButton* peer = static_cast<RadioButton*>(*i);
91 peer->SetChecked(false);
92 }
93 }
94 }
95 }
96 Checkbox::SetChecked(checked);
97 }
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
104 const char* RadioButton::GetClassName() const { 70 const char* RadioButton::GetClassName() const {
105 return kViewClassName; 71 return kViewClassName;
106 } 72 }
107 73
108 void RadioButton::GetAccessibleState(ui::AXViewState* state) { 74 void RadioButton::GetAccessibleState(ui::AXViewState* state) {
109 Checkbox::GetAccessibleState(state); 75 Checkbox::GetAccessibleState(state);
110 state->role = ui::AX_ROLE_RADIO_BUTTON; 76 state->role = ui::AX_ROLE_RADIO_BUTTON;
111 } 77 }
112 78
113 View* RadioButton::GetSelectedViewForGroup(int group) { 79 View* RadioButton::GetSelectedViewForGroup(int group) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (!checked()) 111 if (!checked())
146 SetChecked(true); 112 SetChecked(true);
147 RequestFocus(); 113 RequestFocus();
148 LabelButton::NotifyClick(event); 114 LabelButton::NotifyClick(event);
149 } 115 }
150 116
151 ui::NativeTheme::Part RadioButton::GetThemePart() const { 117 ui::NativeTheme::Part RadioButton::GetThemePart() const {
152 return ui::NativeTheme::kRadio; 118 return ui::NativeTheme::kRadio;
153 } 119 }
154 120
155 gfx::ImageSkia RadioButton::GetImage(ButtonState for_state) const { 121 void RadioButton::SetChecked(bool checked) {
156 if (!UseMd()) 122 if (checked == RadioButton::checked())
157 return Checkbox::GetImage(for_state); 123 return;
124 if (checked) {
125 // We can't just get the root view here because sometimes the radio
126 // button isn't attached to a root view (e.g., if it's part of a tab page
127 // that is currently not active).
128 View* container = parent();
129 while (container && container->parent())
130 container = container->parent();
131 if (container) {
132 Views other;
133 container->GetViewsInGroup(GetGroup(), &other);
134 for (Views::iterator i(other.begin()); i != other.end(); ++i) {
135 if (*i != this) {
136 if (strcmp((*i)->GetClassName(), kViewClassName)) {
137 NOTREACHED() << "radio-button-nt has same group as other non "
138 "radio-button-nt views.";
139 continue;
140 }
141 RadioButton* peer = static_cast<RadioButton*>(*i);
142 peer->SetChecked(false);
143 }
144 }
145 }
146 }
147 Checkbox::SetChecked(checked);
148 }
158 149
159 return gfx::CreateVectorIcon( 150 void RadioButton::PaintFocusRing(gfx::Canvas* canvas, const SkPaint& paint) {
160 checked() ? gfx::VectorIconId::RADIO_BUTTON_ACTIVE 151 canvas->DrawCircle(gfx::RectF(image()->bounds()).CenterPoint(),
161 : gfx::VectorIconId::RADIO_BUTTON_NORMAL, 152 image()->width() / 2, paint);
162 16, GetNativeTheme()->GetSystemColor( 153 }
163 checked() ? ui::NativeTheme::kColorId_FocusedBorderColor 154
164 : ui::NativeTheme::kColorId_UnfocusedBorderColor)); 155 gfx::VectorIconId RadioButton::GetVectorIconId() const {
156 return checked() ? gfx::VectorIconId::RADIO_BUTTON_ACTIVE
157 : gfx::VectorIconId::RADIO_BUTTON_NORMAL;
165 } 158 }
166 159
167 } // namespace views 160 } // 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