|
1 /* |
|
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
|
3 2004, 2005 Rob Buis <buis@kde.org> |
|
4 Copyright (C) 2005, 2006 Apple Computer, Inc. |
|
5 Copyright (C) Research In Motion Limited 2010. All rights reserved. |
|
6 |
|
7 This library is free software; you can redistribute it and/or |
|
8 modify it under the terms of the GNU Library General Public |
|
9 License as published by the Free Software Foundation; either |
|
10 version 2 of the License, or (at your option) any later version. |
|
11 |
|
12 This library is distributed in the hope that it will be useful, |
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 Library General Public License for more details. |
|
16 |
|
17 You should have received a copy of the GNU Library General Public License |
|
18 along with this library; see the file COPYING.LIB. If not, write to |
|
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
20 Boston, MA 02110-1301, USA. |
|
21 */ |
|
22 |
|
23 #ifndef SVGRenderStyle_h |
|
24 #define SVGRenderStyle_h |
|
25 |
|
26 #if ENABLE(SVG) |
|
27 #include "CSSValueList.h" |
|
28 #include "DataRef.h" |
|
29 #include "GraphicsTypes.h" |
|
30 #include "Path.h" |
|
31 #include "RenderStyleConstants.h" |
|
32 #include "SVGPaint.h" |
|
33 #include "SVGRenderStyleDefs.h" |
|
34 |
|
35 namespace WebCore { |
|
36 |
|
37 class FloatRect; |
|
38 class IntRect; |
|
39 class RenderObject; |
|
40 |
|
41 class SVGRenderStyle : public RefCounted<SVGRenderStyle> { |
|
42 public: |
|
43 static PassRefPtr<SVGRenderStyle> create() { return adoptRef(new SVGRenderStyle); } |
|
44 PassRefPtr<SVGRenderStyle> copy() const { return adoptRef(new SVGRenderStyle(*this));} |
|
45 ~SVGRenderStyle(); |
|
46 |
|
47 bool inheritedNotEqual(const SVGRenderStyle*) const; |
|
48 void inheritFrom(const SVGRenderStyle*); |
|
49 |
|
50 // FIXME: These functions should move to ShadowData. |
|
51 void inflateForShadow(IntRect&) const; |
|
52 void inflateForShadow(FloatRect&) const; |
|
53 |
|
54 StyleDifference diff(const SVGRenderStyle*) const; |
|
55 |
|
56 bool operator==(const SVGRenderStyle&) const; |
|
57 bool operator!=(const SVGRenderStyle& o) const { return !(*this == o); } |
|
58 |
|
59 // SVG CSS Properties |
|
60 SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO) |
|
61 SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO) |
|
62 SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE) |
|
63 SVG_RS_DEFINE_ATTRIBUTE(EVectorEffect, VectorEffect, vectorEffect, VE_NONE) |
|
64 |
|
65 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap) |
|
66 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO) |
|
67 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB) |
|
68 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB) |
|
69 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO) |
|
70 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO) |
|
71 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO) |
|
72 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineJoin, JoinStyle, joinStyle, MiterJoin) |
|
73 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO) |
|
74 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START) |
|
75 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB) |
|
76 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationHorizontal, glyphOrientationHorizontal, GO_0DEG) |
|
77 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationVertical, glyphOrientationVertical, GO_AUTO) |
|
78 |
|
79 // SVG CSS Properties (using DataRef's) |
|
80 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0f) |
|
81 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, fill, paint, FillPaint, fillPaint, SVGPaint::defaultFill()) |
|
82 |
|
83 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0f) |
|
84 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, stroke, paint, StrokePaint, strokePaint, SVGPaint::defaultStroke()) |
|
85 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueList, stroke, dashArray, StrokeDashArray, strokeDashArray, 0) |
|
86 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4.0f) |
|
87 |
|
88 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, width, StrokeWidth, strokeWidth, 0) |
|
89 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, 0); |
|
90 |
|
91 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, text, kerning, Kerning, kerning, 0) |
|
92 |
|
93 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0f) |
|
94 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, stops, color, StopColor, stopColor, Color(0, 0, 0)) |
|
95 |
|
96 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0f) |
|
97 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, floodColor, FloodColor, floodColor, Color(0, 0, 0)) |
|
98 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, lightingColor, LightingColor, lightingColor, Color(255, 255, 255)) |
|
99 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, misc, baselineShiftValue, BaselineShiftValue, baselineShiftValue, 0) |
|
100 |
|
101 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_OWNPTR(ShadowData, shadowSVG, shadow, Shadow, shadow, 0) |
|
102 |
|
103 // Non-inherited resources |
|
104 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, resources, clipper, ClipperResource, clipperResource, String()) |
|
105 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, resources, filter, FilterResource, filterResource, String()) |
|
106 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, resources, masker, MaskerResource, maskerResource, String()) |
|
107 |
|
108 // Inherited resources |
|
109 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, inheritedResources, markerStart, MarkerStartResource, markerStartResource, String()) |
|
110 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, inheritedResources, markerMid, MarkerMidResource, markerMidResource, String()) |
|
111 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, inheritedResources, markerEnd, MarkerEndResource, markerEndResource, String()) |
|
112 |
|
113 // convenience |
|
114 bool hasClipper() const { return !clipperResource().isEmpty(); } |
|
115 bool hasMasker() const { return !maskerResource().isEmpty(); } |
|
116 bool hasFilter() const { return !filterResource().isEmpty(); } |
|
117 bool hasMarkers() const { return !markerStartResource().isEmpty() || !markerMidResource().isEmpty() || !markerEndResource().isEmpty(); } |
|
118 bool hasStroke() const { return strokePaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE; } |
|
119 bool hasFill() const { return fillPaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE; } |
|
120 |
|
121 static float cssPrimitiveToLength(const RenderObject*, CSSValue*, float defaultValue = 0.0f); |
|
122 |
|
123 protected: |
|
124 // inherit |
|
125 struct InheritedFlags { |
|
126 bool operator==(const InheritedFlags& other) const |
|
127 { |
|
128 return (_colorRendering == other._colorRendering) |
|
129 && (_imageRendering == other._imageRendering) |
|
130 && (_shapeRendering == other._shapeRendering) |
|
131 && (_clipRule == other._clipRule) |
|
132 && (_fillRule == other._fillRule) |
|
133 && (_capStyle == other._capStyle) |
|
134 && (_joinStyle == other._joinStyle) |
|
135 && (_textAnchor == other._textAnchor) |
|
136 && (_colorInterpolation == other._colorInterpolation) |
|
137 && (_colorInterpolationFilters == other._colorInterpolationFilters) |
|
138 && (_writingMode == other._writingMode) |
|
139 && (_glyphOrientationHorizontal == other._glyphOrientationHorizontal) |
|
140 && (_glyphOrientationVertical == other._glyphOrientationVertical); |
|
141 } |
|
142 |
|
143 bool operator!=(const InheritedFlags& other) const |
|
144 { |
|
145 return !(*this == other); |
|
146 } |
|
147 |
|
148 unsigned _colorRendering : 2; // EColorRendering |
|
149 unsigned _imageRendering : 2; // EImageRendering |
|
150 unsigned _shapeRendering : 2; // EShapeRendering |
|
151 unsigned _clipRule : 1; // WindRule |
|
152 unsigned _fillRule : 1; // WindRule |
|
153 unsigned _capStyle : 2; // LineCap |
|
154 unsigned _joinStyle : 2; // LineJoin |
|
155 unsigned _textAnchor : 2; // ETextAnchor |
|
156 unsigned _colorInterpolation : 2; // EColorInterpolation |
|
157 unsigned _colorInterpolationFilters : 2; // EColorInterpolation |
|
158 unsigned _writingMode : 3; // EWritingMode |
|
159 unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation |
|
160 unsigned _glyphOrientationVertical : 3; // EGlyphOrientation |
|
161 } svg_inherited_flags; |
|
162 |
|
163 // don't inherit |
|
164 struct NonInheritedFlags { |
|
165 // 32 bit non-inherited, don't add to the struct, or the operator will break. |
|
166 bool operator==(const NonInheritedFlags &other) const { return _niflags == other._niflags; } |
|
167 bool operator!=(const NonInheritedFlags &other) const { return _niflags != other._niflags; } |
|
168 |
|
169 union { |
|
170 struct { |
|
171 unsigned _alignmentBaseline : 4; // EAlignmentBaseline |
|
172 unsigned _dominantBaseline : 4; // EDominantBaseline |
|
173 unsigned _baselineShift : 2; // EBaselineShift |
|
174 unsigned _vectorEffect: 1; // EVectorEffect |
|
175 // 21 bits unused |
|
176 } f; |
|
177 uint32_t _niflags; |
|
178 }; |
|
179 } svg_noninherited_flags; |
|
180 |
|
181 // inherited attributes |
|
182 DataRef<StyleFillData> fill; |
|
183 DataRef<StyleStrokeData> stroke; |
|
184 DataRef<StyleTextData> text; |
|
185 DataRef<StyleInheritedResourceData> inheritedResources; |
|
186 |
|
187 // non-inherited attributes |
|
188 DataRef<StyleStopData> stops; |
|
189 DataRef<StyleMiscData> misc; |
|
190 DataRef<StyleShadowSVGData> shadowSVG; |
|
191 DataRef<StyleResourceData> resources; |
|
192 |
|
193 private: |
|
194 enum CreateDefaultType { CreateDefault }; |
|
195 |
|
196 SVGRenderStyle(); |
|
197 SVGRenderStyle(const SVGRenderStyle&); |
|
198 SVGRenderStyle(CreateDefaultType); // Used to create the default style. |
|
199 |
|
200 void setBitDefaults() |
|
201 { |
|
202 svg_inherited_flags._clipRule = initialClipRule(); |
|
203 svg_inherited_flags._colorRendering = initialColorRendering(); |
|
204 svg_inherited_flags._fillRule = initialFillRule(); |
|
205 svg_inherited_flags._imageRendering = initialImageRendering(); |
|
206 svg_inherited_flags._shapeRendering = initialShapeRendering(); |
|
207 svg_inherited_flags._textAnchor = initialTextAnchor(); |
|
208 svg_inherited_flags._capStyle = initialCapStyle(); |
|
209 svg_inherited_flags._joinStyle = initialJoinStyle(); |
|
210 svg_inherited_flags._colorInterpolation = initialColorInterpolation(); |
|
211 svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters(); |
|
212 svg_inherited_flags._writingMode = initialWritingMode(); |
|
213 svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal(); |
|
214 svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical(); |
|
215 |
|
216 svg_noninherited_flags._niflags = 0; |
|
217 svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline(); |
|
218 svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline(); |
|
219 svg_noninherited_flags.f._baselineShift = initialBaselineShift(); |
|
220 svg_noninherited_flags.f._vectorEffect = initialVectorEffect(); |
|
221 } |
|
222 }; |
|
223 |
|
224 } // namespace WebCore |
|
225 |
|
226 #endif // ENABLE(SVG) |
|
227 #endif // SVGRenderStyle_h |