2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
24 #include "wtf/Platform.h"
28 #include "SVGLocatable.h"
30 #include "AffineTransform.h"
31 #include "RenderPath.h"
32 #include "SVGException.h"
33 #include "SVGSVGElement.h"
37 SVGLocatable::SVGLocatable()
41 SVGLocatable::~SVGLocatable()
45 SVGElement
* SVGLocatable::nearestViewportElement(const SVGStyledElement
* e
)
48 Node* n = e->parentNode();
49 while (n && !n->isDocumentNode()) {
50 if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
51 n->hasTagName(SVGNames::imageTag))
52 return static_cast<SVGElement*>(n);
53 #if ENABLE(SVG_FOREIGN_OBJECT)
54 if (n->hasTagName(SVGNames::foreignObjectTag))
55 return static_cast<SVGElement*>(n);
64 SVGElement
* SVGLocatable::farthestViewportElement(const SVGStyledElement
* e
)
66 // FIXME : likely this will be always the <svg> farthest away.
67 // If we have a different implementation of documentElement(), one
68 // that give the documentElement() of the svg fragment, it could be
69 // used instead. This depends on cdf demands though(Rob.)
70 SVGElement
* farthest
= 0;
71 /*Node* n = e->parentNode();
72 while (n && !n->isDocumentNode()) {
73 if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
74 n->hasTagName(SVGNames::imageTag))
75 farthest = static_cast<SVGElement*>(n);
76 #if ENABLE(SVG_FOREIGN_OBJECT)
77 if (n->hasTagName(SVGNames::foreignObjectTag))
78 farthest = static_cast<SVGElement*>(n);
88 // http://www.w3.org/TR/2005/WD-SVGMobile12-20050413/svgudom.html#svg::SVGLocatable
89 FloatRect
SVGLocatable::getBBox(const SVGStyledElement
* e
)
93 /*if (e && e->renderer()) {
94 // Need this to make sure we have render object dimensions.
96 e->document()->updateLayoutIgnorePendingStylesheets();
97 bboxRect = e->renderer()->relativeBBox(false);
103 AffineTransform
SVGLocatable::getCTM(const SVGElement
* element
)
106 return AffineTransform();
110 Node
* parent
= element
->parentNode();
111 if (parent
&& parent
->isSVGElement()) {
112 SVGElement
* parentElement
= static_cast<SVGElement
*>(parent
);
113 if (parentElement
&& parentElement
->isStyledLocatable()) {
114 AffineTransform parentCTM
= static_cast<SVGStyledLocatableElement
*>(parentElement
)->getCTM();
115 ctm
= parentCTM
* ctm
;
122 AffineTransform
SVGLocatable::getScreenCTM(const SVGElement
* element
)
125 return AffineTransform();
129 Node
* parent
= element
->parentNode();
130 if (parent
&& parent
->isSVGElement()) {
131 SVGElement
* parentElement
= static_cast<SVGElement
*>(parent
);
132 if (parentElement
&& parentElement
->isStyledLocatable()) {
133 AffineTransform parentCTM
= static_cast<SVGStyledLocatableElement
*>(parentElement
)->getScreenCTM();
134 ctm
= parentCTM
* ctm
;
141 AffineTransform
SVGLocatable::getTransformToElement(SVGElement
* target
, ExceptionCode
& ec
) const
143 AffineTransform ctm
= getCTM();
145 if (target
&& target
->isStyledLocatable()) {
146 AffineTransform targetCTM
= static_cast<SVGStyledLocatableElement
*>(target
)->getCTM();
147 if (!targetCTM
.isInvertible()) {
148 //ec = SVGException::SVG_MATRIX_NOT_INVERTABLE;
151 ctm
*= targetCTM
.inverse();
159 #endif // ENABLE(SVG)