• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
SVGClipPathElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
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 "config.h"
24#include "wtf/Platform.h"
25
26#if ENABLE(SVG)
27#include "SVGClipPathElement.h"
28
29#include "css/cssstyleselector.h"
30#include "Document.h"
31#include "SVGNames.h"
32#include "SVGTransformList.h"
33#include "SVGUnitTypes.h"
34
35namespace WebCore {
36
37SVGClipPathElement::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
46SVGClipPathElement::~SVGClipPathElement()
47{
48}
49
50ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr, m_clipPathUnits)
51
52void 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 } else {
60 if (SVGTests::parseMappedAttribute(attr))
61 return;
62 if (SVGLangSpace::parseMappedAttribute(attr))
63 return;
64 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
65 return;
66 SVGStyledTransformableElement::parseMappedAttribute(attr);
67 }
68}
69
70void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
71{
72 SVGStyledTransformableElement::svgAttributeChanged(attrName);
73
74 if (!m_clipper)
75 return;
76
77 if (attrName == SVGNames::clipPathUnitsAttr ||
78 SVGTests::isKnownAttribute(attrName) ||
79 SVGLangSpace::isKnownAttribute(attrName) ||
80 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
81 SVGStyledTransformableElement::isKnownAttribute(attrName))
82 m_clipper->invalidate();
83}
84
85void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
86{
87 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
88
89 if (!m_clipper)
90 return;
91
92 m_clipper->invalidate();
93}
94
95SVGResource* SVGClipPathElement::canvasResource()
96{
97 if (!m_clipper)
98 m_clipper = SVGResourceClipper::create();
99 else
100 m_clipper->resetClipData();
101
102 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
103
104 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
105 for (Node* n = firstChild(); n; n = n->nextSibling()) {
106 if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
107 SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
108 RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled/*khtml, clipPathStyle*/);
109 if (pathStyle->display() != NONE) {
110 Path pathData = styled->toClipPath();
111 // FIXME: How do we know the element has done a layout?
112 pathData.transform(styled->animatedLocalTransform());
113 if (!pathData.isEmpty())
114 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
115 }
116 //khtml pathStyle->deref(document()->renderArena());
117 }
118 }
119 if (m_clipper->clipData().isEmpty()) {
120 Path pathData;
121 pathData.addRect(FloatRect());
122 m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
123 }
124 //khtml clipPathStyle->deref(document()->renderArena());
125 return m_clipper.get();
126}
127
128}
129
130#endif // ENABLE(SVG)
SVGClipPathElement.h
SVGNames.h
SVGTransformList.h
SVGUnitTypes.h
khtml::Path::transform
void transform(const AffineTransform &)
Definition: PathQt.cpp:266
khtml::Path::addRect
void addRect(const FloatRect &)
Definition: PathQt.cpp:169
WebCore
Definition: CSSHelper.h:7
WebCore::Path
khtml::Path Path
Definition: PathTraversalState.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal