1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4
5 Based on khtml code by:
6 Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
7 Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
8 Copyright (C) 2002-2003 Dirk Mueller (mueller@kde.org)
9 Copyright (C) 2002 Apple Computer, Inc.
10
11 This file is part of the KDE project
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Library General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Library General Public License for more details.
22
23 You should have received a copy of the GNU Library General Public License
24 along with this library; see the file COPYING.LIB. If not, write to
25 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 Boston, MA 02110-1301, USA.
27 */
28
29 #include "config.h"
30 #if ENABLE(SVG)
31 #include "SVGRenderStyle.h"
32
33 #include "CSSPrimitiveValue.h"
34 #include "CSSValueList.h"
35 #include "NodeRenderStyle.h"
36 #include "RenderObject.h"
37 #include "RenderStyle.h"
38 #include "SVGStyledElement.h"
39
40 namespace WebCore {
41
SVGRenderStyle()42 SVGRenderStyle::SVGRenderStyle()
43 {
44 static SVGRenderStyle* defaultStyle = new SVGRenderStyle(CreateDefault);
45
46 fill = defaultStyle->fill;
47 stroke = defaultStyle->stroke;
48 text = defaultStyle->text;
49 stops = defaultStyle->stops;
50 clip = defaultStyle->clip;
51 mask = defaultStyle->mask;
52 misc = defaultStyle->misc;
53 markers = defaultStyle->markers;
54
55 setBitDefaults();
56 }
57
SVGRenderStyle(CreateDefaultType)58 SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
59 {
60 setBitDefaults();
61
62 fill.init();
63 stroke.init();
64 text.init();
65 stops.init();
66 clip.init();
67 mask.init();
68 misc.init();
69 markers.init();
70 }
71
SVGRenderStyle(const SVGRenderStyle & other)72 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle& other)
73 : RefCounted<SVGRenderStyle>()
74 {
75 fill = other.fill;
76 stroke = other.stroke;
77 text = other.text;
78 stops = other.stops;
79 clip = other.clip;
80 mask = other.mask;
81 misc = other.misc;
82 markers = other.markers;
83
84 svg_inherited_flags = other.svg_inherited_flags;
85 svg_noninherited_flags = other.svg_noninherited_flags;
86 }
87
~SVGRenderStyle()88 SVGRenderStyle::~SVGRenderStyle()
89 {
90 }
91
operator ==(const SVGRenderStyle & o) const92 bool SVGRenderStyle::operator==(const SVGRenderStyle& o) const
93 {
94 return (fill == o.fill && stroke == o.stroke && text == o.text &&
95 stops == o.stops && clip == o.clip && mask == o.mask &&
96 misc == o.misc && markers == o.markers &&
97 svg_inherited_flags == o.svg_inherited_flags &&
98 svg_noninherited_flags == o.svg_noninherited_flags);
99 }
100
inheritedNotEqual(const SVGRenderStyle * other) const101 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle* other) const
102 {
103 return (fill != other->fill
104 || stroke != other->stroke
105 || markers != other->markers
106 || text != other->text
107 || svg_inherited_flags != other->svg_inherited_flags);
108 }
109
inheritFrom(const SVGRenderStyle * svgInheritParent)110 void SVGRenderStyle::inheritFrom(const SVGRenderStyle* svgInheritParent)
111 {
112 if (!svgInheritParent)
113 return;
114
115 fill = svgInheritParent->fill;
116 stroke = svgInheritParent->stroke;
117 markers = svgInheritParent->markers;
118 text = svgInheritParent->text;
119
120 svg_inherited_flags = svgInheritParent->svg_inherited_flags;
121 }
122
cssPrimitiveToLength(const RenderObject * item,CSSValue * value,float defaultValue)123 float SVGRenderStyle::cssPrimitiveToLength(const RenderObject* item, CSSValue* value, float defaultValue)
124 {
125 CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(value);
126
127 unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) CSSPrimitiveValue::CSS_UNKNOWN);
128 if (!(cssType > CSSPrimitiveValue::CSS_UNKNOWN && cssType <= CSSPrimitiveValue::CSS_PC))
129 return defaultValue;
130
131 if (cssType == CSSPrimitiveValue::CSS_PERCENTAGE) {
132 SVGStyledElement* element = static_cast<SVGStyledElement*>(item->node());
133 SVGElement* viewportElement = (element ? element->viewportElement() : 0);
134 if (viewportElement) {
135 float result = primitive->getFloatValue() / 100.0f;
136 return SVGLength::PercentageOfViewport(result, element, LengthModeOther);
137 }
138 }
139
140 return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()), item->document()->documentElement()->renderStyle());
141 }
142
143 }
144
145 #endif // ENABLE(SVG)
146
147 // vim:ts=4:noet
148