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 14 matching lines...) Expand all Loading... | |
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(); |
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 Result<HTMLInputElement> checkedButton() const { return Handle<HTMLInputElem ent>(m_checkedButton); } // FIXME(oilpan): Remove Handle<>(). | 35 Result<HTMLInputElement> checkedButton() const { return adoptRawResult(m_che ckedButton); } |
36 void add(const Handle<HTMLInputElement>&); | 36 void add(const Handle<HTMLInputElement>&); |
37 void updateCheckedState(const Handle<HTMLInputElement>&); | 37 void updateCheckedState(const Handle<HTMLInputElement>&); |
38 void requiredAttributeChanged(const Handle<HTMLInputElement>&); | 38 void requiredAttributeChanged(const Handle<HTMLInputElement>&); |
39 void remove(const Handle<HTMLInputElement>&); | 39 void remove(const Handle<HTMLInputElement>&); |
40 bool contains(const Handle<HTMLInputElement>&) const; | 40 bool contains(const Handle<HTMLInputElement>&) const; |
41 | 41 |
42 private: | 42 private: |
43 RadioButtonGroup(); | 43 RadioButtonGroup(); |
44 void setNeedsValidityCheckForAllButtons(); | 44 void setNeedsValidityCheckForAllButtons(); |
45 bool isValid() const; | 45 bool isValid() const; |
46 void setCheckedButton(const Handle<HTMLInputElement>&); | 46 void setCheckedButton(const Handle<HTMLInputElement>&); |
47 | 47 |
48 // FIXME(oilpan): Move RadioButtonGroup to the heap and use Members. | 48 // FIXME(oilpan): This should be a weak hash set. |
Mads Ager (chromium)
2013/10/01 10:14:55
I don't think should be weak. These should be stro
haraken
2013/10/01 16:46:52
Right. Fixed.
| |
49 HashSet<HTMLInputElement*> m_members; | 49 HashSet<HTMLInputElement*> m_members; |
50 // FIXME(oilpan): This should be a weak pointer. | |
50 HTMLInputElement* m_checkedButton; | 51 HTMLInputElement* m_checkedButton; |
zerny-chromium
2013/10/01 10:18:37
Why should these be weak pointers?
haraken
2013/10/01 16:46:52
Right. This should be a strong pointer. Thanks.
| |
51 size_t m_requiredCount; | 52 size_t m_requiredCount; |
52 }; | 53 }; |
53 | 54 |
54 RadioButtonGroup::RadioButtonGroup() | 55 RadioButtonGroup::RadioButtonGroup() |
55 : m_checkedButton(0) | 56 : m_checkedButton(0) |
56 , m_requiredCount(0) | 57 , m_requiredCount(0) |
57 { | 58 { |
58 } | 59 } |
59 | 60 |
60 PassOwnPtr<RadioButtonGroup> RadioButtonGroup::create() | 61 PassOwnPtr<RadioButtonGroup> RadioButtonGroup::create() |
61 { | 62 { |
62 return adoptPtr(new RadioButtonGroup); | 63 return adoptPtr(new RadioButtonGroup); |
63 } | 64 } |
64 | 65 |
65 inline bool RadioButtonGroup::isValid() const | 66 inline bool RadioButtonGroup::isValid() const |
66 { | 67 { |
67 return !isRequired() || m_checkedButton; | 68 return !isRequired() || m_checkedButton; |
68 } | 69 } |
69 | 70 |
70 void RadioButtonGroup::setCheckedButton(const Handle<HTMLInputElement>& button) | 71 void RadioButtonGroup::setCheckedButton(const Handle<HTMLInputElement>& button) |
71 { | 72 { |
72 Handle<HTMLInputElement> oldCheckedButton = Handle<HTMLInputElement>(m_check edButton); // FIXME(oilpan): Remove Handle<>(). | 73 Handle<HTMLInputElement> oldCheckedButton = adoptRawResult(m_checkedButton); |
73 if (oldCheckedButton == button) | 74 if (oldCheckedButton == button) |
74 return; | 75 return; |
75 m_checkedButton = button.raw(); | 76 m_checkedButton = button.raw(); |
76 if (oldCheckedButton) | 77 if (oldCheckedButton) |
77 oldCheckedButton->setChecked(false); | 78 oldCheckedButton->setChecked(false); |
78 } | 79 } |
79 | 80 |
80 void RadioButtonGroup::add(const Handle<HTMLInputElement>& button) | 81 void RadioButtonGroup::add(const Handle<HTMLInputElement>& button) |
81 { | 82 { |
82 ASSERT(button->isRadioButton()); | 83 ASSERT(button->isRadioButton()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 // FIXME: We may skip deallocating the empty RadioButtonGroup for | 263 // FIXME: We may skip deallocating the empty RadioButtonGroup for |
263 // performance improvement. If we do so, we need to change the key type | 264 // performance improvement. If we do so, we need to change the key type |
264 // of m_nameToGroupMap from AtomicStringImpl* to RefPtr<AtomicStringImpl >. | 265 // of m_nameToGroupMap from AtomicStringImpl* to RefPtr<AtomicStringImpl >. |
265 m_nameToGroupMap->remove(it); | 266 m_nameToGroupMap->remove(it); |
266 if (m_nameToGroupMap->isEmpty()) | 267 if (m_nameToGroupMap->isEmpty()) |
267 m_nameToGroupMap.clear(); | 268 m_nameToGroupMap.clear(); |
268 } | 269 } |
269 } | 270 } |
270 | 271 |
271 } // namespace | 272 } // namespace |
OLD | NEW |