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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 void TreeScope::addElementById(const AtomicString& elementId, Element* element) | 180 void TreeScope::addElementById(const AtomicString& elementId, Element* element) |
181 { | 181 { |
182 if (!m_elementsById) | 182 if (!m_elementsById) |
183 m_elementsById = DocumentOrderedMap::create(); | 183 m_elementsById = DocumentOrderedMap::create(); |
184 m_elementsById->add(elementId, element); | 184 m_elementsById->add(elementId, element); |
185 m_idTargetObserverRegistry->notifyObservers(elementId); | 185 m_idTargetObserverRegistry->notifyObservers(elementId); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 #if ENABLE(ASSERT) | |
190 namespace { | |
191 | |
192 class RemovingElementIdScope { | |
193 STACK_ALLOCATED(); | |
194 public: | |
195 RemovingElementIdScope(DocumentOrderedMap& elementsById, const AtomicString&
id) | |
196 : m_elementsById(&elementsById) | |
197 { | |
198 m_elementsById->willRemoveId(id); | |
199 } | |
200 ~RemovingElementIdScope() | |
201 { | |
202 m_elementsById->willRemoveId(nullAtom); | |
203 } | |
204 | |
205 private: | |
206 RawPtrWillBeMember<DocumentOrderedMap> m_elementsById; | |
207 }; | |
208 | |
209 } | |
210 #endif | |
211 | |
212 void TreeScope::removeElementById(const AtomicString& elementId, Element* elemen
t) | 189 void TreeScope::removeElementById(const AtomicString& elementId, Element* elemen
t) |
213 { | 190 { |
214 if (!m_elementsById) | 191 if (!m_elementsById) |
215 return; | 192 return; |
216 m_elementsById->remove(elementId, element); | 193 m_elementsById->remove(elementId, element); |
217 #if ENABLE(ASSERT) | |
218 // Register 'elementId' as being removed. This is done should observers | |
219 // attempt to also look it up, something that the underlying DocumentOrdered
Map | |
220 // is incapable of answering precisely while an element (and its | |
221 // children) are being removed from the tree. This is _only_ done to avoid | |
222 // an assert in DocumentOrderedMap::get() from falsely triggering for such | |
223 // unusual and unexpected lookups. | |
224 RemovingElementIdScope removalScope(*m_elementsById, elementId); | |
225 #endif | |
226 m_idTargetObserverRegistry->notifyObservers(elementId); | 194 m_idTargetObserverRegistry->notifyObservers(elementId); |
227 } | 195 } |
228 | 196 |
229 Node* TreeScope::ancestorInThisScope(Node* node) const | 197 Node* TreeScope::ancestorInThisScope(Node* node) const |
230 { | 198 { |
231 while (node) { | 199 while (node) { |
232 if (node->treeScope() == this) | 200 if (node->treeScope() == this) |
233 return node; | 201 return node; |
234 if (!node->isInShadowTree()) | 202 if (!node->isInShadowTree()) |
235 return 0; | 203 return 0; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 visitor->trace(m_parentTreeScope); | 574 visitor->trace(m_parentTreeScope); |
607 visitor->trace(m_idTargetObserverRegistry); | 575 visitor->trace(m_idTargetObserverRegistry); |
608 visitor->trace(m_selection); | 576 visitor->trace(m_selection); |
609 visitor->trace(m_elementsById); | 577 visitor->trace(m_elementsById); |
610 visitor->trace(m_imageMapsByName); | 578 visitor->trace(m_imageMapsByName); |
611 visitor->trace(m_labelsByForAttribute); | 579 visitor->trace(m_labelsByForAttribute); |
612 visitor->trace(m_scopedStyleResolver); | 580 visitor->trace(m_scopedStyleResolver); |
613 } | 581 } |
614 | 582 |
615 } // namespace blink | 583 } // namespace blink |
OLD | NEW |