KHTML
SVGForeignObjectElement.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2006 Apple Computer, Inc. 00003 (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 00004 00005 This file is part of the WebKit 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 #include "config.h" 00024 00025 #if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT) 00026 #include "SVGForeignObjectElement.h" 00027 00028 #include "CSSPropertyNames.h" 00029 #include "RenderForeignObject.h" 00030 #include "SVGNames.h" 00031 #include "SVGLength.h" 00032 00033 #include <wtf/Assertions.h> 00034 00035 namespace WebCore { 00036 00037 SVGForeignObjectElement::SVGForeignObjectElement(const QualifiedName& tagName, Document *doc) 00038 : SVGStyledTransformableElement(tagName, doc) 00039 , SVGTests() 00040 , SVGLangSpace() 00041 , SVGExternalResourcesRequired() 00042 , m_x(this, LengthModeWidth) 00043 , m_y(this, LengthModeHeight) 00044 , m_width(this, LengthModeWidth) 00045 , m_height(this, LengthModeHeight) 00046 { 00047 } 00048 00049 SVGForeignObjectElement::~SVGForeignObjectElement() 00050 { 00051 } 00052 00053 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x) 00054 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y) 00055 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width) 00056 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height) 00057 00058 void SVGForeignObjectElement::parseMappedAttribute(MappedAttribute* attr) 00059 { 00060 const AtomicString& value = attr->value(); 00061 if (attr->name() == SVGNames::xAttr) 00062 setXBaseValue(SVGLength(this, LengthModeWidth, value)); 00063 else if (attr->name() == SVGNames::yAttr) 00064 setYBaseValue(SVGLength(this, LengthModeHeight, value)); 00065 else if (attr->name() == SVGNames::widthAttr) 00066 setWidthBaseValue(SVGLength(this, LengthModeWidth, value)); 00067 else if (attr->name() == SVGNames::heightAttr) 00068 setHeightBaseValue(SVGLength(this, LengthModeHeight, value)); 00069 else { 00070 if (SVGTests::parseMappedAttribute(attr)) 00071 return; 00072 if (SVGLangSpace::parseMappedAttribute(attr)) 00073 return; 00074 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) 00075 return; 00076 SVGStyledTransformableElement::parseMappedAttribute(attr); 00077 } 00078 } 00079 00080 // TODO: Move this function in some SVG*Element base class, as SVGSVGElement / SVGImageElement will need the same logic! 00081 00082 // This function mimics addCSSProperty and StyledElement::attributeChanged. 00083 // In HTML code, you'd always call addCSSProperty from your derived parseMappedAttribute() 00084 // function - though in SVG code we need to move this logic into svgAttributeChanged, in 00085 // order to support SVG DOM changes (which don't use the parseMappedAttribute/attributeChanged). 00086 // If we'd ignore SVG DOM, we could use _exactly_ the same logic as HTML. 00087 static inline void addCSSPropertyAndNotifyAttributeMap(StyledElement* element, const QualifiedName& name, int cssProperty, const String& value) 00088 { 00089 ASSERT(element); 00090 00091 if (!element) 00092 return; 00093 00094 NamedMappedAttrMap* attrs = element->mappedAttributes(); 00095 ASSERT(attrs); 00096 00097 if (!attrs) 00098 return; 00099 00100 MappedAttribute* mappedAttr = attrs->getAttributeItem(name); 00101 if (!mappedAttr) 00102 return; 00103 00104 // This logic is only meant to be used for entries that have to be parsed and are mapped to eNone. Assert that. 00105 MappedAttributeEntry entry; 00106 bool needToParse = element->mapToEntry(mappedAttr->name(), entry); 00107 00108 ASSERT(needToParse); 00109 ASSERT(entry == eNone); 00110 00111 if (!needToParse || entry != eNone) 00112 return; 00113 00114 if (mappedAttr->decl()) { 00115 mappedAttr->setDecl(0); 00116 attrs->declRemoved(); 00117 } 00118 00119 element->setChanged(); 00120 element->addCSSProperty(mappedAttr, cssProperty, value); 00121 00122 if (CSSMappedAttributeDeclaration* decl = mappedAttr->decl()) { 00123 // Add the decl to the table in the appropriate spot. 00124 element->setMappedAttributeDecl(entry, mappedAttr, decl); 00125 00126 decl->setMappedState(entry, mappedAttr->name(), mappedAttr->value()); 00127 decl->setParent(0); 00128 decl->setNode(0); 00129 00130 attrs->declAdded(); 00131 } 00132 } 00133 00134 void SVGForeignObjectElement::svgAttributeChanged(const QualifiedName& attrName) 00135 { 00136 SVGStyledTransformableElement::svgAttributeChanged(attrName); 00137 00138 if (attrName == SVGNames::widthAttr) { 00139 addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyWidth, width().valueAsString()); 00140 return; 00141 } else if (attrName == SVGNames::heightAttr) { 00142 addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyHeight, height().valueAsString()); 00143 return; 00144 } 00145 00146 if (!renderer()) 00147 return; 00148 00149 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr || 00150 SVGTests::isKnownAttribute(attrName) || 00151 SVGLangSpace::isKnownAttribute(attrName) || 00152 SVGExternalResourcesRequired::isKnownAttribute(attrName) || 00153 SVGStyledTransformableElement::isKnownAttribute(attrName)) 00154 renderer()->setNeedsLayout(true); 00155 } 00156 00157 RenderObject* SVGForeignObjectElement::createRenderer(RenderArena* arena, RenderStyle* style) 00158 { 00159 return new (arena) RenderForeignObject(this); 00160 } 00161 00162 bool SVGForeignObjectElement::childShouldCreateRenderer(Node* child) const 00163 { 00164 // Skip over SVG rules which disallow non-SVG kids 00165 return StyledElement::childShouldCreateRenderer(child); 00166 } 00167 00168 } // namespace WebCore 00169 00170 #endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
KDE 4.6 API Reference