KHTML
SVGClipPathElement.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 00003 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> 00004 00005 This file is part of the KDE project 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "config.h" 00024 #include "wtf/Platform.h" 00025 00026 #if ENABLE(SVG) 00027 #include "SVGClipPathElement.h" 00028 00029 #include "css/cssstyleselector.h" 00030 #include "Document.h" 00031 #include "SVGNames.h" 00032 #include "SVGTransformList.h" 00033 #include "SVGUnitTypes.h" 00034 00035 namespace WebCore { 00036 00037 SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* doc) 00038 : SVGStyledTransformableElement(tagName, doc) 00039 , SVGTests() 00040 , SVGLangSpace() 00041 , SVGExternalResourcesRequired() 00042 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) 00043 { 00044 } 00045 00046 SVGClipPathElement::~SVGClipPathElement() 00047 { 00048 } 00049 00050 ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr, m_clipPathUnits) 00051 00052 void SVGClipPathElement::parseMappedAttribute(MappedAttribute* attr) 00053 { 00054 if (attr->name() == SVGNames::clipPathUnitsAttr) { 00055 if (attr->value() == "userSpaceOnUse") 00056 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE); 00057 else if (attr->value() == "objectBoundingBox") 00058 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); 00059 } else { 00060 if (SVGTests::parseMappedAttribute(attr)) 00061 return; 00062 if (SVGLangSpace::parseMappedAttribute(attr)) 00063 return; 00064 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) 00065 return; 00066 SVGStyledTransformableElement::parseMappedAttribute(attr); 00067 } 00068 } 00069 00070 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) 00071 { 00072 SVGStyledTransformableElement::svgAttributeChanged(attrName); 00073 00074 if (!m_clipper) 00075 return; 00076 00077 if (attrName == SVGNames::clipPathUnitsAttr || 00078 SVGTests::isKnownAttribute(attrName) || 00079 SVGLangSpace::isKnownAttribute(attrName) || 00080 SVGExternalResourcesRequired::isKnownAttribute(attrName) || 00081 SVGStyledTransformableElement::isKnownAttribute(attrName)) 00082 m_clipper->invalidate(); 00083 } 00084 00085 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 00086 { 00087 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 00088 00089 if (!m_clipper) 00090 return; 00091 00092 m_clipper->invalidate(); 00093 } 00094 00095 SVGResource* SVGClipPathElement::canvasResource() 00096 { 00097 if (!m_clipper) 00098 m_clipper = SVGResourceClipper::create(); 00099 else 00100 m_clipper->resetClipData(); 00101 00102 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX; 00103 00104 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack 00105 for (Node* n = firstChild(); n; n = n->nextSibling()) { 00106 if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) { 00107 SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n); 00108 RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled/*khtml, clipPathStyle*/); 00109 if (pathStyle->display() != NONE) { 00110 Path pathData = styled->toClipPath(); 00111 // FIXME: How do we know the element has done a layout? 00112 pathData.transform(styled->animatedLocalTransform()); 00113 if (!pathData.isEmpty()) 00114 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox); 00115 } 00116 //khtml pathStyle->deref(document()->renderArena()); 00117 } 00118 } 00119 if (m_clipper->clipData().isEmpty()) { 00120 Path pathData; 00121 pathData.addRect(FloatRect()); 00122 m_clipper->addClipData(pathData, RULE_EVENODD, bbox); 00123 } 00124 //khtml clipPathStyle->deref(document()->renderArena()); 00125 return m_clipper.get(); 00126 } 00127 00128 } 00129 00130 #endif // ENABLE(SVG)
KDE 4.6 API Reference