OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved. | 2 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "core/dom/NodeRareData.h" | 31 #include "core/dom/NodeRareData.h" |
32 #include "core/html/HTMLFormElement.h" | 32 #include "core/html/HTMLFormElement.h" |
33 #include "core/html/HTMLInputElement.h" | 33 #include "core/html/HTMLInputElement.h" |
34 #include "core/html/HTMLObjectElement.h" | 34 #include "core/html/HTMLObjectElement.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 using namespace HTMLNames; | 38 using namespace HTMLNames; |
39 | 39 |
40 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name,
CollectionType type) | 40 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name,
CollectionType type) |
41 : LiveNodeList(rootNode, type, InvalidateForFormControls, rootNode.hasTagNam
e(formTag) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode) | 41 : LiveNodeList(rootNode, type, InvalidateForFormControls, isHTMLFormElement(
rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode) |
42 , m_name(name) | 42 , m_name(name) |
43 , m_onlyMatchImgElements(type == RadioImgNodeListType) | 43 , m_onlyMatchImgElements(type == RadioImgNodeListType) |
44 { | 44 { |
45 ScriptWrappable::init(this); | 45 ScriptWrappable::init(this); |
46 } | 46 } |
47 | 47 |
48 RadioNodeList::~RadioNodeList() | 48 RadioNodeList::~RadioNodeList() |
49 { | 49 { |
50 ownerNode().nodeLists()->removeCache(this, m_onlyMatchImgElements ? RadioImg
NodeListType : RadioNodeListType, m_name); | 50 ownerNode().nodeLists()->removeCache(this, m_onlyMatchImgElements ? RadioImg
NodeListType : RadioNodeListType, m_name); |
51 } | 51 } |
52 | 52 |
53 static inline HTMLInputElement* toRadioButtonInputElement(Node* node) | 53 static inline HTMLInputElement* toRadioButtonInputElement(Node& node) |
54 { | 54 { |
55 ASSERT(node->isElementNode()); | 55 ASSERT(node.isElementNode()); |
56 if (!node->hasTagName(inputTag)) | 56 if (!isHTMLInputElement(node)) |
57 return 0; | 57 return 0; |
58 HTMLInputElement* inputElement = toHTMLInputElement(node); | 58 HTMLInputElement& inputElement = toHTMLInputElement(node); |
59 if (!inputElement->isRadioButton() || inputElement->value().isEmpty()) | 59 if (!inputElement.isRadioButton() || inputElement.value().isEmpty()) |
60 return 0; | 60 return 0; |
61 return inputElement; | 61 return &inputElement; |
62 } | 62 } |
63 | 63 |
64 String RadioNodeList::value() const | 64 String RadioNodeList::value() const |
65 { | 65 { |
66 if (m_onlyMatchImgElements) | 66 if (m_onlyMatchImgElements) |
67 return String(); | 67 return String(); |
68 for (unsigned i = 0; i < length(); ++i) { | 68 for (unsigned i = 0; i < length(); ++i) { |
69 Node* node = item(i); | 69 Node* node = item(i); |
70 const HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 70 const HTMLInputElement* inputElement = toRadioButtonInputElement(*node); |
71 if (!inputElement || !inputElement->checked()) | 71 if (!inputElement || !inputElement->checked()) |
72 continue; | 72 continue; |
73 return inputElement->value(); | 73 return inputElement->value(); |
74 } | 74 } |
75 return String(); | 75 return String(); |
76 } | 76 } |
77 | 77 |
78 void RadioNodeList::setValue(const String& value) | 78 void RadioNodeList::setValue(const String& value) |
79 { | 79 { |
80 if (m_onlyMatchImgElements) | 80 if (m_onlyMatchImgElements) |
81 return; | 81 return; |
82 for (unsigned i = 0; i < length(); ++i) { | 82 for (unsigned i = 0; i < length(); ++i) { |
83 Node* node = item(i); | 83 Node* node = item(i); |
84 HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 84 HTMLInputElement* inputElement = toRadioButtonInputElement(*node); |
85 if (!inputElement || inputElement->value() != value) | 85 if (!inputElement || inputElement->value() != value) |
86 continue; | 86 continue; |
87 inputElement->setChecked(true); | 87 inputElement->setChecked(true); |
88 return; | 88 return; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl
ement) const | 92 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl
ement) const |
93 { | 93 { |
94 ASSERT(!m_onlyMatchImgElements); | 94 ASSERT(!m_onlyMatchImgElements); |
95 ASSERT(testElement.hasTagName(objectTag) || testElement.isFormControlElement
()); | 95 ASSERT(isHTMLObjectElement(testElement) || testElement.isFormControlElement(
)); |
96 if (ownerNode().hasTagName(formTag)) { | 96 if (isHTMLFormElement(ownerNode())) { |
97 HTMLFormElement* formElement = toHTMLElement(testElement).formOwner(); | 97 HTMLFormElement* formElement = toHTMLElement(testElement).formOwner(); |
98 if (!formElement || formElement != ownerNode()) | 98 if (!formElement || formElement != ownerNode()) |
99 return false; | 99 return false; |
100 } | 100 } |
101 | 101 |
102 return testElement.getIdAttribute() == m_name || testElement.getNameAttribut
e() == m_name; | 102 return testElement.getIdAttribute() == m_name || testElement.getNameAttribut
e() == m_name; |
103 } | 103 } |
104 | 104 |
105 bool RadioNodeList::elementMatches(const Element& element) const | 105 bool RadioNodeList::elementMatches(const Element& element) const |
106 { | 106 { |
107 if (m_onlyMatchImgElements) | 107 if (m_onlyMatchImgElements) |
108 return element.hasTagName(imgTag); | 108 return isHTMLImageElement(element); |
109 | 109 |
110 if (!element.hasTagName(objectTag) && !element.isFormControlElement()) | 110 if (!isHTMLObjectElement(element) && !element.isFormControlElement()) |
111 return false; | 111 return false; |
112 | 112 |
113 if (element.hasTagName(inputTag) && toHTMLInputElement(element).isImageButto
n()) | 113 if (isHTMLInputElement(element) && toHTMLInputElement(element).isImageButton
()) |
114 return false; | 114 return false; |
115 | 115 |
116 return checkElementMatchesRadioNodeListFilter(element); | 116 return checkElementMatchesRadioNodeListFilter(element); |
117 } | 117 } |
118 | 118 |
119 } // namespace | 119 } // namespace |
120 | 120 |
OLD | NEW |