OSDN Git Service

Merge commit 'remotes/korg/cupcake'
[android-x86/external-webkit.git] / WebCore / css / SVGCSSComputedStyleDeclaration.cpp
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
30 namespace WebCore {
31
32 static PassRefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(EGlyphOrientation orientation)
33 {
34     switch (orientation) {
35         case GO_0DEG:
36             return CSSPrimitiveValue::create(0.0f, CSSPrimitiveValue::CSS_DEG);
37         case GO_90DEG:
38             return CSSPrimitiveValue::create(90.0f, CSSPrimitiveValue::CSS_DEG);
39         case GO_180DEG:
40             return CSSPrimitiveValue::create(180.0f, CSSPrimitiveValue::CSS_DEG);
41         case GO_270DEG:
42             return CSSPrimitiveValue::create(270.0f, CSSPrimitiveValue::CSS_DEG);
43         default:
44             return 0;
45     }
46 }
47
48 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
49 {
50     Node* node = m_node.get();
51     if (!node)
52         return 0;
53     
54     // Make sure our layout is up to date before we allow a query on these attributes.
55     if (updateLayout)
56         node->document()->updateLayout();
57         
58     RenderStyle* style = node->computedStyle();
59     if (!style)
60         return 0;
61     
62     const SVGRenderStyle* svgStyle = style->svgStyle();
63     if (!svgStyle)
64         return 0;
65     
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()) {
151                 case BS_BASELINE:
152                     return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
153                 case BS_SUPER:
154                     return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
155                 case BS_SUB:
156                     return CSSPrimitiveValue::createIdentifier(CSSValueSub);
157                 case BS_LENGTH:
158                     return svgStyle->baselineShiftValue();
159             }
160         }
161         case CSSPropertyGlyphOrientationHorizontal:
162             return glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationHorizontal());
163         case CSSPropertyGlyphOrientationVertical: {
164             if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle->glyphOrientationVertical()))
165                 return value.release();
166
167             if (svgStyle->glyphOrientationVertical() == GO_AUTO)
168                 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
169
170             return 0;
171         }
172         case CSSPropertyMarker:
173         case CSSPropertyEnableBackground:
174         case CSSPropertyColorProfile:
175             // the above properties are not yet implemented in the engine
176             break;
177     default:
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);
181     }
182     LOG_ERROR("unimplemented propertyID: %d", propertyID);
183     return 0;
184 }
185
186 }
187
188 #endif // ENABLE(SVG)
189
190 // vim:ts=4:noet