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

Side by Side Diff: Source/web/WebNodeList.cpp

Issue 143453010: Have getElementsByClassName() / getElementsByTagName*() return an HTMLCollection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/WebNode.cpp ('k') | public/web/WebNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WebNodeList.h" 32 #include "WebNodeList.h"
33 33
34 #include "core/dom/Element.h"
34 #include "core/dom/Node.h" 35 #include "core/dom/Node.h"
35 #include "core/dom/NodeList.h" 36 #include "core/dom/NodeList.h"
37 #include "core/html/HTMLCollection.h"
36 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
37 39
38 #include "WebNode.h" 40 #include "WebNode.h"
39 41
40 using namespace WebCore; 42 using namespace WebCore;
41 43
42 namespace blink { 44 namespace blink {
43 45
46 // FIXME(crbug.com/235008): Remove once chromium has been updated to stop using
47 // WebCollection as a WebNodeList.
48 class NodeListWithInternalCollection FINAL : public NodeList {
49 public:
50 static PassRefPtr<NodeListWithInternalCollection> create(HTMLCollection* col lection)
51 {
52 return adoptRef(new NodeListWithInternalCollection(collection));
53 }
54
55 // We have null checks in the following methods because WebNodeList does not have a isNull() method
56 // and callers need to be moved to WebNodeCollection and need to handle null using
57 // WebNodeCollection::isNull().
58 virtual unsigned length() const OVERRIDE { return m_collection ? m_collectio n->length() : 0; }
59 virtual Node* item(unsigned index) const OVERRIDE { return m_collection ? m_ collection->item(index) : 0; }
60 virtual Node* namedItem(const AtomicString& elementId) const OVERRIDE { retu rn m_collection ? m_collection->namedItem(elementId) : 0; }
61
62 private:
63 explicit NodeListWithInternalCollection(HTMLCollection* collection)
64 : m_collection(collection)
65 {
66 }
67
68 RefPtr<HTMLCollection> m_collection;
69 };
70
71 WebNodeList::WebNodeList(const WebNodeCollection& n)
72 : m_private(0)
73 {
74 assign(NodeListWithInternalCollection::create(n.m_private).leakRef());
75 }
76
44 void WebNodeList::reset() 77 void WebNodeList::reset()
45 { 78 {
46 assign(0); 79 assign(0);
47 } 80 }
48 81
49 void WebNodeList::assign(const WebNodeList& other) 82 void WebNodeList::assign(const WebNodeList& other)
50 { 83 {
51 NodeList* p = const_cast<NodeList*>(other.m_private); 84 NodeList* p = const_cast<NodeList*>(other.m_private);
52 if (p) 85 if (p)
53 p->ref(); 86 p->ref();
(...skipping 17 matching lines...) Expand all
71 { 104 {
72 return m_private->length(); 105 return m_private->length();
73 } 106 }
74 107
75 WebNode WebNodeList::item(size_t index) const 108 WebNode WebNodeList::item(size_t index) const
76 { 109 {
77 return WebNode(m_private->item(index)); 110 return WebNode(m_private->item(index));
78 } 111 }
79 112
80 } // namespace blink 113 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebNode.cpp ('k') | public/web/WebNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698