File indexing completed on 2024-04-21 11:30:57

0001 /*
0002     Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
0003 
0004     This file is part of the KDE project
0005 
0006     This library is free software; you can redistribute it and/or
0007     modify it under the terms of the GNU Library General Public
0008     License as published by the Free Software Foundation; either
0009     version 2 of the License, or (at your option) any later version.
0010 
0011     This library is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014     Library General Public License for more details.
0015 
0016     You should have received a copy of the GNU Library General Public License
0017     along with this library; see the file COPYING.LIB.  If not, write to
0018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019     Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef SVGElementInstance_h
0023 #define SVGElementInstance_h
0024 
0025 #if ENABLE(SVG)
0026 
0027 /*#include "EventTarget.h"*/
0028 #include "Document.h" //khtml
0029 
0030 #include <wtf/RefPtr.h>
0031 #include <wtf/PassRefPtr.h>
0032 
0033 namespace WebCore
0034 {
0035 class SVGElement;
0036 class SVGUseElement;
0037 class SVGElementInstanceList;
0038 
0039 class SVGElementInstance /*: public EventTarget*/
0040 {
0041 public:
0042     SVGElementInstance(SVGUseElement *, PassRefPtr<SVGElement> originalElement);
0043     virtual ~SVGElementInstance();
0044 
0045     // 'SVGElementInstance' functions
0046     SVGElement *correspondingElement() const;
0047     SVGUseElement *correspondingUseElement() const;
0048 
0049     SVGElementInstance *parentNode() const;
0050     PassRefPtr<SVGElementInstanceList> childNodes();
0051 
0052     SVGElementInstance *previousSibling() const;
0053     SVGElementInstance *nextSibling() const;
0054 
0055     SVGElementInstance *firstChild() const;
0056     SVGElementInstance *lastChild() const;
0057 
0058     // Internal usage only!
0059     SVGElement *shadowTreeElement() const;
0060     void setShadowTreeElement(SVGElement *);
0061 
0062     // Model the TreeShared concept, integrated within EventTarget inheritance.
0063     virtual void refEventTarget()
0064     {
0065         ++m_refCount;
0066     }
0067     virtual void derefEventTarget()
0068     {
0069         if (--m_refCount <= 0 && !m_parent) {
0070             delete this;
0071         }
0072     }
0073     // khtml compat
0074     virtual void ref()
0075     {
0076         refEventTarget();
0077     }
0078     virtual void deref()
0079     {
0080         derefEventTarget();
0081     }
0082 
0083     bool hasOneRef()
0084     {
0085         return m_refCount == 1;
0086     }
0087     int refCount() const
0088     {
0089         return m_refCount;
0090     }
0091 
0092     void setParent(SVGElementInstance *parent)
0093     {
0094         m_parent = parent;
0095     }
0096     SVGElementInstance *parent() const
0097     {
0098         return m_parent;
0099     }
0100 
0101     // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node.
0102     virtual EventTargetNode *toNode();
0103     virtual SVGElementInstance *toSVGElementInstance();
0104 
0105     virtual void addEventListener(const AtomicString &eventType, PassRefPtr<EventListener>, bool useCapture);
0106     virtual void removeEventListener(const AtomicString &eventType, EventListener *, bool useCapture);
0107     virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode &, bool tempEvent = false);
0108 
0109 private:
0110     SVGElementInstance(const SVGElementInstance &);
0111     SVGElementInstance &operator=(const SVGElementInstance &);
0112 
0113 private: // Helper methods
0114     friend class SVGUseElement;
0115     void appendChild(PassRefPtr<SVGElementInstance> child);
0116 
0117     friend class SVGStyledElement;
0118     void updateInstance(SVGElement *);
0119 
0120 private:
0121     int m_refCount;
0122     SVGElementInstance *m_parent;
0123 
0124     SVGUseElement *m_useElement;
0125     RefPtr<SVGElement> m_element;
0126     SVGElement *m_shadowTreeElement;
0127 
0128     SVGElementInstance *m_previousSibling;
0129     SVGElementInstance *m_nextSibling;
0130 
0131     SVGElementInstance *m_firstChild;
0132     SVGElementInstance *m_lastChild;
0133 };
0134 
0135 } // namespace WebCore
0136 
0137 #endif // ENABLE(SVG)
0138 #endif
0139