00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "config.h"
00025
00026 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00027 #include "SVGFilterElement.h"
00028
00029 #include "Attr.h"
00030 #include "SVGResourceFilter.h"
00031 #include "SVGFilterPrimitiveStandardAttributes.h"
00032 #include "SVGLength.h"
00033 #include "SVGNames.h"
00034 #include "SVGUnitTypes.h"
00035
00036 namespace WebCore {
00037
00038 SVGFilterElement::SVGFilterElement(const QualifiedName& tagName, Document* doc)
00039 : SVGStyledElement(tagName, doc)
00040 , SVGURIReference()
00041 , SVGLangSpace()
00042 , SVGExternalResourcesRequired()
00043 , m_filterUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
00044 , m_primitiveUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
00045 , m_x(this, LengthModeWidth)
00046 , m_y(this, LengthModeHeight)
00047 , m_width(this, LengthModeWidth)
00048 , m_height(this, LengthModeHeight)
00049 , m_filterResX(0)
00050 , m_filterResY(0)
00051 {
00052
00053 setXBaseValue(SVGLength(this, LengthModeWidth, "-10%"));
00054 setYBaseValue(SVGLength(this, LengthModeHeight, "-10%"));
00055
00056
00057 setWidthBaseValue(SVGLength(this, LengthModeWidth, "120%"));
00058 setHeightBaseValue(SVGLength(this, LengthModeHeight, "120%"));
00059 }
00060
00061 SVGFilterElement::~SVGFilterElement()
00062 {
00063 }
00064
00065 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, FilterUnits, filterUnits, SVGNames::filterUnitsAttr, m_filterUnits)
00066 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, int, Enumeration, enumeration, PrimitiveUnits, primitiveUnits, SVGNames::primitiveUnitsAttr, m_primitiveUnits)
00067 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00068 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00069 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00070 ANIMATED_PROPERTY_DEFINITIONS(SVGFilterElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00071 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResX, filterResX, SVGNames::filterResAttr, "filterResX", m_filterResX)
00072 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFilterElement, long, Integer, integer, FilterResY, filterResY, SVGNames::filterResAttr, "filterResY", m_filterResY)
00073
00074 void SVGFilterElement::setFilterRes(unsigned long, unsigned long) const
00075 {
00076 }
00077
00078 void SVGFilterElement::parseMappedAttribute(MappedAttribute* attr)
00079 {
00080 const String& value = attr->value();
00081 if (attr->name() == SVGNames::filterUnitsAttr) {
00082 if (value == "userSpaceOnUse")
00083 setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
00084 else if (value == "objectBoundingBox")
00085 setFilterUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
00086 } else if (attr->name() == SVGNames::primitiveUnitsAttr) {
00087 if (value == "userSpaceOnUse")
00088 setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
00089 else if (value == "objectBoundingBox")
00090 setPrimitiveUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
00091 } else if (attr->name() == SVGNames::xAttr)
00092 setXBaseValue(SVGLength(this, LengthModeWidth, value));
00093 else if (attr->name() == SVGNames::yAttr)
00094 setYBaseValue(SVGLength(this, LengthModeHeight, value));
00095 else if (attr->name() == SVGNames::widthAttr)
00096 setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
00097 else if (attr->name() == SVGNames::heightAttr)
00098 setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
00099 else {
00100 if (SVGURIReference::parseMappedAttribute(attr)) return;
00101 if (SVGLangSpace::parseMappedAttribute(attr)) return;
00102 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) return;
00103
00104 SVGStyledElement::parseMappedAttribute(attr);
00105 }
00106 }
00107
00108 SVGResource* SVGFilterElement::canvasResource()
00109 {
00110 if (!attached())
00111 return 0;
00112
00113 if (!m_filter)
00114 m_filter = new SVGResourceFilter();
00115
00116 bool filterBBoxMode = filterUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
00117 m_filter->setFilterBoundingBoxMode(filterBBoxMode);
00118
00119 float _x, _y, _width, _height;
00120
00121 if (filterBBoxMode) {
00122 _x = x().valueAsPercentage();
00123 _y = y().valueAsPercentage();
00124 _width = width().valueAsPercentage();
00125 _height = height().valueAsPercentage();
00126 } else {
00127 m_filter->setXBoundingBoxMode(x().unitType() == LengthTypePercentage);
00128 m_filter->setYBoundingBoxMode(y().unitType() == LengthTypePercentage);
00129
00130 _x = x().value();
00131 _y = y().value();
00132 _width = width().value();
00133 _height = height().value();
00134 }
00135
00136 m_filter->setFilterRect(FloatRect(_x, _y, _width, _height));
00137
00138 bool primitiveBBoxMode = primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
00139 m_filter->setEffectBoundingBoxMode(primitiveBBoxMode);
00140
00141
00142 m_filter->clearEffects();
00143 for (Node* n = firstChild(); n != 0; n = n->nextSibling()) {
00144 SVGElement* element = 0;
00145 if (n->isSVGElement())
00146 element = static_cast<SVGElement*>(n);
00147 if (element && element->isFilterEffect()) {
00148 SVGFilterPrimitiveStandardAttributes* filterAttributes = static_cast<SVGFilterPrimitiveStandardAttributes*>(element);
00149 SVGFilterEffect* filterEffect = filterAttributes->filterEffect(m_filter.get());
00150 if (!filterEffect)
00151 continue;
00152
00153 m_filter->addFilterEffect(filterEffect);
00154 }
00155 }
00156
00157 return m_filter.get();
00158 }
00159
00160 }
00161
00162 #endif // ENABLE(SVG)
00163
00164