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

Side by Side Diff: Source/WebCore/dom/DynamicNodeList.h

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/dom/ClassNodeList.cpp ('k') | Source/WebCore/dom/DynamicNodeList.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, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2006, 2007 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 MicroDataItemListType, 46 MicroDataItemListType,
47 }; 47 };
48 enum RootType { 48 enum RootType {
49 RootedAtNode, 49 RootedAtNode,
50 RootedAtDocument, 50 RootedAtDocument,
51 }; 51 };
52 enum InvalidationType { 52 enum InvalidationType {
53 AlwaysInvalidate, 53 AlwaysInvalidate,
54 DoNotInvalidateOnAttributeChange, 54 DoNotInvalidateOnAttributeChange,
55 }; 55 };
56 DynamicNodeList(PassRefPtr<Node> node, RootType rootType, InvalidationType i nvalidationType) 56 DynamicNodeList(PassRefPtr<Node> ownerNode, RootType rootType, InvalidationT ype invalidationType)
57 : m_node(node) 57 : m_ownerNode(ownerNode)
58 , m_caches(rootType, invalidationType) 58 , m_caches(rootType, invalidationType)
59 { } 59 { }
60 virtual ~DynamicNodeList() { } 60 virtual ~DynamicNodeList() { }
61 61
62 // DOM methods & attributes for NodeList 62 // DOM methods & attributes for NodeList
63 virtual unsigned length() const = 0; 63 virtual unsigned length() const = 0;
64 virtual Node* item(unsigned index) const = 0; 64 virtual Node* item(unsigned index) const = 0;
65 virtual Node* itemWithName(const AtomicString&) const; 65 virtual Node* itemWithName(const AtomicString&) const;
66 66
67 // Other methods (not part of DOM) 67 // Other methods (not part of DOM)
68 Node* node() const 68 Node* ownerNode() const { return m_ownerNode.get(); }
69 { 69 bool isRootedAtDocument() const { return m_caches.rootedAtDocument; }
70 if (m_caches.rootedAtDocument && m_node->inDocument())
71 return m_node->document();
72 return m_node.get();
73 }
74 Document* document() { return m_node->document(); }
75
76 bool shouldInvalidateOnAttributeChange() const { return m_caches.shouldInval idateOnAttributeChange; } 70 bool shouldInvalidateOnAttributeChange() const { return m_caches.shouldInval idateOnAttributeChange; }
77
78 void invalidateCache() { m_caches.reset(); } 71 void invalidateCache() { m_caches.reset(); }
79 72
80 protected: 73 protected:
74 Node* rootNode() const
75 {
76 if (m_caches.rootedAtDocument && m_ownerNode->inDocument())
77 return m_ownerNode->document();
78 return m_ownerNode.get();
79 }
80 Document* document() const { return m_ownerNode->document(); }
81 virtual bool nodeMatches(Element*) const = 0; 81 virtual bool nodeMatches(Element*) const = 0;
82 82
83 struct Caches { 83 struct Caches {
84 Caches(RootType rootType, InvalidationType invalidationType) 84 Caches(RootType rootType, InvalidationType invalidationType)
85 : rootedAtDocument(rootType == RootedAtDocument) 85 : rootedAtDocument(rootType == RootedAtDocument)
86 , shouldInvalidateOnAttributeChange(invalidationType == AlwaysInvali date) 86 , shouldInvalidateOnAttributeChange(invalidationType == AlwaysInvali date)
87 { 87 {
88 reset(); 88 reset();
89 } 89 }
90 90
91 void reset() 91 void reset()
92 { 92 {
93 lastItem = 0; 93 lastItem = 0;
94 isLengthCacheValid = false; 94 isLengthCacheValid = false;
95 isItemCacheValid = false; 95 isItemCacheValid = false;
96 } 96 }
97 97
98 Node* lastItem; 98 Node* lastItem;
99 unsigned cachedLength; 99 unsigned cachedLength;
100 unsigned lastItemOffset; 100 unsigned lastItemOffset;
101 unsigned isLengthCacheValid : 1; 101 unsigned isLengthCacheValid : 1;
102 unsigned isItemCacheValid : 1; 102 unsigned isItemCacheValid : 1;
103 103
104 // Following flags should belong in DynamicSubtreeNode but are here for bit-packing. 104 // Following flags should belong in DynamicSubtreeNode but are here for bit-packing.
105 unsigned type : 4; 105 unsigned type : 4;
106 unsigned rootedAtDocument : 1; 106 unsigned rootedAtDocument : 1;
107 unsigned shouldInvalidateOnAttributeChange : 1; 107 unsigned shouldInvalidateOnAttributeChange : 1;
108 }; 108 };
109 109
110 RefPtr<Node> m_node; 110 RefPtr<Node> m_ownerNode;
111 mutable Caches m_caches; 111 mutable Caches m_caches;
112 112
113 private: 113 private:
114 virtual bool isDynamicNodeList() const OVERRIDE { return true; } 114 virtual bool isDynamicNodeList() const OVERRIDE { return true; }
115 }; 115 };
116 116
117 class DynamicSubtreeNodeList : public DynamicNodeList { 117 class DynamicSubtreeNodeList : public DynamicNodeList {
118 public: 118 public:
119 virtual ~DynamicSubtreeNodeList(); 119 virtual ~DynamicSubtreeNodeList();
120 virtual unsigned length() const OVERRIDE; 120 virtual unsigned length() const OVERRIDE;
121 virtual Node* item(unsigned index) const OVERRIDE; 121 virtual Node* item(unsigned index) const OVERRIDE;
122 122
123 protected: 123 protected:
124 DynamicSubtreeNodeList(PassRefPtr<Node> node, RootType rootType = RootedAtNo de, InvalidationType invalidationType = AlwaysInvalidate) 124 DynamicSubtreeNodeList(PassRefPtr<Node> node, RootType rootType = RootedAtNo de, InvalidationType invalidationType = AlwaysInvalidate)
125 : DynamicNodeList(node, rootType, invalidationType) 125 : DynamicNodeList(node, rootType, invalidationType)
126 { } 126 { }
127 127
128 private: 128 private:
129 Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOff set) const; 129 Node* itemForwardsFromCurrent(Node* start, unsigned offset, int remainingOff set) const;
130 Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOf fset) const; 130 Node* itemBackwardsFromCurrent(Node* start, unsigned offset, int remainingOf fset) const;
131 }; 131 };
132 132
133 } // namespace WebCore 133 } // namespace WebCore
134 134
135 #endif // DynamicNodeList_h 135 #endif // DynamicNodeList_h
OLDNEW
« no previous file with comments | « Source/WebCore/dom/ClassNodeList.cpp ('k') | Source/WebCore/dom/DynamicNodeList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698