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

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

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

Powered by Google App Engine
This is Rietveld 408576698