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 19 matching lines...) Expand all Loading... |
30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
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(Node* rootNode, const AtomicString& name) | 40 RadioNodeList::RadioNodeList(Node* rootNode, const AtomicString& name, Collectio
nType type) |
41 : LiveNodeList(rootNode, RadioNodeListType, InvalidateForFormControls, rootN
ode->hasTagName(formTag) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode) | 41 : LiveNodeList(rootNode, type, InvalidateForFormControls, rootNode->hasTagNa
me(formTag) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode) |
42 , m_name(name) | 42 , m_name(name) |
| 43 , m_onlyMatchImgElements(type == RadioImgNodeListType) |
43 { | 44 { |
44 ScriptWrappable::init(this); | 45 ScriptWrappable::init(this); |
45 } | 46 } |
46 | 47 |
47 RadioNodeList::~RadioNodeList() | 48 RadioNodeList::~RadioNodeList() |
48 { | 49 { |
49 ownerNode()->nodeLists()->removeCacheWithAtomicName(this, RadioNodeListType,
m_name); | 50 ownerNode()->nodeLists()->removeCacheWithAtomicName(this, m_onlyMatchImgElem
ents ? RadioImgNodeListType : RadioNodeListType, m_name); |
50 } | 51 } |
51 | 52 |
52 static inline HTMLInputElement* toRadioButtonInputElement(Node* node) | 53 static inline HTMLInputElement* toRadioButtonInputElement(Node* node) |
53 { | 54 { |
54 ASSERT(node->isElementNode()); | 55 ASSERT(node->isElementNode()); |
55 if (!node->hasTagName(inputTag)) | 56 if (!node->hasTagName(inputTag)) |
56 return 0; | 57 return 0; |
57 HTMLInputElement* inputElement = toHTMLInputElement(node); | 58 HTMLInputElement* inputElement = toHTMLInputElement(node); |
58 if (!inputElement->isRadioButton() || inputElement->value().isEmpty()) | 59 if (!inputElement->isRadioButton() || inputElement->value().isEmpty()) |
59 return 0; | 60 return 0; |
60 return inputElement; | 61 return inputElement; |
61 } | 62 } |
62 | 63 |
63 String RadioNodeList::value() const | 64 String RadioNodeList::value() const |
64 { | 65 { |
| 66 if (m_onlyMatchImgElements) |
| 67 return String(); |
65 for (unsigned i = 0; i < length(); ++i) { | 68 for (unsigned i = 0; i < length(); ++i) { |
66 Node* node = item(i); | 69 Node* node = item(i); |
67 const HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 70 const HTMLInputElement* inputElement = toRadioButtonInputElement(node); |
68 if (!inputElement || !inputElement->checked()) | 71 if (!inputElement || !inputElement->checked()) |
69 continue; | 72 continue; |
70 return inputElement->value(); | 73 return inputElement->value(); |
71 } | 74 } |
72 return String(); | 75 return String(); |
73 } | 76 } |
74 | 77 |
75 void RadioNodeList::setValue(const String& value) | 78 void RadioNodeList::setValue(const String& value) |
76 { | 79 { |
| 80 if (m_onlyMatchImgElements) |
| 81 return; |
77 for (unsigned i = 0; i < length(); ++i) { | 82 for (unsigned i = 0; i < length(); ++i) { |
78 Node* node = item(i); | 83 Node* node = item(i); |
79 HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 84 HTMLInputElement* inputElement = toRadioButtonInputElement(node); |
80 if (!inputElement || inputElement->value() != value) | 85 if (!inputElement || inputElement->value() != value) |
81 continue; | 86 continue; |
82 inputElement->setChecked(true); | 87 inputElement->setChecked(true); |
83 return; | 88 return; |
84 } | 89 } |
85 } | 90 } |
86 | 91 |
87 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(Element* testElement)
const | 92 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(Element* testElement)
const |
88 { | 93 { |
| 94 ASSERT(!m_onlyMatchImgElements); |
89 ASSERT(testElement->hasTagName(objectTag) || testElement->isFormControlEleme
nt()); | 95 ASSERT(testElement->hasTagName(objectTag) || testElement->isFormControlEleme
nt()); |
90 if (ownerNode()->hasTagName(formTag)) { | 96 if (ownerNode()->hasTagName(formTag)) { |
91 HTMLFormElement* formElement = toHTMLElement(testElement)->formOwner(); | 97 HTMLFormElement* formElement = toHTMLElement(testElement)->formOwner(); |
92 if (!formElement || formElement != ownerNode()) | 98 if (!formElement || formElement != ownerNode()) |
93 return false; | 99 return false; |
94 } | 100 } |
95 | 101 |
96 return testElement->getIdAttribute() == m_name || testElement->getNameAttrib
ute() == m_name; | 102 return testElement->getIdAttribute() == m_name || testElement->getNameAttrib
ute() == m_name; |
97 } | 103 } |
98 | 104 |
99 bool RadioNodeList::nodeMatches(Element* testElement) const | 105 bool RadioNodeList::nodeMatches(Element* testElement) const |
100 { | 106 { |
| 107 if (m_onlyMatchImgElements) |
| 108 return testElement->hasTagName(imgTag); |
| 109 |
101 if (!testElement->hasTagName(objectTag) && !testElement->isFormControlElemen
t()) | 110 if (!testElement->hasTagName(objectTag) && !testElement->isFormControlElemen
t()) |
102 return false; | 111 return false; |
103 | 112 |
104 if (testElement->hasTagName(inputTag) && toHTMLInputElement(testElement)->is
ImageButton()) | 113 if (testElement->hasTagName(inputTag) && toHTMLInputElement(testElement)->is
ImageButton()) |
105 return false; | 114 return false; |
106 | 115 |
107 return checkElementMatchesRadioNodeListFilter(testElement); | 116 return checkElementMatchesRadioNodeListFilter(testElement); |
108 } | 117 } |
109 | 118 |
110 } // namspace | 119 } // namespace |
111 | 120 |
OLD | NEW |