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

Side by Side Diff: Source/core/html/forms/CheckedRadioButtons.cpp

Issue 24246011: Move form-related 78 files to core/html/forms/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | « Source/core/html/forms/CheckedRadioButtons.h ('k') | Source/core/html/forms/ColorInputType.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/dom/CheckedRadioButtons.h" 22 #include "core/html/forms/CheckedRadioButtons.h"
23 23
24 #include "core/html/HTMLInputElement.h" 24 #include "core/html/HTMLInputElement.h"
25 #include "wtf/HashSet.h" 25 #include "wtf/HashSet.h"
26 26
27 namespace WebCore { 27 namespace WebCore {
28 28
29 class RadioButtonGroup { 29 class RadioButtonGroup {
30 WTF_MAKE_FAST_ALLOCATED; 30 WTF_MAKE_FAST_ALLOCATED;
31 public: 31 public:
32 static PassOwnPtr<RadioButtonGroup> create(); 32 static PassOwnPtr<RadioButtonGroup> create();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ASSERT(button->isRadioButton()); 81 ASSERT(button->isRadioButton());
82 if (!m_members.add(button).isNewEntry) 82 if (!m_members.add(button).isNewEntry)
83 return; 83 return;
84 bool groupWasValid = isValid(); 84 bool groupWasValid = isValid();
85 if (button->isRequired()) 85 if (button->isRequired())
86 ++m_requiredCount; 86 ++m_requiredCount;
87 if (button->checked()) 87 if (button->checked())
88 setCheckedButton(button); 88 setCheckedButton(button);
89 89
90 bool groupIsValid = isValid(); 90 bool groupIsValid = isValid();
91 if (groupWasValid != groupIsValid) 91 if (groupWasValid != groupIsValid) {
92 setNeedsValidityCheckForAllButtons(); 92 setNeedsValidityCheckForAllButtons();
93 else if (!groupIsValid) { 93 } else if (!groupIsValid) {
94 // A radio button not in a group is always valid. We need to make it 94 // A radio button not in a group is always valid. We need to make it
95 // invalid only if the group is invalid. 95 // invalid only if the group is invalid.
96 button->setNeedsValidityCheck(); 96 button->setNeedsValidityCheck();
97 } 97 }
98 } 98 }
99 99
100 void RadioButtonGroup::updateCheckedState(HTMLInputElement* button) 100 void RadioButtonGroup::updateCheckedState(HTMLInputElement* button)
101 { 101 {
102 ASSERT(button->isRadioButton()); 102 ASSERT(button->isRadioButton());
103 ASSERT(m_members.contains(button)); 103 ASSERT(m_members.contains(button));
104 bool wasValid = isValid(); 104 bool wasValid = isValid();
105 if (button->checked()) 105 if (button->checked()) {
106 setCheckedButton(button); 106 setCheckedButton(button);
107 else { 107 } else {
108 if (m_checkedButton == button) 108 if (m_checkedButton == button)
109 m_checkedButton = 0; 109 m_checkedButton = 0;
110 } 110 }
111 if (wasValid != isValid()) 111 if (wasValid != isValid())
112 setNeedsValidityCheckForAllButtons(); 112 setNeedsValidityCheckForAllButtons();
113 } 113 }
114 114
115 void RadioButtonGroup::requiredAttributeChanged(HTMLInputElement* button) 115 void RadioButtonGroup::requiredAttributeChanged(HTMLInputElement* button)
116 { 116 {
117 ASSERT(button->isRadioButton()); 117 ASSERT(button->isRadioButton());
118 ASSERT(m_members.contains(button)); 118 ASSERT(m_members.contains(button));
119 bool wasValid = isValid(); 119 bool wasValid = isValid();
120 if (button->isRequired()) 120 if (button->isRequired()) {
121 ++m_requiredCount; 121 ++m_requiredCount;
122 else { 122 } else {
123 ASSERT(m_requiredCount); 123 ASSERT(m_requiredCount);
124 --m_requiredCount; 124 --m_requiredCount;
125 } 125 }
126 if (wasValid != isValid()) 126 if (wasValid != isValid())
127 setNeedsValidityCheckForAllButtons(); 127 setNeedsValidityCheckForAllButtons();
128 } 128 }
129 129
130 void RadioButtonGroup::remove(HTMLInputElement* button) 130 void RadioButtonGroup::remove(HTMLInputElement* button)
131 { 131 {
132 ASSERT(button->isRadioButton()); 132 ASSERT(button->isRadioButton());
133 HashSet<HTMLInputElement*>::iterator it = m_members.find(button); 133 HashSet<HTMLInputElement*>::iterator it = m_members.find(button);
134 if (it == m_members.end()) 134 if (it == m_members.end())
135 return; 135 return;
136 bool wasValid = isValid(); 136 bool wasValid = isValid();
137 m_members.remove(it); 137 m_members.remove(it);
138 if (button->isRequired()) { 138 if (button->isRequired()) {
139 ASSERT(m_requiredCount); 139 ASSERT(m_requiredCount);
140 --m_requiredCount; 140 --m_requiredCount;
141 } 141 }
142 if (m_checkedButton == button) 142 if (m_checkedButton == button)
143 m_checkedButton = 0; 143 m_checkedButton = 0;
144 144
145 if (m_members.isEmpty()) { 145 if (m_members.isEmpty()) {
146 ASSERT(!m_requiredCount); 146 ASSERT(!m_requiredCount);
147 ASSERT(!m_checkedButton); 147 ASSERT(!m_checkedButton);
148 } else if (wasValid != isValid()) 148 } else if (wasValid != isValid()) {
149 setNeedsValidityCheckForAllButtons(); 149 setNeedsValidityCheckForAllButtons();
150 }
150 if (!wasValid) { 151 if (!wasValid) {
151 // A radio button not in a group is always valid. We need to make it 152 // A radio button not in a group is always valid. We need to make it
152 // valid only if the group was invalid. 153 // valid only if the group was invalid.
153 button->setNeedsValidityCheck(); 154 button->setNeedsValidityCheck();
154 } 155 }
155 } 156 }
156 157
157 void RadioButtonGroup::setNeedsValidityCheckForAllButtons() 158 void RadioButtonGroup::setNeedsValidityCheckForAllButtons()
158 { 159 {
159 typedef HashSet<HTMLInputElement*>::const_iterator Iterator; 160 typedef HashSet<HTMLInputElement*>::const_iterator Iterator;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // FIXME: We may skip deallocating the empty RadioButtonGroup for 260 // FIXME: We may skip deallocating the empty RadioButtonGroup for
260 // performance improvement. If we do so, we need to change the key type 261 // performance improvement. If we do so, we need to change the key type
261 // of m_nameToGroupMap from StringImpl* to AtomicString. 262 // of m_nameToGroupMap from StringImpl* to AtomicString.
262 m_nameToGroupMap->remove(it); 263 m_nameToGroupMap->remove(it);
263 if (m_nameToGroupMap->isEmpty()) 264 if (m_nameToGroupMap->isEmpty())
264 m_nameToGroupMap.clear(); 265 m_nameToGroupMap.clear();
265 } 266 }
266 } 267 }
267 268
268 } // namespace 269 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/forms/CheckedRadioButtons.h ('k') | Source/core/html/forms/ColorInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698