1 /*
2 Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
4
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.
9
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.
14
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.
19 */
20
21 #include "config.h"
22
23 #if ENABLE(SVG)
24 #include "CSSComputedStyleDeclaration.h"
25
26 #include "CSSPrimitiveValueMappings.h"
27 #include "CSSPropertyNames.h"
28 #include "Document.h"
29 #include "RenderStyle.h"
30
31 namespace WebCore {
32
glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)33 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
34 {
35 switch (orientation) {
36 case GO_0DEG:
37 return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
38 case GO_90DEG:
39 return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
40 case GO_180DEG:
41 return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
42 case GO_270DEG:
43 return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
44 default:
45 return 0;
46 }
47 }
48
getSVGPropertyCSSValue(int propertyID,EUpdateLayout updateLayout) const49 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
50 {
51 Node* node = m_node.get();
52 if (!node)
53 return 0;
54
55 // Make sure our layout is up to date before we allow a query on these attributes.
56 if (updateLayout)
57 node->document()->updateLayout();
58
59 RenderStyle* style = node->computedStyle();
60 if (!style)
61 return 0;
62
63 const SVGRenderStyle* svgStyle = style->svgStyle();
64 if (!svgStyle)
65 return 0;
66
67 switch (static_cast<CSSPropertyID>(propertyID)) {
68 case CSSPropertyClipRule:
69 return CSSPrimitiveValue::create(svgStyle->clipRule());
70 case CSSPropertyFloodOpacity:
71 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
72 case CSSPropertyStopOpacity:
73 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
74 case CSSPropertyColorInterpolation:
75 return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
76 case CSSPropertyColorInterpolationFilters:
77 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
78 case CSSPropertyFillOpacity:
79 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
80 case CSSPropertyFillRule:
81 return CSSPrimitiveValue::create(svgStyle->fillRule());
82 case CSSPropertyColorRendering:
83 return CSSPrimitiveValue::create(svgStyle->colorRendering());
84 case CSSPropertyImageRendering:
85 return CSSPrimitiveValue::create(svgStyle->imageRendering());
86 case CSSPropertyShapeRendering:
87 return CSSPrimitiveValue::create(svgStyle->shapeRendering());
88 case CSSPropertyStrokeLinecap:
89 return CSSPrimitiveValue::create(svgStyle->capStyle());
90 case CSSPropertyStrokeLinejoin:
91 return CSSPrimitiveValue::create(svgStyle->joinStyle());
92 case CSSPropertyStrokeMiterlimit:
93 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
94 case CSSPropertyStrokeOpacity:
95 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
96 case CSSPropertyTextRendering:
97 return CSSPrimitiveValue::create(svgStyle->textRendering());
98 case CSSPropertyAlignmentBaseline:
99 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
100 case CSSPropertyDominantBaseline:
101 return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
102 case CSSPropertyTextAnchor:
103 return CSSPrimitiveValue::create(svgStyle->textAnchor());
104 case CSSPropertyWritingMode:
105 return CSSPrimitiveValue::create(svgStyle->writingMode());
106 case CSSPropertyClipPath:
107 if (!svgStyle->clipPath().isEmpty())
108 return CSSPrimitiveValue::create(svgStyle->clipPath(), CSSPrimitiveValue::CSS_URI);
109 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
110 case CSSPropertyMask:
111 if (!svgStyle->maskElement().isEmpty())
112 return CSSPrimitiveValue::create(svgStyle->maskElement(), CSSPrimitiveValue::CSS_URI);
113 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
114 case CSSPropertyFilter:
115 if (!svgStyle->filter().isEmpty())
116 return CSSPrimitiveValue::create(svgStyle->filter(), CSSPrimitiveValue::CSS_URI);
117 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
118 case CSSPropertyFloodColor:
119 return CSSPrimitiveValue::createColor(svgStyle->floodColor().rgb());
120 case CSSPropertyLightingColor:
121 return CSSPrimitiveValue::createColor(svgStyle->lightingColor().rgb());
122 case CSSPropertyStopColor:
123 return CSSPrimitiveValue::createColor(svgStyle->stopColor().rgb());
124 case CSSPropertyFill:
125 return svgStyle->fillPaint();
126 case CSSPropertyKerning:
127 return svgStyle->kerning();
128 case CSSPropertyMarkerEnd:
129 if (!svgStyle->endMarker().isEmpty())
130 return CSSPrimitiveValue::create(svgStyle->endMarker(), CSSPrimitiveValue::CSS_URI);
131 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
132 case CSSPropertyMarkerMid:
133 if (!svgStyle->midMarker().isEmpty())
134 return CSSPrimitiveValue::create(svgStyle->midMarker(), CSSPrimitiveValue::CSS_URI);
135 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
136 case CSSPropertyMarkerStart:
137 if (!svgStyle->startMarker().isEmpty())
138 return CSSPrimitiveValue::create(svgStyle->startMarker(), CSSPrimitiveValue::CSS_URI);
139 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
140 case CSSPropertyStroke:
141 return svgStyle->strokePaint();
142 case CSSPropertyStrokeDasharray:
143 return svgStyle->strokeDashArray();
144 case CSSPropertyStrokeDashoffset:
145 return svgStyle->strokeDashOffset();
146 case CSSPropertyStrokeWidth:
147 return svgStyle->strokeWidth();
148 case CSSPropertyBaselineShift: {
149 switch (svgStyle->baselineShift()) {
150 case BS_BASELINE:
151 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
152 case BS_SUPER:
153 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
154 case BS_SUB:
155 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
156 case BS_LENGTH:
157 return svgStyle->baselineShiftValue();
158 }
159 }
160 case CSSPropertyGlyphOrientationHorizontal:
161 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
162 case CSSPropertyGlyphOrientationVertical: {
163 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
164 return value.release();
165
166 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
167 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
168
169 return 0;
170 }
171 case CSSPropertyMarker:
172 case CSSPropertyEnableBackground:
173 case CSSPropertyColorProfile:
174 // the above properties are not yet implemented in the engine
175 break;
176 default:
177 // If you crash here, it's because you added a css property and are not handling it
178 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
179 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
180 }
181 LOG_ERROR("unimplemented propertyID: %d", propertyID);
182 return 0;
183 }
184
185 }
186
187 #endif // ENABLE(SVG)
188
189 // vim:ts=4:noet
190