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.
30 #include "core/rendering/style/SVGRenderStyle.h"
34 SVGRenderStyle::SVGRenderStyle()
36 static SVGRenderStyle* defaultStyle = new SVGRenderStyle(CreateDefault);
38 fill = defaultStyle->fill;
39 stroke = defaultStyle->stroke;
40 stops = defaultStyle->stops;
41 misc = defaultStyle->misc;
42 inheritedResources = defaultStyle->inheritedResources;
43 resources = defaultStyle->resources;
48 SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
56 inheritedResources.init();
60 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle& other)
61 : RefCounted<SVGRenderStyle>()
64 stroke = other.stroke;
67 inheritedResources = other.inheritedResources;
68 resources = other.resources;
70 svg_inherited_flags = other.svg_inherited_flags;
71 svg_noninherited_flags = other.svg_noninherited_flags;
74 SVGRenderStyle::~SVGRenderStyle()
78 bool SVGRenderStyle::operator==(const SVGRenderStyle& other) const
80 return fill == other.fill
81 && stroke == other.stroke
82 && stops == other.stops
84 && inheritedResources == other.inheritedResources
85 && resources == other.resources
86 && svg_inherited_flags == other.svg_inherited_flags
87 && svg_noninherited_flags == other.svg_noninherited_flags;
90 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle* other) const
92 return fill != other->fill
93 || stroke != other->stroke
94 || inheritedResources != other->inheritedResources
95 || svg_inherited_flags != other->svg_inherited_flags;
98 void SVGRenderStyle::inheritFrom(const SVGRenderStyle* svgInheritParent)
100 if (!svgInheritParent)
103 fill = svgInheritParent->fill;
104 stroke = svgInheritParent->stroke;
105 inheritedResources = svgInheritParent->inheritedResources;
107 svg_inherited_flags = svgInheritParent->svg_inherited_flags;
110 void SVGRenderStyle::copyNonInheritedFrom(const SVGRenderStyle* other)
112 svg_noninherited_flags = other->svg_noninherited_flags;
113 stops = other->stops;
115 resources = other->resources;
118 StyleDifference SVGRenderStyle::diff(const SVGRenderStyle* other) const
120 StyleDifference styleDifference;
122 if (diffNeedsLayoutAndPaintInvalidation(other)) {
123 styleDifference.setNeedsFullLayout();
124 styleDifference.setNeedsPaintInvalidationObject();
125 } else if (diffNeedsPaintInvalidation(other)) {
126 styleDifference.setNeedsPaintInvalidationObject();
129 return styleDifference;
132 bool SVGRenderStyle::diffNeedsLayoutAndPaintInvalidation(const SVGRenderStyle* other) const
134 // If resources change, we need a relayout, as the presence of resources influences the paint invalidation rect.
135 if (resources != other->resources)
138 // If markers change, we need a relayout, as marker boundaries are cached in RenderSVGPath.
139 if (inheritedResources != other->inheritedResources)
142 // All text related properties influence layout.
143 if (svg_inherited_flags._textAnchor != other->svg_inherited_flags._textAnchor
144 || svg_inherited_flags._writingMode != other->svg_inherited_flags._writingMode
145 || svg_inherited_flags._glyphOrientationHorizontal != other->svg_inherited_flags._glyphOrientationHorizontal
146 || svg_inherited_flags._glyphOrientationVertical != other->svg_inherited_flags._glyphOrientationVertical
147 || svg_noninherited_flags.f._alignmentBaseline != other->svg_noninherited_flags.f._alignmentBaseline
148 || svg_noninherited_flags.f._dominantBaseline != other->svg_noninherited_flags.f._dominantBaseline
149 || svg_noninherited_flags.f._baselineShift != other->svg_noninherited_flags.f._baselineShift)
152 // Text related properties influence layout.
153 if (misc->baselineShiftValue != other->misc->baselineShiftValue)
156 // These properties affect the cached stroke bounding box rects.
157 if (svg_inherited_flags._capStyle != other->svg_inherited_flags._capStyle
158 || svg_inherited_flags._joinStyle != other->svg_inherited_flags._joinStyle)
161 // vector-effect changes require a re-layout.
162 if (svg_noninherited_flags.f._vectorEffect != other->svg_noninherited_flags.f._vectorEffect)
165 // Some stroke properties, requires relayouts, as the cached stroke boundaries need to be recalculated.
166 if (stroke.get() != other->stroke.get()) {
167 if (stroke->width != other->stroke->width
168 || stroke->paintType != other->stroke->paintType
169 || stroke->paintColor != other->stroke->paintColor
170 || stroke->paintUri != other->stroke->paintUri
171 || stroke->miterLimit != other->stroke->miterLimit
172 || stroke->dashArray != other->stroke->dashArray
173 || stroke->dashOffset != other->stroke->dashOffset
174 || stroke->visitedLinkPaintColor != other->stroke->visitedLinkPaintColor
175 || stroke->visitedLinkPaintUri != other->stroke->visitedLinkPaintUri
176 || stroke->visitedLinkPaintType != other->stroke->visitedLinkPaintType)
183 bool SVGRenderStyle::diffNeedsPaintInvalidation(const SVGRenderStyle* other) const
185 if (stroke->opacity != other->stroke->opacity)
188 // Painting related properties only need paint invalidation.
189 if (misc.get() != other->misc.get()) {
190 if (misc->floodColor != other->misc->floodColor
191 || misc->floodOpacity != other->misc->floodOpacity
192 || misc->lightingColor != other->misc->lightingColor)
196 // If fill changes, we just need to issue paint invalidations. Fill boundaries are not influenced by this, only by the Path, that RenderSVGPath contains.
197 if (fill.get() != other->fill.get()) {
198 if (fill->paintType != other->fill->paintType
199 || fill->paintColor != other->fill->paintColor
200 || fill->paintUri != other->fill->paintUri
201 || fill->opacity != other->fill->opacity)
205 // If gradient stops change, we just need to issue paint invalidations. Style updates are already handled through RenderSVGGradientSTop.
206 if (stops != other->stops)
209 // Changes of these flags only cause paint invalidations.
210 if (svg_inherited_flags._colorRendering != other->svg_inherited_flags._colorRendering
211 || svg_inherited_flags._shapeRendering != other->svg_inherited_flags._shapeRendering
212 || svg_inherited_flags._clipRule != other->svg_inherited_flags._clipRule
213 || svg_inherited_flags._fillRule != other->svg_inherited_flags._fillRule
214 || svg_inherited_flags._colorInterpolation != other->svg_inherited_flags._colorInterpolation
215 || svg_inherited_flags._colorInterpolationFilters != other->svg_inherited_flags._colorInterpolationFilters
216 || svg_inherited_flags._paintOrder != other->svg_inherited_flags._paintOrder)
219 if (svg_noninherited_flags.f.bufferedRendering != other->svg_noninherited_flags.f.bufferedRendering)
222 if (svg_noninherited_flags.f.maskType != other->svg_noninherited_flags.f.maskType)
228 EPaintOrderType SVGRenderStyle::paintOrderType(unsigned index) const
230 ASSERT(index < ((1 << kPaintOrderBitwidth)-1));
231 unsigned pt = (paintOrder() >> (kPaintOrderBitwidth*index)) & ((1u << kPaintOrderBitwidth) - 1);
232 return (EPaintOrderType)pt;