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"
34 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
36 switch (orientation) {
38 return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
40 return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
42 return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
44 return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
50 static PassRefPtr<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLength>& dashes)
53 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
55 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
56 const Vector<SVGLength>::const_iterator end = dashes.end();
57 for (Vector<SVGLength>::const_iterator it = dashes.begin(); it != end; ++it)
58 list->append(SVGLength::toCSSPrimitiveValue(*it));
60 return list.release();
63 PassRefPtr<SVGPaint> CSSComputedStyleDeclaration::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const
65 RefPtr<SVGPaint> paint = newPaint;
66 if (paint->paintType() == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR || paint->paintType() == SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR)
67 paint->setColor(style->color());
68 return paint.release();
71 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
73 Node* node = m_node.get();
77 // Make sure our layout is up to date before we allow a query on these attributes.
79 node->document()->updateLayout();
81 RenderStyle* style = node->computedStyle();
85 const SVGRenderStyle* svgStyle = style->svgStyle();
89 switch (static_cast<CSSPropertyID>(propertyID)) {
90 case CSSPropertyClipRule:
91 return CSSPrimitiveValue::create(svgStyle->clipRule());
92 case CSSPropertyFloodOpacity:
93 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
94 case CSSPropertyStopOpacity:
95 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
96 case CSSPropertyColorInterpolation:
97 return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
98 case CSSPropertyColorInterpolationFilters:
99 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
100 case CSSPropertyFillOpacity:
101 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
102 case CSSPropertyFillRule:
103 return CSSPrimitiveValue::create(svgStyle->fillRule());
104 case CSSPropertyColorRendering:
105 return CSSPrimitiveValue::create(svgStyle->colorRendering());
106 case CSSPropertyShapeRendering:
107 return CSSPrimitiveValue::create(svgStyle->shapeRendering());
108 case CSSPropertyStrokeLinecap:
109 return CSSPrimitiveValue::create(svgStyle->capStyle());
110 case CSSPropertyStrokeLinejoin:
111 return CSSPrimitiveValue::create(svgStyle->joinStyle());
112 case CSSPropertyStrokeMiterlimit:
113 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
114 case CSSPropertyStrokeOpacity:
115 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
116 case CSSPropertyAlignmentBaseline:
117 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
118 case CSSPropertyDominantBaseline:
119 return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
120 case CSSPropertyTextAnchor:
121 return CSSPrimitiveValue::create(svgStyle->textAnchor());
122 case CSSPropertyWritingMode:
123 return CSSPrimitiveValue::create(svgStyle->writingMode());
124 case CSSPropertyClipPath:
125 if (!svgStyle->clipperResource().isEmpty())
126 return CSSPrimitiveValue::create(svgStyle->clipperResource(), CSSPrimitiveValue::CSS_URI);
127 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
128 case CSSPropertyMask:
129 if (!svgStyle->maskerResource().isEmpty())
130 return CSSPrimitiveValue::create(svgStyle->maskerResource(), CSSPrimitiveValue::CSS_URI);
131 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
132 case CSSPropertyFilter:
133 if (!svgStyle->filterResource().isEmpty())
134 return CSSPrimitiveValue::create(svgStyle->filterResource(), CSSPrimitiveValue::CSS_URI);
135 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
136 case CSSPropertyFloodColor:
137 return currentColorOrValidColor(style, svgStyle->floodColor());
138 case CSSPropertyLightingColor:
139 return currentColorOrValidColor(style, svgStyle->lightingColor());
140 case CSSPropertyStopColor:
141 return currentColorOrValidColor(style, svgStyle->stopColor());
142 case CSSPropertyFill:
143 return adjustSVGPaintForCurrentColor(SVGPaint::create(svgStyle->fillPaintType(), svgStyle->fillPaintUri(), svgStyle->fillPaintColor()), style);
144 case CSSPropertyKerning:
145 return SVGLength::toCSSPrimitiveValue(svgStyle->kerning());
146 case CSSPropertyMarkerEnd:
147 if (!svgStyle->markerEndResource().isEmpty())
148 return CSSPrimitiveValue::create(svgStyle->markerEndResource(), CSSPrimitiveValue::CSS_URI);
149 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
150 case CSSPropertyMarkerMid:
151 if (!svgStyle->markerMidResource().isEmpty())
152 return CSSPrimitiveValue::create(svgStyle->markerMidResource(), CSSPrimitiveValue::CSS_URI);
153 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
154 case CSSPropertyMarkerStart:
155 if (!svgStyle->markerStartResource().isEmpty())
156 return CSSPrimitiveValue::create(svgStyle->markerStartResource(), CSSPrimitiveValue::CSS_URI);
157 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
158 case CSSPropertyStroke:
159 return adjustSVGPaintForCurrentColor(SVGPaint::create(svgStyle->strokePaintType(), svgStyle->strokePaintUri(), svgStyle->strokePaintColor()), style);
160 case CSSPropertyStrokeDasharray:
161 return strokeDashArrayToCSSValueList(svgStyle->strokeDashArray());
162 case CSSPropertyStrokeDashoffset:
163 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeDashOffset());
164 case CSSPropertyStrokeWidth:
165 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeWidth());
166 case CSSPropertyBaselineShift: {
167 switch (svgStyle->baselineShift()) {
169 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
171 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
173 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
175 return SVGLength::toCSSPrimitiveValue(svgStyle->baselineShiftValue());
178 case CSSPropertyGlyphOrientationHorizontal:
179 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
180 case CSSPropertyGlyphOrientationVertical: {
181 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
182 return value.release();
184 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
185 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
189 case CSSPropertyWebkitSvgShadow:
190 return valueForShadow(svgStyle->shadow(), propertyID, style);
191 case CSSPropertyVectorEffect:
192 return CSSPrimitiveValue::create(svgStyle->vectorEffect());
193 case CSSPropertyMarker:
194 case CSSPropertyEnableBackground:
195 case CSSPropertyColorProfile:
196 // the above properties are not yet implemented in the engine
199 // If you crash here, it's because you added a css property and are not handling it
200 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
201 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
203 LOG_ERROR("unimplemented propertyID: %d", propertyID);
209 #endif // ENABLE(SVG)