OLD | NEW |
---|---|
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 class IsMatch { |
29 { | 29 public: |
30 return nodeList.elementMatches(element); | 30 IsMatch(const LiveNodeList& list) |
31 } | 31 : m_list(list) |
32 { } | |
33 | |
34 bool operator() (Element& element) const | |
rwlbuis
2014/08/13 15:10:03
Should this be const?
Inactive
2014/08/13 15:11:28
Done.
| |
35 { | |
36 return m_list.elementMatches(element); | |
37 } | |
38 | |
39 private: | |
40 const LiveNodeList& m_list; | |
41 }; | |
32 | 42 |
33 Node* LiveNodeList::virtualOwnerNode() const | 43 Node* LiveNodeList::virtualOwnerNode() const |
34 { | 44 { |
35 return &ownerNode(); | 45 return &ownerNode(); |
36 } | 46 } |
37 | 47 |
38 void LiveNodeList::invalidateCache(Document*) const | 48 void LiveNodeList::invalidateCache(Document*) const |
39 { | 49 { |
40 m_collectionIndexCache.invalidate(); | 50 m_collectionIndexCache.invalidate(); |
41 } | 51 } |
42 | 52 |
43 unsigned LiveNodeList::length() const | 53 unsigned LiveNodeList::length() const |
44 { | 54 { |
45 return m_collectionIndexCache.nodeCount(*this); | 55 return m_collectionIndexCache.nodeCount(*this); |
46 } | 56 } |
47 | 57 |
48 Element* LiveNodeList::item(unsigned offset) const | 58 Element* LiveNodeList::item(unsigned offset) const |
49 { | 59 { |
50 return m_collectionIndexCache.nodeAt(*this, offset); | 60 return m_collectionIndexCache.nodeAt(*this, offset); |
51 } | 61 } |
52 | 62 |
53 Element* LiveNodeList::traverseToFirstElement() const | 63 Element* LiveNodeList::traverseToFirstElement() const |
54 { | 64 { |
55 return firstMatchingElement(*this); | 65 return ElementTraversal::firstWithin(rootNode(), IsMatch(*this)); |
56 } | 66 } |
57 | 67 |
58 Element* LiveNodeList::traverseToLastElement() const | 68 Element* LiveNodeList::traverseToLastElement() const |
59 { | 69 { |
60 return lastMatchingElement(*this); | 70 return ElementTraversal::lastWithin(rootNode(), IsMatch(*this)); |
61 } | 71 } |
62 | 72 |
63 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current Node, unsigned& currentOffset) const | 73 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current Element, unsigned& currentOffset) const |
64 { | 74 { |
65 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c urrentOffset); | 75 return traverseMatchingElementsForwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this)); |
66 } | 76 } |
67 | 77 |
68 Element* LiveNodeList::traverseBackwardToOffset(unsigned offset, Element& curren tNode, unsigned& currentOffset) const | 78 Element* LiveNodeList::traverseBackwardToOffset(unsigned offset, Element& curren tElement, unsigned& currentOffset) const |
69 { | 79 { |
70 return traverseMatchingElementsBackwardToOffset(*this, offset, currentNode, currentOffset); | 80 return traverseMatchingElementsBackwardToOffset(currentElement, &rootNode(), offset, currentOffset, IsMatch(*this)); |
71 } | 81 } |
72 | 82 |
73 void LiveNodeList::trace(Visitor* visitor) | 83 void LiveNodeList::trace(Visitor* visitor) |
74 { | 84 { |
75 visitor->trace(m_collectionIndexCache); | 85 visitor->trace(m_collectionIndexCache); |
76 LiveNodeListBase::trace(visitor); | 86 LiveNodeListBase::trace(visitor); |
77 NodeList::trace(visitor); | 87 NodeList::trace(visitor); |
78 } | 88 } |
79 | 89 |
80 } // namespace blink | 90 } // namespace blink |
OLD | NEW |