2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / rendering / style / SVGRenderStyle.h
blob57246218383e1ad15fdff393c012a54c7b8772fe
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.
6 This file is part of the KDE project
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 #ifndef SVGRenderStyle_h
25 #define SVGRenderStyle_h
27 #if ENABLE(SVG)
28 #include "CSSValueList.h"
29 #include "DataRef.h"
30 #include "GraphicsTypes.h"
31 #include "SVGPaint.h"
32 #include "SVGRenderStyleDefs.h"
34 #include <wtf/Platform.h>
36 namespace WebCore {
38 class RenderObject;
39 class RenderStyle;
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();
47 bool inheritedNotEqual(const SVGRenderStyle*) const;
48 void inheritFrom(const SVGRenderStyle*);
50 bool operator==(const SVGRenderStyle&) const;
51 bool operator!=(const SVGRenderStyle& o) const { return !(*this == o); }
53 // SVG CSS Properties
54 SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO)
55 SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO)
56 SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE)
58 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap)
59 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO)
60 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB)
61 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB)
62 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO)
63 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO)
64 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO)
65 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineJoin, JoinStyle, joinStyle, MiterJoin)
66 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EPointerEvents, PointerEvents, pointerEvents, PE_VISIBLE_PAINTED)
67 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO)
68 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START)
69 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextRendering, TextRendering, textRendering, TR_AUTO)
70 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB)
71 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationHorizontal, glyphOrientationHorizontal, GO_0DEG)
72 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationVertical, glyphOrientationVertical, GO_AUTO)
74 // SVG CSS Properties (using DataRef's)
75 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0f)
76 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, fill, paint, FillPaint, fillPaint, SVGPaint::defaultFill())
78 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0f)
79 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, stroke, paint, StrokePaint, strokePaint, SVGPaint::defaultStroke())
80 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueList, stroke, dashArray, StrokeDashArray, strokeDashArray, 0)
81 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4.0f)
83 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, width, StrokeWidth, strokeWidth, 0)
84 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, 0);
86 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, text, kerning, Kerning, kerning, 0)
88 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0f)
89 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, stops, color, StopColor, stopColor, Color(0, 0, 0))
91 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, clip, clipPath, ClipPath, clipPath, String())
92 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, mask, maskElement, MaskElement, maskElement, String())
93 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, startMarker, StartMarker, startMarker, String())
94 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, midMarker, MidMarker, midMarker, String())
95 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, endMarker, EndMarker, endMarker, String())
97 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, misc, filter, Filter, filter, String())
98 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0f)
99 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, floodColor, FloodColor, floodColor, Color(0, 0, 0))
100 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, lightingColor, LightingColor, lightingColor, Color(255, 255, 255))
101 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, misc, baselineShiftValue, BaselineShiftValue, baselineShiftValue, 0)
103 // convenience
104 bool hasStroke() const { return (strokePaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE); }
105 bool hasFill() const { return (fillPaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE); }
107 static float cssPrimitiveToLength(const RenderObject*, CSSValue*, float defaultValue = 0.0f);
109 protected:
110 // inherit
111 struct InheritedFlags {
112 bool operator==(const InheritedFlags& other) const
114 return (_colorRendering == other._colorRendering) &&
115 (_imageRendering == other._imageRendering) &&
116 (_shapeRendering == other._shapeRendering) &&
117 (_textRendering == other._textRendering) &&
118 (_clipRule == other._clipRule) &&
119 (_fillRule == other._fillRule) &&
120 (_capStyle == other._capStyle) &&
121 (_joinStyle == other._joinStyle) &&
122 (_textAnchor == other._textAnchor) &&
123 (_colorInterpolation == other._colorInterpolation) &&
124 (_colorInterpolationFilters == other._colorInterpolationFilters) &&
125 (_pointerEvents == other._pointerEvents) &&
126 (_writingMode == other._writingMode) &&
127 (_glyphOrientationHorizontal == other._glyphOrientationHorizontal) &&
128 (_glyphOrientationVertical == other._glyphOrientationVertical);
131 bool operator!=(const InheritedFlags& other) const
133 return !(*this == other);
136 unsigned _colorRendering : 2; // EColorRendering
137 unsigned _imageRendering : 2; // EImageRendering
138 unsigned _shapeRendering : 2; // EShapeRendering
139 unsigned _textRendering : 2; // ETextRendering
140 unsigned _clipRule : 1; // WindRule
141 unsigned _fillRule : 1; // WindRule
142 unsigned _capStyle : 2; // LineCap
143 unsigned _joinStyle : 2; // LineJoin
144 unsigned _textAnchor : 2; // ETextAnchor
145 unsigned _colorInterpolation : 2; // EColorInterpolation
146 unsigned _colorInterpolationFilters : 2; // EColorInterpolation
147 unsigned _pointerEvents : 4; // EPointerEvents
148 unsigned _writingMode : 3; // EWritingMode
149 unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation
150 unsigned _glyphOrientationVertical : 3; // EGlyphOrientation
151 } svg_inherited_flags;
153 // don't inherit
154 struct NonInheritedFlags {
155 // 32 bit non-inherited, don't add to the struct, or the operator will break.
156 bool operator==(const NonInheritedFlags &other) const { return _niflags == other._niflags; }
157 bool operator!=(const NonInheritedFlags &other) const { return _niflags != other._niflags; }
159 union {
160 struct {
161 unsigned _alignmentBaseline : 4; // EAlignmentBaseline
162 unsigned _dominantBaseline : 4; // EDominantBaseline
163 unsigned _baselineShift : 2; // EBaselineShift
164 // 22 bits unused
165 } f;
166 uint32_t _niflags;
168 } svg_noninherited_flags;
170 // inherited attributes
171 DataRef<StyleFillData> fill;
172 DataRef<StyleStrokeData> stroke;
173 DataRef<StyleMarkerData> markers;
174 DataRef<StyleTextData> text;
176 // non-inherited attributes
177 DataRef<StyleStopData> stops;
178 DataRef<StyleClipData> clip;
179 DataRef<StyleMaskData> mask;
180 DataRef<StyleMiscData> misc;
182 private:
183 enum CreateDefaultType { CreateDefault };
185 SVGRenderStyle();
186 SVGRenderStyle(const SVGRenderStyle&);
187 SVGRenderStyle(CreateDefaultType); // Used to create the default style.
189 void setBitDefaults()
191 svg_inherited_flags._clipRule = initialClipRule();
192 svg_inherited_flags._colorRendering = initialColorRendering();
193 svg_inherited_flags._fillRule = initialFillRule();
194 svg_inherited_flags._imageRendering = initialImageRendering();
195 svg_inherited_flags._shapeRendering = initialShapeRendering();
196 svg_inherited_flags._textRendering = initialTextRendering();
197 svg_inherited_flags._textAnchor = initialTextAnchor();
198 svg_inherited_flags._capStyle = initialCapStyle();
199 svg_inherited_flags._joinStyle = initialJoinStyle();
200 svg_inherited_flags._colorInterpolation = initialColorInterpolation();
201 svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters();
202 svg_inherited_flags._pointerEvents = initialPointerEvents();
203 svg_inherited_flags._writingMode = initialWritingMode();
204 svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal();
205 svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical();
207 svg_noninherited_flags._niflags = 0;
208 svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline();
209 svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
210 svg_noninherited_flags.f._baselineShift = initialBaselineShift();
214 } // namespace WebCore
216 #endif // ENABLE(SVG)
217 #endif // SVGRenderStyle_h
219 // vim:ts=4:noet