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, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2007, 2008 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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace WebCore { | 28 namespace WebCore { |
29 | 29 |
30 ChildNodeList::ChildNodeList(PassRefPtr<Node> node) | 30 ChildNodeList::ChildNodeList(PassRefPtr<Node> node) |
31 : DynamicNodeList(node, RootedAtNode, DoNotInvalidateOnAttributeChange) | 31 : DynamicNodeList(node, RootedAtNode, DoNotInvalidateOnAttributeChange) |
32 { | 32 { |
33 } | 33 } |
34 | 34 |
35 ChildNodeList::~ChildNodeList() | 35 ChildNodeList::~ChildNodeList() |
36 { | 36 { |
37 node()->removeCachedChildNodeList(); | 37 ownerNode()->removeCachedChildNodeList(); |
38 } | 38 } |
39 | 39 |
40 unsigned ChildNodeList::length() const | 40 unsigned ChildNodeList::length() const |
41 { | 41 { |
42 if (m_caches.isLengthCacheValid) | 42 if (m_caches.isLengthCacheValid) |
43 return m_caches.cachedLength; | 43 return m_caches.cachedLength; |
44 | 44 |
45 unsigned len = 0; | 45 unsigned len = 0; |
46 for (Node* n = node()->firstChild(); n; n = n->nextSibling()) | 46 for (Node* n = rootNode()->firstChild(); n; n = n->nextSibling()) |
47 len++; | 47 len++; |
48 | 48 |
49 m_caches.cachedLength = len; | 49 m_caches.cachedLength = len; |
50 m_caches.isLengthCacheValid = true; | 50 m_caches.isLengthCacheValid = true; |
51 | 51 |
52 return len; | 52 return len; |
53 } | 53 } |
54 | 54 |
55 Node* ChildNodeList::item(unsigned index) const | 55 Node* ChildNodeList::item(unsigned index) const |
56 { | 56 { |
57 unsigned int pos = 0; | 57 unsigned int pos = 0; |
58 Node* n = node()->firstChild(); | 58 Node* n = rootNode()->firstChild(); |
59 | 59 |
60 if (m_caches.isItemCacheValid) { | 60 if (m_caches.isItemCacheValid) { |
61 if (index == m_caches.lastItemOffset) | 61 if (index == m_caches.lastItemOffset) |
62 return m_caches.lastItem; | 62 return m_caches.lastItem; |
63 | 63 |
64 int diff = index - m_caches.lastItemOffset; | 64 int diff = index - m_caches.lastItemOffset; |
65 unsigned dist = abs(diff); | 65 unsigned dist = abs(diff); |
66 if (dist < index) { | 66 if (dist < index) { |
67 n = m_caches.lastItem; | 67 n = m_caches.lastItem; |
68 pos = m_caches.lastItemOffset; | 68 pos = m_caches.lastItemOffset; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 if (m_caches.isLengthCacheValid) { | 72 if (m_caches.isLengthCacheValid) { |
73 if (index >= m_caches.cachedLength) | 73 if (index >= m_caches.cachedLength) |
74 return 0; | 74 return 0; |
75 | 75 |
76 int diff = index - pos; | 76 int diff = index - pos; |
77 unsigned dist = abs(diff); | 77 unsigned dist = abs(diff); |
78 if (dist > m_caches.cachedLength - 1 - index) { | 78 if (dist > m_caches.cachedLength - 1 - index) { |
79 n = node()->lastChild(); | 79 n = rootNode()->lastChild(); |
80 pos = m_caches.cachedLength - 1; | 80 pos = m_caches.cachedLength - 1; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 if (pos <= index) { | 84 if (pos <= index) { |
85 while (n && pos < index) { | 85 while (n && pos < index) { |
86 n = n->nextSibling(); | 86 n = n->nextSibling(); |
87 ++pos; | 87 ++pos; |
88 } | 88 } |
89 } else { | 89 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
101 } | 101 } |
102 | 102 |
103 return 0; | 103 return 0; |
104 } | 104 } |
105 | 105 |
106 bool ChildNodeList::nodeMatches(Element* testNode) const | 106 bool ChildNodeList::nodeMatches(Element* testNode) const |
107 { | 107 { |
108 // Note: Due to the overrides of the length and item functions above, | 108 // Note: Due to the overrides of the length and item functions above, |
109 // this function will be called only by DynamicNodeList::itemWithName, | 109 // this function will be called only by DynamicNodeList::itemWithName, |
110 // for an element that was located with getElementById. | 110 // for an element that was located with getElementById. |
111 return testNode->parentNode() == node(); | 111 return testNode->parentNode() == rootNode(); |
112 } | 112 } |
113 | 113 |
114 } // namespace WebCore | 114 } // namespace WebCore |
OLD | NEW |