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