OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. | 3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // Anchor name matching is case sensitive in strict mode and not case sensit
ive in | 85 // Anchor name matching is case sensitive in strict mode and not case sensit
ive in |
86 // quirks mode for historical compatibility reasons. | 86 // quirks mode for historical compatibility reasons. |
87 Element* findAnchor(const String& name); | 87 Element* findAnchor(const String& name); |
88 | 88 |
89 virtual bool applyAuthorStyles() const; | 89 virtual bool applyAuthorStyles() const; |
90 virtual bool resetStyleInheritance() const; | 90 virtual bool resetStyleInheritance() const; |
91 | 91 |
92 // Used by the basic DOM mutation methods (e.g., appendChild()). | 92 // Used by the basic DOM mutation methods (e.g., appendChild()). |
93 void adoptIfNeeded(Node*); | 93 void adoptIfNeeded(Node*); |
94 | 94 |
95 ContainerNode* rootNode() const { return m_rootNode; } | 95 Node* rootNode() const { return m_rootNode; } |
96 | 96 |
97 IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTar
getObserverRegistry.get(); } | 97 IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTar
getObserverRegistry.get(); } |
98 | 98 |
99 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 99 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
100 | 100 |
101 static TreeScope* noDocumentInstance() | 101 static TreeScope* noDocumentInstance() |
102 { | 102 { |
103 DEFINE_STATIC_LOCAL(TreeScope, instance, ()); | 103 DEFINE_STATIC_LOCAL(TreeScope, instance, ()); |
104 return &instance; | 104 return &instance; |
105 } | 105 } |
106 | 106 |
| 107 // Nodes belonging to this scope hold guard references - |
| 108 // these are enough to keep the scope from being destroyed, but |
| 109 // not enough to keep it from removing its children. This allows a |
| 110 // node that outlives its scope to still have a valid document |
| 111 // pointer without introducing reference cycles. |
| 112 void guardRef() |
| 113 { |
| 114 ASSERT(!deletionHasBegun()); |
| 115 ++m_guardRefCount; |
| 116 } |
| 117 |
| 118 void guardDeref() |
| 119 { |
| 120 ASSERT(!deletionHasBegun()); |
| 121 --m_guardRefCount; |
| 122 if (!m_guardRefCount && !refCount() && this != noDocumentInstance()) { |
| 123 beginDeletion(); |
| 124 delete this; |
| 125 } |
| 126 } |
| 127 |
| 128 void removedLastRefToScope(); |
| 129 |
107 protected: | 130 protected: |
108 TreeScope(ContainerNode*, Document*); | 131 TreeScope(ContainerNode*, Document*); |
109 TreeScope(Document*); | 132 TreeScope(Document*); |
110 virtual ~TreeScope(); | 133 virtual ~TreeScope(); |
111 | 134 |
112 void destroyTreeScopeData(); | 135 void destroyTreeScopeData(); |
113 void clearDocumentScope(); | 136 void clearDocumentScope(); |
114 void setDocumentScope(Document* document) | 137 void setDocumentScope(Document* document) |
115 { | 138 { |
116 ASSERT(document); | 139 ASSERT(document); |
117 ASSERT(this != noDocumentInstance()); | 140 ASSERT(this != noDocumentInstance()); |
118 m_documentScope = document; | 141 m_documentScope = document; |
119 } | 142 } |
120 | 143 |
| 144 bool hasGuardRefCount() const { return m_guardRefCount; } |
| 145 |
121 private: | 146 private: |
122 TreeScope(); | 147 TreeScope(); |
123 | 148 |
124 ContainerNode* m_rootNode; | 149 virtual void dispose() { } |
| 150 |
| 151 int refCount() const; |
| 152 #ifndef NDEBUG |
| 153 bool deletionHasBegun(); |
| 154 void beginDeletion(); |
| 155 #else |
| 156 bool deletionHasBegun() { return false; } |
| 157 void beginDeletion() { } |
| 158 #endif |
| 159 |
| 160 Node* m_rootNode; |
125 Document* m_documentScope; | 161 Document* m_documentScope; |
126 TreeScope* m_parentTreeScope; | 162 TreeScope* m_parentTreeScope; |
| 163 int m_guardRefCount; |
127 | 164 |
128 OwnPtr<DocumentOrderedMap> m_elementsById; | 165 OwnPtr<DocumentOrderedMap> m_elementsById; |
129 OwnPtr<DocumentOrderedMap> m_imageMapsByName; | 166 OwnPtr<DocumentOrderedMap> m_imageMapsByName; |
130 OwnPtr<DocumentOrderedMap> m_labelsByForAttribute; | 167 OwnPtr<DocumentOrderedMap> m_labelsByForAttribute; |
131 | 168 |
132 OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry; | 169 OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry; |
133 | 170 |
134 mutable RefPtr<DOMSelection> m_selection; | 171 mutable RefPtr<DOMSelection> m_selection; |
135 }; | 172 }; |
136 | 173 |
137 inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const | 174 inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const |
138 { | 175 { |
139 ASSERT(id); | 176 ASSERT(id); |
140 return m_elementsById && m_elementsById->contains(id); | 177 return m_elementsById && m_elementsById->contains(id); |
141 } | 178 } |
142 | 179 |
143 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co
nst | 180 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co
nst |
144 { | 181 { |
145 return m_elementsById && m_elementsById->containsMultiple(id.impl()); | 182 return m_elementsById && m_elementsById->containsMultiple(id.impl()); |
146 } | 183 } |
147 | 184 |
148 Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0); | 185 Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0); |
149 TreeScope* commonTreeScope(Node*, Node*); | 186 TreeScope* commonTreeScope(Node*, Node*); |
150 | 187 |
151 } // namespace WebCore | 188 } // namespace WebCore |
152 | 189 |
153 #endif // TreeScope_h | 190 #endif // TreeScope_h |
OLD | NEW |