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