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

Side by Side Diff: Source/core/dom/ChildNodeList.h

Issue 154693002: Have ChildNodeList subclass NodeList instead of LiveNodeList (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update copyright 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
« no previous file with comments | « no previous file | Source/core/dom/ChildNodeList.cpp » ('j') | Source/core/dom/NodeList.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
11 * 12 *
12 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 16 * Library General Public License for more details.
16 * 17 *
17 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
21 * 22 *
22 */ 23 */
23 24
24 #ifndef ChildNodeList_h 25 #ifndef ChildNodeList_h
25 #define ChildNodeList_h 26 #define ChildNodeList_h
26 27
27 #include "core/dom/LiveNodeList.h" 28 #include "core/dom/NodeList.h"
29 #include "core/html/CollectionIndexCache.h"
28 #include "wtf/PassRefPtr.h" 30 #include "wtf/PassRefPtr.h"
29 31
30 namespace WebCore { 32 namespace WebCore {
31 33
32 class ChildNodeList FINAL : public LiveNodeList { 34 class ChildNodeList FINAL : public NodeList {
33 public: 35 public:
34 static PassRefPtr<ChildNodeList> create(PassRefPtr<ContainerNode> rootNode) 36 static PassRefPtr<ChildNodeList> create(PassRefPtr<ContainerNode> rootNode)
35 { 37 {
36 return adoptRef(new ChildNodeList(rootNode)); 38 return adoptRef(new ChildNodeList(rootNode));
37 } 39 }
38 40
39 virtual ~ChildNodeList(); 41 virtual ~ChildNodeList();
40 42
41 protected: 43 // DOM API.
44 virtual unsigned length() const OVERRIDE { return m_collectionIndexCache.nod eCount(*this); }
45 virtual Node* item(unsigned index) const OVERRIDE { return m_collectionIndex Cache.nodeAt(*this, index); }
46
47 // Non-DOM API.
48 void invalidateCache() { m_collectionIndexCache.invalidate(); }
49 ContainerNode* ownerNode() const { return m_parent.get(); }
50
51 // CollectionIndexCache API.
52 ContainerNode& rootNode() const { return *m_parent; }
53 bool canTraverseBackward() const { return true; }
54 Node* itemBefore(const Node* previousItem) const;
55 Node* traverseToFirstElement(const ContainerNode& root) const { return root. firstChild(); }
56 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned& currentOffset, const ContainerNode& root) const;
57
58 private:
42 explicit ChildNodeList(PassRefPtr<ContainerNode> rootNode); 59 explicit ChildNodeList(PassRefPtr<ContainerNode> rootNode);
43 60
44 virtual bool isChildNodeList() const OVERRIDE { return true; } 61 virtual bool isChildNodeList() const OVERRIDE { return true; }
45 virtual bool nodeMatches(const Element&) const OVERRIDE; 62
63 RefPtr<ContainerNode> m_parent;
64 mutable CollectionIndexCache<ChildNodeList, Node> m_collectionIndexCache;
46 }; 65 };
47 66
48 DEFINE_TYPE_CASTS(ChildNodeList, NodeList, nodeList, nodeList->isChildNodeList() , nodeList.isChildNodeList()); 67 DEFINE_TYPE_CASTS(ChildNodeList, NodeList, nodeList, nodeList->isChildNodeList() , nodeList.isChildNodeList());
49 68
50 } // namespace WebCore 69 } // namespace WebCore
51 70
52 #endif // ChildNodeList_h 71 #endif // ChildNodeList_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/ChildNodeList.cpp » ('j') | Source/core/dom/NodeList.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698