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"
32 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
34 switch (orientation) {
36 return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
38 return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
40 return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
42 return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
48 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
50 Node* node = m_node.get();
54 // Make sure our layout is up to date before we allow a query on these attributes.
56 node->document()->updateLayout();
58 RenderStyle* style = node->computedStyle();
62 const SVGRenderStyle* svgStyle = style->svgStyle();
66 switch (static_cast<CSSPropertyID>(propertyID)) {
67 case CSSPropertyClipRule:
68 return CSSPrimitiveValue::create(svgStyle->clipRule());
69 case CSSPropertyFloodOpacity:
70 return CSSPrimitiveValue::create(svgStyle->floodOpacity(), CSSPrimitiveValue::CSS_NUMBER);
71 case CSSPropertyStopOpacity:
72 return CSSPrimitiveValue::create(svgStyle->stopOpacity(), CSSPrimitiveValue::CSS_NUMBER);
73 case CSSPropertyPointerEvents:
74 return CSSPrimitiveValue::create(svgStyle->pointerEvents());
75 case CSSPropertyColorInterpolation:
76 return CSSPrimitiveValue::create(svgStyle->colorInterpolation());
77 case CSSPropertyColorInterpolationFilters:
78 return CSSPrimitiveValue::create(svgStyle->colorInterpolationFilters());
79 case CSSPropertyFillOpacity:
80 return CSSPrimitiveValue::create(svgStyle->fillOpacity(), CSSPrimitiveValue::CSS_NUMBER);
81 case CSSPropertyFillRule:
82 return CSSPrimitiveValue::create(svgStyle->fillRule());
83 case CSSPropertyColorRendering:
84 return CSSPrimitiveValue::create(svgStyle->colorRendering());
85 case CSSPropertyImageRendering:
86 return CSSPrimitiveValue::create(svgStyle->imageRendering());
87 case CSSPropertyShapeRendering:
88 return CSSPrimitiveValue::create(svgStyle->shapeRendering());
89 case CSSPropertyStrokeLinecap:
90 return CSSPrimitiveValue::create(svgStyle->capStyle());
91 case CSSPropertyStrokeLinejoin:
92 return CSSPrimitiveValue::create(svgStyle->joinStyle());
93 case CSSPropertyStrokeMiterlimit:
94 return CSSPrimitiveValue::create(svgStyle->strokeMiterLimit(), CSSPrimitiveValue::CSS_NUMBER);
95 case CSSPropertyStrokeOpacity:
96 return CSSPrimitiveValue::create(svgStyle->strokeOpacity(), CSSPrimitiveValue::CSS_NUMBER);
97 case CSSPropertyTextRendering:
98 return CSSPrimitiveValue::create(svgStyle->textRendering());
99 case CSSPropertyAlignmentBaseline:
100 return CSSPrimitiveValue::create(svgStyle->alignmentBaseline());
101 case CSSPropertyDominantBaseline:
102 return CSSPrimitiveValue::create(svgStyle->dominantBaseline());
103 case CSSPropertyTextAnchor:
104 return CSSPrimitiveValue::create(svgStyle->textAnchor());
105 case CSSPropertyWritingMode:
106 return CSSPrimitiveValue::create(svgStyle->writingMode());
107 case CSSPropertyClipPath:
108 if (!svgStyle->clipPath().isEmpty())
109 return CSSPrimitiveValue::create(svgStyle->clipPath(), CSSPrimitiveValue::CSS_URI);
110 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
111 case CSSPropertyMask:
112 if (!svgStyle->maskElement().isEmpty())
113 return CSSPrimitiveValue::create(svgStyle->maskElement(), CSSPrimitiveValue::CSS_URI);
114 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
115 case CSSPropertyFilter:
116 if (!svgStyle->filter().isEmpty())
117 return CSSPrimitiveValue::create(svgStyle->filter(), CSSPrimitiveValue::CSS_URI);
118 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
119 case CSSPropertyFloodColor:
120 return CSSPrimitiveValue::createColor(svgStyle->floodColor().rgb());
121 case CSSPropertyLightingColor:
122 return CSSPrimitiveValue::createColor(svgStyle->lightingColor().rgb());
123 case CSSPropertyStopColor:
124 return CSSPrimitiveValue::createColor(svgStyle->stopColor().rgb());
125 case CSSPropertyFill:
126 return svgStyle->fillPaint();
127 case CSSPropertyKerning:
128 return svgStyle->kerning();
129 case CSSPropertyMarkerEnd:
130 if (!svgStyle->endMarker().isEmpty())
131 return CSSPrimitiveValue::create(svgStyle->endMarker(), CSSPrimitiveValue::CSS_URI);
132 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
133 case CSSPropertyMarkerMid:
134 if (!svgStyle->midMarker().isEmpty())
135 return CSSPrimitiveValue::create(svgStyle->midMarker(), CSSPrimitiveValue::CSS_URI);
136 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
137 case CSSPropertyMarkerStart:
138 if (!svgStyle->startMarker().isEmpty())
139 return CSSPrimitiveValue::create(svgStyle->startMarker(), CSSPrimitiveValue::CSS_URI);
140 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
141 case CSSPropertyStroke:
142 return svgStyle->strokePaint();
143 case CSSPropertyStrokeDasharray:
144 return svgStyle->strokeDashArray();
145 case CSSPropertyStrokeDashoffset:
146 return svgStyle->strokeDashOffset();
147 case CSSPropertyStrokeWidth:
148 return svgStyle->strokeWidth();
149 case CSSPropertyBaselineShift: {
150 switch (svgStyle->baselineShift()) {
152 return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
154 return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
156 return CSSPrimitiveValue::createIdentifier(CSSValueSub);
158 return svgStyle->baselineShiftValue();
161 case CSSPropertyGlyphOrientationHorizontal:
162 return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
163 case CSSPropertyGlyphOrientationVertical: {
164 if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
165 return value.release();
167 if (svgStyle->glyphOrientationVertical() == GO_AUTO)
168 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
172 case CSSPropertyMarker:
173 case CSSPropertyEnableBackground:
174 case CSSPropertyColorProfile:
175 // the above properties are not yet implemented in the engine
178 // If you crash here, it's because you added a css property and are not handling it
179 // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
180 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
182 LOG_ERROR("unimplemented propertyID: %d", propertyID);
188 #endif // ENABLE(SVG)