Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGDocument.cpp
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 #include "core/svg/SVGDocument.h"
23
24 #include "SVGNames.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"
33
34 namespace WebCore {
35
36 SVGDocument::SVGDocument(const DocumentInit& initializer)
37     : XMLDocument(initializer, XMLDocumentClass | SVGDocumentClass)
38 {
39 }
40
41 SVGSVGElement* SVGDocument::rootElement(const Document& document)
42 {
43     Element* elem = document.documentElement();
44     return isSVGSVGElement(elem) ? toSVGSVGElement(elem) : 0;
45 }
46
47 SVGSVGElement* SVGDocument::rootElement() const
48 {
49     return rootElement(*this);
50 }
51
52 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale)
53 {
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);
59 }
60
61 void SVGDocument::dispatchScrollEvent()
62 {
63     RefPtr<Event> event = Event::create();
64     event->initEvent(EventTypeNames::scroll, true, false);
65     rootElement()->dispatchEvent(event.release(), IGNORE_EXCEPTION);
66 }
67
68 bool SVGDocument::zoomAndPanEnabled() const
69 {
70     if (SVGSVGElement* svg = rootElement()) {
71         if (svg->useCurrentView()) {
72             if (svg->currentView())
73                 return svg->currentView()->zoomAndPan() == SVGZoomAndPanMagnify;
74         } else {
75             return svg->zoomAndPan() == SVGZoomAndPanMagnify;
76         }
77     }
78
79     return false;
80 }
81
82 void SVGDocument::startPan(const FloatPoint& start)
83 {
84     if (SVGSVGElement* svg = rootElement())
85         m_translate = FloatPoint(start.x() - svg->currentTranslate().x(), start.y() - svg->currentTranslate().y());
86 }
87
88 void SVGDocument::updatePan(const FloatPoint& pos) const
89 {
90     if (SVGSVGElement* svg = rootElement()) {
91         svg->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), pos.y() - m_translate.y()));
92         if (renderer())
93             renderer()->repaint();
94     }
95 }
96
97 PassRefPtr<Document> SVGDocument::cloneDocumentWithoutChildren()
98 {
99     return create(DocumentInit(url()));
100 }
101
102 }