#include "config.h"
#include "core/html/RadioNodeList.h"
-#include "HTMLNames.h"
+#include "core/HTMLNames.h"
+#include "core/InputTypeNames.h"
#include "core/dom/Element.h"
#include "core/dom/NodeRareData.h"
#include "core/html/HTMLFormElement.h"
+#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLObjectElement.h"
-namespace WebCore {
+namespace blink {
using namespace HTMLNames;
-RadioNodeList::RadioNodeList(ContainerNode* rootNode, const AtomicString& name, CollectionType type)
- : LiveNodeList(rootNode, type, InvalidateForFormControls, rootNode->hasTagName(formTag) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
+RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name, CollectionType type)
+ : LiveNodeList(rootNode, type, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
, m_name(name)
- , m_onlyMatchImgElements(type == RadioImgNodeListType)
{
- ScriptWrappable::init(this);
}
RadioNodeList::~RadioNodeList()
{
- ownerNode()->nodeLists()->removeCacheWithAtomicName(this, m_onlyMatchImgElements ? RadioImgNodeListType : RadioNodeListType, m_name);
+#if !ENABLE(OILPAN)
+ ownerNode().nodeLists()->removeCache(this, type(), m_name);
+#endif
}
-static inline HTMLInputElement* toRadioButtonInputElement(Node* node)
+static inline HTMLInputElement* toRadioButtonInputElement(Element& element)
{
- ASSERT(node->isElementNode());
- if (!node->hasTagName(inputTag))
+ if (!isHTMLInputElement(element))
return 0;
- HTMLInputElement* inputElement = toHTMLInputElement(node);
- if (!inputElement->isRadioButton() || inputElement->value().isEmpty())
+ HTMLInputElement& inputElement = toHTMLInputElement(element);
+ if (inputElement.type() != InputTypeNames::radio || inputElement.value().isEmpty())
return 0;
- return inputElement;
+ return &inputElement;
}
String RadioNodeList::value() const
{
- if (m_onlyMatchImgElements)
+ if (shouldOnlyMatchImgElements())
return String();
- for (unsigned i = 0; i < length(); ++i) {
- Node* node = item(i);
- const HTMLInputElement* inputElement = toRadioButtonInputElement(node);
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
+ const HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
if (!inputElement || !inputElement->checked())
continue;
return inputElement->value();
void RadioNodeList::setValue(const String& value)
{
- if (m_onlyMatchImgElements)
+ if (shouldOnlyMatchImgElements())
return;
- for (unsigned i = 0; i < length(); ++i) {
- Node* node = item(i);
- HTMLInputElement* inputElement = toRadioButtonInputElement(node);
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
+ HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
if (!inputElement || inputElement->value() != value)
continue;
inputElement->setChecked(true);
}
}
+bool RadioNodeList::matchesByIdOrName(const Element& testElement) const
+{
+ return testElement.getIdAttribute() == m_name || testElement.getNameAttribute() == m_name;
+}
+
bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testElement) const
{
- ASSERT(!m_onlyMatchImgElements);
- ASSERT(testElement.hasTagName(objectTag) || testElement.isFormControlElement());
- if (ownerNode()->hasTagName(formTag)) {
+ ASSERT(!shouldOnlyMatchImgElements());
+ ASSERT(isHTMLObjectElement(testElement) || testElement.isFormControlElement());
+ if (isHTMLFormElement(ownerNode())) {
HTMLFormElement* formElement = toHTMLElement(testElement).formOwner();
if (!formElement || formElement != ownerNode())
return false;
}
- return testElement.getIdAttribute() == m_name || testElement.getNameAttribute() == m_name;
+ return matchesByIdOrName(testElement);
}
-bool RadioNodeList::nodeMatches(const Element& testElement) const
+bool RadioNodeList::elementMatches(const Element& element) const
{
- if (m_onlyMatchImgElements)
- return testElement.hasTagName(imgTag);
+ if (shouldOnlyMatchImgElements()) {
+ if (!isHTMLImageElement(element))
+ return false;
- if (!testElement.hasTagName(objectTag) && !testElement.isFormControlElement())
+ if (toHTMLImageElement(element).formOwner() != ownerNode())
+ return false;
+
+ return matchesByIdOrName(element);
+ }
+
+ if (!isHTMLObjectElement(element) && !element.isFormControlElement())
return false;
- if (testElement.hasTagName(inputTag) && toHTMLInputElement(testElement).isImageButton())
+ if (isHTMLInputElement(element) && toHTMLInputElement(element).type() == InputTypeNames::image)
return false;
- return checkElementMatchesRadioNodeListFilter(testElement);
+ return checkElementMatchesRadioNodeListFilter(element);
}
} // namespace
-