| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "core/dom/MutationObserverInterestGroup.h" | 33 #include "core/dom/MutationObserverInterestGroup.h" |
| 34 | 34 |
| 35 #include "core/dom/MutationRecord.h" | 35 #include "core/dom/MutationRecord.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 PassOwnPtrWillBeRawPtr<MutationObserverInterestGroup> MutationObserverInterestGr
oup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationR
ecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName) | 39 PassOwnPtrWillBeRawPtr<MutationObserverInterestGroup> MutationObserverInterestGr
oup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationR
ecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName) |
| 40 { | 40 { |
| 41 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); | 41 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); |
| 42 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationRecordDelive
ryOptions> observers; | 42 WillBeHeapHashMap<RefPtrWillBeMember<MutationObserver>, MutationRecordDelive
ryOptions> observers; |
| 43 target.getRegisteredMutationObserversOfType(observers, type, attributeName); | 43 target.getRegisteredMutationObserversOfType(observers, type, attributeName); |
| 44 if (observers.isEmpty()) | 44 if (observers.isEmpty()) |
| 45 return nullptr; | 45 return nullptr; |
| 46 | 46 |
| 47 return adoptPtrWillBeNoop(new MutationObserverInterestGroup(observers, oldVa
lueFlag)); | 47 return adoptPtrWillBeNoop(new MutationObserverInterestGroup(observers, oldVa
lueFlag)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 MutationObserverInterestGroup::MutationObserverInterestGroup(WillBeHeapHashMap<R
awPtrWillBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers,
MutationRecordDeliveryOptions oldValueFlag) | 50 MutationObserverInterestGroup::MutationObserverInterestGroup(WillBeHeapHashMap<R
efPtrWillBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers,
MutationRecordDeliveryOptions oldValueFlag) |
| 51 : m_oldValueFlag(oldValueFlag) | 51 : m_oldValueFlag(oldValueFlag) |
| 52 { | 52 { |
| 53 ASSERT(!observers.isEmpty()); | 53 ASSERT(!observers.isEmpty()); |
| 54 m_observers.swap(observers); | 54 m_observers.swap(observers); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool MutationObserverInterestGroup::isOldValueRequested() | 57 bool MutationObserverInterestGroup::isOldValueRequested() |
| 58 { | 58 { |
| 59 for (auto& observer : m_observers) { | 59 for (auto& observer : m_observers) { |
| 60 if (hasOldValue(observer.value)) | 60 if (hasOldValue(observer.value)) |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void MutationObserverInterestGroup::enqueueMutationRecord(PassRefPtrWillBeRawPtr
<MutationRecord> prpMutation) | 66 void MutationObserverInterestGroup::enqueueMutationRecord(PassRefPtrWillBeRawPtr
<MutationRecord> prpMutation) |
| 67 { | 67 { |
| 68 RefPtrWillBeRawPtr<MutationRecord> mutation = prpMutation; | 68 RefPtrWillBeRawPtr<MutationRecord> mutation = prpMutation; |
| 69 RefPtrWillBeRawPtr<MutationRecord> mutationWithNullOldValue = nullptr; | 69 RefPtrWillBeRawPtr<MutationRecord> mutationWithNullOldValue = nullptr; |
| 70 for (auto& iter : m_observers) { | 70 for (auto& iter : m_observers) { |
| 71 MutationObserver* observer = iter.key; | 71 MutationObserver* observer = iter.key.get(); |
| 72 if (hasOldValue(iter.value)) { | 72 if (hasOldValue(iter.value)) { |
| 73 observer->enqueueMutationRecord(mutation); | 73 observer->enqueueMutationRecord(mutation); |
| 74 continue; | 74 continue; |
| 75 } | 75 } |
| 76 if (!mutationWithNullOldValue) { | 76 if (!mutationWithNullOldValue) { |
| 77 if (mutation->oldValue().isNull()) | 77 if (mutation->oldValue().isNull()) |
| 78 mutationWithNullOldValue = mutation; | 78 mutationWithNullOldValue = mutation; |
| 79 else | 79 else |
| 80 mutationWithNullOldValue = MutationRecord::createWithNullOldValu
e(mutation).get(); | 80 mutationWithNullOldValue = MutationRecord::createWithNullOldValu
e(mutation).get(); |
| 81 } | 81 } |
| 82 observer->enqueueMutationRecord(mutationWithNullOldValue); | 82 observer->enqueueMutationRecord(mutationWithNullOldValue); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 DEFINE_TRACE(MutationObserverInterestGroup) | 86 DEFINE_TRACE(MutationObserverInterestGroup) |
| 87 { | 87 { |
| 88 #if ENABLE(OILPAN) | 88 #if ENABLE(OILPAN) |
| 89 visitor->trace(m_observers); | 89 visitor->trace(m_observers); |
| 90 #endif | 90 #endif |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |