2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
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.
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.
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.
22 #include "core/svg/SVGDocument.h"
25 #include "bindings/v8/ExceptionStatePlaceholder.h"
26 #include "core/frame/FrameView.h"
27 #include "core/rendering/RenderView.h"
28 #include "core/svg/SVGElement.h"
29 #include "core/svg/SVGSVGElement.h"
30 #include "core/svg/SVGViewSpec.h"
31 #include "core/svg/SVGZoomAndPan.h"
32 #include "core/svg/SVGZoomEvent.h"
36 SVGDocument::SVGDocument(const DocumentInit& initializer)
37 : XMLDocument(initializer, XMLDocumentClass | SVGDocumentClass)
41 SVGSVGElement* SVGDocument::rootElement(const Document& document)
43 Element* elem = document.documentElement();
44 return isSVGSVGElement(elem) ? toSVGSVGElement(elem) : 0;
47 SVGSVGElement* SVGDocument::rootElement() const
49 return rootElement(*this);
52 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale)
54 RefPtr<SVGZoomEvent> event = SVGZoomEvent::create();
55 event->initEvent(EventTypeNames::zoom, true, false);
56 event->setPreviousScale(prevScale);
57 event->setNewScale(newScale);
58 rootElement()->dispatchEvent(event.release(), IGNORE_EXCEPTION);
61 void SVGDocument::dispatchScrollEvent()
63 RefPtr<Event> event = Event::create();
64 event->initEvent(EventTypeNames::scroll, true, false);
65 rootElement()->dispatchEvent(event.release(), IGNORE_EXCEPTION);
68 bool SVGDocument::zoomAndPanEnabled() const
70 if (SVGSVGElement* svg = rootElement()) {
71 if (svg->useCurrentView()) {
72 if (svg->currentView())
73 return svg->currentView()->zoomAndPan() == SVGZoomAndPanMagnify;
75 return svg->zoomAndPan() == SVGZoomAndPanMagnify;
82 void SVGDocument::startPan(const FloatPoint& start)
84 if (SVGSVGElement* svg = rootElement())
85 m_translate = FloatPoint(start.x() - svg->currentTranslate().x(), start.y() - svg->currentTranslate().y());
88 void SVGDocument::updatePan(const FloatPoint& pos) const
90 if (SVGSVGElement* svg = rootElement()) {
91 svg->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), pos.y() - m_translate.y()));
93 renderer()->repaint();
97 PassRefPtr<Document> SVGDocument::cloneDocumentWithoutChildren()
99 return create(DocumentInit(url()));