• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 
4     This file is part of the KDE project
5 
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.
10 
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.
15 
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.
20 */
21 
22 #ifndef SVGElementInstance_h
23 #define SVGElementInstance_h
24 
25 #if ENABLE(SVG)
26 #include "EventTarget.h"
27 #include "SVGElement.h"
28 #include "TreeShared.h"
29 
30 #include <wtf/RefPtr.h>
31 #include <wtf/PassRefPtr.h>
32 
33 namespace WebCore {
34 
35     namespace Private {
36         template<class GenericNode, class GenericNodeContainer>
37         void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
38     };
39 
40     class EventListener;
41     class Frame;
42     class SVGUseElement;
43     class SVGElementInstanceList;
44 
45     // SVGElementInstance mimics Node, but without providing all its functionality
46     class SVGElementInstance : public TreeShared<SVGElementInstance>,
47                                public EventTarget
48     {
49     public:
50         SVGElementInstance(SVGUseElement*, SVGElement* originalElement);
51         virtual ~SVGElementInstance();
52 
needsUpdate()53         bool needsUpdate() const { return m_needsUpdate; }
54         void setNeedsUpdate(bool);
55 
56         virtual ScriptExecutionContext* scriptExecutionContext() const;
57 
toNode()58         virtual EventTargetNode* toNode() { return shadowTreeElement(); }
toSVGElementInstance()59         virtual SVGElementInstance* toSVGElementInstance() { return this; }
60 
61         virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
62         virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
63         virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&);
64 
correspondingElement()65         SVGElement* correspondingElement() const { return m_element.get(); }
correspondingUseElement()66         SVGUseElement* correspondingUseElement() const { return m_useElement; }
shadowTreeElement()67         SVGElement* shadowTreeElement() const { return m_shadowTreeElement.get(); }
68 
parentNode()69         SVGElementInstance* parentNode() const { return parent(); }
70         PassRefPtr<SVGElementInstanceList> childNodes();
71 
previousSibling()72         SVGElementInstance* previousSibling() const { return m_previousSibling; }
nextSibling()73         SVGElementInstance* nextSibling() const { return m_nextSibling; }
74 
firstChild()75         SVGElementInstance* firstChild() const { return m_firstChild; }
lastChild()76         SVGElementInstance* lastChild() const { return m_lastChild; }
77 
ownerDocument()78         Document* ownerDocument() const { return m_element ? m_element->ownerDocument() : 0; }
79 
80         static void invalidateAllInstancesOfElement(SVGElement*);
81 
82         using TreeShared<SVGElementInstance>::ref;
83         using TreeShared<SVGElementInstance>::deref;
84 
85         // EventTarget API
86         EventListener* onabort() const;
87         void setOnabort(PassRefPtr<EventListener>);
88         EventListener* onblur() const;
89         void setOnblur(PassRefPtr<EventListener>);
90         EventListener* onchange() const;
91         void setOnchange(PassRefPtr<EventListener>);
92         EventListener* onclick() const;
93         void setOnclick(PassRefPtr<EventListener>);
94         EventListener* oncontextmenu() const;
95         void setOncontextmenu(PassRefPtr<EventListener>);
96         EventListener* ondblclick() const;
97         void setOndblclick(PassRefPtr<EventListener>);
98         EventListener* onerror() const;
99         void setOnerror(PassRefPtr<EventListener>);
100         EventListener* onfocus() const;
101         void setOnfocus(PassRefPtr<EventListener>);
102         EventListener* oninput() const;
103         void setOninput(PassRefPtr<EventListener>);
104         EventListener* onkeydown() const;
105         void setOnkeydown(PassRefPtr<EventListener>);
106         EventListener* onkeypress() const;
107         void setOnkeypress(PassRefPtr<EventListener>);
108         EventListener* onkeyup() const;
109         void setOnkeyup(PassRefPtr<EventListener>);
110         EventListener* onload() const;
111         void setOnload(PassRefPtr<EventListener>);
112         EventListener* onmousedown() const;
113         void setOnmousedown(PassRefPtr<EventListener>);
114         EventListener* onmousemove() const;
115         void setOnmousemove(PassRefPtr<EventListener>);
116         EventListener* onmouseout() const;
117         void setOnmouseout(PassRefPtr<EventListener>);
118         EventListener* onmouseover() const;
119         void setOnmouseover(PassRefPtr<EventListener>);
120         EventListener* onmouseup() const;
121         void setOnmouseup(PassRefPtr<EventListener>);
122         EventListener* onmousewheel() const;
123         void setOnmousewheel(PassRefPtr<EventListener>);
124         EventListener* onbeforecut() const;
125         void setOnbeforecut(PassRefPtr<EventListener>);
126         EventListener* oncut() const;
127         void setOncut(PassRefPtr<EventListener>);
128         EventListener* onbeforecopy() const;
129         void setOnbeforecopy(PassRefPtr<EventListener>);
130         EventListener* oncopy() const;
131         void setOncopy(PassRefPtr<EventListener>);
132         EventListener* onbeforepaste() const;
133         void setOnbeforepaste(PassRefPtr<EventListener>);
134         EventListener* onpaste() const;
135         void setOnpaste(PassRefPtr<EventListener>);
136         EventListener* ondragenter() const;
137         void setOndragenter(PassRefPtr<EventListener>);
138         EventListener* ondragover() const;
139         void setOndragover(PassRefPtr<EventListener>);
140         EventListener* ondragleave() const;
141         void setOndragleave(PassRefPtr<EventListener>);
142         EventListener* ondrop() const;
143         void setOndrop(PassRefPtr<EventListener>);
144         EventListener* ondragstart() const;
145         void setOndragstart(PassRefPtr<EventListener>);
146         EventListener* ondrag() const;
147         void setOndrag(PassRefPtr<EventListener>);
148         EventListener* ondragend() const;
149         void setOndragend(PassRefPtr<EventListener>);
150         EventListener* onreset() const;
151         void setOnreset(PassRefPtr<EventListener>);
152         EventListener* onresize() const;
153         void setOnresize(PassRefPtr<EventListener>);
154         EventListener* onscroll() const;
155         void setOnscroll(PassRefPtr<EventListener>);
156         EventListener* onsearch() const;
157         void setOnsearch(PassRefPtr<EventListener>);
158         EventListener* onselect() const;
159         void setOnselect(PassRefPtr<EventListener>);
160         EventListener* onselectstart() const;
161         void setOnselectstart(PassRefPtr<EventListener>);
162         EventListener* onsubmit() const;
163         void setOnsubmit(PassRefPtr<EventListener>);
164         EventListener* onunload() const;
165         void setOnunload(PassRefPtr<EventListener>);
166 
167     private:
168         friend class SVGUseElement;
169 
170         void appendChild(PassRefPtr<SVGElementInstance> child);
171         void setShadowTreeElement(SVGElement*);
172         void forgetWrapper();
173 
174         template<class GenericNode, class GenericNodeContainer>
175         friend void appendChildToContainer(GenericNode* child, GenericNodeContainer* container);
176 
177         template<class GenericNode, class GenericNodeContainer>
178         friend void removeAllChildrenInContainer(GenericNodeContainer* container);
179 
180         template<class GenericNode, class GenericNodeContainer>
181         friend void Private::addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container);
182 
hasChildNodes()183         bool hasChildNodes() const { return m_firstChild; }
184 
setFirstChild(SVGElementInstance * child)185         void setFirstChild(SVGElementInstance* child) { m_firstChild = child; }
setLastChild(SVGElementInstance * child)186         void setLastChild(SVGElementInstance* child) { m_lastChild = child; }
187 
setNextSibling(SVGElementInstance * sibling)188         void setNextSibling(SVGElementInstance* sibling) { m_nextSibling = sibling; }
setPreviousSibling(SVGElementInstance * sibling)189         void setPreviousSibling(SVGElementInstance* sibling) { m_previousSibling = sibling; }
190 
refEventTarget()191         virtual void refEventTarget() { ref(); }
derefEventTarget()192         virtual void derefEventTarget() { deref(); }
193 
194     private:
195         bool m_needsUpdate : 1;
196 
197         SVGUseElement* m_useElement;
198         RefPtr<SVGElement> m_element;
199         RefPtr<SVGElement> m_shadowTreeElement;
200 
201         SVGElementInstance* m_previousSibling;
202         SVGElementInstance* m_nextSibling;
203 
204         SVGElementInstance* m_firstChild;
205         SVGElementInstance* m_lastChild;
206     };
207 
208 } // namespace WebCore
209 
210 #endif // ENABLE(SVG)
211 #endif
212