WebCore/svg/SVGDocument.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
       
     3                   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 "SVGZoomEvent.h"
       
    34 #include "SVGZoomAndPan.h"
       
    35 
       
    36 namespace WebCore {
       
    37 
       
    38 SVGDocument::SVGDocument(Frame* frame, const KURL& url)
       
    39     : Document(frame, url, false, false)
       
    40 {
       
    41 }
       
    42 
       
    43 SVGDocument::~SVGDocument()
       
    44 {
       
    45 }
       
    46 
       
    47 SVGSVGElement* SVGDocument::rootElement() const
       
    48 {
       
    49     Element* elem = documentElement();
       
    50     if (elem && elem->hasTagName(SVGNames::svgTag))
       
    51         return static_cast<SVGSVGElement*>(elem);
       
    52 
       
    53     return 0;
       
    54 }
       
    55 
       
    56 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale)
       
    57 {
       
    58     ExceptionCode ec = 0;
       
    59     RefPtr<SVGZoomEvent> event = static_pointer_cast<SVGZoomEvent>(createEvent("SVGZoomEvents", ec));
       
    60     event->initEvent(eventNames().zoomEvent, true, false);
       
    61     event->setPreviousScale(prevScale);
       
    62     event->setNewScale(newScale);
       
    63     rootElement()->dispatchEvent(event.release(), ec);
       
    64 }
       
    65 
       
    66 void SVGDocument::dispatchScrollEvent()
       
    67 {
       
    68     ExceptionCode ec = 0;
       
    69     RefPtr<Event> event = createEvent("SVGEvents", ec);
       
    70     event->initEvent(eventNames().scrollEvent, true, false);
       
    71     rootElement()->dispatchEvent(event.release(), ec);
       
    72 }
       
    73 
       
    74 bool SVGDocument::zoomAndPanEnabled() const
       
    75 {
       
    76     if (rootElement()) {
       
    77         if (rootElement()->useCurrentView()) {
       
    78             if (rootElement()->currentView())
       
    79                 return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
       
    80         } else
       
    81             return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
       
    82     }
       
    83 
       
    84     return false;
       
    85 }
       
    86 
       
    87 void SVGDocument::startPan(const FloatPoint& start)
       
    88 {
       
    89     if (rootElement())
       
    90         m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), rootElement()->currentTranslate().y() + start.y());
       
    91 }
       
    92 
       
    93 void SVGDocument::updatePan(const FloatPoint& pos) const
       
    94 {
       
    95     if (rootElement()) {
       
    96         rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), m_translate.y() - pos.y()));
       
    97         if (renderer())
       
    98             renderer()->repaint();
       
    99     }
       
   100 }
       
   101 
       
   102 bool SVGDocument::childShouldCreateRenderer(Node* node) const
       
   103 {
       
   104     if (node->hasTagName(SVGNames::svgTag))
       
   105         return static_cast<SVGSVGElement*>(node)->isValid();
       
   106     return true;
       
   107 }
       
   108 
       
   109 }
       
   110 
       
   111 // vim:ts=4:noet
       
   112 #endif // ENABLE(SVG)