22 #include "wtf/Platform.h"
31 #include "cssstyleselector.h"
39 #include "SVGRenderStyle.h"
42 #include <wtf/Assertions.h>
50 using namespace SVGNames;
53 static HashSet<const SVGStyledElement*>* gElementsWithInstanceUpdatesBlocked = 0;
56 : SVGElement(tagName, doc)
60 SVGStyledElement::~SVGStyledElement()
67 bool SVGStyledElement::rendererIsNeeded(RenderStyle* style)
74 if (!parentNode() || parentNode()->isSVGElement())
75 return StyledElement::rendererIsNeeded(style);
80 static void mapAttributeToCSSProperty(HashMap<DOMStringImpl*, int>* propertyNameToIdMap,
const QualifiedName& attrName)
84 int propertyId = DOM::getPropertyID(propName.toLatin1(), propName.length());
85 ASSERT(propertyId > 0);
89 int SVGStyledElement::cssPropertyIdForSVGAttributeName(
const QualifiedName& attrName)
95 static HashMap<DOMStringImpl*, int>* propertyNameToIdMap = 0;
96 if (!propertyNameToIdMap) {
97 propertyNameToIdMap =
new HashMap<DOMStringImpl*, int>;
101 mapAttributeToCSSProperty(propertyNameToIdMap,
clipAttr);
102 mapAttributeToCSSProperty(propertyNameToIdMap,
clip_pathAttr);
103 mapAttributeToCSSProperty(propertyNameToIdMap,
clip_ruleAttr);
104 mapAttributeToCSSProperty(propertyNameToIdMap,
colorAttr);
109 mapAttributeToCSSProperty(propertyNameToIdMap,
cursorAttr);
110 mapAttributeToCSSProperty(propertyNameToIdMap,
directionAttr);
111 mapAttributeToCSSProperty(propertyNameToIdMap,
displayAttr);
114 mapAttributeToCSSProperty(propertyNameToIdMap,
fillAttr);
116 mapAttributeToCSSProperty(propertyNameToIdMap,
fill_ruleAttr);
117 mapAttributeToCSSProperty(propertyNameToIdMap,
filterAttr);
121 mapAttributeToCSSProperty(propertyNameToIdMap,
font_sizeAttr);
129 mapAttributeToCSSProperty(propertyNameToIdMap,
kerningAttr);
135 mapAttributeToCSSProperty(propertyNameToIdMap,
maskAttr);
136 mapAttributeToCSSProperty(propertyNameToIdMap,
opacityAttr);
137 mapAttributeToCSSProperty(propertyNameToIdMap,
overflowAttr);
142 mapAttributeToCSSProperty(propertyNameToIdMap,
strokeAttr);
170 void SVGStyledElement::parseMappedAttribute(MappedAttribute* attr)
175 if (
id == ATTR_STYLE) {
176 if (inlineStyleDecls()) {
177 inlineStyleDecls()->clear();
181 inlineStyleDecls()->setProperty(attr->value());
185 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attr->name());
187 addCSSProperty(attr, propId, attr->value());
193 SVGElement::parseMappedAttribute(attr);
196 bool SVGStyledElement::isKnownAttribute(
const QualifiedName& attrName)
199 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName);
202 return (attrName.
id() == ATTR_ID || attrName.
id() == ATTR_STYLE);
206 void SVGStyledElement::svgAttributeChanged(
const QualifiedName& attrName)
208 SVGElement::svgAttributeChanged(attrName);
211 invalidateResourcesInAncestorChain();
213 SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
222 updateElementInstance(extensions);
225 void SVGStyledElement::invalidateResourcesInAncestorChain()
const
227 Node* node = parentNode();
229 if (!node->isSVGElement())
232 SVGElement* element =
static_cast<SVGElement*
>(node);
233 if (SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(element->isStyled() ? element : 0)) {
242 void SVGStyledElement::childrenChanged(
bool changedByParser,
Node* beforeChange,
Node* afterChange,
int childCountDelta)
244 Q_UNUSED(changedByParser);
245 Q_UNUSED(beforeChange);
246 Q_UNUSED(afterChange);
247 Q_UNUSED(childCountDelta);
248 SVGElement::childrenChanged();
265 void SVGStyledElement::updateElementInstance(SVGDocumentExtensions* extensions)
const
267 Q_UNUSED(extensions);
295 RenderStyle* SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
297 Q_UNUSED(parentStyle);
299 RenderStyle* renderStyle = renderer()->style();
304 return document()->styleSelector()->styleForElement(
this);
307 PassRefPtr<DOM::CSSValueImpl> SVGStyledElement::getPresentationAttribute(
const String& name)
315 return new CSSPrimitiveValueImpl(0);
318 void SVGStyledElement::detach()
321 SVGElement::detach();
324 void SVGStyledElement::setInstanceUpdatesBlocked(
bool blockUpdates)
327 if (!gElementsWithInstanceUpdatesBlocked)
328 gElementsWithInstanceUpdatesBlocked =
new HashSet<const SVGStyledElement*>;
329 gElementsWithInstanceUpdatesBlocked->add(
this);
331 ASSERT(gElementsWithInstanceUpdatesBlocked);
332 ASSERT(gElementsWithInstanceUpdatesBlocked->contains(
this));
333 gElementsWithInstanceUpdatesBlocked->remove(
this);
339 #endif // ENABLE(SVG)