00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #include "wtf/Platform.h"
00023
00024 #if ENABLE(SVG)
00025 #include "SVGStyledElement.h"
00026
00027
00028
00029
00030
00031 #include "cssstyleselector.h"
00032 #include "Document.h"
00033
00034 #include "PlatformString.h"
00035 #include "SVGElement.h"
00036
00037 #include "SVGNames.h"
00038 #include "RenderObject.h"
00039 #include "SVGRenderStyle.h"
00040
00041 #include "SVGSVGElement.h"
00042 #include <wtf/Assertions.h>
00043
00044
00045 #include "css_base.h"
00046
00047
00048 namespace WebCore {
00049
00050 using namespace SVGNames;
00051 using namespace DOM;
00052
00053 static HashSet<const SVGStyledElement*>* gElementsWithInstanceUpdatesBlocked = 0;
00054
00055 SVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* doc)
00056 : SVGElement(tagName, doc)
00057 {
00058 }
00059
00060 SVGStyledElement::~SVGStyledElement()
00061 {
00062
00063 }
00064
00065 ANIMATED_PROPERTY_DEFINITIONS(SVGStyledElement, String, String, string, ClassName, className, HTMLNames::classAttr, m_className)
00066
00067 bool SVGStyledElement::rendererIsNeeded(RenderStyle* style)
00068 {
00069
00070
00071
00072
00073
00074 if (!parentNode() || parentNode()->isSVGElement())
00075 return StyledElement::rendererIsNeeded(style);
00076
00077 return false;
00078 }
00079
00080 static void mapAttributeToCSSProperty(HashMap<DOMStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName)
00081 {
00082
00083 QString propName = attrName.localName().string();
00084 int propertyId = DOM::getPropertyID(propName.toLatin1(), propName.length());
00085 ASSERT(propertyId > 0);
00086 propertyNameToIdMap->set(attrName.localName().implementation(), propertyId);
00087 }
00088
00089 int SVGStyledElement::cssPropertyIdForSVGAttributeName(const QualifiedName& attrName)
00090 {
00091 if (!attrName.namespaceURI().isEmpty())
00092 return 0;
00093
00094
00095 static HashMap<DOMStringImpl*, int>* propertyNameToIdMap = 0;
00096 if (!propertyNameToIdMap) {
00097 propertyNameToIdMap = new HashMap<DOMStringImpl*, int>;
00098
00099 mapAttributeToCSSProperty(propertyNameToIdMap, alignment_baselineAttr);
00100 mapAttributeToCSSProperty(propertyNameToIdMap, baseline_shiftAttr);
00101 mapAttributeToCSSProperty(propertyNameToIdMap, clipAttr);
00102 mapAttributeToCSSProperty(propertyNameToIdMap, clip_pathAttr);
00103 mapAttributeToCSSProperty(propertyNameToIdMap, clip_ruleAttr);
00104 mapAttributeToCSSProperty(propertyNameToIdMap, colorAttr);
00105 mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolationAttr);
00106 mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolation_filtersAttr);
00107 mapAttributeToCSSProperty(propertyNameToIdMap, color_profileAttr);
00108 mapAttributeToCSSProperty(propertyNameToIdMap, color_renderingAttr);
00109 mapAttributeToCSSProperty(propertyNameToIdMap, cursorAttr);
00110 mapAttributeToCSSProperty(propertyNameToIdMap, directionAttr);
00111 mapAttributeToCSSProperty(propertyNameToIdMap, displayAttr);
00112 mapAttributeToCSSProperty(propertyNameToIdMap, dominant_baselineAttr);
00113 mapAttributeToCSSProperty(propertyNameToIdMap, enable_backgroundAttr);
00114 mapAttributeToCSSProperty(propertyNameToIdMap, fillAttr);
00115 mapAttributeToCSSProperty(propertyNameToIdMap, fill_opacityAttr);
00116 mapAttributeToCSSProperty(propertyNameToIdMap, fill_ruleAttr);
00117 mapAttributeToCSSProperty(propertyNameToIdMap, filterAttr);
00118 mapAttributeToCSSProperty(propertyNameToIdMap, flood_colorAttr);
00119 mapAttributeToCSSProperty(propertyNameToIdMap, flood_opacityAttr);
00120 mapAttributeToCSSProperty(propertyNameToIdMap, font_familyAttr);
00121 mapAttributeToCSSProperty(propertyNameToIdMap, font_sizeAttr);
00122 mapAttributeToCSSProperty(propertyNameToIdMap, font_stretchAttr);
00123 mapAttributeToCSSProperty(propertyNameToIdMap, font_styleAttr);
00124 mapAttributeToCSSProperty(propertyNameToIdMap, font_variantAttr);
00125 mapAttributeToCSSProperty(propertyNameToIdMap, font_weightAttr);
00126 mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_horizontalAttr);
00127 mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_verticalAttr);
00128 mapAttributeToCSSProperty(propertyNameToIdMap, image_renderingAttr);
00129 mapAttributeToCSSProperty(propertyNameToIdMap, kerningAttr);
00130 mapAttributeToCSSProperty(propertyNameToIdMap, letter_spacingAttr);
00131 mapAttributeToCSSProperty(propertyNameToIdMap, lighting_colorAttr);
00132 mapAttributeToCSSProperty(propertyNameToIdMap, marker_endAttr);
00133 mapAttributeToCSSProperty(propertyNameToIdMap, marker_midAttr);
00134 mapAttributeToCSSProperty(propertyNameToIdMap, marker_startAttr);
00135 mapAttributeToCSSProperty(propertyNameToIdMap, maskAttr);
00136 mapAttributeToCSSProperty(propertyNameToIdMap, opacityAttr);
00137 mapAttributeToCSSProperty(propertyNameToIdMap, overflowAttr);
00138 mapAttributeToCSSProperty(propertyNameToIdMap, pointer_eventsAttr);
00139 mapAttributeToCSSProperty(propertyNameToIdMap, shape_renderingAttr);
00140 mapAttributeToCSSProperty(propertyNameToIdMap, stop_colorAttr);
00141 mapAttributeToCSSProperty(propertyNameToIdMap, stop_opacityAttr);
00142 mapAttributeToCSSProperty(propertyNameToIdMap, strokeAttr);
00143 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dasharrayAttr);
00144 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dashoffsetAttr);
00145 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linecapAttr);
00146 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linejoinAttr);
00147 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_miterlimitAttr);
00148 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_opacityAttr);
00149 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_widthAttr);
00150 mapAttributeToCSSProperty(propertyNameToIdMap, text_anchorAttr);
00151 mapAttributeToCSSProperty(propertyNameToIdMap, text_decorationAttr);
00152 mapAttributeToCSSProperty(propertyNameToIdMap, text_renderingAttr);
00153 mapAttributeToCSSProperty(propertyNameToIdMap, unicode_bidiAttr);
00154 mapAttributeToCSSProperty(propertyNameToIdMap, visibilityAttr);
00155 mapAttributeToCSSProperty(propertyNameToIdMap, word_spacingAttr);
00156 mapAttributeToCSSProperty(propertyNameToIdMap, writing_modeAttr);
00157 }
00158 return propertyNameToIdMap->get(attrName.localName().implementation());
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void SVGStyledElement::parseMappedAttribute(MappedAttribute* attr)
00171 {
00172
00173
00174 int id = attr->id();
00175 if (id == ATTR_STYLE) {
00176 if (inlineStyleDecls()) {
00177 inlineStyleDecls()->clear();
00178 } else {
00179 createInlineDecl();
00180 }
00181 inlineStyleDecls()->setProperty(attr->value());
00182 setChanged();
00183 return;
00184 }
00185 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attr->name());
00186 if (propId > 0) {
00187 addCSSProperty(attr, propId, attr->value());
00188 setChanged();
00189 return;
00190 }
00191
00192
00193 SVGElement::parseMappedAttribute(attr);
00194 }
00195
00196 bool SVGStyledElement::isKnownAttribute(const QualifiedName& attrName)
00197 {
00198
00199 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName);
00200 if (propId > 0)
00201 return true;
00202 return (attrName.id() == ATTR_ID || attrName.id() == ATTR_STYLE);
00203
00204 }
00205
00206 void SVGStyledElement::svgAttributeChanged(const QualifiedName& attrName)
00207 {
00208 SVGElement::svgAttributeChanged(attrName);
00209
00210
00211 invalidateResourcesInAncestorChain();
00212
00213 SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
00214 if (!extensions)
00215 return;
00216
00217
00218
00219
00220
00221
00222 updateElementInstance(extensions);
00223 }
00224
00225 void SVGStyledElement::invalidateResourcesInAncestorChain() const
00226 {
00227 Node* node = parentNode();
00228 while (node) {
00229 if (!node->isSVGElement())
00230 break;
00231
00232 SVGElement* element = static_cast<SVGElement*>(node);
00233 if (SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(element->isStyled() ? element : 0)) {
00234
00235
00236 }
00237
00238 node = node->parentNode();
00239 }
00240 }
00241
00242 void SVGStyledElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
00243 {
00244 SVGElement::childrenChanged();
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 }
00260
00261 void SVGStyledElement::updateElementInstance(SVGDocumentExtensions* extensions) const
00262 {
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 }
00289
00290 RenderStyle* SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
00291 {
00292 if (renderer()) {
00293 RenderStyle* renderStyle = renderer()->style();
00294 renderStyle->ref();
00295 return renderStyle;
00296 }
00297
00298 return document()->styleSelector()->styleForElement(this);
00299 }
00300
00301 PassRefPtr<DOM::CSSValueImpl> SVGStyledElement::getPresentationAttribute(const String& name)
00302 {
00303
00304
00305
00306
00307 Q_ASSERT(false);
00308 return new CSSPrimitiveValueImpl(0);
00309 }
00310
00311 void SVGStyledElement::detach()
00312 {
00313
00314 SVGElement::detach();
00315 }
00316
00317 void SVGStyledElement::setInstanceUpdatesBlocked(bool blockUpdates)
00318 {
00319 if (blockUpdates) {
00320 if (!gElementsWithInstanceUpdatesBlocked)
00321 gElementsWithInstanceUpdatesBlocked = new HashSet<const SVGStyledElement*>;
00322 gElementsWithInstanceUpdatesBlocked->add(this);
00323 } else {
00324 ASSERT(gElementsWithInstanceUpdatesBlocked);
00325 ASSERT(gElementsWithInstanceUpdatesBlocked->contains(this));
00326 gElementsWithInstanceUpdatesBlocked->remove(this);
00327 }
00328 }
00329
00330 }
00331
00332 #endif // ENABLE(SVG)