2 Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
24 #include "CSSComputedStyleDeclaration.h"
26 #include "CSSPrimitiveValueMappings.h"
27 #include "CSSPropertyNames.h"
29 #include "RenderStyle.h"
33 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
35 switch (orientation) {
37 return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
39 return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
41 return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
43 return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
49 static PassRefPtr<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLength>& dashes)
52 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
54 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
55 const Vector<SVGLength>::const_iterator end = dashes.end();
56 for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
57 list->append(SVGLength::toCSSPrimitiveValue(*it));
59 return list.release();
62 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
64 Node* node = m_node.get();
68 // Make sure our layout is up to date before we allow a query on these attributes.
70 node->document()->updateLayout();
72 RenderStyle* style = node->computedStyle();
76 const SVGRenderStyle* svgStyle = style->svgStyle();
80 switch (static_cast<CSSPropertyID>(propertyID)) {
81 case CSSPropertyClipRule:
82 return CSSPrimitiveValue::create(svgStyle->clipRule());
83 case CSSPropertyFloodOpacity:
84 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
85 case CSSPropertyStopOpacity:
86 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
87 case CSSPropertyColorInterpolation:
88 return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
89 case CSSPropertyColorInterpolationFilters:
90 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
91 case CSSPropertyFillOpacity:
92 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
93 case CSSPropertyFillRule:
94 return CSSPrimitiveValue::create(svgStyle->fillRule());
95 case CSSPropertyColorRendering:
96 return CSSPrimitiveValue::create(svgStyle->colorRendering());
97 case CSSPropertyImageRendering:
98 return CSSPrimitiveValue::create(svgStyle->imageRendering());
99 case CSSPropertyShapeRendering:
100 return CSSPrimitiveValue::create(svgStyle->shapeRendering());
101 case CSSPropertyStrokeLinecap:
102 return CSSPrimitiveValue::create(svgStyle->capStyle());
103 case CSSPropertyStrokeLinejoin:
104 return CSSPrimitiveValue::create(svgStyle->joinStyle());
105 case CSSPropertyStrokeMiterlimit:
106 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
107 case CSSPropertyStrokeOpacity:
108 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
109 case CSSPropertyAlignmentBaseline:
110 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
111 case CSSPropertyDominantBaseline:
112 return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
113 case CSSPropertyTextAnchor:
114 return CSSPrimitiveValue::create(svgStyle->textAnchor());
115 case CSSPropertyWritingMode:
116 return CSSPrimitiveValue::create(svgStyle->writingMode());
117 case CSSPropertyClipPath:
118 if (!svgStyle->clipperResource().isEmpty())
119 return CSSPrimitiveValue::create(svgStyle->clipperResource(), CSSPrimitiveValue::CSS_URI);
120 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
121 case CSSPropertyMask:
122 if (!svgStyle->maskerResource().isEmpty())
123 return CSSPrimitiveValue::create(svgStyle->maskerResource(), CSSPrimitiveValue::CSS_URI);
124 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
125 case CSSPropertyFilter:
126 if (!svgStyle->filterResource().isEmpty())
127 return CSSPrimitiveValue::create(svgStyle->filterResource(), CSSPrimitiveValue::CSS_URI);
128 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
129 case CSSPropertyFloodColor:
130 return CSSPrimitiveValue::createColor(svgStyle->floodColor().rgb());
131 case CSSPropertyLightingColor:
132 return CSSPrimitiveValue::createColor(svgStyle->lightingColor().rgb());
133 case CSSPropertyStopColor:
134 return CSSPrimitiveValue::createColor(svgStyle->stopColor().rgb());
135 case CSSPropertyFill:
136 return svgStyle->fillPaint();
137 case CSSPropertyKerning:
138 return SVGLength::toCSSPrimitiveValue(svgStyle->kerning());
139 case CSSPropertyMarkerEnd:
140 if (!svgStyle->markerEndResource().isEmpty())
141 return CSSPrimitiveValue::create(svgStyle->markerEndResource(), CSSPrimitiveValue::CSS_URI);
142 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
143 case CSSPropertyMarkerMid:
144 if (!svgStyle->markerMidResource().isEmpty())
145 return CSSPrimitiveValue::create(svgStyle->markerMidResource(), CSSPrimitiveValue::CSS_URI);
146 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
147 case CSSPropertyMarkerStart:
148 if (!svgStyle->markerStartResource().isEmpty())
149 return CSSPrimitiveValue::create(svgStyle->markerStartResource(), CSSPrimitiveValue::CSS_URI);
150 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
151 case CSSPropertyStroke:
152 return svgStyle->strokePaint();
153 case CSSPropertyStrokeDasharray:
154 return strokeDashArrayToCSSValueList(svgStyle->strokeDashArray());
155 case CSSPropertyStrokeDashoffset:
156 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeDashOffset());
157 case CSSPropertyStrokeWidth:
158 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeWidth());
159 case CSSPropertyBaselineShift: {
160 switch (svgStyle->baselineShift()) {
162 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
164 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
166 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
168 return SVGLength::toCSSPrimitiveValue(svgStyle->baselineShiftValue());
171 case CSSPropertyGlyphOrientationHorizontal:
172 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
173 case CSSPropertyGlyphOrientationVertical: {
174 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
175 return value.release();
177 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
178 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
182 case CSSPropertyWebkitSvgShadow:
183 return valueForShadow(svgStyle->shadow(), propertyID);
184 case CSSPropertyVectorEffect:
185 return CSSPrimitiveValue::create(svgStyle->vectorEffect());
186 case CSSPropertyMarker:
187 case CSSPropertyEnableBackground:
188 case CSSPropertyColorProfile:
189 // the above properties are not yet implemented in the engine
192 // If you crash here, it's because you added a css property and are not handling it
193 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
194 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
196 LOG_ERROR("unimplemented propertyID: %d", propertyID);
202 #endif // ENABLE(SVG)