KHtml

SVGClipPathElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2007, 2008 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
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.
11 
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.
16 
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.
21 */
22 
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGClipPathElement.h"
27 
28 #include "css/cssstyleselector.h"
29 #include "Document.h"
30 #include "SVGNames.h"
31 #include "SVGTransformList.h"
32 #include "SVGUnitTypes.h"
33 
34 namespace WebCore
35 {
36 
37 SVGClipPathElement::SVGClipPathElement(const QualifiedName &tagName, Document *doc)
38  : SVGStyledTransformableElement(tagName, doc)
39  , SVGTests()
40  , SVGLangSpace()
41  , SVGExternalResourcesRequired()
42  , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
43 {
44 }
45 
46 SVGClipPathElement::~SVGClipPathElement()
47 {
48 }
49 
50 ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr, m_clipPathUnits)
51 
52 void SVGClipPathElement::parseMappedAttribute(MappedAttribute *attr)
53 {
54  if (attr->name() == SVGNames::clipPathUnitsAttr) {
55  if (attr->value() == "userSpaceOnUse") {
56  setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
57  } else if (attr->value() == "objectBoundingBox") {
58  setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
59  }
60  } else {
61  if (SVGTests::parseMappedAttribute(attr)) {
62  return;
63  }
64  if (SVGLangSpace::parseMappedAttribute(attr)) {
65  return;
66  }
67  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
68  return;
69  }
70  SVGStyledTransformableElement::parseMappedAttribute(attr);
71  }
72 }
73 
74 void SVGClipPathElement::svgAttributeChanged(const QualifiedName &attrName)
75 {
76  SVGStyledTransformableElement::svgAttributeChanged(attrName);
77 
78  if (!m_clipper) {
79  return;
80  }
81 
82  if (attrName == SVGNames::clipPathUnitsAttr ||
83  SVGTests::isKnownAttribute(attrName) ||
84  SVGLangSpace::isKnownAttribute(attrName) ||
85  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
86  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
87  m_clipper->invalidate();
88  }
89 }
90 
91 void SVGClipPathElement::childrenChanged(bool changedByParser, Node *beforeChange, Node *afterChange, int childCountDelta)
92 {
93  SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
94 
95  if (!m_clipper) {
96  return;
97  }
98 
99  m_clipper->invalidate();
100 }
101 
102 SVGResource *SVGClipPathElement::canvasResource()
103 {
104  if (!m_clipper) {
105  m_clipper = SVGResourceClipper::create();
106  } else {
107  m_clipper->resetClipData();
108  }
109 
110  bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
111 
112  //RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
113  for (Node *n = firstChild(); n; n = n->nextSibling()) {
114  if (n->isSVGElement() && static_cast<SVGElement *>(n)->isStyledTransformable()) {
115  SVGStyledTransformableElement *styled = static_cast<SVGStyledTransformableElement *>(n);
116  RenderStyle *pathStyle = document()->styleSelector()->styleForElement(styled/*khtml, clipPathStyle*/);
117  if (pathStyle->display() != NONE) {
118  Path pathData = styled->toClipPath();
119  // FIXME: How do we know the element has done a layout?
120  pathData.transform(styled->animatedLocalTransform());
121  if (!pathData.isEmpty()) {
122  m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
123  }
124  }
125  //khtml pathStyle->deref(document()->renderArena());
126  }
127  }
128  if (m_clipper->clipData().isEmpty()) {
129  Path pathData;
130  pathData.addRect(FloatRect());
131  m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
132  }
133  //khtml clipPathStyle->deref(document()->renderArena());
134  return m_clipper.get();
135 }
136 
137 }
138 
139 #endif // ENABLE(SVG)
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.