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 "SVGDocument.h" 23 24#include "EventNames.h" 25#include "ExceptionCode.h" 26#include "FrameView.h" 27#include "RenderView.h" 28#include "SVGElement.h" 29#include "SVGNames.h" 30#include "SVGSVGElement.h" 31#include "SVGViewSpec.h" 32#include "SVGZoomAndPan.h" 33#include "SVGZoomEvent.h" 34 35namespace WebCore { 36 37SVGDocument::SVGDocument(Frame* frame, const URL& url) 38 : Document(frame, url, SVGDocumentClass) 39{ 40} 41 42SVGSVGElement* SVGDocument::rootElement() const 43{ 44 Element* elem = documentElement(); 45 if (elem && elem->hasTagName(SVGNames::svgTag)) 46 return toSVGSVGElement(elem); 47 48 return 0; 49} 50 51bool SVGDocument::zoomAndPanEnabled() const 52{ 53 if (rootElement()) { 54 if (rootElement()->useCurrentView()) { 55 if (rootElement()->currentView()) 56 return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPanMagnify; 57 } else 58 return rootElement()->zoomAndPan() == SVGZoomAndPanMagnify; 59 } 60 61 return false; 62} 63 64void SVGDocument::startPan(const FloatPoint& start) 65{ 66 if (rootElement()) 67 m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), start.y() - rootElement()->currentTranslate().y()); 68} 69 70void SVGDocument::updatePan(const FloatPoint& pos) const 71{ 72 if (rootElement()) { 73 rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), pos.y() - m_translate.y())); 74 if (renderView()) 75 renderView()->repaint(); 76 } 77} 78 79bool SVGDocument::childShouldCreateRenderer(const Node& child) const 80{ 81 if (isSVGSVGElement(child)) 82 return toSVGSVGElement(child).isValid(); 83 return true; 84} 85 86PassRefPtr<Document> SVGDocument::cloneDocumentWithoutChildren() const 87{ 88 return create(nullptr, url()); 89} 90 91} 92