OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 bool contains(HTMLInputElement*) const; | 41 bool contains(HTMLInputElement*) const; |
42 | 42 |
43 void trace(Visitor*); | 43 void trace(Visitor*); |
44 | 44 |
45 private: | 45 private: |
46 RadioButtonGroup(); | 46 RadioButtonGroup(); |
47 void setNeedsValidityCheckForAllButtons(); | 47 void setNeedsValidityCheckForAllButtons(); |
48 bool isValid() const; | 48 bool isValid() const; |
49 void setCheckedButton(HTMLInputElement*); | 49 void setCheckedButton(HTMLInputElement*); |
50 | 50 |
51 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement> > m_members; | 51 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement>> m_members; |
52 RawPtrWillBeMember<HTMLInputElement> m_checkedButton; | 52 RawPtrWillBeMember<HTMLInputElement> m_checkedButton; |
53 size_t m_requiredCount; | 53 size_t m_requiredCount; |
54 }; | 54 }; |
55 | 55 |
56 RadioButtonGroup::RadioButtonGroup() | 56 RadioButtonGroup::RadioButtonGroup() |
57 : m_checkedButton(nullptr) | 57 : m_checkedButton(nullptr) |
58 , m_requiredCount(0) | 58 , m_requiredCount(0) |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 ASSERT(m_members.contains(button)); | 106 ASSERT(m_members.contains(button)); |
107 bool wasValid = isValid(); | 107 bool wasValid = isValid(); |
108 if (button->checked()) { | 108 if (button->checked()) { |
109 setCheckedButton(button); | 109 setCheckedButton(button); |
110 } else { | 110 } else { |
111 if (m_checkedButton == button) | 111 if (m_checkedButton == button) |
112 m_checkedButton = nullptr; | 112 m_checkedButton = nullptr; |
113 } | 113 } |
114 if (wasValid != isValid()) | 114 if (wasValid != isValid()) |
115 setNeedsValidityCheckForAllButtons(); | 115 setNeedsValidityCheckForAllButtons(); |
116 typedef WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement> >::const_iter
ator Iterator; | 116 for (HTMLInputElement* const inputElement : m_members) { |
117 Iterator end = m_members.end(); | 117 inputElement->pseudoStateChanged(CSSSelector::PseudoIndeterminate); |
118 for (Iterator it = m_members.begin(); it != end; ++it) { | |
119 (*it)->pseudoStateChanged(CSSSelector::PseudoIndeterminate); | |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 void RadioButtonGroup::requiredAttributeChanged(HTMLInputElement* button) | 121 void RadioButtonGroup::requiredAttributeChanged(HTMLInputElement* button) |
124 { | 122 { |
125 ASSERT(button->type() == InputTypeNames::radio); | 123 ASSERT(button->type() == InputTypeNames::radio); |
126 ASSERT(m_members.contains(button)); | 124 ASSERT(m_members.contains(button)); |
127 bool wasValid = isValid(); | 125 bool wasValid = isValid(); |
128 if (button->isRequired()) { | 126 if (button->isRequired()) { |
129 ++m_requiredCount; | 127 ++m_requiredCount; |
130 } else { | 128 } else { |
131 ASSERT(m_requiredCount); | 129 ASSERT(m_requiredCount); |
132 --m_requiredCount; | 130 --m_requiredCount; |
133 } | 131 } |
134 if (wasValid != isValid()) | 132 if (wasValid != isValid()) |
135 setNeedsValidityCheckForAllButtons(); | 133 setNeedsValidityCheckForAllButtons(); |
136 } | 134 } |
137 | 135 |
138 void RadioButtonGroup::remove(HTMLInputElement* button) | 136 void RadioButtonGroup::remove(HTMLInputElement* button) |
139 { | 137 { |
140 ASSERT(button->type() == InputTypeNames::radio); | 138 ASSERT(button->type() == InputTypeNames::radio); |
141 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement> >::iterator it = m_me
mbers.find(button); | 139 WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement>>::iterator it = m_mem
bers.find(button); |
142 if (it == m_members.end()) | 140 if (it == m_members.end()) |
143 return; | 141 return; |
144 bool wasValid = isValid(); | 142 bool wasValid = isValid(); |
145 m_members.remove(it); | 143 m_members.remove(it); |
146 if (button->isRequired()) { | 144 if (button->isRequired()) { |
147 ASSERT(m_requiredCount); | 145 ASSERT(m_requiredCount); |
148 --m_requiredCount; | 146 --m_requiredCount; |
149 } | 147 } |
150 if (m_checkedButton == button) | 148 if (m_checkedButton == button) |
151 m_checkedButton = nullptr; | 149 m_checkedButton = nullptr; |
152 | 150 |
153 if (m_members.isEmpty()) { | 151 if (m_members.isEmpty()) { |
154 ASSERT(!m_requiredCount); | 152 ASSERT(!m_requiredCount); |
155 ASSERT(!m_checkedButton); | 153 ASSERT(!m_checkedButton); |
156 } else if (wasValid != isValid()) { | 154 } else if (wasValid != isValid()) { |
157 setNeedsValidityCheckForAllButtons(); | 155 setNeedsValidityCheckForAllButtons(); |
158 } | 156 } |
159 if (!wasValid) { | 157 if (!wasValid) { |
160 // A radio button not in a group is always valid. We need to make it | 158 // A radio button not in a group is always valid. We need to make it |
161 // valid only if the group was invalid. | 159 // valid only if the group was invalid. |
162 button->setNeedsValidityCheck(); | 160 button->setNeedsValidityCheck(); |
163 } | 161 } |
164 } | 162 } |
165 | 163 |
166 void RadioButtonGroup::setNeedsValidityCheckForAllButtons() | 164 void RadioButtonGroup::setNeedsValidityCheckForAllButtons() |
167 { | 165 { |
168 typedef WillBeHeapHashSet<RawPtrWillBeMember<HTMLInputElement> >::const_iter
ator Iterator; | 166 for (HTMLInputElement* const button : m_members) { |
169 Iterator end = m_members.end(); | |
170 for (Iterator it = m_members.begin(); it != end; ++it) { | |
171 HTMLInputElement* button = *it; | |
172 ASSERT(button->type() == InputTypeNames::radio); | 167 ASSERT(button->type() == InputTypeNames::radio); |
173 button->setNeedsValidityCheck(); | 168 button->setNeedsValidityCheck(); |
174 } | 169 } |
175 } | 170 } |
176 | 171 |
177 bool RadioButtonGroup::contains(HTMLInputElement* button) const | 172 bool RadioButtonGroup::contains(HTMLInputElement* button) const |
178 { | 173 { |
179 return m_members.contains(button); | 174 return m_members.contains(button); |
180 } | 175 } |
181 | 176 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (!m_nameToGroupMap) | 232 if (!m_nameToGroupMap) |
238 return; | 233 return; |
239 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); | 234 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); |
240 ASSERT(group); | 235 ASSERT(group); |
241 group->requiredAttributeChanged(element); | 236 group->requiredAttributeChanged(element); |
242 } | 237 } |
243 | 238 |
244 HTMLInputElement* RadioButtonGroupScope::checkedButtonForGroup(const AtomicStrin
g& name) const | 239 HTMLInputElement* RadioButtonGroupScope::checkedButtonForGroup(const AtomicStrin
g& name) const |
245 { | 240 { |
246 if (!m_nameToGroupMap) | 241 if (!m_nameToGroupMap) |
247 return 0; | 242 return nullptr; |
248 RadioButtonGroup* group = m_nameToGroupMap->get(name); | 243 RadioButtonGroup* group = m_nameToGroupMap->get(name); |
249 return group ? group->checkedButton() : 0; | 244 return group ? group->checkedButton() : nullptr; |
250 } | 245 } |
251 | 246 |
252 bool RadioButtonGroupScope::isInRequiredGroup(HTMLInputElement* element) const | 247 bool RadioButtonGroupScope::isInRequiredGroup(HTMLInputElement* element) const |
253 { | 248 { |
254 ASSERT(element->type() == InputTypeNames::radio); | 249 ASSERT(element->type() == InputTypeNames::radio); |
255 if (element->name().isEmpty()) | 250 if (element->name().isEmpty()) |
256 return false; | 251 return false; |
257 if (!m_nameToGroupMap) | 252 if (!m_nameToGroupMap) |
258 return false; | 253 return false; |
259 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); | 254 RadioButtonGroup* group = m_nameToGroupMap->get(element->name()); |
(...skipping 21 matching lines...) Expand all Loading... |
281 } | 276 } |
282 | 277 |
283 void RadioButtonGroupScope::trace(Visitor* visitor) | 278 void RadioButtonGroupScope::trace(Visitor* visitor) |
284 { | 279 { |
285 #if ENABLE(OILPAN) | 280 #if ENABLE(OILPAN) |
286 visitor->trace(m_nameToGroupMap); | 281 visitor->trace(m_nameToGroupMap); |
287 #endif | 282 #endif |
288 } | 283 } |
289 | 284 |
290 } // namespace | 285 } // namespace |
OLD | NEW |