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 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
51 Node* node = m_node.get();
55 // Make sure our layout is up to date before we allow a query on these attributes.
57 node->document()->updateLayout();
59 RenderStyle* style = node->computedStyle();
63 const SVGRenderStyle* svgStyle = style->svgStyle();
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()) {
151 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
153 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
155 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
157 return svgStyle->baselineShiftValue();
160 case CSSPropertyGlyphOrientationHorizontal:
161 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
162 case CSSPropertyGlyphOrientationVertical: {
163 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
164 return value.release();
166 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
167 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
171 case CSSPropertyMarker:
172 case CSSPropertyEnableBackground:
173 case CSSPropertyColorProfile:
174 // the above properties are not yet implemented in the engine
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);
181 LOG_ERROR("unimplemented propertyID: %d", propertyID);
187 #endif // ENABLE(SVG)