This source file includes following definitions.
- createIfNeeded
- isOldValueRequested
- enqueueMutationRecord
#include "config.h"
#include "core/dom/MutationObserverInterestGroup.h"
#include "core/dom/MutationRecord.h"
namespace WebCore {
PassOwnPtr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
{
ASSERT((type == MutationObserver::Attributes && attributeName) || !attributeName);
HashMap<MutationObserver*, MutationRecordDeliveryOptions> observers;
target.getRegisteredMutationObserversOfType(observers, type, attributeName);
if (observers.isEmpty())
return nullptr;
return adoptPtr(new MutationObserverInterestGroup(observers, oldValueFlag));
}
MutationObserverInterestGroup::MutationObserverInterestGroup(HashMap<MutationObserver*, MutationRecordDeliveryOptions>& observers, MutationRecordDeliveryOptions oldValueFlag)
: m_oldValueFlag(oldValueFlag)
{
ASSERT(!observers.isEmpty());
m_observers.swap(observers);
}
bool MutationObserverInterestGroup::isOldValueRequested()
{
for (HashMap<MutationObserver*, MutationRecordDeliveryOptions>::iterator iter = m_observers.begin(); iter != m_observers.end(); ++iter) {
if (hasOldValue(iter->value))
return true;
}
return false;
}
void MutationObserverInterestGroup::enqueueMutationRecord(PassRefPtr<MutationRecord> prpMutation)
{
RefPtr<MutationRecord> mutation = prpMutation;
RefPtr<MutationRecord> mutationWithNullOldValue;
for (HashMap<MutationObserver*, MutationRecordDeliveryOptions>::iterator iter = m_observers.begin(); iter != m_observers.end(); ++iter) {
MutationObserver* observer = iter->key;
if (hasOldValue(iter->value)) {
observer->enqueueMutationRecord(mutation);
continue;
}
if (!mutationWithNullOldValue) {
if (mutation->oldValue().isNull())
mutationWithNullOldValue = mutation;
else
mutationWithNullOldValue = MutationRecord::createWithNullOldValue(mutation).get();
}
observer->enqueueMutationRecord(mutationWithNullOldValue);
}
}
}