fix logic
[personal-kdelibs.git] / khtml / rendering / SVGRenderStyle.cpp
blobf42d6af08d828622226646276d0b0860d3e94359
1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
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.
11 This file is part of the KDE project
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.
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.
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.
29 #include "config.h"
30 #include "wtf/Platform.h"
31 #if ENABLE(SVG)
32 #include "SVGRenderStyle.h"
34 #include "CSSPrimitiveValue.h"
35 #include "CSSValueList.h"
36 #include "RenderObject.h"
37 #include "RenderStyle.h"
38 #include "SVGStyledElement.h"
40 namespace WebCore {
42 SVGRenderStyle::SVGRenderStyle()
44 static SVGRenderStyle* defaultStyle = new SVGRenderStyle(CreateDefault);
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;
55 setBitDefaults();
58 SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
60 setBitDefaults();
62 fill.init();
63 stroke.init();
64 text.init();
65 stops.init();
66 clip.init();
67 mask.init();
68 misc.init();
69 markers.init();
72 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle& other)
73 : RefCounted<SVGRenderStyle>()
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;
84 svg_inherited_flags = other.svg_inherited_flags;
85 svg_noninherited_flags = other.svg_noninherited_flags;
88 SVGRenderStyle::~SVGRenderStyle()
92 bool SVGRenderStyle::operator==(const SVGRenderStyle& o) const
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);
101 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle* other) const
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);
110 void SVGRenderStyle::inheritFrom(const SVGRenderStyle* svgInheritParent)
112 if (!svgInheritParent)
113 return;
115 fill = svgInheritParent->fill;
116 stroke = svgInheritParent->stroke;
117 markers = svgInheritParent->markers;
118 text = svgInheritParent->text;
120 svg_inherited_flags = svgInheritParent->svg_inherited_flags;
123 float SVGRenderStyle::cssPrimitiveToLength(const RenderObject* item, CSSValue* value, float defaultValue)
125 CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(value);
126 if (!primitive) return defaultValue;
128 /*unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) DOM::CSSPrimitiveValue::CSS_UNKNOWN);
129 if (!(cssType > DOM::CSSPrimitiveValue::CSS_UNKNOWN && cssType <= DOM::CSSPrimitiveValue::CSS_PC))
130 return defaultValue;
132 if (cssType == DOM::CSSPrimitiveValue::CSS_PERCENTAGE) {
133 SVGStyledElement* element = static_cast<SVGStyledElement*>(item->element());
134 SVGElement* viewportElement = (element ? element->viewportElement() : 0);
135 if (viewportElement) {
136 float result = primitive->getFloatValue() / 100.0f;
137 return SVGLength::PercentageOfViewport(result, element, LengthModeOther);
141 return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()));*/
142 return (primitive->floatValue() > 0 ? primitive->floatValue() : defaultValue);
147 #endif // ENABLE(SVG)
149 // vim:ts=4