don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGFilterPrimitiveStandardAttributes.cpp
blobeae043469efd76f0b449de5f542d65d2bede1beb
1 /*
2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include "config.h"
25 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
26 #include "SVGFilterPrimitiveStandardAttributes.h"
28 #include "SVGFilterElement.h"
29 #include "SVGFilterEffect.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 #include "SVGStyledElement.h"
33 #include "SVGUnitTypes.h"
35 namespace WebCore {
37 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* doc)
38 : SVGStyledElement(tagName, doc)
39 , m_x(this, LengthModeWidth)
40 , m_y(this, LengthModeHeight)
41 , m_width(this, LengthModeWidth)
42 , m_height(this, LengthModeHeight)
44 // Spec: If the attribute is not specified, the effect is as if a value of "0%" were specified.
45 setXBaseValue(SVGLength(this, LengthModeWidth, "0%"));
46 setYBaseValue(SVGLength(this, LengthModeHeight, "0%"));
48 // Spec: If the attribute is not specified, the effect is as if a value of "100%" were specified.
49 setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%"));
50 setHeightBaseValue(SVGLength(this, LengthModeHeight, "100%"));
53 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
57 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
59 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
60 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
61 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, String, String, string, Result, result, SVGNames::resultAttr, m_result)
63 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute* attr)
65 const AtomicString& value = attr->value();
66 if (attr->name() == SVGNames::xAttr)
67 setXBaseValue(SVGLength(this, LengthModeWidth, value));
68 else if (attr->name() == SVGNames::yAttr)
69 setYBaseValue(SVGLength(this, LengthModeHeight, value));
70 else if (attr->name() == SVGNames::widthAttr)
71 setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
72 else if (attr->name() == SVGNames::heightAttr)
73 setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
74 else if (attr->name() == SVGNames::resultAttr)
75 setResultBaseValue(value);
76 else
77 return SVGStyledElement::parseMappedAttribute(attr);
80 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGFilterEffect* filterEffect) const
82 ASSERT(filterEffect);
83 if (!filterEffect)
84 return;
86 ASSERT(filterEffect->filter());
88 float _x, _y, _width, _height;
90 if (filterEffect->filter()->effectBoundingBoxMode()) {
91 _x = x().valueAsPercentage();
92 _y = y().valueAsPercentage();
93 _width = width().valueAsPercentage();
94 _height = height().valueAsPercentage();
95 } else {
96 // We need to resolve any percentages in filter rect space.
97 if (x().unitType() == LengthTypePercentage) {
98 filterEffect->setXBoundingBoxMode(true);
99 _x = x().valueAsPercentage();
100 } else {
101 filterEffect->setXBoundingBoxMode(false);
102 _x = x().value();
105 if (y().unitType() == LengthTypePercentage) {
106 filterEffect->setYBoundingBoxMode(true);
107 _y = y().valueAsPercentage();
108 } else {
109 filterEffect->setYBoundingBoxMode(false);
110 _y = y().value();
113 if (width().unitType() == LengthTypePercentage) {
114 filterEffect->setWidthBoundingBoxMode(true);
115 _width = width().valueAsPercentage();
116 } else {
117 filterEffect->setWidthBoundingBoxMode(false);
118 _width = width().value();
121 if (height().unitType() == LengthTypePercentage) {
122 filterEffect->setHeightBoundingBoxMode(true);
123 _height = height().valueAsPercentage();
124 } else {
125 filterEffect->setHeightBoundingBoxMode(false);
126 _height = height().value();
130 filterEffect->setSubRegion(FloatRect(_x, _y, _width, _height));
131 filterEffect->setResult(result());
136 #endif // ENABLE(SVG)
138 // vim:ts=4:noet