Commit d5292cda authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Have NodeList::item() overrides return an Element* when appropriate

Have NodeList::item() overrides return an Element* when appropriate instead
of a generic Node*. This makes it clear to callers that these are actually
returning Elements and avoids unnecessary isElementNode() checks or casts
that look unsafe.

R=adamk@chromium.org, esprehn@chromium.org

Review URL: https://codereview.chromium.org/331863003

git-svn-id: svn://svn.chromium.org/blink/trunk@176239 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0002e54a
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
: LiveNodeListBase(ownerNode, rootType, invalidationType, collectionType) { } : LiveNodeListBase(ownerNode, rootType, invalidationType, collectionType) { }
virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCache.nodeCount(*this); } virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCache.nodeCount(*this); }
virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collectionIndexCache.nodeAt(*this, offset); } virtual Element* item(unsigned offset) const OVERRIDE FINAL { return m_collectionIndexCache.nodeAt(*this, offset); }
virtual bool elementMatches(const Element&) const = 0; virtual bool elementMatches(const Element&) const = 0;
virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE FINAL; virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE FINAL;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
namespace WebCore { namespace WebCore {
Node* NamedNodesCollection::item(unsigned index) const Element* NamedNodesCollection::item(unsigned index) const
{ {
if (index < m_nodes.size()) if (index < m_nodes.size())
return m_nodes[index].get(); return m_nodes[index].get();
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#ifndef NamedNodesCollection_h #ifndef NamedNodesCollection_h
#define NamedNodesCollection_h #define NamedNodesCollection_h
#include "core/dom/Node.h" #include "core/dom/Element.h"
#include "core/dom/NodeList.h" #include "core/dom/NodeList.h"
#include "wtf/PassRefPtr.h" #include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h" #include "wtf/RefPtr.h"
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
} }
virtual unsigned length() const OVERRIDE { return m_nodes.size(); } virtual unsigned length() const OVERRIDE { return m_nodes.size(); }
virtual Node* item(unsigned) const OVERRIDE; virtual Element* item(unsigned) const OVERRIDE;
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
......
...@@ -52,12 +52,11 @@ RadioNodeList::~RadioNodeList() ...@@ -52,12 +52,11 @@ RadioNodeList::~RadioNodeList()
#endif #endif
} }
static inline HTMLInputElement* toRadioButtonInputElement(Node& node) static inline HTMLInputElement* toRadioButtonInputElement(Element& element)
{ {
ASSERT(node.isElementNode()); if (!isHTMLInputElement(element))
if (!isHTMLInputElement(node))
return 0; return 0;
HTMLInputElement& inputElement = toHTMLInputElement(node); HTMLInputElement& inputElement = toHTMLInputElement(element);
if (!inputElement.isRadioButton() || inputElement.value().isEmpty()) if (!inputElement.isRadioButton() || inputElement.value().isEmpty())
return 0; return 0;
return &inputElement; return &inputElement;
...@@ -67,9 +66,9 @@ String RadioNodeList::value() const ...@@ -67,9 +66,9 @@ String RadioNodeList::value() const
{ {
if (m_onlyMatchImgElements) if (m_onlyMatchImgElements)
return String(); return String();
for (unsigned i = 0; i < length(); ++i) { unsigned length = this->length();
Node* node = item(i); for (unsigned i = 0; i < length; ++i) {
const HTMLInputElement* inputElement = toRadioButtonInputElement(*node); const HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
if (!inputElement || !inputElement->checked()) if (!inputElement || !inputElement->checked())
continue; continue;
return inputElement->value(); return inputElement->value();
...@@ -81,9 +80,9 @@ void RadioNodeList::setValue(const String& value) ...@@ -81,9 +80,9 @@ void RadioNodeList::setValue(const String& value)
{ {
if (m_onlyMatchImgElements) if (m_onlyMatchImgElements)
return; return;
for (unsigned i = 0; i < length(); ++i) { unsigned length = this->length();
Node* node = item(i); for (unsigned i = 0; i < length; ++i) {
HTMLInputElement* inputElement = toRadioButtonInputElement(*node); HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
if (!inputElement || inputElement->value() != value) if (!inputElement || inputElement->value() != value)
continue; continue;
inputElement->setChecked(true); inputElement->setChecked(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment