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

Side by Side Diff: Source/core/dom/LiveNodeList.cpp

Issue 468183002: Move matching Element traversal functions from LiveNodeListBase to ElementTraversal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use anonymous namespace Created 6 years, 4 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/core/dom/ElementTraversal.h ('k') | Source/core/dom/LiveNodeListBase.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) 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, 2008, 2010 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * 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 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/dom/LiveNodeList.h" 24 #include "core/dom/LiveNodeList.h"
25 25
26 namespace blink { 26 namespace blink {
27 27
28 static inline bool isMatchingElement(const LiveNodeList& nodeList, const Element & element) 28 namespace {
29 { 29
30 return nodeList.elementMatches(element); 30 class IsMatch {
31 } 31 public:
32 IsMatch(const LiveNodeList& list)
33 : m_list(list)
34 { }
35
36 bool operator() (const Element& element) const
37 {
38 return m_list.elementMatches(element);
39 }
40
41 private:
42 const LiveNodeList& m_list;
43 };
44
45 } // namespace
32 46
33 Node* LiveNodeList::virtualOwnerNode() const 47 Node* LiveNodeList::virtualOwnerNode() const
34 { 48 {
35 return &ownerNode(); 49 return &ownerNode();
36 } 50 }
37 51
38 void LiveNodeList::invalidateCache(Document*) const 52 void LiveNodeList::invalidateCache(Document*) const
39 { 53 {
40 m_collectionIndexCache.invalidate(); 54 m_collectionIndexCache.invalidate();
41 } 55 }
42 56
43 unsigned LiveNodeList::length() const 57 unsigned LiveNodeList::length() const
44 { 58 {
45 return m_collectionIndexCache.nodeCount(*this); 59 return m_collectionIndexCache.nodeCount(*this);
46 } 60 }
47 61
48 Element* LiveNodeList::item(unsigned offset) const 62 Element* LiveNodeList::item(unsigned offset) const
49 { 63 {
50 return m_collectionIndexCache.nodeAt(*this, offset); 64 return m_collectionIndexCache.nodeAt(*this, offset);
51 } 65 }
52 66
53 Element* LiveNodeList::traverseToFirstElement() const 67 Element* LiveNodeList::traverseToFirstElement() const
54 { 68 {
55 return firstMatchingElement(*this); 69 return ElementTraversal::firstWithin(rootNode(), IsMatch(*this));
56 } 70 }
57 71
58 Element* LiveNodeList::traverseToLastElement() const 72 Element* LiveNodeList::traverseToLastElement() const
59 { 73 {
60 return lastMatchingElement(*this); 74 return ElementTraversal::lastWithin(rootNode(), IsMatch(*this));
61 } 75 }
62 76
63 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current Node, unsigned& currentOffset) const 77 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current Element, unsigned& currentOffset) const
64 { 78 {
65 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c urrentOffset); 79 return traverseMatchingElementsForwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this));
66 } 80 }
67 81
68 Element* LiveNodeList::traverseBackwardToOffset(unsigned offset, Element& curren tNode, unsigned& currentOffset) const 82 Element* LiveNodeList::traverseBackwardToOffset(unsigned offset, Element& curren tElement, unsigned& currentOffset) const
69 { 83 {
70 return traverseMatchingElementsBackwardToOffset(*this, offset, currentNode, currentOffset); 84 return traverseMatchingElementsBackwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this));
71 } 85 }
72 86
73 void LiveNodeList::trace(Visitor* visitor) 87 void LiveNodeList::trace(Visitor* visitor)
74 { 88 {
75 visitor->trace(m_collectionIndexCache); 89 visitor->trace(m_collectionIndexCache);
76 LiveNodeListBase::trace(visitor); 90 LiveNodeListBase::trace(visitor);
77 NodeList::trace(visitor); 91 NodeList::trace(visitor);
78 } 92 }
79 93
80 } // namespace blink 94 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ElementTraversal.h ('k') | Source/core/dom/LiveNodeListBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698