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.
23 #include "core/css/CSSComputedStyleDeclaration.h"
25 #include "CSSPropertyNames.h"
26 #include "core/css/CSSPrimitiveValueMappings.h"
27 #include "core/dom/Document.h"
28 #include "core/rendering/style/RenderStyle.h"
29 #include "core/svg/SVGPaint.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 static PassRefPtr<CSSValue> paintOrderToCSSValueList(EPaintOrder paintorder)
64 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
66 EPaintOrderType paintOrderType = (EPaintOrderType)(paintorder & ((1 << kPaintOrderBitwidth) - 1));
67 switch (paintOrderType) {
71 list->append(CSSPrimitiveValue::create(paintOrderType));
78 } while (paintorder >>= kPaintOrderBitwidth);
80 return list.release();
83 PassRefPtr<SVGPaint> CSSComputedStyleDeclaration::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const
85 RefPtr<SVGPaint> paint = newPaint;
86 if (paint->paintType() == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR || paint->paintType() == SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR)
87 paint->setColor(style->color());
88 return paint.release();
91 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
93 Node* node = m_node.get();
97 // Make sure our layout is up to date before we allow a query on these attributes.
99 node->document().updateLayout();
101 RenderStyle* style = node->computedStyle();
105 const SVGRenderStyle* svgStyle = style->svgStyle();
109 switch (propertyID) {
110 case CSSPropertyClipRule:
111 return CSSPrimitiveValue::create(svgStyle->clipRule());
112 case CSSPropertyFloodOpacity:
113 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
114 case CSSPropertyStopOpacity:
115 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
116 case CSSPropertyColorInterpolation:
117 return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
118 case CSSPropertyColorInterpolationFilters:
119 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
120 case CSSPropertyFillOpacity:
121 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
122 case CSSPropertyFillRule:
123 return CSSPrimitiveValue::create(svgStyle->fillRule());
124 case CSSPropertyColorRendering:
125 return CSSPrimitiveValue::create(svgStyle->colorRendering());
126 case CSSPropertyShapeRendering:
127 return CSSPrimitiveValue::create(svgStyle->shapeRendering());
128 case CSSPropertyStrokeLinecap:
129 return CSSPrimitiveValue::create(svgStyle->capStyle());
130 case CSSPropertyStrokeLinejoin:
131 return CSSPrimitiveValue::create(svgStyle->joinStyle());
132 case CSSPropertyStrokeMiterlimit:
133 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
134 case CSSPropertyStrokeOpacity:
135 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
136 case CSSPropertyAlignmentBaseline:
137 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
138 case CSSPropertyDominantBaseline:
139 return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
140 case CSSPropertyTextAnchor:
141 return CSSPrimitiveValue::create(svgStyle->textAnchor());
142 case CSSPropertyWritingMode:
143 return CSSPrimitiveValue::create(svgStyle->writingMode());
144 case CSSPropertyClipPath:
145 if (!svgStyle->clipperResource().isEmpty())
146 return CSSPrimitiveValue::create(svgStyle->clipperResource(), CSSPrimitiveValue::CSS_URI);
147 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
148 case CSSPropertyMask:
149 if (!svgStyle->maskerResource().isEmpty())
150 return CSSPrimitiveValue::create(svgStyle->maskerResource(), CSSPrimitiveValue::CSS_URI);
151 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
152 case CSSPropertyFilter:
153 if (!svgStyle->filterResource().isEmpty())
154 return CSSPrimitiveValue::create(svgStyle->filterResource(), CSSPrimitiveValue::CSS_URI);
155 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
156 case CSSPropertyFloodColor:
157 return currentColorOrValidColor(style, svgStyle->floodColor());
158 case CSSPropertyLightingColor:
159 return currentColorOrValidColor(style, svgStyle->lightingColor());
160 case CSSPropertyStopColor:
161 return currentColorOrValidColor(style, svgStyle->stopColor());
162 case CSSPropertyFill:
163 return adjustSVGPaintForCurrentColor(SVGPaint::create(svgStyle->fillPaintType(), svgStyle->fillPaintUri(), svgStyle->fillPaintColor()), style);
164 case CSSPropertyKerning:
165 return SVGLength::toCSSPrimitiveValue(svgStyle->kerning());
166 case CSSPropertyMarkerEnd:
167 if (!svgStyle->markerEndResource().isEmpty())
168 return CSSPrimitiveValue::create(svgStyle->markerEndResource(), CSSPrimitiveValue::CSS_URI);
169 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
170 case CSSPropertyMarkerMid:
171 if (!svgStyle->markerMidResource().isEmpty())
172 return CSSPrimitiveValue::create(svgStyle->markerMidResource(), CSSPrimitiveValue::CSS_URI);
173 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
174 case CSSPropertyMarkerStart:
175 if (!svgStyle->markerStartResource().isEmpty())
176 return CSSPrimitiveValue::create(svgStyle->markerStartResource(), CSSPrimitiveValue::CSS_URI);
177 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
178 case CSSPropertyStroke:
179 return adjustSVGPaintForCurrentColor(SVGPaint::create(svgStyle->strokePaintType(), svgStyle->strokePaintUri(), svgStyle->strokePaintColor()), style);
180 case CSSPropertyStrokeDasharray:
181 return strokeDashArrayToCSSValueList(svgStyle->strokeDashArray());
182 case CSSPropertyStrokeDashoffset:
183 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeDashOffset());
184 case CSSPropertyStrokeWidth:
185 return SVGLength::toCSSPrimitiveValue(svgStyle->strokeWidth());
186 case CSSPropertyBaselineShift: {
187 switch (svgStyle->baselineShift()) {
189 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
191 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
193 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
195 return SVGLength::toCSSPrimitiveValue(svgStyle->baselineShiftValue());
197 ASSERT_NOT_REACHED();
200 case CSSPropertyBufferedRendering:
201 return CSSPrimitiveValue::create(svgStyle->bufferedRendering());
202 case CSSPropertyGlyphOrientationHorizontal:
203 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
204 case CSSPropertyGlyphOrientationVertical: {
205 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
206 return value.release();
208 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
209 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
213 case CSSPropertyPaintOrder:
214 return paintOrderToCSSValueList(svgStyle->paintOrder());
215 case CSSPropertyVectorEffect:
216 return CSSPrimitiveValue::create(svgStyle->vectorEffect());
217 case CSSPropertyMaskType:
218 return CSSPrimitiveValue::create(svgStyle->maskType());
219 case CSSPropertyMarker:
220 case CSSPropertyEnableBackground:
221 case CSSPropertyColorProfile:
222 // the above properties are not yet implemented in the engine
225 // If you crash here, it's because you added a css property and are not handling it
226 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
227 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
229 LOG_ERROR("unimplemented propertyID: %d", propertyID);