| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 DCHECK(node); | 70 DCHECK(node); |
| 71 | 71 |
| 72 MutationObserverOptions options = 0; | 72 MutationObserverOptions options = 0; |
| 73 | 73 |
| 74 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) | 74 if (observerInit.hasAttributeOldValue() && observerInit.attributeOldValue()) |
| 75 options |= AttributeOldValue; | 75 options |= AttributeOldValue; |
| 76 | 76 |
| 77 HashSet<AtomicString> attributeFilter; | 77 HashSet<AtomicString> attributeFilter; |
| 78 if (observerInit.hasAttributeFilter()) { | 78 if (observerInit.hasAttributeFilter()) { |
| 79 for (const auto& name : observerInit.attributeFilter()) | 79 for (const auto& name : observerInit.attributeFilter()) |
| 80 attributeFilter.add(AtomicString(name)); | 80 attributeFilter.insert(AtomicString(name)); |
| 81 options |= AttributeFilter; | 81 options |= AttributeFilter; |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool attributes = observerInit.hasAttributes() && observerInit.attributes(); | 84 bool attributes = observerInit.hasAttributes() && observerInit.attributes(); |
| 85 if (attributes || | 85 if (attributes || |
| 86 (!observerInit.hasAttributes() && (observerInit.hasAttributeOldValue() || | 86 (!observerInit.hasAttributes() && (observerInit.hasAttributeOldValue() || |
| 87 observerInit.hasAttributeFilter()))) | 87 observerInit.hasAttributeFilter()))) |
| 88 options |= Attributes; | 88 options |= Attributes; |
| 89 | 89 |
| 90 if (observerInit.hasCharacterDataOldValue() && | 90 if (observerInit.hasCharacterDataOldValue() && |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Only call unregister if it is still in the original set. | 150 // Only call unregister if it is still in the original set. |
| 151 if (m_registrations.contains(registration)) | 151 if (m_registrations.contains(registration)) |
| 152 registration->unregister(); | 152 registration->unregister(); |
| 153 } | 153 } |
| 154 DCHECK(m_registrations.isEmpty()); | 154 DCHECK(m_registrations.isEmpty()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void MutationObserver::observationStarted( | 157 void MutationObserver::observationStarted( |
| 158 MutationObserverRegistration* registration) { | 158 MutationObserverRegistration* registration) { |
| 159 DCHECK(!m_registrations.contains(registration)); | 159 DCHECK(!m_registrations.contains(registration)); |
| 160 m_registrations.add(registration); | 160 m_registrations.insert(registration); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void MutationObserver::observationEnded( | 163 void MutationObserver::observationEnded( |
| 164 MutationObserverRegistration* registration) { | 164 MutationObserverRegistration* registration) { |
| 165 DCHECK(m_registrations.contains(registration)); | 165 DCHECK(m_registrations.contains(registration)); |
| 166 m_registrations.remove(registration); | 166 m_registrations.remove(registration); |
| 167 } | 167 } |
| 168 | 168 |
| 169 static MutationObserverSet& activeMutationObservers() { | 169 static MutationObserverSet& activeMutationObservers() { |
| 170 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, | 170 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 kept.reserveCapacity(activeSlotChangeList().size()); | 204 kept.reserveCapacity(activeSlotChangeList().size()); |
| 205 for (auto& slot : activeSlotChangeList()) { | 205 for (auto& slot : activeSlotChangeList()) { |
| 206 if (slot->document() != document) | 206 if (slot->document() != document) |
| 207 kept.push_back(slot); | 207 kept.push_back(slot); |
| 208 } | 208 } |
| 209 activeSlotChangeList().swap(kept); | 209 activeSlotChangeList().swap(kept); |
| 210 } | 210 } |
| 211 | 211 |
| 212 static void activateObserver(MutationObserver* observer) { | 212 static void activateObserver(MutationObserver* observer) { |
| 213 ensureEnqueueMicrotask(); | 213 ensureEnqueueMicrotask(); |
| 214 activeMutationObservers().add(observer); | 214 activeMutationObservers().insert(observer); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void MutationObserver::enqueueMutationRecord(MutationRecord* mutation) { | 217 void MutationObserver::enqueueMutationRecord(MutationRecord* mutation) { |
| 218 DCHECK(isMainThread()); | 218 DCHECK(isMainThread()); |
| 219 m_records.push_back(mutation); | 219 m_records.push_back(mutation); |
| 220 activateObserver(this); | 220 activateObserver(this); |
| 221 InspectorInstrumentation::asyncTaskScheduled( | 221 InspectorInstrumentation::asyncTaskScheduled( |
| 222 m_callback->getExecutionContext(), mutation->type(), mutation); | 222 m_callback->getExecutionContext(), mutation->type(), mutation); |
| 223 } | 223 } |
| 224 | 224 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 activeMutationObservers().clear(); | 296 activeMutationObservers().clear(); |
| 297 | 297 |
| 298 SlotChangeList slots; | 298 SlotChangeList slots; |
| 299 slots.swap(activeSlotChangeList()); | 299 slots.swap(activeSlotChangeList()); |
| 300 for (const auto& slot : slots) | 300 for (const auto& slot : slots) |
| 301 slot->clearSlotChangeEventEnqueued(); | 301 slot->clearSlotChangeEventEnqueued(); |
| 302 | 302 |
| 303 std::sort(observers.begin(), observers.end(), ObserverLessThan()); | 303 std::sort(observers.begin(), observers.end(), ObserverLessThan()); |
| 304 for (const auto& observer : observers) { | 304 for (const auto& observer : observers) { |
| 305 if (observer->shouldBeSuspended()) | 305 if (observer->shouldBeSuspended()) |
| 306 suspendedMutationObservers().add(observer); | 306 suspendedMutationObservers().insert(observer); |
| 307 else | 307 else |
| 308 observer->deliver(); | 308 observer->deliver(); |
| 309 } | 309 } |
| 310 for (const auto& slot : slots) | 310 for (const auto& slot : slots) |
| 311 slot->dispatchSlotChangeEvent(); | 311 slot->dispatchSlotChangeEvent(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 DEFINE_TRACE(MutationObserver) { | 314 DEFINE_TRACE(MutationObserver) { |
| 315 visitor->trace(m_callback); | 315 visitor->trace(m_callback); |
| 316 visitor->trace(m_records); | 316 visitor->trace(m_records); |
| 317 visitor->trace(m_registrations); | 317 visitor->trace(m_registrations); |
| 318 visitor->trace(m_callback); | 318 visitor->trace(m_callback); |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace blink | 321 } // namespace blink |
| OLD | NEW |