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. |
(...skipping 20 matching lines...) Expand all Loading... |
31 DynamicSubtreeNodeList::~DynamicSubtreeNodeList() | 31 DynamicSubtreeNodeList::~DynamicSubtreeNodeList() |
32 { | 32 { |
33 } | 33 } |
34 | 34 |
35 unsigned DynamicSubtreeNodeList::length() const | 35 unsigned DynamicSubtreeNodeList::length() const |
36 { | 36 { |
37 if (m_caches.isLengthCacheValid) | 37 if (m_caches.isLengthCacheValid) |
38 return m_caches.cachedLength; | 38 return m_caches.cachedLength; |
39 | 39 |
40 unsigned length = 0; | 40 unsigned length = 0; |
41 Node* rootNode = node(); | 41 Node* rootNode = this->rootNode(); |
42 | 42 |
43 for (Node* n = rootNode->firstChild(); n; n = n->traverseNextNode(rootNode)) | 43 for (Node* n = rootNode->firstChild(); n; n = n->traverseNextNode(rootNode)) |
44 length += n->isElementNode() && nodeMatches(static_cast<Element*>(n)); | 44 length += n->isElementNode() && nodeMatches(static_cast<Element*>(n)); |
45 | 45 |
46 m_caches.cachedLength = length; | 46 m_caches.cachedLength = length; |
47 m_caches.isLengthCacheValid = true; | 47 m_caches.isLengthCacheValid = true; |
48 | 48 |
49 return length; | 49 return length; |
50 } | 50 } |
51 | 51 |
52 Node* DynamicSubtreeNodeList::itemForwardsFromCurrent(Node* start, unsigned offs
et, int remainingOffset) const | 52 Node* DynamicSubtreeNodeList::itemForwardsFromCurrent(Node* start, unsigned offs
et, int remainingOffset) const |
53 { | 53 { |
54 ASSERT(remainingOffset >= 0); | 54 ASSERT(remainingOffset >= 0); |
55 Node* rootNode = node(); | 55 Node* rootNode = this->rootNode(); |
56 for (Node* n = start; n; n = n->traverseNextNode(rootNode)) { | 56 for (Node* n = start; n; n = n->traverseNextNode(rootNode)) { |
57 if (n->isElementNode() && nodeMatches(static_cast<Element*>(n))) { | 57 if (n->isElementNode() && nodeMatches(static_cast<Element*>(n))) { |
58 if (!remainingOffset) { | 58 if (!remainingOffset) { |
59 m_caches.lastItem = n; | 59 m_caches.lastItem = n; |
60 m_caches.lastItemOffset = offset; | 60 m_caches.lastItemOffset = offset; |
61 m_caches.isItemCacheValid = true; | 61 m_caches.isItemCacheValid = true; |
62 return n; | 62 return n; |
63 } | 63 } |
64 --remainingOffset; | 64 --remainingOffset; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 return 0; // no matching node in this subtree | 68 return 0; // no matching node in this subtree |
69 } | 69 } |
70 | 70 |
71 Node* DynamicSubtreeNodeList::itemBackwardsFromCurrent(Node* start, unsigned off
set, int remainingOffset) const | 71 Node* DynamicSubtreeNodeList::itemBackwardsFromCurrent(Node* start, unsigned off
set, int remainingOffset) const |
72 { | 72 { |
73 ASSERT(remainingOffset < 0); | 73 ASSERT(remainingOffset < 0); |
74 Node* rootNode = node(); | 74 Node* rootNode = this->rootNode(); |
75 for (Node* n = start; n; n = n->traversePreviousNode(rootNode)) { | 75 for (Node* n = start; n; n = n->traversePreviousNode(rootNode)) { |
76 if (n->isElementNode() && nodeMatches(static_cast<Element*>(n))) { | 76 if (n->isElementNode() && nodeMatches(static_cast<Element*>(n))) { |
77 if (!remainingOffset) { | 77 if (!remainingOffset) { |
78 m_caches.lastItem = n; | 78 m_caches.lastItem = n; |
79 m_caches.lastItemOffset = offset; | 79 m_caches.lastItemOffset = offset; |
80 m_caches.isItemCacheValid = true; | 80 m_caches.isItemCacheValid = true; |
81 return n; | 81 return n; |
82 } | 82 } |
83 ++remainingOffset; | 83 ++remainingOffset; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 return 0; // no matching node in this subtree | 87 return 0; // no matching node in this subtree |
88 } | 88 } |
89 | 89 |
90 Node* DynamicSubtreeNodeList::item(unsigned offset) const | 90 Node* DynamicSubtreeNodeList::item(unsigned offset) const |
91 { | 91 { |
92 int remainingOffset = offset; | 92 int remainingOffset = offset; |
93 Node* start = node()->firstChild(); | 93 Node* start = rootNode()->firstChild(); |
94 if (m_caches.isItemCacheValid) { | 94 if (m_caches.isItemCacheValid) { |
95 if (offset == m_caches.lastItemOffset) | 95 if (offset == m_caches.lastItemOffset) |
96 return m_caches.lastItem; | 96 return m_caches.lastItem; |
97 if (offset > m_caches.lastItemOffset || m_caches.lastItemOffset - offset
< offset) { | 97 if (offset > m_caches.lastItemOffset || m_caches.lastItemOffset - offset
< offset) { |
98 start = m_caches.lastItem; | 98 start = m_caches.lastItem; |
99 remainingOffset -= m_caches.lastItemOffset; | 99 remainingOffset -= m_caches.lastItemOffset; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 if (remainingOffset < 0) | 103 if (remainingOffset < 0) |
104 return itemBackwardsFromCurrent(start, offset, remainingOffset); | 104 return itemBackwardsFromCurrent(start, offset, remainingOffset); |
105 return itemForwardsFromCurrent(start, offset, remainingOffset); | 105 return itemForwardsFromCurrent(start, offset, remainingOffset); |
106 } | 106 } |
107 | 107 |
108 Node* DynamicNodeList::itemWithName(const AtomicString& elementId) const | 108 Node* DynamicNodeList::itemWithName(const AtomicString& elementId) const |
109 { | 109 { |
110 Node* rootNode = node(); | 110 Node* rootNode = this->rootNode(); |
111 | 111 |
112 if (rootNode->inDocument()) { | 112 if (rootNode->inDocument()) { |
113 Element* element = rootNode->treeScope()->getElementById(elementId); | 113 Element* element = rootNode->treeScope()->getElementById(elementId); |
114 if (element && nodeMatches(element) && element->isDescendantOf(rootNode)
) | 114 if (element && nodeMatches(element) && element->isDescendantOf(rootNode)
) |
115 return element; | 115 return element; |
116 if (!element) | 116 if (!element) |
117 return 0; | 117 return 0; |
118 // In the case of multiple nodes with the same name, just fall through. | 118 // In the case of multiple nodes with the same name, just fall through. |
119 } | 119 } |
120 | 120 |
121 unsigned length = this->length(); | 121 unsigned length = this->length(); |
122 for (unsigned i = 0; i < length; i++) { | 122 for (unsigned i = 0; i < length; i++) { |
123 Node* node = item(i); | 123 Node* node = item(i); |
124 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. | 124 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. |
125 if (node->hasID() && static_cast<Element*>(node)->idForStyleResolution()
== elementId) | 125 if (node->hasID() && static_cast<Element*>(node)->idForStyleResolution()
== elementId) |
126 return node; | 126 return node; |
127 } | 127 } |
128 | 128 |
129 return 0; | 129 return 0; |
130 } | 130 } |
131 | 131 |
132 } // namespace WebCore | 132 } // namespace WebCore |
OLD | NEW |