1 | /*
|
---|
2 | Copyright (C) 2007 Eric Seidel <[email protected]>
|
---|
3 | Copyright (C) 2007 Alexey Proskuryakov <[email protected]>
|
---|
4 | Copyright (C) 2019 Apple Inc. All rights reserved.
|
---|
5 |
|
---|
6 | This library is free software; you can redistribute it and/or
|
---|
7 | modify it under the terms of the GNU Library General Public
|
---|
8 | License as published by the Free Software Foundation; either
|
---|
9 | version 2 of the License, or (at your option) any later version.
|
---|
10 |
|
---|
11 | This library is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | Library General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU Library General Public License
|
---|
17 | along with this library; see the file COPYING.LIB. If not, write to
|
---|
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
19 | Boston, MA 02110-1301, USA.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "config.h"
|
---|
23 | #include "CSSComputedStyleDeclaration.h"
|
---|
24 |
|
---|
25 | #include "CSSPrimitiveValueMappings.h"
|
---|
26 | #include "CSSPropertyNames.h"
|
---|
27 | #include "CSSValueList.h"
|
---|
28 | #include "Document.h"
|
---|
29 | #include "Element.h"
|
---|
30 | #include "RenderStyle.h"
|
---|
31 |
|
---|
32 | namespace WebCore {
|
---|
33 |
|
---|
34 | static RefPtr<CSSPrimitiveValue> glyphOrientationToCSSPrimitiveValue(GlyphOrientation orientation)
|
---|
35 | {
|
---|
36 | switch (orientation) {
|
---|
37 | case GlyphOrientation::Degrees0:
|
---|
38 | return CSSPrimitiveValue::create(0.0f, CSSUnitType::CSS_DEG);
|
---|
39 | case GlyphOrientation::Degrees90:
|
---|
40 | return CSSPrimitiveValue::create(90.0f, CSSUnitType::CSS_DEG);
|
---|
41 | case GlyphOrientation::Degrees180:
|
---|
42 | return CSSPrimitiveValue::create(180.0f, CSSUnitType::CSS_DEG);
|
---|
43 | case GlyphOrientation::Degrees270:
|
---|
44 | return CSSPrimitiveValue::create(270.0f, CSSUnitType::CSS_DEG);
|
---|
45 | case GlyphOrientation::Auto:
|
---|
46 | return nullptr;
|
---|
47 | }
|
---|
48 |
|
---|
49 | RELEASE_ASSERT_NOT_REACHED();
|
---|
50 | }
|
---|
51 |
|
---|
52 | static Ref<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLengthValue>& dashes)
|
---|
53 | {
|
---|
54 | if (dashes.isEmpty())
|
---|
55 | return CSSPrimitiveValue::createIdentifier(CSSValueNone);
|
---|
56 |
|
---|
57 | auto list = CSSValueList::createCommaSeparated();
|
---|
58 | for (auto& length : dashes)
|
---|
59 | list->append(SVGLengthValue::toCSSPrimitiveValue(length));
|
---|
60 |
|
---|
61 | return list;
|
---|
62 | }
|
---|
63 |
|
---|
64 | Ref<CSSValue> ComputedStyleExtractor::adjustSVGPaintForCurrentColor(SVGPaintType paintType, const String& url, const Color& color, const Color& currentColor) const
|
---|
65 | {
|
---|
66 | if (paintType >= SVGPaintType::URINone) {
|
---|
67 | auto values = CSSValueList::createSpaceSeparated();
|
---|
68 | values->append(CSSPrimitiveValue::create(url, CSSUnitType::CSS_URI));
|
---|
69 | if (paintType == SVGPaintType::URINone)
|
---|
70 | values->append(CSSPrimitiveValue::createIdentifier(CSSValueNone));
|
---|
71 | else if (paintType == SVGPaintType::URICurrentColor)
|
---|
72 | values->append(CSSPrimitiveValue::create(currentColor));
|
---|
73 | else if (paintType == SVGPaintType::URIRGBColor)
|
---|
74 | values->append(CSSPrimitiveValue::create(color));
|
---|
75 | return values;
|
---|
76 | }
|
---|
77 | if (paintType == SVGPaintType::None)
|
---|
78 | return CSSPrimitiveValue::createIdentifier(CSSValueNone);
|
---|
79 | if (paintType == SVGPaintType::CurrentColor)
|
---|
80 | return CSSPrimitiveValue::create(currentColor);
|
---|
81 |
|
---|
82 | return CSSPrimitiveValue::create(color);
|
---|
83 | }
|
---|
84 |
|
---|
85 | RefPtr<CSSValue> ComputedStyleExtractor::svgPropertyValue(CSSPropertyID propertyID)
|
---|
86 | {
|
---|
87 | if (!m_element)
|
---|
88 | return nullptr;
|
---|
89 |
|
---|
90 | auto* style = m_element->computedStyle();
|
---|
91 | if (!style)
|
---|
92 | return nullptr;
|
---|
93 |
|
---|
94 | const SVGRenderStyle& svgStyle = style->svgStyle();
|
---|
95 |
|
---|
96 | switch (propertyID) {
|
---|
97 | case CSSPropertyClipRule:
|
---|
98 | return CSSPrimitiveValue::create(svgStyle.clipRule());
|
---|
99 | case CSSPropertyFloodOpacity:
|
---|
100 | return CSSPrimitiveValue::create(svgStyle.floodOpacity(), CSSUnitType::CSS_NUMBER);
|
---|
101 | case CSSPropertyStopOpacity:
|
---|
102 | return CSSPrimitiveValue::create(svgStyle.stopOpacity(), CSSUnitType::CSS_NUMBER);
|
---|
103 | case CSSPropertyColorInterpolation:
|
---|
104 | return CSSPrimitiveValue::create(svgStyle.colorInterpolation());
|
---|
105 | case CSSPropertyColorInterpolationFilters:
|
---|
106 | return CSSPrimitiveValue::create(svgStyle.colorInterpolationFilters());
|
---|
107 | case CSSPropertyFillOpacity:
|
---|
108 | return CSSPrimitiveValue::create(svgStyle.fillOpacity(), CSSUnitType::CSS_NUMBER);
|
---|
109 | case CSSPropertyFillRule:
|
---|
110 | return CSSPrimitiveValue::create(svgStyle.fillRule());
|
---|
111 | case CSSPropertyShapeRendering:
|
---|
112 | return CSSPrimitiveValue::create(svgStyle.shapeRendering());
|
---|
113 | case CSSPropertyStrokeOpacity:
|
---|
114 | return CSSPrimitiveValue::create(svgStyle.strokeOpacity(), CSSUnitType::CSS_NUMBER);
|
---|
115 | case CSSPropertyAlignmentBaseline:
|
---|
116 | return CSSPrimitiveValue::create(svgStyle.alignmentBaseline());
|
---|
117 | case CSSPropertyDominantBaseline:
|
---|
118 | return CSSPrimitiveValue::create(svgStyle.dominantBaseline());
|
---|
119 | case CSSPropertyTextAnchor:
|
---|
120 | return CSSPrimitiveValue::create(svgStyle.textAnchor());
|
---|
121 | case CSSPropertyFloodColor:
|
---|
122 | return currentColorOrValidColor(style, svgStyle.floodColor());
|
---|
123 | case CSSPropertyLightingColor:
|
---|
124 | return currentColorOrValidColor(style, svgStyle.lightingColor());
|
---|
125 | case CSSPropertyStopColor:
|
---|
126 | return currentColorOrValidColor(style, svgStyle.stopColor());
|
---|
127 | case CSSPropertyFill:
|
---|
128 | return adjustSVGPaintForCurrentColor(svgStyle.fillPaintType(), svgStyle.fillPaintUri(), svgStyle.fillPaintColor(), style->color());
|
---|
129 | case CSSPropertyKerning:
|
---|
130 | return SVGLengthValue::toCSSPrimitiveValue(svgStyle.kerning());
|
---|
131 | case CSSPropertyMarkerEnd:
|
---|
132 | if (!svgStyle.markerEndResource().isEmpty())
|
---|
133 | return CSSPrimitiveValue::create(makeString('#', svgStyle.markerEndResource()), CSSUnitType::CSS_URI);
|
---|
134 | return CSSPrimitiveValue::createIdentifier(CSSValueNone);
|
---|
135 | case CSSPropertyMarkerMid:
|
---|
136 | if (!svgStyle.markerMidResource().isEmpty())
|
---|
137 | return CSSPrimitiveValue::create(makeString('#', svgStyle.markerMidResource()), CSSUnitType::CSS_URI);
|
---|
138 | return CSSPrimitiveValue::createIdentifier(CSSValueNone);
|
---|
139 | case CSSPropertyMarkerStart:
|
---|
140 | if (!svgStyle.markerStartResource().isEmpty())
|
---|
141 | return CSSPrimitiveValue::create(makeString('#', svgStyle.markerStartResource()), CSSUnitType::CSS_URI);
|
---|
142 | return CSSPrimitiveValue::createIdentifier(CSSValueNone);
|
---|
143 | case CSSPropertyStroke:
|
---|
144 | return adjustSVGPaintForCurrentColor(svgStyle.strokePaintType(), svgStyle.strokePaintUri(), svgStyle.strokePaintColor(), style->color());
|
---|
145 | case CSSPropertyStrokeDasharray:
|
---|
146 | return strokeDashArrayToCSSValueList(svgStyle.strokeDashArray());
|
---|
147 | case CSSPropertyBaselineShift: {
|
---|
148 | switch (svgStyle.baselineShift()) {
|
---|
149 | case BaselineShift::Baseline:
|
---|
150 | return CSSPrimitiveValue::createIdentifier(CSSValueBaseline);
|
---|
151 | case BaselineShift::Super:
|
---|
152 | return CSSPrimitiveValue::createIdentifier(CSSValueSuper);
|
---|
153 | case BaselineShift::Sub:
|
---|
154 | return CSSPrimitiveValue::createIdentifier(CSSValueSub);
|
---|
155 | case BaselineShift::Length:
|
---|
156 | return SVGLengthValue::toCSSPrimitiveValue(svgStyle.baselineShiftValue());
|
---|
157 | }
|
---|
158 | ASSERT_NOT_REACHED();
|
---|
159 | return nullptr;
|
---|
160 | }
|
---|
161 | case CSSPropertyBufferedRendering:
|
---|
162 | return CSSPrimitiveValue::create(svgStyle.bufferedRendering());
|
---|
163 | case CSSPropertyGlyphOrientationHorizontal:
|
---|
164 | return glyphOrientationToCSSPrimitiveValue(svgStyle.glyphOrientationHorizontal());
|
---|
165 | case CSSPropertyGlyphOrientationVertical: {
|
---|
166 | if (RefPtr<CSSPrimitiveValue> value = glyphOrientationToCSSPrimitiveValue(svgStyle.glyphOrientationVertical()))
|
---|
167 | return value;
|
---|
168 |
|
---|
169 | if (svgStyle.glyphOrientationVertical() == GlyphOrientation::Auto)
|
---|
170 | return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
|
---|
171 |
|
---|
172 | return nullptr;
|
---|
173 | }
|
---|
174 | case CSSPropertyVectorEffect:
|
---|
175 | return CSSPrimitiveValue::create(svgStyle.vectorEffect());
|
---|
176 | case CSSPropertyMaskType:
|
---|
177 | return CSSPrimitiveValue::create(svgStyle.maskType());
|
---|
178 | case CSSPropertyMarker:
|
---|
179 | // this property is not yet implemented in the engine
|
---|
180 | break;
|
---|
181 | default:
|
---|
182 | // If you crash here, it's because you added a css property and are not handling it
|
---|
183 | // in either this switch statement or the one in CSSComputedStyleDelcaration::getPropertyCSSValue
|
---|
184 | ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propertyID);
|
---|
185 | }
|
---|
186 | return nullptr;
|
---|
187 | }
|
---|
188 |
|
---|
189 | }
|
---|