2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2010 Rob Buis <buis@kde.org>
4 Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 Based on khtml code by:
7 Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
8 Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
9 Copyright (C) 2002-2003 Dirk Mueller (mueller@kde.org)
10 Copyright (C) 2002 Apple Computer, Inc.
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.
31 #include "SVGRenderStyle.h"
33 #include "CSSPrimitiveValue.h"
34 #include "CSSValueList.h"
36 #include "NodeRenderStyle.h"
37 #include "SVGStyledElement.h"
43 SVGRenderStyle::SVGRenderStyle()
45 static SVGRenderStyle* defaultStyle = new SVGRenderStyle(CreateDefault);
47 fill = defaultStyle->fill;
48 stroke = defaultStyle->stroke;
49 text = defaultStyle->text;
50 stops = defaultStyle->stops;
51 misc = defaultStyle->misc;
52 shadowSVG = defaultStyle->shadowSVG;
53 inheritedResources = defaultStyle->inheritedResources;
54 resources = defaultStyle->resources;
59 SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
69 inheritedResources.init();
73 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle& other)
74 : RefCounted<SVGRenderStyle>()
77 stroke = other.stroke;
81 shadowSVG = other.shadowSVG;
82 inheritedResources = other.inheritedResources;
83 resources = other.resources;
85 svg_inherited_flags = other.svg_inherited_flags;
86 svg_noninherited_flags = other.svg_noninherited_flags;
89 SVGRenderStyle::~SVGRenderStyle()
93 bool SVGRenderStyle::operator==(const SVGRenderStyle& other) const
95 return fill == other.fill
96 && stroke == other.stroke
98 && stops == other.stops
100 && shadowSVG == other.shadowSVG
101 && inheritedResources == other.inheritedResources
102 && resources == other.resources
103 && svg_inherited_flags == other.svg_inherited_flags
104 && svg_noninherited_flags == other.svg_noninherited_flags;
107 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle* other) const
109 return fill != other->fill
110 || stroke != other->stroke
111 || text != other->text
112 || inheritedResources != other->inheritedResources
113 || svg_inherited_flags != other->svg_inherited_flags;
116 void SVGRenderStyle::inheritFrom(const SVGRenderStyle* svgInheritParent)
118 if (!svgInheritParent)
121 fill = svgInheritParent->fill;
122 stroke = svgInheritParent->stroke;
123 text = svgInheritParent->text;
124 inheritedResources = svgInheritParent->inheritedResources;
126 svg_inherited_flags = svgInheritParent->svg_inherited_flags;
129 StyleDifference SVGRenderStyle::diff(const SVGRenderStyle* other) const
131 // NOTE: All comparisions that may return StyleDifferenceLayout have to go before those who return StyleDifferenceRepaint
133 // If kerning changes, we need a relayout, to force SVGCharacterData to be recalculated in the SVGRootInlineBox.
134 if (text != other->text)
135 return StyleDifferenceLayout;
137 // If resources change, we need a relayout, as the presence of resources influences the repaint rect.
138 if (resources != other->resources)
139 return StyleDifferenceLayout;
141 // If markers change, we need a relayout, as marker boundaries are cached in RenderSVGPath.
142 if (inheritedResources != other->inheritedResources)
143 return StyleDifferenceLayout;
145 // All text related properties influence layout.
146 if (svg_inherited_flags._textAnchor != other->svg_inherited_flags._textAnchor
147 || svg_inherited_flags._writingMode != other->svg_inherited_flags._writingMode
148 || svg_inherited_flags._glyphOrientationHorizontal != other->svg_inherited_flags._glyphOrientationHorizontal
149 || svg_inherited_flags._glyphOrientationVertical != other->svg_inherited_flags._glyphOrientationVertical
150 || svg_noninherited_flags.f._alignmentBaseline != other->svg_noninherited_flags.f._alignmentBaseline
151 || svg_noninherited_flags.f._dominantBaseline != other->svg_noninherited_flags.f._dominantBaseline
152 || svg_noninherited_flags.f._baselineShift != other->svg_noninherited_flags.f._baselineShift)
153 return StyleDifferenceLayout;
155 // Text related properties influence layout.
156 bool miscNotEqual = misc != other->misc;
157 if (miscNotEqual && misc->baselineShiftValue != other->misc->baselineShiftValue)
158 return StyleDifferenceLayout;
160 // These properties affect the cached stroke bounding box rects.
161 if (svg_inherited_flags._capStyle != other->svg_inherited_flags._capStyle
162 || svg_inherited_flags._joinStyle != other->svg_inherited_flags._joinStyle)
163 return StyleDifferenceLayout;
165 // Shadow changes require relayouts, as they affect the repaint rects.
166 if (shadowSVG != other->shadowSVG)
167 return StyleDifferenceLayout;
169 // Some stroke properties, requires relayouts, as the cached stroke boundaries need to be recalculated.
170 if (stroke != other->stroke) {
171 if (stroke->width != other->stroke->width
172 || stroke->paintType != other->stroke->paintType
173 || stroke->paintColor != other->stroke->paintColor
174 || stroke->paintUri != other->stroke->paintUri
175 || stroke->miterLimit != other->stroke->miterLimit
176 || stroke->dashArray != other->stroke->dashArray
177 || stroke->dashOffset != other->stroke->dashOffset)
178 return StyleDifferenceLayout;
180 // Only the stroke-opacity case remains, where we only need a repaint.
181 ASSERT(stroke->opacity != other->stroke->opacity);
182 return StyleDifferenceRepaint;
185 // NOTE: All comparisions below may only return StyleDifferenceRepaint
187 // Painting related properties only need repaints.
189 if (misc->floodColor != other->misc->floodColor
190 || misc->floodOpacity != other->misc->floodOpacity
191 || misc->lightingColor != other->misc->lightingColor)
192 return StyleDifferenceRepaint;
195 // If fill changes, we just need to repaint. Fill boundaries are not influenced by this, only by the Path, that RenderSVGPath contains.
196 if (fill->paintType != other->fill->paintType || fill->paintColor != other->fill->paintColor
197 || fill->paintUri != other->fill->paintUri || fill->opacity != other->fill->opacity)
198 return StyleDifferenceRepaint;
200 // If gradient stops change, we just need to repaint. Style updates are already handled through RenderSVGGradientSTop.
201 if (stops != other->stops)
202 return StyleDifferenceRepaint;
204 // Changes of these flags only cause repaints.
205 if (svg_inherited_flags._colorRendering != other->svg_inherited_flags._colorRendering
206 || svg_inherited_flags._shapeRendering != other->svg_inherited_flags._shapeRendering
207 || svg_inherited_flags._clipRule != other->svg_inherited_flags._clipRule
208 || svg_inherited_flags._fillRule != other->svg_inherited_flags._fillRule
209 || svg_inherited_flags._colorInterpolation != other->svg_inherited_flags._colorInterpolation
210 || svg_inherited_flags._colorInterpolationFilters != other->svg_inherited_flags._colorInterpolationFilters)
211 return StyleDifferenceRepaint;
213 // FIXME: vector-effect is not taken into account in the layout-phase. Once this is fixed, we should relayout here.
214 if (svg_noninherited_flags.f._vectorEffect != other->svg_noninherited_flags.f._vectorEffect)
215 return StyleDifferenceRepaint;
217 return StyleDifferenceEqual;
222 #endif // ENABLE(SVG)