This source file includes following definitions.
- create
- m_attributeFilter
- resetObservation
- observedSubtreeNodeWillDetach
- clearTransientRegistrations
- unregister
- shouldReceiveMutationFrom
- addRegistrationNodesToSet
#include "config.h"
#include "core/dom/MutationObserverRegistration.h"
#include "core/dom/Node.h"
#include "core/dom/QualifiedName.h"
namespace WebCore {
PassOwnPtr<MutationObserverRegistration> MutationObserverRegistration::create(MutationObserver& observer, Node& registrationNode, MutationObserverOptions options, const HashSet<AtomicString>& attributeFilter)
{
return adoptPtr(new MutationObserverRegistration(observer, registrationNode, options, attributeFilter));
}
MutationObserverRegistration::MutationObserverRegistration(MutationObserver& observer, Node& registrationNode, MutationObserverOptions options, const HashSet<AtomicString>& attributeFilter)
: m_observer(observer)
, m_registrationNode(registrationNode)
, m_options(options)
, m_attributeFilter(attributeFilter)
{
m_observer->observationStarted(this);
}
MutationObserverRegistration::~MutationObserverRegistration()
{
clearTransientRegistrations();
m_observer->observationEnded(this);
}
void MutationObserverRegistration::resetObservation(MutationObserverOptions options, const HashSet<AtomicString>& attributeFilter)
{
clearTransientRegistrations();
m_options = options;
m_attributeFilter = attributeFilter;
}
void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node)
{
if (!isSubtree())
return;
node.registerTransientMutationObserver(this);
m_observer->setHasTransientRegistration();
if (!m_transientRegistrationNodes) {
m_transientRegistrationNodes = adoptPtr(new NodeHashSet);
ASSERT(!m_registrationNodeKeepAlive);
m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode);
}
m_transientRegistrationNodes->add(&node);
}
void MutationObserverRegistration::clearTransientRegistrations()
{
if (!m_transientRegistrationNodes) {
ASSERT(!m_registrationNodeKeepAlive);
return;
}
for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); iter != m_transientRegistrationNodes->end(); ++iter)
(*iter)->unregisterTransientMutationObserver(this);
m_transientRegistrationNodes.clear();
ASSERT(m_registrationNodeKeepAlive);
m_registrationNodeKeepAlive = nullptr;
}
void MutationObserverRegistration::unregister()
{
m_registrationNode.unregisterMutationObserver(this);
}
bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, MutationObserver::MutationType type, const QualifiedName* attributeName) const
{
ASSERT((type == MutationObserver::Attributes && attributeName) || !attributeName);
if (!(m_options & type))
return false;
if (m_registrationNode != node && !isSubtree())
return false;
if (type != MutationObserver::Attributes || !(m_options & MutationObserver::AttributeFilter))
return true;
if (!attributeName->namespaceURI().isNull())
return false;
return m_attributeFilter.contains(attributeName->localName());
}
void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nodes) const
{
nodes.add(&m_registrationNode);
if (!m_transientRegistrationNodes)
return;
for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin(); iter != m_transientRegistrationNodes->end(); ++iter)
nodes.add(iter->get());
}
}