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

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

Issue 180383002: Move LiveNodeListBase code out of HTMLCollection.cpp (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 | « no previous file | Source/core/html/HTMLCollection.cpp » ('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) 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, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * 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.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * 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
19 * 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
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #ifndef LiveNodeListBase_h 25 #ifndef LiveNodeListBase_h
26 #define LiveNodeListBase_h 26 #define LiveNodeListBase_h
27 27
28 #include "HTMLNames.h" 28 #include "HTMLNames.h"
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/dom/Element.h"
31 #include "core/dom/NodeTraversal.h"
30 #include "core/html/CollectionType.h" 32 #include "core/html/CollectionType.h"
31 33
32 namespace WebCore { 34 namespace WebCore {
33 35
34 enum NodeListRootType { 36 enum NodeListRootType {
35 NodeListIsRootedAtNode, 37 NodeListIsRootedAtNode,
36 NodeListIsRootedAtDocument 38 NodeListIsRootedAtDocument
37 }; 39 };
38 40
39 class LiveNodeListBase { 41 class LiveNodeListBase {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 virtual void invalidateCache(Document* oldDocument = 0) const = 0; 78 virtual void invalidateCache(Document* oldDocument = 0) const = 0;
77 79
78 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&); 80 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&);
79 81
80 protected: 82 protected:
81 Document& document() const { return m_ownerNode->document(); } 83 Document& document() const { return m_ownerNode->document(); }
82 84
83 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); } 85 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); }
84 86
85 template <typename Collection> 87 template <typename Collection>
86 static Element* iterateForPreviousNode(const Collection&, Node* current);
87 template <typename Collection>
88 static Element* itemBefore(const Collection&, const Element* previousItem); 88 static Element* itemBefore(const Collection&, const Element* previousItem);
89 89
90 private: 90 private:
91 void invalidateIdNameCacheMaps() const; 91 void invalidateIdNameCacheMaps() const;
92 template <typename Collection>
93 static Element* iterateForPreviousNode(const Collection&, Node* current);
94 static Node* previousNode(const ContainerNode&, const Node& previous, bool o nlyIncludeDirectChildren);
95 static Node* lastDescendant(const ContainerNode&);
96 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren);
92 97
93 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. 98 RefPtr<ContainerNode> m_ownerNode; // Cannot be null.
94 const unsigned m_rootType : 1; 99 const unsigned m_rootType : 1;
95 const unsigned m_invalidationType : 4; 100 const unsigned m_invalidationType : 4;
96 const unsigned m_collectionType : 5; 101 const unsigned m_collectionType : 5;
97 }; 102 };
98 103
99 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL istInvalidationType type, const QualifiedName& attrName) 104 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL istInvalidationType type, const QualifiedName& attrName)
100 { 105 {
101 switch (type) { 106 switch (type) {
(...skipping 11 matching lines...) Expand all
113 case InvalidateOnHRefAttrChange: 118 case InvalidateOnHRefAttrChange:
114 return attrName == HTMLNames::hrefAttr; 119 return attrName == HTMLNames::hrefAttr;
115 case DoNotInvalidateOnAttributeChanges: 120 case DoNotInvalidateOnAttributeChanges:
116 return false; 121 return false;
117 case InvalidateOnAnyAttrChange: 122 case InvalidateOnAnyAttrChange:
118 return true; 123 return true;
119 } 124 }
120 return false; 125 return false;
121 } 126 }
122 127
128 inline Node* LiveNodeListBase::previousNode(const ContainerNode& base, const Nod e& previous, bool onlyIncludeDirectChildren)
129 {
130 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa l::previous(previous, &base);
131 }
132
133 inline Node* LiveNodeListBase::lastDescendant(const ContainerNode& node)
134 {
135 Node* descendant = node.lastChild();
136 for (Node* current = descendant; current; current = current->lastChild())
137 descendant = current;
138 return descendant;
139 }
140
141 inline Node* LiveNodeListBase::lastNode(const ContainerNode& rootNode, bool only IncludeDirectChildren)
142 {
143 return onlyIncludeDirectChildren ? rootNode.lastChild() : lastDescendant(roo tNode);
144 }
145
146 template <typename Collection>
147 Element* LiveNodeListBase::iterateForPreviousNode(const Collection& collection, Node* current)
148 {
149 bool onlyIncludeDirectChildren = collection.shouldOnlyIncludeDirectChildren( );
150 ContainerNode& rootNode = collection.rootNode();
151 for (; current; current = previousNode(rootNode, *current, onlyIncludeDirect Children)) {
152 if (current->isElementNode() && isMatchingElement(collection, toElement( *current)))
153 return toElement(current);
154 }
155 return 0;
156 }
157
158 template <typename Collection>
159 Element* LiveNodeListBase::itemBefore(const Collection& collection, const Elemen t* previous)
160 {
161 Node* current;
162 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1 0% slower.
163 current = previousNode(collection.rootNode(), *previous, collection.shou ldOnlyIncludeDirectChildren());
164 else
165 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi rectChildren());
166
167 return iterateForPreviousNode(collection, current);
168 }
169
123 } // namespace WebCore 170 } // namespace WebCore
124 171
125 #endif // LiveNodeListBase_h 172 #endif // LiveNodeListBase_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/html/HTMLCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698