This source file includes following definitions.
- create
- m_lastChild
- removedLastRef
- detach
- childNodes
- setShadowTreeElement
- appendChild
- invalidateAllInstancesOfElement
- interfaceName
- executionContext
- addEventListener
- removeEventListener
- removeAllEventListeners
- toNode
- ownerDocument
- dispatchEvent
- eventTargetData
- ensureEventTargetData
#include "config.h"
#include "core/svg/SVGElementInstance.h"
#include "core/dom/ContainerNodeAlgorithms.h"
#include "core/events/Event.h"
#include "core/events/EventListener.h"
#include "core/svg/SVGElement.h"
#include "core/svg/SVGElementInstanceList.h"
#include "core/svg/SVGUseElement.h"
#include "wtf/RefCountedLeakCounter.h"
namespace WebCore {
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, instanceCounter, ("WebCoreSVGElementInstance"));
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), abort);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), blur);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), change);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), click);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), contextmenu);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dblclick);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), error);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), focus);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), input);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), keydown);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), keypress);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), keyup);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), load);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mousedown);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mouseenter);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mouseleave);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mousemove);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mouseout);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mouseover);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mouseup);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), mousewheel);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), wheel);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), beforecut);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), cut);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), beforecopy);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), copy);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), beforepaste);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), paste);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dragenter);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dragover);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dragleave);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), drop);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dragstart);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), drag);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), dragend);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), reset);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), resize);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), scroll);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), search);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), select);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), selectstart);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), submit);
DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(SVGElementInstance, correspondingElement(), unload);
PassRefPtr<SVGElementInstance> SVGElementInstance::create(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
{
return adoptRef(new SVGElementInstance(correspondingUseElement, directUseElement, originalElement));
}
SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
: m_parentInstance(0)
, m_correspondingUseElement(correspondingUseElement)
, m_directUseElement(directUseElement)
, m_element(originalElement)
, m_previousSibling(0)
, m_nextSibling(0)
, m_firstChild(0)
, m_lastChild(0)
{
ASSERT(m_correspondingUseElement);
ASSERT(m_element);
ScriptWrappable::init(this);
m_element->mapInstanceToElement(this);
#ifndef NDEBUG
instanceCounter.increment();
#endif
}
SVGElementInstance::~SVGElementInstance()
{
detach();
#ifndef NDEBUG
instanceCounter.decrement();
#endif
m_element = nullptr;
}
void SVGElementInstance::removedLastRef()
{
#if !ENABLE(OILPAN)
#if SECURITY_ASSERT_ENABLED
m_deletionHasBegun = true;
#endif
delete this;
#endif
}
void SVGElementInstance::detach()
{
for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling())
node->detach();
if (m_element->instancesForElement().contains(this))
m_element->removeInstanceMapping(this);
m_shadowTreeElement = nullptr;
m_directUseElement = 0;
m_correspondingUseElement = 0;
removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*this);
}
PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
{
return SVGElementInstanceList::create(this);
}
void SVGElementInstance::setShadowTreeElement(SVGElement* element)
{
ASSERT(element);
m_shadowTreeElement = element;
}
void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
{
appendChildToContainer<SVGElementInstance, SVGElementInstance>(*child, *this);
}
void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element)
{
if (!element || !element->inDocument())
return;
if (element->instanceUpdatesBlocked())
return;
const HashSet<SVGElementInstance*>& set = element->instancesForElement();
if (set.isEmpty())
return;
const HashSet<SVGElementInstance*>::const_iterator end = set.end();
for (HashSet<SVGElementInstance*>::const_iterator it = set.begin(); it != end; ++it) {
ASSERT((*it)->shadowTreeElement());
ASSERT((*it)->shadowTreeElement()->correspondingElement());
ASSERT((*it)->shadowTreeElement()->correspondingElement() == (*it)->correspondingElement());
ASSERT((*it)->correspondingElement() == element);
(*it)->shadowTreeElement()->setCorrespondingElement(0);
if (SVGUseElement* element = (*it)->correspondingUseElement()) {
ASSERT(element->inDocument());
element->invalidateShadowTree();
}
}
element->document().updateRenderTreeIfNeeded();
}
const AtomicString& SVGElementInstance::interfaceName() const
{
return EventTargetNames::SVGElementInstance;
}
ExecutionContext* SVGElementInstance::executionContext() const
{
return &m_element->document();
}
bool SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
{
return m_element->addEventListener(eventType, listener, useCapture);
}
bool SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
{
return m_element->removeEventListener(eventType, listener, useCapture);
}
void SVGElementInstance::removeAllEventListeners()
{
m_element->removeAllEventListeners();
}
Node* SVGElementInstance::toNode()
{
return shadowTreeElement();
}
Document* SVGElementInstance::ownerDocument() const
{
return m_element ? m_element->ownerDocument() : 0;
}
bool SVGElementInstance::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
{
SVGElement* element = shadowTreeElement();
if (!element)
return false;
return element->dispatchEvent(event);
}
EventTargetData* SVGElementInstance::eventTargetData()
{
return 0;
}
EventTargetData& SVGElementInstance::ensureEventTargetData()
{
ASSERT_NOT_REACHED();
return *eventTargetData();
}
SVGElementInstance::InstanceUpdateBlocker::InstanceUpdateBlocker(SVGElement* targetElement)
: m_targetElement(targetElement)
{
if (m_targetElement)
m_targetElement->setInstanceUpdatesBlocked(true);
}
SVGElementInstance::InstanceUpdateBlocker::~InstanceUpdateBlocker()
{
if (m_targetElement)
m_targetElement->setInstanceUpdatesBlocked(false);
}
}