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.
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.
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.
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.
23 #ifndef SVGRenderStyle_h
24 #define SVGRenderStyle_h
27 #include "CSSValueList.h"
29 #include "GraphicsTypes.h"
31 #include "RenderStyleConstants.h"
33 #include "SVGRenderStyleDefs.h"
41 class SVGRenderStyle : public RefCounted<SVGRenderStyle> {
43 static PassRefPtr<SVGRenderStyle> create() { return adoptRef(new SVGRenderStyle); }
44 PassRefPtr<SVGRenderStyle> copy() const { return adoptRef(new SVGRenderStyle(*this));}
47 bool inheritedNotEqual(const SVGRenderStyle*) const;
48 void inheritFrom(const SVGRenderStyle*);
49 void copyNonInheritedFrom(const SVGRenderStyle*);
51 StyleDifference diff(const SVGRenderStyle*) const;
53 bool operator==(const SVGRenderStyle&) const;
54 bool operator!=(const SVGRenderStyle& o) const { return !(*this == o); }
56 // Initial values for all the properties
57 static EAlignmentBaseline initialAlignmentBaseline() { return AB_AUTO; }
58 static EDominantBaseline initialDominantBaseline() { return DB_AUTO; }
59 static EBaselineShift initialBaselineShift() { return BS_BASELINE; }
60 static EVectorEffect initialVectorEffect() { return VE_NONE; }
61 static LineCap initialCapStyle() { return ButtCap; }
62 static WindRule initialClipRule() { return RULE_NONZERO; }
63 static EColorInterpolation initialColorInterpolation() { return CI_SRGB; }
64 static EColorInterpolation initialColorInterpolationFilters() { return CI_LINEARRGB; }
65 static EColorRendering initialColorRendering() { return CR_AUTO; }
66 static WindRule initialFillRule() { return RULE_NONZERO; }
67 static LineJoin initialJoinStyle() { return MiterJoin; }
68 static EShapeRendering initialShapeRendering() { return SR_AUTO; }
69 static ETextAnchor initialTextAnchor() { return TA_START; }
70 static SVGWritingMode initialWritingMode() { return WM_LRTB; }
71 static EGlyphOrientation initialGlyphOrientationHorizontal() { return GO_0DEG; }
72 static EGlyphOrientation initialGlyphOrientationVertical() { return GO_AUTO; }
73 static float initialFillOpacity() { return 1; }
74 static SVGPaint::SVGPaintType initialFillPaintType() { return SVGPaint::SVG_PAINTTYPE_RGBCOLOR; }
75 static Color initialFillPaintColor() { return Color::black; }
76 static String initialFillPaintUri() { return String(); }
77 static float initialStrokeOpacity() { return 1; }
78 static SVGPaint::SVGPaintType initialStrokePaintType() { return SVGPaint::SVG_PAINTTYPE_NONE; }
79 static Color initialStrokePaintColor() { return Color(); }
80 static String initialStrokePaintUri() { return String(); }
81 static Vector<SVGLength> initialStrokeDashArray() { return Vector<SVGLength>(); }
82 static float initialStrokeMiterLimit() { return 4; }
83 static float initialStopOpacity() { return 1; }
84 static Color initialStopColor() { return Color(0, 0, 0); }
85 static float initialFloodOpacity() { return 1; }
86 static Color initialFloodColor() { return Color(0, 0, 0); }
87 static Color initialLightingColor() { return Color(255, 255, 255); }
88 static ShadowData* initialShadow() { return 0; }
89 static String initialClipperResource() { return String(); }
90 static String initialFilterResource() { return String(); }
91 static String initialMaskerResource() { return String(); }
92 static String initialMarkerStartResource() { return String(); }
93 static String initialMarkerMidResource() { return String(); }
94 static String initialMarkerEndResource() { return String(); }
96 static SVGLength initialBaselineShiftValue()
100 length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
105 static SVGLength initialKerning()
108 ExceptionCode ec = 0;
109 length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
114 static SVGLength initialStrokeDashOffset()
117 ExceptionCode ec = 0;
118 length.newValueSpecifiedUnits(LengthTypeNumber, 0, ec);
123 static SVGLength initialStrokeWidth()
126 ExceptionCode ec = 0;
127 length.newValueSpecifiedUnits(LengthTypeNumber, 1, ec);
132 // SVG CSS Property setters
133 void setAlignmentBaseline(EAlignmentBaseline val) { svg_noninherited_flags.f._alignmentBaseline = val; }
134 void setDominantBaseline(EDominantBaseline val) { svg_noninherited_flags.f._dominantBaseline = val; }
135 void setBaselineShift(EBaselineShift val) { svg_noninherited_flags.f._baselineShift = val; }
136 void setVectorEffect(EVectorEffect val) { svg_noninherited_flags.f._vectorEffect = val; }
137 void setCapStyle(LineCap val) { svg_inherited_flags._capStyle = val; }
138 void setClipRule(WindRule val) { svg_inherited_flags._clipRule = val; }
139 void setColorInterpolation(EColorInterpolation val) { svg_inherited_flags._colorInterpolation = val; }
140 void setColorInterpolationFilters(EColorInterpolation val) { svg_inherited_flags._colorInterpolationFilters = val; }
141 void setColorRendering(EColorRendering val) { svg_inherited_flags._colorRendering = val; }
142 void setFillRule(WindRule val) { svg_inherited_flags._fillRule = val; }
143 void setJoinStyle(LineJoin val) { svg_inherited_flags._joinStyle = val; }
144 void setShapeRendering(EShapeRendering val) { svg_inherited_flags._shapeRendering = val; }
145 void setTextAnchor(ETextAnchor val) { svg_inherited_flags._textAnchor = val; }
146 void setWritingMode(SVGWritingMode val) { svg_inherited_flags._writingMode = val; }
147 void setGlyphOrientationHorizontal(EGlyphOrientation val) { svg_inherited_flags._glyphOrientationHorizontal = val; }
148 void setGlyphOrientationVertical(EGlyphOrientation val) { svg_inherited_flags._glyphOrientationVertical = val; }
150 void setFillOpacity(float obj)
152 if (!(fill->opacity == obj))
153 fill.access()->opacity = obj;
156 void setFillPaint(SVGPaint::SVGPaintType type, const Color& color, const String& uri, bool applyToRegularStyle = true, bool applyToVisitedLinkStyle = false)
158 if (applyToRegularStyle) {
159 if (!(fill->paintType == type))
160 fill.access()->paintType = type;
161 if (!(fill->paintColor == color))
162 fill.access()->paintColor = color;
163 if (!(fill->paintUri == uri))
164 fill.access()->paintUri = uri;
166 if (applyToVisitedLinkStyle) {
167 if (!(fill->visitedLinkPaintType == type))
168 fill.access()->visitedLinkPaintType = type;
169 if (!(fill->visitedLinkPaintColor == color))
170 fill.access()->visitedLinkPaintColor = color;
171 if (!(fill->visitedLinkPaintUri == uri))
172 fill.access()->visitedLinkPaintUri = uri;
176 void setStrokeOpacity(float obj)
178 if (!(stroke->opacity == obj))
179 stroke.access()->opacity = obj;
182 void setStrokePaint(SVGPaint::SVGPaintType type, const Color& color, const String& uri, bool applyToRegularStyle = true, bool applyToVisitedLinkStyle = false)
184 if (applyToRegularStyle) {
185 if (!(stroke->paintType == type))
186 stroke.access()->paintType = type;
187 if (!(stroke->paintColor == color))
188 stroke.access()->paintColor = color;
189 if (!(stroke->paintUri == uri))
190 stroke.access()->paintUri = uri;
192 if (applyToVisitedLinkStyle) {
193 if (!(stroke->visitedLinkPaintType == type))
194 stroke.access()->visitedLinkPaintType = type;
195 if (!(stroke->visitedLinkPaintColor == color))
196 stroke.access()->visitedLinkPaintColor = color;
197 if (!(stroke->visitedLinkPaintUri == uri))
198 stroke.access()->visitedLinkPaintUri = uri;
202 void setStrokeDashArray(const Vector<SVGLength>& obj)
204 if (!(stroke->dashArray == obj))
205 stroke.access()->dashArray = obj;
208 void setStrokeMiterLimit(float obj)
210 if (!(stroke->miterLimit == obj))
211 stroke.access()->miterLimit = obj;
214 void setStrokeWidth(const SVGLength& obj)
216 if (!(stroke->width == obj))
217 stroke.access()->width = obj;
220 void setStrokeDashOffset(const SVGLength& obj)
222 if (!(stroke->dashOffset == obj))
223 stroke.access()->dashOffset = obj;
226 void setKerning(const SVGLength& obj)
228 if (!(text->kerning == obj))
229 text.access()->kerning = obj;
232 void setStopOpacity(float obj)
234 if (!(stops->opacity == obj))
235 stops.access()->opacity = obj;
238 void setStopColor(const Color& obj)
240 if (!(stops->color == obj))
241 stops.access()->color = obj;
244 void setFloodOpacity(float obj)
246 if (!(misc->floodOpacity == obj))
247 misc.access()->floodOpacity = obj;
250 void setFloodColor(const Color& obj)
252 if (!(misc->floodColor == obj))
253 misc.access()->floodColor = obj;
256 void setLightingColor(const Color& obj)
258 if (!(misc->lightingColor == obj))
259 misc.access()->lightingColor = obj;
262 void setBaselineShiftValue(const SVGLength& obj)
264 if (!(misc->baselineShiftValue == obj))
265 misc.access()->baselineShiftValue = obj;
268 void setShadow(PassOwnPtr<ShadowData> obj) { shadowSVG.access()->shadow = obj; }
270 // Setters for non-inherited resources
271 void setClipperResource(const String& obj)
273 if (!(resources->clipper == obj))
274 resources.access()->clipper = obj;
277 void setFilterResource(const String& obj)
279 if (!(resources->filter == obj))
280 resources.access()->filter = obj;
283 void setMaskerResource(const String& obj)
285 if (!(resources->masker == obj))
286 resources.access()->masker = obj;
289 // Setters for inherited resources
290 void setMarkerStartResource(const String& obj)
292 if (!(inheritedResources->markerStart == obj))
293 inheritedResources.access()->markerStart = obj;
296 void setMarkerMidResource(const String& obj)
298 if (!(inheritedResources->markerMid == obj))
299 inheritedResources.access()->markerMid = obj;
302 void setMarkerEndResource(const String& obj)
304 if (!(inheritedResources->markerEnd == obj))
305 inheritedResources.access()->markerEnd = obj;
308 // Read accessors for all the properties
309 EAlignmentBaseline alignmentBaseline() const { return (EAlignmentBaseline) svg_noninherited_flags.f._alignmentBaseline; }
310 EDominantBaseline dominantBaseline() const { return (EDominantBaseline) svg_noninherited_flags.f._dominantBaseline; }
311 EBaselineShift baselineShift() const { return (EBaselineShift) svg_noninherited_flags.f._baselineShift; }
312 EVectorEffect vectorEffect() const { return (EVectorEffect) svg_noninherited_flags.f._vectorEffect; }
313 LineCap capStyle() const { return (LineCap) svg_inherited_flags._capStyle; }
314 WindRule clipRule() const { return (WindRule) svg_inherited_flags._clipRule; }
315 EColorInterpolation colorInterpolation() const { return (EColorInterpolation) svg_inherited_flags._colorInterpolation; }
316 EColorInterpolation colorInterpolationFilters() const { return (EColorInterpolation) svg_inherited_flags._colorInterpolationFilters; }
317 EColorRendering colorRendering() const { return (EColorRendering) svg_inherited_flags._colorRendering; }
318 WindRule fillRule() const { return (WindRule) svg_inherited_flags._fillRule; }
319 LineJoin joinStyle() const { return (LineJoin) svg_inherited_flags._joinStyle; }
320 EShapeRendering shapeRendering() const { return (EShapeRendering) svg_inherited_flags._shapeRendering; }
321 ETextAnchor textAnchor() const { return (ETextAnchor) svg_inherited_flags._textAnchor; }
322 SVGWritingMode writingMode() const { return (SVGWritingMode) svg_inherited_flags._writingMode; }
323 EGlyphOrientation glyphOrientationHorizontal() const { return (EGlyphOrientation) svg_inherited_flags._glyphOrientationHorizontal; }
324 EGlyphOrientation glyphOrientationVertical() const { return (EGlyphOrientation) svg_inherited_flags._glyphOrientationVertical; }
325 float fillOpacity() const { return fill->opacity; }
326 const SVGPaint::SVGPaintType& fillPaintType() const { return fill->paintType; }
327 const Color& fillPaintColor() const { return fill->paintColor; }
328 const String& fillPaintUri() const { return fill->paintUri; }
329 float strokeOpacity() const { return stroke->opacity; }
330 const SVGPaint::SVGPaintType& strokePaintType() const { return stroke->paintType; }
331 const Color& strokePaintColor() const { return stroke->paintColor; }
332 const String& strokePaintUri() const { return stroke->paintUri; }
333 Vector<SVGLength> strokeDashArray() const { return stroke->dashArray; }
334 float strokeMiterLimit() const { return stroke->miterLimit; }
335 SVGLength strokeWidth() const { return stroke->width; }
336 SVGLength strokeDashOffset() const { return stroke->dashOffset; }
337 SVGLength kerning() const { return text->kerning; }
338 float stopOpacity() const { return stops->opacity; }
339 const Color& stopColor() const { return stops->color; }
340 float floodOpacity() const { return misc->floodOpacity; }
341 const Color& floodColor() const { return misc->floodColor; }
342 const Color& lightingColor() const { return misc->lightingColor; }
343 SVGLength baselineShiftValue() const { return misc->baselineShiftValue; }
344 ShadowData* shadow() const { return shadowSVG->shadow.get(); }
345 String clipperResource() const { return resources->clipper; }
346 String filterResource() const { return resources->filter; }
347 String maskerResource() const { return resources->masker; }
348 String markerStartResource() const { return inheritedResources->markerStart; }
349 String markerMidResource() const { return inheritedResources->markerMid; }
350 String markerEndResource() const { return inheritedResources->markerEnd; }
352 const SVGPaint::SVGPaintType& visitedLinkFillPaintType() const { return fill->visitedLinkPaintType; }
353 const Color& visitedLinkFillPaintColor() const { return fill->visitedLinkPaintColor; }
354 const String& visitedLinkFillPaintUri() const { return fill->visitedLinkPaintUri; }
355 const SVGPaint::SVGPaintType& visitedLinkStrokePaintType() const { return stroke->visitedLinkPaintType; }
356 const Color& visitedLinkStrokePaintColor() const { return stroke->visitedLinkPaintColor; }
357 const String& visitedLinkStrokePaintUri() const { return stroke->visitedLinkPaintUri; }
360 bool hasClipper() const { return !clipperResource().isEmpty(); }
361 bool hasMasker() const { return !maskerResource().isEmpty(); }
362 bool hasFilter() const { return !filterResource().isEmpty(); }
363 bool hasMarkers() const { return !markerStartResource().isEmpty() || !markerMidResource().isEmpty() || !markerEndResource().isEmpty(); }
364 bool hasStroke() const { return strokePaintType() != SVGPaint::SVG_PAINTTYPE_NONE; }
365 bool hasFill() const { return fillPaintType() != SVGPaint::SVG_PAINTTYPE_NONE; }
366 bool isVerticalWritingMode() const { return writingMode() == WM_TBRL || writingMode() == WM_TB; }
370 struct InheritedFlags {
371 bool operator==(const InheritedFlags& other) const
373 return (_colorRendering == other._colorRendering)
374 && (_shapeRendering == other._shapeRendering)
375 && (_clipRule == other._clipRule)
376 && (_fillRule == other._fillRule)
377 && (_capStyle == other._capStyle)
378 && (_joinStyle == other._joinStyle)
379 && (_textAnchor == other._textAnchor)
380 && (_colorInterpolation == other._colorInterpolation)
381 && (_colorInterpolationFilters == other._colorInterpolationFilters)
382 && (_writingMode == other._writingMode)
383 && (_glyphOrientationHorizontal == other._glyphOrientationHorizontal)
384 && (_glyphOrientationVertical == other._glyphOrientationVertical);
387 bool operator!=(const InheritedFlags& other) const
389 return !(*this == other);
392 unsigned _colorRendering : 2; // EColorRendering
393 unsigned _shapeRendering : 2; // EShapeRendering
394 unsigned _clipRule : 1; // WindRule
395 unsigned _fillRule : 1; // WindRule
396 unsigned _capStyle : 2; // LineCap
397 unsigned _joinStyle : 2; // LineJoin
398 unsigned _textAnchor : 2; // ETextAnchor
399 unsigned _colorInterpolation : 2; // EColorInterpolation
400 unsigned _colorInterpolationFilters : 2; // EColorInterpolation
401 unsigned _writingMode : 3; // SVGWritingMode
402 unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation
403 unsigned _glyphOrientationVertical : 3; // EGlyphOrientation
404 } svg_inherited_flags;
407 struct NonInheritedFlags {
408 // 32 bit non-inherited, don't add to the struct, or the operator will break.
409 bool operator==(const NonInheritedFlags &other) const { return _niflags == other._niflags; }
410 bool operator!=(const NonInheritedFlags &other) const { return _niflags != other._niflags; }
414 unsigned _alignmentBaseline : 4; // EAlignmentBaseline
415 unsigned _dominantBaseline : 4; // EDominantBaseline
416 unsigned _baselineShift : 2; // EBaselineShift
417 unsigned _vectorEffect: 1; // EVectorEffect
422 } svg_noninherited_flags;
424 // inherited attributes
425 DataRef<StyleFillData> fill;
426 DataRef<StyleStrokeData> stroke;
427 DataRef<StyleTextData> text;
428 DataRef<StyleInheritedResourceData> inheritedResources;
430 // non-inherited attributes
431 DataRef<StyleStopData> stops;
432 DataRef<StyleMiscData> misc;
433 DataRef<StyleShadowSVGData> shadowSVG;
434 DataRef<StyleResourceData> resources;
437 enum CreateDefaultType { CreateDefault };
440 SVGRenderStyle(const SVGRenderStyle&);
441 SVGRenderStyle(CreateDefaultType); // Used to create the default style.
443 void setBitDefaults()
445 svg_inherited_flags._clipRule = initialClipRule();
446 svg_inherited_flags._colorRendering = initialColorRendering();
447 svg_inherited_flags._fillRule = initialFillRule();
448 svg_inherited_flags._shapeRendering = initialShapeRendering();
449 svg_inherited_flags._textAnchor = initialTextAnchor();
450 svg_inherited_flags._capStyle = initialCapStyle();
451 svg_inherited_flags._joinStyle = initialJoinStyle();
452 svg_inherited_flags._colorInterpolation = initialColorInterpolation();
453 svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters();
454 svg_inherited_flags._writingMode = initialWritingMode();
455 svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal();
456 svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical();
458 svg_noninherited_flags._niflags = 0;
459 svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline();
460 svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
461 svg_noninherited_flags.f._baselineShift = initialBaselineShift();
462 svg_noninherited_flags.f._vectorEffect = initialVectorEffect();
466 } // namespace WebCore
468 #endif // ENABLE(SVG)
469 #endif // SVGRenderStyle_h