don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGLocatable.cpp
blob359e622b410827bd9b88b2fb337f2231b0b3688d
1 /*
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.
23 #include "config.h"
24 #include "wtf/Platform.h"
26 #if ENABLE(SVG)
28 #include "SVGLocatable.h"
30 #include "AffineTransform.h"
31 #include "RenderPath.h"
32 #include "SVGException.h"
33 #include "SVGSVGElement.h"
35 namespace WebCore {
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);
56 #endif
58 n = n->parentNode();
59 }*/
61 return 0;
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);
79 #endif
81 n = n->parentNode();
82 }*/
84 return farthest;
87 // Spec:
88 // http://www.w3.org/TR/2005/WD-SVGMobile12-20050413/svgudom.html#svg::SVGLocatable
89 FloatRect SVGLocatable::getBBox(const SVGStyledElement* e)
91 FloatRect bboxRect;
93 /*if (e && e->renderer()) {
94 // Need this to make sure we have render object dimensions.
95 // See bug 11686.
96 e->document()->updateLayoutIgnorePendingStylesheets();
97 bboxRect = e->renderer()->relativeBBox(false);
98 }*/
100 return bboxRect;
103 AffineTransform SVGLocatable::getCTM(const SVGElement* element)
105 if (!element)
106 return AffineTransform();
108 AffineTransform ctm;
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;
119 return ctm;
122 AffineTransform SVGLocatable::getScreenCTM(const SVGElement* element)
124 if (!element)
125 return AffineTransform();
127 AffineTransform ctm;
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;
138 return 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;
149 return ctm;
151 ctm *= targetCTM.inverse();
154 return ctm;
159 #endif // ENABLE(SVG)
161 // vim:ts=4:noet