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

Side by Side Diff: Source/WebCore/dom/ChildNodeList.cpp

Issue 10696159: Merge 121003 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1180/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « Source/WebCore/bindings/js/JSNodeListCustom.cpp ('k') | Source/WebCore/dom/ClassNodeList.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, 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
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
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
OLDNEW
« no previous file with comments | « Source/WebCore/bindings/js/JSNodeListCustom.cpp ('k') | Source/WebCore/dom/ClassNodeList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698