MutationObserverInterestGroup.cpp [plain text]
#include "config.h"
#include "MutationObserverInterestGroup.h"
#include "MutationObserverRegistration.h"
#include "MutationRecord.h"
namespace WebCore {
inline MutationObserverInterestGroup::MutationObserverInterestGroup(HashMap<Ref<MutationObserver>, MutationRecordDeliveryOptions>&& observers, MutationRecordDeliveryOptions oldValueFlag)
: m_observers(WTFMove(observers))
, m_oldValueFlag(oldValueFlag)
{
ASSERT(!m_observers.isEmpty());
}
std::unique_ptr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
{
ASSERT((type == MutationObserver::Attributes && attributeName) || !attributeName);
auto observers = target.registeredMutationObservers(type, attributeName);
if (observers.isEmpty())
return nullptr;
return makeUnique<MutationObserverInterestGroup>(WTFMove(observers), oldValueFlag);
}
bool MutationObserverInterestGroup::isOldValueRequested() const
{
for (auto options : m_observers.values()) {
if (hasOldValue(options))
return true;
}
return false;
}
void MutationObserverInterestGroup::enqueueMutationRecord(Ref<MutationRecord>&& mutation)
{
RefPtr<MutationRecord> mutationWithNullOldValue;
for (auto& observerOptionsPair : m_observers) {
auto& observer = observerOptionsPair.key.get();
if (hasOldValue(observerOptionsPair.value)) {
observer.enqueueMutationRecord(mutation.copyRef());
continue;
}
if (!mutationWithNullOldValue) {
if (mutation->oldValue().isNull())
mutationWithNullOldValue = mutation.ptr();
else
mutationWithNullOldValue = MutationRecord::createWithNullOldValue(mutation).ptr();
}
observer.enqueueMutationRecord(*mutationWithNullOldValue);
}
}
}