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

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: 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 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, 39 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr,
38 }; 40 };
39 41
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 virtual void invalidateCache(Document* oldDocument = 0) const = 0; 79 virtual void invalidateCache(Document* oldDocument = 0) const = 0;
78 80
79 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&); 81 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&);
80 82
81 protected: 83 protected:
82 Document& document() const { return m_ownerNode->document(); } 84 Document& document() const { return m_ownerNode->document(); }
83 85
84 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); } 86 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); }
85 87
86 template <typename Collection> 88 template <typename Collection>
87 static Element* iterateForPreviousNode(const Collection&, Node* current);
88 template <typename Collection>
89 static Element* itemBefore(const Collection&, const Element* previousItem); 89 static Element* itemBefore(const Collection&, const Element* previousItem);
90 90
91 private: 91 private:
92 void invalidateIdNameCacheMaps() const; 92 void invalidateIdNameCacheMaps() const;
93 template <typename Collection>
94 static Element* iterateForPreviousNode(const Collection&, Node* current);
95 static Node* previousNode(const ContainerNode&, const Node& previous, bool o nlyIncludeDirectChildren);
96 static Node* lastDescendant(const ContainerNode&);
97 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren);
93 98
94 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. 99 RefPtr<ContainerNode> m_ownerNode; // Cannot be null.
95 const unsigned m_rootType : 2; 100 const unsigned m_rootType : 2;
96 const unsigned m_invalidationType : 4; 101 const unsigned m_invalidationType : 4;
97 const unsigned m_collectionType : 5; 102 const unsigned m_collectionType : 5;
98 }; 103 };
99 104
100 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL istInvalidationType type, const QualifiedName& attrName) 105 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL istInvalidationType type, const QualifiedName& attrName)
101 { 106 {
102 switch (type) { 107 switch (type) {
(...skipping 11 matching lines...) Expand all
114 case InvalidateOnHRefAttrChange: 119 case InvalidateOnHRefAttrChange:
115 return attrName == HTMLNames::hrefAttr; 120 return attrName == HTMLNames::hrefAttr;
116 case DoNotInvalidateOnAttributeChanges: 121 case DoNotInvalidateOnAttributeChanges:
117 return false; 122 return false;
118 case InvalidateOnAnyAttrChange: 123 case InvalidateOnAnyAttrChange:
119 return true; 124 return true;
120 } 125 }
121 return false; 126 return false;
122 } 127 }
123 128
129 inline Node* LiveNodeListBase::previousNode(const ContainerNode& base, const Nod e& previous, bool onlyIncludeDirectChildren)
130 {
131 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa l::previous(previous, &base);
132 }
133
134 inline Node* LiveNodeListBase::lastDescendant(const ContainerNode& node)
135 {
136 Node* descendant = node.lastChild();
137 for (Node* current = descendant; current; current = current->lastChild())
138 descendant = current;
139 return descendant;
140 }
141
142 inline Node* LiveNodeListBase::lastNode(const ContainerNode& rootNode, bool only IncludeDirectChildren)
143 {
144 return onlyIncludeDirectChildren ? rootNode.lastChild() : lastDescendant(roo tNode);
145 }
146
147 template <typename Collection>
148 inline Element* LiveNodeListBase::iterateForPreviousNode(const Collection& colle ction, Node* current)
adamk 2014/02/25 22:05:40 I take it you're hoping the ALWAYS_INLINE wasn't n
Inactive 2014/02/25 22:32:45 I dropped the inline as it shouldn't be needed for
149 {
150 bool onlyIncludeDirectChildren = collection.shouldOnlyIncludeDirectChildren( );
151 ContainerNode& rootNode = collection.rootNode();
152 for (; current; current = previousNode(rootNode, *current, onlyIncludeDirect Children)) {
153 if (current->isElementNode() && isMatchingElement(collection, toElement( *current)))
154 return toElement(current);
155 }
156 return 0;
157 }
158
159 template <typename Collection>
160 Element* LiveNodeListBase::itemBefore(const Collection& collection, const Elemen t* previous)
161 {
162 Node* current;
163 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1 0% slower.
164 current = previousNode(collection.rootNode(), *previous, collection.shou ldOnlyIncludeDirectChildren());
165 else
166 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi rectChildren());
167
168 return iterateForPreviousNode(collection, current);
169 }
170
124 } // namespace WebCore 171 } // namespace WebCore
125 172
126 #endif // LiveNodeListBase_h 173 #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