KHTML
SVGElement.h
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 00003 2004, 2005, 2006 Rob Buis <buis@kde.org> 00004 00005 This file is part of the KDE project 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef SVGElement_h 00024 #define SVGElement_h 00025 00026 #if ENABLE(SVG) 00027 #include "Document.h" 00028 #include "FloatRect.h" 00029 //#include "StyledElement.h" 00030 #include "SVGAnimatedTemplate.h" 00031 #include "SVGDocumentExtensions.h" 00032 #include "SVGNames.h" 00033 00034 #include "ExceptionCode.h" 00035 00036 #define ANIMATED_PROPERTY_EMPTY_DECLARATIONS(BareType, NullType, UpperProperty, LowerProperty) \ 00037 public: \ 00038 virtual BareType LowerProperty() const { ASSERT_NOT_REACHED(); return NullType; } \ 00039 virtual void set##UpperProperty(BareType) { ASSERT_NOT_REACHED(); }\ 00040 virtual BareType LowerProperty##BaseValue() const { ASSERT_NOT_REACHED(); return NullType; } \ 00041 virtual void set##UpperProperty##BaseValue(BareType) { ASSERT_NOT_REACHED(); } \ 00042 virtual void start##UpperProperty() const { ASSERT_NOT_REACHED(); } \ 00043 virtual void stop##UpperProperty() { ASSERT_NOT_REACHED(); } 00044 00045 #define ANIMATED_PROPERTY_FORWARD_DECLARATIONS(ForwardClass, BareType, UpperProperty, LowerProperty) \ 00046 public: \ 00047 virtual BareType LowerProperty() const { return ForwardClass::LowerProperty(); } \ 00048 virtual void set##UpperProperty(BareType newValue) { ForwardClass::set##UpperProperty(newValue); } \ 00049 virtual BareType LowerProperty##BaseValue() const { return ForwardClass::LowerProperty##BaseValue(); } \ 00050 virtual void set##UpperProperty##BaseValue(BareType newValue) { ForwardClass::set##UpperProperty##BaseValue(newValue); } \ 00051 virtual void start##UpperProperty() const { ForwardClass::start##UpperProperty(); } \ 00052 virtual void stop##UpperProperty() { ForwardClass::stop##UpperProperty(); } 00053 00054 #define ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(ClassType, ClassStorageType, BareType, StorageType, UpperProperty, LowerProperty) \ 00055 class SVGAnimatedTemplate##UpperProperty \ 00056 : public SVGAnimatedTemplate<BareType> \ 00057 { \ 00058 public: \ 00059 SVGAnimatedTemplate##UpperProperty(const ClassType*, const QualifiedName&); \ 00060 virtual ~SVGAnimatedTemplate##UpperProperty() { } \ 00061 virtual BareType baseVal() const; \ 00062 virtual void setBaseVal(BareType); \ 00063 virtual BareType animVal() const; \ 00064 virtual void setAnimVal(BareType); \ 00065 \ 00066 protected: \ 00067 ClassStorageType m_element; \ 00068 }; \ 00069 public: \ 00070 BareType LowerProperty() const; \ 00071 void set##UpperProperty(BareType); \ 00072 BareType LowerProperty##BaseValue() const; \ 00073 void set##UpperProperty##BaseValue(BareType); \ 00074 PassRefPtr<SVGAnimatedTemplate##UpperProperty> LowerProperty##Animated() const; \ 00075 void start##UpperProperty() const; \ 00076 void stop##UpperProperty(); \ 00077 \ 00078 private: \ 00079 StorageType m_##LowerProperty; 00080 00081 #define ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, ClassType, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter, ContextElement) \ 00082 ClassName::SVGAnimatedTemplate##UpperProperty::SVGAnimatedTemplate##UpperProperty(const ClassType* element, const QualifiedName& attributeName) \ 00083 : SVGAnimatedTemplate<BareType>(attributeName), m_element(const_cast<ClassType*>(element)) { } \ 00084 \ 00085 BareType ClassName::SVGAnimatedTemplate##UpperProperty::baseVal() const \ 00086 { \ 00087 return m_element->LowerProperty##BaseValue(); \ 00088 } \ 00089 void ClassName::SVGAnimatedTemplate##UpperProperty::setBaseVal(BareType newBaseVal) \ 00090 { \ 00091 m_element->set##UpperProperty##BaseValue(newBaseVal); \ 00092 } \ 00093 BareType ClassName::SVGAnimatedTemplate##UpperProperty::animVal() const \ 00094 { \ 00095 return m_element->LowerProperty(); \ 00096 } \ 00097 void ClassName::SVGAnimatedTemplate##UpperProperty::setAnimVal(BareType newAnimVal) \ 00098 { \ 00099 m_element->set##UpperProperty(newAnimVal); \ 00100 } \ 00101 BareType ClassName::LowerProperty() const \ 00102 { \ 00103 return StorageGetter; \ 00104 } \ 00105 void ClassName::set##UpperProperty(BareType newValue) \ 00106 { \ 00107 m_##LowerProperty = newValue; \ 00108 } \ 00109 BareType ClassName::LowerProperty##BaseValue() const \ 00110 { \ 00111 const SVGElement* context = ContextElement; \ 00112 ASSERT(context); \ 00113 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \ 00114 if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) \ 00115 return extensions->baseValue<BareType>(context, AttrName); \ 00116 return LowerProperty(); \ 00117 } \ 00118 void ClassName::set##UpperProperty##BaseValue(BareType newValue) \ 00119 { \ 00120 const SVGElement* context = ContextElement; \ 00121 ASSERT(context); \ 00122 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \ 00123 if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) { \ 00124 extensions->setBaseValue<BareType>(context, AttrName, newValue); \ 00125 return; \ 00126 } \ 00127 /* Only update stored property, if not animating */ \ 00128 set##UpperProperty(newValue); \ 00129 } \ 00130 \ 00131 void ClassName::start##UpperProperty() const \ 00132 { \ 00133 const SVGElement* context = ContextElement; \ 00134 ASSERT(context); \ 00135 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \ 00136 if (extensions) { \ 00137 ASSERT(!extensions->hasBaseValue<BareType>(context, AttrName)); \ 00138 extensions->setBaseValue<BareType>(context, AttrName, LowerProperty()); \ 00139 } \ 00140 } \ 00141 \ 00142 void ClassName::stop##UpperProperty() \ 00143 { \ 00144 const SVGElement* context = ContextElement; \ 00145 ASSERT(context); \ 00146 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \ 00147 if (extensions) { \ 00148 ASSERT(extensions->hasBaseValue<BareType>(context, AttrName)); \ 00149 set##UpperProperty(extensions->baseValue<BareType>(context, AttrName)); \ 00150 extensions->removeBaseValue<BareType>(context, AttrName); \ 00151 } \ 00152 } 00153 00154 // These are the macros which will be used to declare/implement the svg animated properties... 00155 #define ANIMATED_PROPERTY_DECLARATIONS_WITH_CONTEXT(ClassName, BareType, StorageType, UpperProperty, LowerProperty) \ 00156 ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(SVGElement, RefPtr<SVGElement>, BareType, StorageType, UpperProperty, LowerProperty) 00157 00158 #define ANIMATED_PROPERTY_DECLARATIONS(ClassName, BareType, StorageType, UpperProperty, LowerProperty) \ 00159 ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(ClassName, RefPtr<ClassName>, BareType, StorageType, UpperProperty, LowerProperty) 00160 00161 #define ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter) \ 00162 ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, SVGElement, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName.localName(), StorageGetter, contextElement()) \ 00163 PassRefPtr<ClassName::SVGAnimatedTemplate##UpperProperty> ClassName::LowerProperty##Animated() const \ 00164 { \ 00165 const SVGElement* context = contextElement(); \ 00166 ASSERT(context); \ 00167 return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, SVGElement>(context, AttrName, AttrName.localName()); \ 00168 } 00169 00170 #define ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, AttrIdentifier, StorageGetter) \ 00171 ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName.localName(), StorageGetter, this) \ 00172 PassRefPtr<ClassName::SVGAnimatedTemplate##UpperProperty> ClassName::LowerProperty##Animated() const \ 00173 { \ 00174 return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, ClassName>(this, AttrName, AttrIdentifier); \ 00175 } 00176 00177 #define ANIMATED_PROPERTY_DEFINITIONS(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter) \ 00178 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, AttrName.localName(), StorageGetter) 00179 00180 namespace WebCore { 00181 00182 class SVGPreserveAspectRatio; 00183 class SVGSVGElement; 00184 00185 class SVGElement : public StyledElement { 00186 public: 00187 SVGElement(const QualifiedName&, Document*); 00188 virtual ~SVGElement(); 00189 virtual bool isSVGElement() const { return true; } 00190 virtual bool isSupported(StringImpl* feature, StringImpl* version) const; 00191 00192 String attrid() const; 00193 void setId(const String&, ExceptionCode&); 00194 String xmlbase() const; 00195 void setXmlbase(const String&, ExceptionCode&); 00196 00197 SVGSVGElement* ownerSVGElement() const; 00198 SVGElement* viewportElement() const; 00199 00200 virtual void parseMappedAttribute(MappedAttribute*); 00201 00202 virtual bool isStyled() const { return false; } 00203 virtual bool isStyledTransformable() const { return false; } 00204 virtual bool isStyledLocatable() const { return false; } 00205 virtual bool isSVG() const { return false; } 00206 virtual bool isFilterEffect() const { return false; } 00207 virtual bool isGradientStop() const { return false; } 00208 virtual bool isTextContent() const { return false; } 00209 00210 virtual bool isShadowNode() const { return false; /*FIXME khtml return m_shadowParent;*/ } 00211 virtual Node* shadowParentNode() { return m_shadowParent; } 00212 void setShadowParentNode(Node* node) { m_shadowParent = node; } 00213 virtual Node* eventParentNode() { return isShadowNode() ? shadowParentNode() : parentNode(); } 00214 00215 // For SVGTests 00216 virtual bool isValid() const { return true; } 00217 00218 virtual void finishParsingChildren(); 00219 // KHTML compatibility 00220 virtual void close() { finishParsingChildren(); Element::close(); } 00221 virtual bool rendererIsNeeded(RenderStyle*) { return false; } 00222 virtual bool childShouldCreateRenderer(Node*) const; 00223 00224 virtual void insertedIntoDocument(); 00225 virtual void buildPendingResource() { } 00226 00227 virtual void svgAttributeChanged(const QualifiedName&) { } 00228 using DOM::ElementImpl::attributeChanged; 00229 virtual void attributeChanged(Attribute*, bool preserveDecls = false); 00230 00231 void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false); 00232 00233 virtual AffineTransform* supplementalTransform() { return 0; } 00234 00235 // Forwarded properties (declared/defined anywhere else in the inheritance structure) 00236 00237 00238 // -> For SVGURIReference 00239 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(String, String(), Href, href) 00240 00241 // -> For SVGFitToViewBox 00242 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(FloatRect, FloatRect(), ViewBox, viewBox) 00243 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(SVGPreserveAspectRatio*, 0, PreserveAspectRatio, preserveAspectRatio) 00244 00245 // -> For SVGExternalResourcesRequired 00246 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(bool, false, ExternalResourcesRequired, externalResourcesRequired) 00247 00248 virtual bool dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent = false); 00249 00250 // for KHTML compatibility 00251 virtual void parseAttribute(Attribute* attr) { parseMappedAttribute(attr); } 00252 virtual void addCSSProperty(Attribute* attr, int id, const String& value); 00253 virtual void addCSSProperty(Attribute* attr, int id, int value); 00254 00255 private: 00256 void addSVGEventListener(const DOM::EventImpl::EventId& eventType, const DOM::AttributeImpl*); 00257 virtual bool haveLoadedRequiredResources(); 00258 00259 Node* m_shadowParent; 00260 }; 00261 00262 } // namespace WebCore 00263 00264 #endif // ENABLE(SVG) 00265 #endif // SVGElement_h
KDE 4.6 API Reference