1 /*
2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #if ENABLE(SVG)
23 #include "SVGDocument.h"
24
25 #include "EventNames.h"
26 #include "ExceptionCode.h"
27 #include "FrameView.h"
28 #include "RenderView.h"
29 #include "SVGElement.h"
30 #include "SVGNames.h"
31 #include "SVGSVGElement.h"
32 #include "SVGViewSpec.h"
33 #include "SVGZoomAndPan.h"
34 #include "SVGZoomEvent.h"
35
36 namespace WebCore {
37
SVGDocument(Frame * frame,const KURL & url)38 SVGDocument::SVGDocument(Frame* frame, const KURL& url)
39 : Document(frame, url, false, false)
40 {
41 }
42
rootElement() const43 SVGSVGElement* SVGDocument::rootElement() const
44 {
45 Element* elem = documentElement();
46 if (elem && elem->hasTagName(SVGNames::svgTag))
47 return static_cast<SVGSVGElement*>(elem);
48
49 return 0;
50 }
51
dispatchZoomEvent(float prevScale,float newScale)52 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale)
53 {
54 ExceptionCode ec = 0;
55 RefPtr<SVGZoomEvent> event = static_pointer_cast<SVGZoomEvent>(createEvent("SVGZoomEvents", ec));
56 event->initEvent(eventNames().zoomEvent, true, false);
57 event->setPreviousScale(prevScale);
58 event->setNewScale(newScale);
59 rootElement()->dispatchEvent(event.release(), ec);
60 }
61
dispatchScrollEvent()62 void SVGDocument::dispatchScrollEvent()
63 {
64 ExceptionCode ec = 0;
65 RefPtr<Event> event = createEvent("SVGEvents", ec);
66 event->initEvent(eventNames().scrollEvent, true, false);
67 rootElement()->dispatchEvent(event.release(), ec);
68 }
69
zoomAndPanEnabled() const70 bool SVGDocument::zoomAndPanEnabled() const
71 {
72 if (rootElement()) {
73 if (rootElement()->useCurrentView()) {
74 if (rootElement()->currentView())
75 return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
76 } else
77 return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
78 }
79
80 return false;
81 }
82
startPan(const FloatPoint & start)83 void SVGDocument::startPan(const FloatPoint& start)
84 {
85 if (rootElement())
86 m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), rootElement()->currentTranslate().y() + start.y());
87 }
88
updatePan(const FloatPoint & pos) const89 void SVGDocument::updatePan(const FloatPoint& pos) const
90 {
91 if (rootElement()) {
92 rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), m_translate.y() - pos.y()));
93 if (renderer())
94 renderer()->repaint();
95 }
96 }
97
childShouldCreateRenderer(Node * node) const98 bool SVGDocument::childShouldCreateRenderer(Node* node) const
99 {
100 if (node->hasTagName(SVGNames::svgTag))
101 return static_cast<SVGSVGElement*>(node)->isValid();
102 return true;
103 }
104
105 }
106
107 // vim:ts=4:noet
108 #endif // ENABLE(SVG)
109