• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef SVGElementInstance_h
22 #define SVGElementInstance_h
23 
24 #include "bindings/v8/ScriptWrappable.h"
25 #include "core/dom/TreeShared.h"
26 #include "core/events/EventTarget.h"
27 
28 namespace WebCore {
29 
30 namespace Private {
31 template<class GenericNode, class GenericNodeContainer>
32 void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
33 };
34 
35 class Document;
36 class SVGElement;
37 class SVGElementInstanceList;
38 class SVGUseElement;
39 
40 // SVGElementInstance mimics Node, but without providing all its functionality
41 class SVGElementInstance : public EventTarget, public ScriptWrappable, public TreeShared<SVGElementInstance> {
42     DEFINE_EVENT_TARGET_REFCOUNTING(TreeShared<SVGElementInstance>);
43 public:
44     static PassRefPtr<SVGElementInstance> create(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement);
45 
46     virtual ~SVGElementInstance();
47 
setParentOrShadowHostNode(SVGElementInstance * instance)48     void setParentOrShadowHostNode(SVGElementInstance* instance) { m_parentInstance = instance; }
49 
50     virtual const AtomicString& interfaceName() const;
51     virtual ExecutionContext* executionContext() const;
52 
53     virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
54     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
55     virtual void removeAllEventListeners();
56 
57     using EventTarget::dispatchEvent;
58     virtual bool dispatchEvent(PassRefPtr<Event>) OVERRIDE;
59 
correspondingElement()60     SVGElement* correspondingElement() const { return m_element.get(); }
correspondingUseElement()61     SVGUseElement* correspondingUseElement() const { return m_correspondingUseElement; }
directUseElement()62     SVGUseElement* directUseElement() const { return m_directUseElement; }
shadowTreeElement()63     SVGElement* shadowTreeElement() const { return m_shadowTreeElement.get(); }
64 
65     void detach();
66 
parentNode()67     SVGElementInstance* parentNode() const { return m_parentInstance; }
68     PassRefPtr<SVGElementInstanceList> childNodes();
69 
previousSibling()70     SVGElementInstance* previousSibling() const { return m_previousSibling; }
nextSibling()71     SVGElementInstance* nextSibling() const { return m_nextSibling; }
72 
firstChild()73     SVGElementInstance* firstChild() const { return m_firstChild; }
lastChild()74     SVGElementInstance* lastChild() const { return m_lastChild; }
75 
76     inline Document* ownerDocument() const;
77 
78     class InvalidationGuard {
79         WTF_MAKE_NONCOPYABLE(InvalidationGuard);
80     public:
InvalidationGuard(SVGElement * element)81         InvalidationGuard(SVGElement* element) : m_element(element) { }
~InvalidationGuard()82         ~InvalidationGuard() { SVGElementInstance::invalidateAllInstancesOfElement(m_element); }
83     private:
84         SVGElement* m_element;
85     };
86 
87     class InstanceUpdateBlocker {
88         WTF_MAKE_NONCOPYABLE(InstanceUpdateBlocker);
89     public:
90         InstanceUpdateBlocker(SVGElement* targetElement);
91         ~InstanceUpdateBlocker();
92 
93     private:
94         SVGElement* m_targetElement;
95     };
96 
97     static void invalidateAllInstancesOfElement(SVGElement*);
98 
99     // EventTarget API
100     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), abort);
101     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), blur);
102     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), change);
103     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), click);
104     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), contextmenu);
105     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dblclick);
106     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), error);
107     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), focus);
108     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), input);
109     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keydown);
110     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keypress);
111     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), keyup);
112     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), load);
113     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousedown);
114     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseenter);
115     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseleave);
116     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousemove);
117     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseout);
118     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseover);
119     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mouseup);
120     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), mousewheel);
121     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), wheel);
122     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforecut);
123     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), cut);
124     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforecopy);
125     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), copy);
126     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), beforepaste);
127     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), paste);
128     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragenter);
129     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragover);
130     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragleave);
131     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), drop);
132     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragstart);
133     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), drag);
134     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), dragend);
135     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), reset);
136     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), resize);
137     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), scroll);
138     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), search);
139     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), select);
140     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), selectstart);
141     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), submit);
142     DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(correspondingElement(), unload);
143 
144 private:
145     friend class SVGUseElement;
146     friend class TreeShared<SVGElementInstance>;
147 
148     SVGElementInstance(SVGUseElement*, SVGUseElement*, PassRefPtr<SVGElement> originalElement);
149 
150     void removedLastRef();
hasTreeSharedParent()151     bool hasTreeSharedParent() const { return !!m_parentInstance; }
152 
153     virtual Node* toNode();
154 
155     void appendChild(PassRefPtr<SVGElementInstance> child);
156     void setShadowTreeElement(SVGElement*);
157 
158     template<class GenericNode, class GenericNodeContainer>
159     friend void appendChildToContainer(GenericNode& child, GenericNodeContainer&);
160 
161     template<class GenericNode, class GenericNodeContainer>
162     friend void removeDetachedChildrenInContainer(GenericNodeContainer&);
163 
164     template<class GenericNode, class GenericNodeContainer>
165     friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
166 
hasChildNodes()167     bool hasChildNodes() const { return m_firstChild; }
168 
setFirstChild(SVGElementInstance * child)169     void setFirstChild(SVGElementInstance* child) { m_firstChild = child; }
setLastChild(SVGElementInstance * child)170     void setLastChild(SVGElementInstance* child) { m_lastChild = child; }
171 
setNextSibling(SVGElementInstance * sibling)172     void setNextSibling(SVGElementInstance* sibling) { m_nextSibling = sibling; }
setPreviousSibling(SVGElementInstance * sibling)173     void setPreviousSibling(SVGElementInstance* sibling) { m_previousSibling = sibling; }
174 
175     virtual EventTargetData* eventTargetData() OVERRIDE;
176     virtual EventTargetData& ensureEventTargetData() OVERRIDE;
177 
178     SVGElementInstance* m_parentInstance;
179 
180     SVGUseElement* m_correspondingUseElement;
181     SVGUseElement* m_directUseElement;
182     RefPtr<SVGElement> m_element;
183     RefPtr<SVGElement> m_shadowTreeElement;
184 
185     SVGElementInstance* m_previousSibling;
186     SVGElementInstance* m_nextSibling;
187 
188     SVGElementInstance* m_firstChild;
189     SVGElementInstance* m_lastChild;
190 };
191 
192 } // namespace WebCore
193 
194 #endif
195