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

Side by Side Diff: third_party/WebKit/Source/core/html/forms/RadioButtonGroupScope.cpp

Issue 1628283002: posinset and setsize for input type, radio, exposed in AX tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 20 matching lines...) Expand all
31 public: 31 public:
32 static PassOwnPtrWillBeRawPtr<RadioButtonGroup> create(); 32 static PassOwnPtrWillBeRawPtr<RadioButtonGroup> create();
33 bool isEmpty() const { return m_members.isEmpty(); } 33 bool isEmpty() const { return m_members.isEmpty(); }
34 bool isRequired() const { return m_requiredCount; } 34 bool isRequired() const { return m_requiredCount; }
35 HTMLInputElement* checkedButton() const { return m_checkedButton; } 35 HTMLInputElement* checkedButton() const { return m_checkedButton; }
36 void add(HTMLInputElement*); 36 void add(HTMLInputElement*);
37 void updateCheckedState(HTMLInputElement*); 37 void updateCheckedState(HTMLInputElement*);
38 void requiredAttributeChanged(HTMLInputElement*); 38 void requiredAttributeChanged(HTMLInputElement*);
39 void remove(HTMLInputElement*); 39 void remove(HTMLInputElement*);
40 bool contains(HTMLInputElement*) const; 40 bool contains(HTMLInputElement*) const;
41 unsigned posInMembers(HTMLInputElement*) const;
keishi 2016/01/26 01:32:23 nit: Blink style avoid abbreviations so positionIn
je_julie(Not used) 2016/02/02 00:36:17 Done
42 unsigned sizeOfMembers() const;
41 43
42 DECLARE_TRACE(); 44 DECLARE_TRACE();
43 45
44 private: 46 private:
45 RadioButtonGroup(); 47 RadioButtonGroup();
46 void setNeedsValidityCheckForAllButtons(); 48 void setNeedsValidityCheckForAllButtons();
47 bool isValid() const; 49 bool isValid() const;
48 void setCheckedButton(HTMLInputElement*); 50 void setCheckedButton(HTMLInputElement*);
49 51
50 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement>> m_members; 52 WillBeHeapVector<RawPtrWillBeMember<HTMLInputElement>> m_members;
keishi 2016/01/26 01:32:23 This change will conflict with https://codereview.
je_julie(Not used) 2016/02/02 00:36:17 I rebased code on that CL.
51 RawPtrWillBeMember<HTMLInputElement> m_checkedButton; 53 RawPtrWillBeMember<HTMLInputElement> m_checkedButton;
52 size_t m_requiredCount; 54 size_t m_requiredCount;
53 }; 55 };
54 56
55 RadioButtonGroup::RadioButtonGroup() 57 RadioButtonGroup::RadioButtonGroup()
56 : m_checkedButton(nullptr) 58 : m_checkedButton(nullptr)
57 , m_requiredCount(0) 59 , m_requiredCount(0)
58 { 60 {
59 } 61 }
60 62
(...skipping 13 matching lines...) Expand all
74 if (oldCheckedButton == button) 76 if (oldCheckedButton == button)
75 return; 77 return;
76 m_checkedButton = button; 78 m_checkedButton = button;
77 if (oldCheckedButton) 79 if (oldCheckedButton)
78 oldCheckedButton->setChecked(false); 80 oldCheckedButton->setChecked(false);
79 } 81 }
80 82
81 void RadioButtonGroup::add(HTMLInputElement* button) 83 void RadioButtonGroup::add(HTMLInputElement* button)
82 { 84 {
83 ASSERT(button->type() == InputTypeNames::radio); 85 ASSERT(button->type() == InputTypeNames::radio);
84 if (!m_members.add(button).isNewEntry) 86 if (m_members.contains(button))
85 return; 87 return;
88 m_members.append(button);
86 bool groupWasValid = isValid(); 89 bool groupWasValid = isValid();
87 if (button->isRequired()) 90 if (button->isRequired())
88 ++m_requiredCount; 91 ++m_requiredCount;
89 if (button->checked()) 92 if (button->checked())
90 setCheckedButton(button); 93 setCheckedButton(button);
91 94
92 bool groupIsValid = isValid(); 95 bool groupIsValid = isValid();
93 if (groupWasValid != groupIsValid) { 96 if (groupWasValid != groupIsValid) {
94 setNeedsValidityCheckForAllButtons(); 97 setNeedsValidityCheckForAllButtons();
95 } else if (!groupIsValid) { 98 } else if (!groupIsValid) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ASSERT(m_requiredCount); 131 ASSERT(m_requiredCount);
129 --m_requiredCount; 132 --m_requiredCount;
130 } 133 }
131 if (wasValid != isValid()) 134 if (wasValid != isValid())
132 setNeedsValidityCheckForAllButtons(); 135 setNeedsValidityCheckForAllButtons();
133 } 136 }
134 137
135 void RadioButtonGroup::remove(HTMLInputElement* button) 138 void RadioButtonGroup::remove(HTMLInputElement* button)
136 { 139 {
137 ASSERT(button->type() == InputTypeNames::radio); 140 ASSERT(button->type() == InputTypeNames::radio);
138 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement>>::iterator it = m_mem bers.find(button); 141 size_t idx = m_members.find(button);
139 if (it == m_members.end()) 142 if (idx == kNotFound)
140 return; 143 return;
141 bool wasValid = isValid(); 144 bool wasValid = isValid();
142 m_members.remove(it); 145 m_members.remove(idx);
143 if (button->isRequired()) { 146 if (button->isRequired()) {
144 ASSERT(m_requiredCount); 147 ASSERT(m_requiredCount);
145 --m_requiredCount; 148 --m_requiredCount;
146 } 149 }
147 if (m_checkedButton == button) 150 if (m_checkedButton == button)
148 m_checkedButton = nullptr; 151 m_checkedButton = nullptr;
149 152
150 if (m_members.isEmpty()) { 153 if (m_members.isEmpty()) {
151 ASSERT(!m_requiredCount); 154 ASSERT(!m_requiredCount);
152 ASSERT(!m_checkedButton); 155 ASSERT(!m_checkedButton);
(...skipping 13 matching lines...) Expand all
166 ASSERT(button->type() == InputTypeNames::radio); 169 ASSERT(button->type() == InputTypeNames::radio);
167 button->setNeedsValidityCheck(); 170 button->setNeedsValidityCheck();
168 } 171 }
169 } 172 }
170 173
171 bool RadioButtonGroup::contains(HTMLInputElement* button) const 174 bool RadioButtonGroup::contains(HTMLInputElement* button) const
172 { 175 {
173 return m_members.contains(button); 176 return m_members.contains(button);
174 } 177 }
175 178
179 unsigned RadioButtonGroup::posInMembers(HTMLInputElement* element) const
180 {
181 unsigned index = 0;
182 for (HTMLInputElement* const button : m_members) {
183 index++;
184 if (button == element)
185 return index;
186 }
187 return 0;
188 }
189
190 unsigned RadioButtonGroup::sizeOfMembers() const
191 {
192 return m_members.size();
193 }
194
176 DEFINE_TRACE(RadioButtonGroup) 195 DEFINE_TRACE(RadioButtonGroup)
177 { 196 {
178 #if ENABLE(OILPAN) 197 #if ENABLE(OILPAN)
179 visitor->trace(m_members); 198 visitor->trace(m_members);
180 visitor->trace(m_checkedButton); 199 visitor->trace(m_checkedButton);
181 #endif 200 #endif
182 } 201 }
183 202
184 // ---------------------------------------------------------------- 203 // ----------------------------------------------------------------
185 204
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 { 266 {
248 ASSERT(element->type() == InputTypeNames::radio); 267 ASSERT(element->type() == InputTypeNames::radio);
249 if (element->name().isEmpty()) 268 if (element->name().isEmpty())
250 return false; 269 return false;
251 if (!m_nameToGroupMap) 270 if (!m_nameToGroupMap)
252 return false; 271 return false;
253 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); 272 RadioButtonGroup* group = m_nameToGroupMap->get(element->name());
254 return group && group->isRequired() && group->contains(element); 273 return group && group->isRequired() && group->contains(element);
255 } 274 }
256 275
276 unsigned RadioButtonGroupScope::posInGroup(HTMLInputElement* element) const
277 {
278 if (!m_nameToGroupMap)
279 return 0;
280
281 RadioButtonGroup* group = m_nameToGroupMap->get(element->name());
282 if (!group)
283 return 0;
284
285 return group->posInMembers(element);
286 }
287
288 unsigned RadioButtonGroupScope::sizeOfGroup(HTMLInputElement* element) const
289 {
290 if (!m_nameToGroupMap)
291 return 0;
292
293 RadioButtonGroup* group = m_nameToGroupMap->get(element->name());
294 if (!group)
295 return 0;
296 return group->sizeOfMembers();
297 }
298
257 void RadioButtonGroupScope::removeButton(HTMLInputElement* element) 299 void RadioButtonGroupScope::removeButton(HTMLInputElement* element)
258 { 300 {
259 ASSERT(element->type() == InputTypeNames::radio); 301 ASSERT(element->type() == InputTypeNames::radio);
260 if (element->name().isEmpty()) 302 if (element->name().isEmpty())
261 return; 303 return;
262 if (!m_nameToGroupMap) 304 if (!m_nameToGroupMap)
263 return; 305 return;
264 306
265 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); 307 RadioButtonGroup* group = m_nameToGroupMap->get(element->name());
266 if (!group) 308 if (!group)
267 return; 309 return;
268 group->remove(element); 310 group->remove(element);
269 if (group->isEmpty()) { 311 if (group->isEmpty()) {
270 // We don't remove an empty RadioButtonGroup from m_nameToGroupMap for 312 // We don't remove an empty RadioButtonGroup from m_nameToGroupMap for
271 // better performance. 313 // better performance.
272 ASSERT(!group->isRequired()); 314 ASSERT(!group->isRequired());
273 ASSERT_WITH_SECURITY_IMPLICATION(!group->checkedButton()); 315 ASSERT_WITH_SECURITY_IMPLICATION(!group->checkedButton());
274 } 316 }
275 } 317 }
276 318
277 DEFINE_TRACE(RadioButtonGroupScope) 319 DEFINE_TRACE(RadioButtonGroupScope)
278 { 320 {
279 #if ENABLE(OILPAN) 321 #if ENABLE(OILPAN)
280 visitor->trace(m_nameToGroupMap); 322 visitor->trace(m_nameToGroupMap);
281 #endif 323 #endif
282 } 324 }
283 325
284 } // namespace 326 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698