00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00081
00082
00083
00084
00085
00086
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
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
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
00165 return StyledElement::childShouldCreateRenderer(child);
00166 }
00167
00168 }
00169
00170 #endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)