Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: Source/web/WebNodeList.cpp

Issue 143453010: Have getElementsByClassName() / getElementsByTagName*() return an HTMLCollection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Null HTMLCollection handling Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/web/WebNodeList.cpp
diff --git a/Source/web/WebNodeList.cpp b/Source/web/WebNodeList.cpp
index 3a162831a1aeb4101f19fd5f96bd01d52e812581..0a0097313fba1e13149e658c2f7d386521ca81a9 100644
--- a/Source/web/WebNodeList.cpp
+++ b/Source/web/WebNodeList.cpp
@@ -33,6 +33,7 @@
#include "core/dom/Node.h"
#include "core/dom/NodeList.h"
+#include "core/html/HTMLCollection.h"
#include "wtf/PassRefPtr.h"
#include "WebNode.h"
@@ -41,6 +42,32 @@ using namespace WebCore;
namespace blink {
+// FIXME(crbug.com/235008): Remove once chromium has been updated to stop using
+// WebCollection as a WebNodeList.
+class NodeListWithInternalCollection FINAL : public NodeList {
+public:
+ explicit NodeListWithInternalCollection(HTMLCollection* collection)
+ : m_collection(collection)
+ {
+ }
+
+ // We have null checks in the following methods because WebNodeList does not have a isNull() method
+ // and callers need to be moved to WebNodeCollection and need to handle null using
+ // WebNodeCollection::isNull().
+ virtual unsigned length() const OVERRIDE { return m_collection ? m_collection->length() : 0; }
+ virtual Node* item(unsigned index) const OVERRIDE { return m_collection ? m_collection->item(index) : 0; }
+ virtual Node* namedItem(const AtomicString& elementId) const OVERRIDE { return m_collection ? m_collection->namedItem(elementId) : 0; }
+
+private:
+ RefPtr<HTMLCollection> m_collection;
+};
+
+WebNodeList::WebNodeList(const WebNodeCollection& n)
+ : m_private(0)
+{
+ assign(new NodeListWithInternalCollection(n.m_private));
+}
+
void WebNodeList::reset()
{
assign(0);

Powered by Google App Engine
This is Rietveld 408576698