Changeset 21925 in webkit


Ignore:
Timestamp:
May 31, 2007 6:52:31 PM (17 years ago)
Author:
weinig
Message:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=11272
Implement currentScale(), setCurrentScale() and currentTranslate() in SVGSVGElement

Allow zooming and panning, thereby implementing the above methods.

  • ksvg2/svg/SVGDocument.cpp: (WebCore::SVGDocument::zoomEnabled): (WebCore::SVGDocument::startPan): (WebCore::SVGDocument::updatePan):
  • ksvg2/svg/SVGDocument.h:
  • ksvg2/svg/SVGSVGElement.cpp: (WebCore::SVGSVGElement::currentScale): (WebCore::SVGSVGElement::setCurrentScale): (WebCore::SVGSVGElement::currentTranslate): (WebCore::SVGSVGElement::setCurrentTranslate):
  • ksvg2/svg/SVGSVGElement.h:
  • page/EventHandler.cpp: (WebCore::EventHandler::EventHandler): (WebCore::EventHandler::handleMousePressEvent): (WebCore::EventHandler::handleMouseMoveEvent): (WebCore::EventHandler::handleMouseReleaseEvent):
  • page/EventHandler.h:
  • page/Frame.cpp: (WebCore::Frame::setZoomFactor):
  • rendering/RenderSVGContainer.cpp: (WebCore::RenderSVGContainer::layout): (WebCore::RenderSVGContainer::paint): (WebCore::RenderSVGContainer::absoluteTransform):
  • rendering/RenderSVGContainer.h:
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r21924 r21925  
     12007-05-31  Rob Buis  <buis@kde.org>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=11272
     6        Implement currentScale(), setCurrentScale() and currentTranslate() in SVGSVGElement
     7
     8        Allow zooming and panning, thereby implementing the above methods.
     9
     10        * ksvg2/svg/SVGDocument.cpp:
     11        (WebCore::SVGDocument::zoomEnabled):
     12        (WebCore::SVGDocument::startPan):
     13        (WebCore::SVGDocument::updatePan):
     14        * ksvg2/svg/SVGDocument.h:
     15        * ksvg2/svg/SVGSVGElement.cpp:
     16        (WebCore::SVGSVGElement::currentScale):
     17        (WebCore::SVGSVGElement::setCurrentScale):
     18        (WebCore::SVGSVGElement::currentTranslate):
     19        (WebCore::SVGSVGElement::setCurrentTranslate):
     20        * ksvg2/svg/SVGSVGElement.h:
     21        * page/EventHandler.cpp:
     22        (WebCore::EventHandler::EventHandler):
     23        (WebCore::EventHandler::handleMousePressEvent):
     24        (WebCore::EventHandler::handleMouseMoveEvent):
     25        (WebCore::EventHandler::handleMouseReleaseEvent):
     26        * page/EventHandler.h:
     27        * page/Frame.cpp:
     28        (WebCore::Frame::setZoomFactor):
     29        * rendering/RenderSVGContainer.cpp:
     30        (WebCore::RenderSVGContainer::layout):
     31        (WebCore::RenderSVGContainer::paint):
     32        (WebCore::RenderSVGContainer::absoluteTransform):
     33        * rendering/RenderSVGContainer.h:
     34
    1352007-05-31  Eric Seidel  <eric@webkit.org>
    236
  • trunk/WebCore/ksvg2/svg/SVGDocument.cpp

    r21179 r21925  
    11/*
    22    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
    3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    2727#include "EventNames.h"
    2828#include "ExceptionCode.h"
     29#include "FrameView.h"
     30#include "RenderView.h"
    2931#include "SVGElement.h"
    3032#include "SVGNames.h"
    3133#include "SVGSVGElement.h"
    3234#include "SVGZoomEvent.h"
     35#include "SVGZoomAndPan.h"
    3336
    3437namespace WebCore {
     
    7578}
    7679
     80bool SVGDocument::zoomAndPanEnabled() const
     81{
     82    if (rootElement())
     83        return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
     84
     85    return false;
     86}
     87
     88void SVGDocument::startPan(const FloatPoint& start)
     89{
     90    if (rootElement())
     91        m_translate = FloatPoint(start.x() - rootElement()->currentTranslate().x(), rootElement()->currentTranslate().y() + start.y());
     92}
     93
     94void SVGDocument::updatePan(const FloatPoint& pos) const
     95{
     96    if (rootElement()) {
     97        rootElement()->setCurrentTranslate(FloatPoint(pos.x() - m_translate.x(), m_translate.y() - pos.y()));
     98        if (renderer())
     99            renderer()->repaint();
     100    }
     101}
     102
    77103}
    78104
  • trunk/WebCore/ksvg2/svg/SVGDocument.h

    r21179 r21925  
    11/*
    22    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
    3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    2626
    2727#include "Document.h"
     28#include "FloatPoint.h"
    2829
    2930namespace WebCore {
    3031
     32    class DOMImplementation;
    3133    class SVGElement;
    3234    class SVGSVGElement;
    33     class DOMImplementation;
    3435
    3536    class SVGDocument : public Document {
     
    4647        void dispatchZoomEvent(float prevScale, float newScale);
    4748        void dispatchScrollEvent();
     49
     50        virtual bool zoomAndPanEnabled() const;
     51
     52        void startPan(const FloatPoint& start);
     53        void updatePan(const FloatPoint& pos) const;
     54
     55    private:
     56        FloatPoint m_translate;
    4857    };
    4958
  • trunk/WebCore/ksvg2/svg/SVGSVGElement.cpp

    r21820 r21925  
    159159float SVGSVGElement::currentScale() const
    160160{
    161     // FIXME: Return the current zoom/scale value (see bug 11272)
    162     return 1.;
     161    if (document() && document()->frame())
     162        return document()->frame()->zoomFactor() / 100.0f;
     163    return 1.0f;
    163164}
    164165
    165166void SVGSVGElement::setCurrentScale(float scale)
    166167{
    167     // FIXME: Set the current zoom/scale value (see bug 11272)
     168    if (document() && document()->frame())
     169        document()->frame()->setZoomFactor(scale / 100.0f);
    168170}
    169171
    170172FloatPoint SVGSVGElement::currentTranslate() const
    171173{
    172     // FIXME: Return the current pan/translate value (see bug 11272)
    173     return FloatPoint();
     174    return m_translation;
     175}
     176
     177void SVGSVGElement::setCurrentTranslate(const FloatPoint &translation)
     178{
     179    m_translation = translation;
    174180}
    175181
     
    399405}
    400406
    401 void SVGSVGElement::setZoomAndPan(unsigned short zoomAndPan)
    402 {
    403     SVGZoomAndPan::setZoomAndPan(zoomAndPan);
    404     //canvasView()->enableZoomAndPan(zoomAndPan == SVG_ZOOMANDPAN_MAGNIFY);
    405 }
    406 
    407407void SVGSVGElement::pauseAnimations()
    408408{
  • trunk/WebCore/ksvg2/svg/SVGSVGElement.h

    r19855 r21925  
    11/*
    22    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
    3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    7878
    7979        FloatPoint currentTranslate() const;
     80        void setCurrentTranslate(const FloatPoint&);
    8081       
    8182        TimeScheduler* timeScheduler() { return m_timeScheduler; }
     
    120121        virtual void removedFromDocument();
    121122
    122         // 'virtual SVGZoomAndPan functions
    123         virtual void setZoomAndPan(unsigned short zoomAndPan);
    124 
    125123        virtual void attributeChanged(Attribute*, bool preserveDecls = false);
    126124
     
    145143        bool m_useCurrentView;
    146144        TimeScheduler* m_timeScheduler;
     145        FloatPoint m_translation;
    147146    };
    148147
  • trunk/WebCore/page/EventHandler.cpp

    r21749 r21925  
    6262#if ENABLE(SVG)
    6363#include "SVGCursorElement.h"
     64#include "SVGDocument.h"
    6465#include "SVGLength.h"
    6566#include "SVGNames.h"
     
    100101    , m_mouseDownMayStartAutoscroll(false)
    101102    , m_mouseDownWasInSubframe(false)
     103#if ENABLE(SVG)
     104    , m_svgPan(false)
     105#endif
    102106    , m_resizeLayer(0)
    103107    , m_capturingMouseEventsNode(0)
     
    276280    if (passWidgetMouseDownEventToWidget(event))
    277281        return true;
     282
     283#if ENABLE(SVG)
     284    if (m_frame->document()->isSVGDocument() &&
     285       static_cast<SVGDocument*>(m_frame->document())->zoomAndPanEnabled()) {
     286        if (event.event().shiftKey() && singleClick) {
     287            m_svgPan = true;
     288            static_cast<SVGDocument*>(m_frame->document())->startPan(event.event().pos());
     289            return true;
     290        }
     291    }
     292#endif
    278293
    279294    // We don't do this at the start of mouse down handling,
     
    893908        m_hoverTimer.stop();
    894909
     910#if ENABLE(SVG)
     911    if (m_svgPan) {
     912        static_cast<SVGDocument*>(m_frame->document())->updatePan(m_currentMousePosition);
     913        return true;
     914    }
     915#endif
    895916    if (m_frameSetBeingResized)
    896917        return dispatchMouseEvent(mousemoveEvent, m_frameSetBeingResized.get(), false, 0, mouseEvent, false);
     
    972993    m_mousePressed = false;
    973994    m_currentMousePosition = mouseEvent.pos();
     995
     996#if ENABLE(SVG)
     997    if (m_svgPan) {
     998        m_svgPan = false;
     999        return true;
     1000    }
     1001#endif
    9741002
    9751003    if (m_frameSetBeingResized)
  • trunk/WebCore/page/EventHandler.h

    r21042 r21925  
    269269    bool m_mouseDownMayStartAutoscroll;
    270270    bool m_mouseDownWasInSubframe;
     271#if ENABLE(SVG)
     272    bool m_svgPan;
     273#endif
    271274
    272275    RenderLayer* m_resizeLayer;
  • trunk/WebCore/page/Frame.cpp

    r21773 r21925  
    642642
    643643  d->m_zoomFactor = percent;
    644 
    645   if (d->m_doc)
     644  if (d->m_doc) {
     645#if ENABLE(SVG)
     646    if (d->m_doc->isSVGDocument()) {
     647         if (d->m_doc->renderer())
     648             d->m_doc->renderer()->repaint();
     649         return;
     650    }
     651#endif
    646652      d->m_doc->recalcStyle(Node::Force);
     653  }
    647654
    648655  for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
  • trunk/WebCore/rendering/RenderSVGContainer.cpp

    r21820 r21925  
    118118
    119119    m_absoluteBounds = absoluteClippedOverflowRect();
     120    if (!parent()->isSVGContainer()) {
     121        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
     122        m_width = float(m_width) * svg->currentScale();
     123        m_height = float(m_height) * svg->currentScale();
     124    }
    120125
    121126    if (selfNeedsLayout() && checkForRepaint)
     
    169174        }
    170175        parentX = parentY = 0;
     176        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
     177        paintInfo.context->concatCTM(AffineTransform().scale(svg->currentScale()));
    171178    } else {
    172179        // Only the root <svg> element should need any translations using the HTML/CSS system
     
    184191        paintInfo.context->concatCTM(AffineTransform().translate(viewport().x(), viewport().y()));
    185192    }
    186 
    187193    if (!localTransform().isIdentity())
    188194        paintInfo.context->concatCTM(localTransform());
     195    if (!parent()->isSVGContainer()) {
     196        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
     197        paintInfo.context->concatCTM(AffineTransform().translate(svg->currentTranslate().x(), svg->currentTranslate().y()));
     198    }
    189199
    190200    FloatRect strokeBBox = relativeBBox(true);
     
    342352{
    343353    AffineTransform ctm = RenderContainer::absoluteTransform();
     354    if (!parent()->isSVGContainer()) {
     355        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
     356        ctm.scale(svg->currentScale());
     357        ctm.translate(svg->currentTranslate().x(), svg->currentTranslate().y());
     358    }
    344359    ctm.translate(viewport().x(), viewport().y());
    345360    return viewportTransform() * ctm;
Note: See TracChangeset for help on using the changeset viewer.