1 /* 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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/dom/EventNames.h" 27 #include "core/dom/NodeRenderingContext.h" 28 #include "core/page/FrameView.h" 29 #include "core/rendering/RenderView.h" 30 #include "core/svg/SVGElement.h" 31 #include "core/svg/SVGSVGElement.h" 32 #include "core/svg/SVGViewSpec.h" 33 #include "core/svg/SVGZoomAndPan.h" 34 #include "core/svg/SVGZoomEvent.h" 35 36 namespace WebCore { 37 38 SVGDocument::SVGDocument(const DocumentInit& initializer) 39 : Document(initializer, SVGDocumentClass) 40 { 41 ScriptWrappable::init(this); 42 } 43 44 SVGSVGElement* SVGDocument::rootElement() const 45 { 46 Element* elem = documentElement(); 47 if (elem && elem->hasTagName(SVGNames::svgTag)) 48 return toSVGSVGElement(elem); 49 50 return 0; 51 } 52 53 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale) 54 { 55 RefPtr<SVGZoomEvent> event = static_pointer_cast<SVGZoomEvent>(createEvent("SVGZoomEvents", IGNORE_EXCEPTION)); 56 event->initEvent(eventNames().zoomEvent, true, false); 57 event->setPreviousScale(prevScale); 58 event->setNewScale(newScale); 59 rootElement()->dispatchEvent(event.release(), IGNORE_EXCEPTION); 60 } 61 62 void SVGDocument::dispatchScrollEvent() 63 { 64 RefPtr<Event> event = createEvent("SVGEvents", IGNORE_EXCEPTION); 65 event->initEvent(eventNames().scrollEvent, true, false); 66 rootElement()->dispatchEvent(event.release(), IGNORE_EXCEPTION); 67 } 68 69 bool SVGDocument::zoomAndPanEnabled() const 70 { 71 if (rootElement()) { 72 if (rootElement()->useCurrentView()) { 73 if (rootElement()->currentView()) 74 return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPanMagnify; 75 } else 76 return rootElement()->zoomAndPan() == SVGZoomAndPanMagnify; 77 } 78 79 return false; 80 } 81 82 void SVGDocument::startPan(const FloatPoint& start) 83 { 84 if (rootElement()) 85 m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), start.y() - rootElement()->currentTranslate().y()); 86 } 87 88 void SVGDocument::updatePan(const FloatPoint& pos) const 89 { 90 if (rootElement()) { 91 rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), pos.y() - m_translate.y())); 92 if (renderer()) 93 renderer()->repaint(); 94 } 95 } 96 97 bool SVGDocument::childShouldCreateRenderer(const NodeRenderingContext& childContext) const 98 { 99 if (childContext.node()->hasTagName(SVGNames::svgTag)) 100 return toSVGSVGElement(childContext.node())->isValid(); 101 return true; 102 } 103 104 } 105