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:
: LiveNodeListBase(ownerNode, rootType, invalidationType, collectionType) { }
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 void invalidateCache(Document* oldDocument = 0) const OVERRIDE FINAL;
......
......@@ -34,7 +34,7 @@
namespace WebCore {
Node* NamedNodesCollection::item(unsigned index) const
Element* NamedNodesCollection::item(unsigned index) const
{
if (index < m_nodes.size())
return m_nodes[index].get();
......
......@@ -31,7 +31,7 @@
#ifndef NamedNodesCollection_h
#define NamedNodesCollection_h
#include "core/dom/Node.h"
#include "core/dom/Element.h"
#include "core/dom/NodeList.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
......@@ -47,7 +47,7 @@ public:
}
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;
......
......@@ -52,12 +52,11 @@ RadioNodeList::~RadioNodeList()
#endif
}
static inline HTMLInputElement* toRadioButtonInputElement(Node& node)
static inline HTMLInputElement* toRadioButtonInputElement(Element& element)
{
ASSERT(node.isElementNode());
if (!isHTMLInputElement(node))
if (!isHTMLInputElement(element))
return 0;
HTMLInputElement& inputElement = toHTMLInputElement(node);
HTMLInputElement& inputElement = toHTMLInputElement(element);
if (!inputElement.isRadioButton() || inputElement.value().isEmpty())
return 0;
return &inputElement;
......@@ -67,9 +66,9 @@ String RadioNodeList::value() const
{
if (m_onlyMatchImgElements)
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();
......@@ -81,9 +80,9 @@ void RadioNodeList::setValue(const String& value)
{
if (m_onlyMatchImgElements)
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);
......
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