2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
25 #include "SVGElementInstance.h"
27 #include "ContainerNodeAlgorithms.h"
29 #include "EventException.h"
30 #include "EventListener.h"
31 #include "EventNames.h"
32 #include "FrameView.h"
33 #include "SVGElementInstanceList.h"
34 #include "SVGUseElement.h"
36 #include <wtf/RefCountedLeakCounter.h>
41 static WTF::RefCountedLeakCounter instanceCounter("WebCoreSVGElementInstance");
44 SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
45 : m_correspondingUseElement(correspondingUseElement)
46 , m_directUseElement(directUseElement)
47 , m_element(originalElement)
48 , m_previousSibling(0)
53 ASSERT(m_correspondingUseElement);
56 // Register as instance for passed element.
57 m_element->mapInstanceToElement(this);
60 instanceCounter.increment();
64 SVGElementInstance::~SVGElementInstance()
67 instanceCounter.decrement();
70 // Deregister as instance for passed element.
71 m_element->removeInstanceMapping(this);
76 void SVGElementInstance::clearChildren()
78 removeAllChildrenInContainer<SVGElementInstance, SVGElementInstance>(this);
81 PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
83 return SVGElementInstanceList::create(this);
86 void SVGElementInstance::setShadowTreeElement(SVGElement* element)
89 m_shadowTreeElement = element;
92 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
94 appendChildToContainer<SVGElementInstance, SVGElementInstance>(child.get(), this);
97 void SVGElementInstance::invalidateAllInstancesOfElement(SVGElement* element)
99 if (!element || !element->inDocument())
102 if (element->isStyled() && static_cast<SVGStyledElement*>(element)->instanceUpdatesBlocked())
105 const HashSet<SVGElementInstance*>& set = element->instancesForElement();
109 // Mark all use elements referencing 'element' for rebuilding
110 const HashSet<SVGElementInstance*>::const_iterator end = set.end();
111 for (HashSet<SVGElementInstance*>::const_iterator it = set.begin(); it != end; ++it) {
112 ASSERT((*it)->shadowTreeElement());
113 ASSERT((*it)->shadowTreeElement()->correspondingElement());
114 ASSERT((*it)->correspondingElement() == element);
115 (*it)->shadowTreeElement()->setCorrespondingElement(0);
116 if (SVGUseElement* element = (*it)->correspondingUseElement()) {
117 ASSERT(element->inDocument());
118 element->invalidateShadowTree();
122 // Be sure to rebuild use trees, if needed
123 element->document()->updateLayoutIgnorePendingStylesheets();
126 ScriptExecutionContext* SVGElementInstance::scriptExecutionContext() const
128 return m_element->document();
131 bool SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
133 return m_element->addEventListener(eventType, listener, useCapture);
136 bool SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
138 return m_element->removeEventListener(eventType, listener, useCapture);
141 void SVGElementInstance::removeAllEventListeners()
143 m_element->removeAllEventListeners();
146 bool SVGElementInstance::dispatchEvent(PassRefPtr<Event> event)
148 SVGElement* element = shadowTreeElement();
152 return element->dispatchEvent(event);
155 EventTargetData* SVGElementInstance::eventTargetData()
157 // EventTarget would use these methods if we were actually using its add/removeEventListener logic.
158 // As we're forwarding those calls to the correspondingElement(), no one should ever call this function.
159 ASSERT_NOT_REACHED();
163 EventTargetData* SVGElementInstance::ensureEventTargetData()
165 // EventTarget would use these methods if we were actually using its add/removeEventListener logic.
166 // As we're forwarding those calls to the correspondingElement(), no one should ever call this function.
167 ASSERT_NOT_REACHED();