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 "wtf/Platform.h"
30 #if ENABLE(SVG)
31 #include "SVGRenderStyle.h"
32
33 #include "RenderObject.h"
34 #include "RenderStyle.h"
35 #include "SVGStyledElement.h"
36
37 namespace khtml
38 {
39
SVGRenderStyle()40 SVGRenderStyle::SVGRenderStyle()
41 {
42 static SVGRenderStyle *defaultStyle = new SVGRenderStyle(CreateDefault);
43
44 fill = defaultStyle->fill;
45 stroke = defaultStyle->stroke;
46 text = defaultStyle->text;
47 stops = defaultStyle->stops;
48 clip = defaultStyle->clip;
49 mask = defaultStyle->mask;
50 misc = defaultStyle->misc;
51 markers = defaultStyle->markers;
52
53 setBitDefaults();
54 }
55
SVGRenderStyle(CreateDefaultType)56 SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
57 {
58 setBitDefaults();
59
60 fill.init();
61 stroke.init();
62 text.init();
63 stops.init();
64 clip.init();
65 mask.init();
66 misc.init();
67 markers.init();
68 }
69
SVGRenderStyle(const SVGRenderStyle & other)70 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle &other)
71 : RefCounted<SVGRenderStyle>()
72 {
73 fill = other.fill;
74 stroke = other.stroke;
75 text = other.text;
76 stops = other.stops;
77 clip = other.clip;
78 mask = other.mask;
79 misc = other.misc;
80 markers = other.markers;
81
82 svg_inherited_flags = other.svg_inherited_flags;
83 svg_noninherited_flags = other.svg_noninherited_flags;
84 }
85
~SVGRenderStyle()86 SVGRenderStyle::~SVGRenderStyle()
87 {
88 }
89
operator ==(const SVGRenderStyle & o) const90 bool SVGRenderStyle::operator==(const SVGRenderStyle &o) const
91 {
92 return (fill == o.fill && stroke == o.stroke && text == o.text &&
93 stops == o.stops && clip == o.clip && mask == o.mask &&
94 misc == o.misc && markers == o.markers &&
95 svg_inherited_flags == o.svg_inherited_flags &&
96 svg_noninherited_flags == o.svg_noninherited_flags);
97 }
98
inheritedNotEqual(const SVGRenderStyle * other) const99 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle *other) const
100 {
101 return (fill != other->fill
102 || stroke != other->stroke
103 || markers != other->markers
104 || text != other->text
105 || svg_inherited_flags != other->svg_inherited_flags);
106 }
107
inheritFrom(const SVGRenderStyle * svgInheritParent)108 void SVGRenderStyle::inheritFrom(const SVGRenderStyle *svgInheritParent)
109 {
110 if (!svgInheritParent) {
111 return;
112 }
113
114 fill = svgInheritParent->fill;
115 stroke = svgInheritParent->stroke;
116 markers = svgInheritParent->markers;
117 text = svgInheritParent->text;
118
119 svg_inherited_flags = svgInheritParent->svg_inherited_flags;
120 }
121
cssPrimitiveToLength(const RenderObject * item,DOM::CSSValueImpl * value,float defaultValue)122 float SVGRenderStyle::cssPrimitiveToLength(const RenderObject *item, DOM::CSSValueImpl *value, float defaultValue)
123 {
124 Q_UNUSED(item);
125 DOM::CSSPrimitiveValueImpl *primitive = static_cast<DOM::CSSPrimitiveValueImpl *>(value);
126 if (!primitive) {
127 return defaultValue;
128 }
129
130 /*unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) DOM::CSSPrimitiveValue::CSS_UNKNOWN);
131 if (!(cssType > DOM::CSSPrimitiveValue::CSS_UNKNOWN && cssType <= DOM::CSSPrimitiveValue::CSS_PC))
132 return defaultValue;
133
134 if (cssType == DOM::CSSPrimitiveValue::CSS_PERCENTAGE) {
135 SVGStyledElement* element = static_cast<SVGStyledElement*>(item->element());
136 SVGElement* viewportElement = (element ? element->viewportElement() : 0);
137 if (viewportElement) {
138 float result = primitive->getFloatValue() / 100.0f;
139 return SVGLength::PercentageOfViewport(result, element, LengthModeOther);
140 }
141 }
142
143 return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()));*/
144 return (primitive->floatValue() > 0 ? primitive->floatValue() : defaultValue);
145 }
146
147 }
148
149 #endif // ENABLE(SVG)
150
151