00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024
00025 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00026 #include "SVGFilterPrimitiveStandardAttributes.h"
00027
00028 #include "SVGFilterElement.h"
00029 #include "SVGFilterEffect.h"
00030 #include "SVGLength.h"
00031 #include "SVGNames.h"
00032 #include "SVGStyledElement.h"
00033 #include "SVGUnitTypes.h"
00034
00035 namespace WebCore {
00036
00037 SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document* doc)
00038 : SVGStyledElement(tagName, doc)
00039 , m_x(this, LengthModeWidth)
00040 , m_y(this, LengthModeHeight)
00041 , m_width(this, LengthModeWidth)
00042 , m_height(this, LengthModeHeight)
00043 {
00044
00045 setXBaseValue(SVGLength(this, LengthModeWidth, "0%"));
00046 setYBaseValue(SVGLength(this, LengthModeHeight, "0%"));
00047
00048
00049 setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%"));
00050 setHeightBaseValue(SVGLength(this, LengthModeHeight, "100%"));
00051 }
00052
00053 SVGFilterPrimitiveStandardAttributes::~SVGFilterPrimitiveStandardAttributes()
00054 {
00055 }
00056
00057 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00058 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00059 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00060 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00061 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterPrimitiveStandardAttributes, String, String, string, Result, result, SVGNames::resultAttr, m_result)
00062
00063 void SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(MappedAttribute* attr)
00064 {
00065 const AtomicString& value = attr->value();
00066 if (attr->name() == SVGNames::xAttr)
00067 setXBaseValue(SVGLength(this, LengthModeWidth, value));
00068 else if (attr->name() == SVGNames::yAttr)
00069 setYBaseValue(SVGLength(this, LengthModeHeight, value));
00070 else if (attr->name() == SVGNames::widthAttr)
00071 setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
00072 else if (attr->name() == SVGNames::heightAttr)
00073 setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
00074 else if (attr->name() == SVGNames::resultAttr)
00075 setResultBaseValue(value);
00076 else
00077 return SVGStyledElement::parseMappedAttribute(attr);
00078 }
00079
00080 void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(SVGFilterEffect* filterEffect) const
00081 {
00082 ASSERT(filterEffect);
00083 if (!filterEffect)
00084 return;
00085
00086 ASSERT(filterEffect->filter());
00087
00088 float _x, _y, _width, _height;
00089
00090 if (filterEffect->filter()->effectBoundingBoxMode()) {
00091 _x = x().valueAsPercentage();
00092 _y = y().valueAsPercentage();
00093 _width = width().valueAsPercentage();
00094 _height = height().valueAsPercentage();
00095 } else {
00096
00097 if (x().unitType() == LengthTypePercentage) {
00098 filterEffect->setXBoundingBoxMode(true);
00099 _x = x().valueAsPercentage();
00100 } else {
00101 filterEffect->setXBoundingBoxMode(false);
00102 _x = x().value();
00103 }
00104
00105 if (y().unitType() == LengthTypePercentage) {
00106 filterEffect->setYBoundingBoxMode(true);
00107 _y = y().valueAsPercentage();
00108 } else {
00109 filterEffect->setYBoundingBoxMode(false);
00110 _y = y().value();
00111 }
00112
00113 if (width().unitType() == LengthTypePercentage) {
00114 filterEffect->setWidthBoundingBoxMode(true);
00115 _width = width().valueAsPercentage();
00116 } else {
00117 filterEffect->setWidthBoundingBoxMode(false);
00118 _width = width().value();
00119 }
00120
00121 if (height().unitType() == LengthTypePercentage) {
00122 filterEffect->setHeightBoundingBoxMode(true);
00123 _height = height().valueAsPercentage();
00124 } else {
00125 filterEffect->setHeightBoundingBoxMode(false);
00126 _height = height().value();
00127 }
00128 }
00129
00130 filterEffect->setSubRegion(FloatRect(_x, _y, _width, _height));
00131 filterEffect->setResult(result());
00132 }
00133
00134 }
00135
00136 #endif // ENABLE(SVG)
00137
00138