Changeset 24349 in webkit


Ignore:
Timestamp:
Jul 16, 2007 9:07:37 PM (17 years ago)
Author:
rwlbuis
Message:

Reviewed by Nikolas.

http://bugs.webkit.org/show_bug.cgi?id=5996
SVG <view> is unimplemented

Implement <view> and refactor the code in the svg renderer container classes.

Location:
branches/feature-branch
Files:
31 added
27 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-branch/LayoutTests/ChangeLog

    r24320 r24349  
     12007-07-17  Rob Buis  <buis@kde.org>
     2
     3        Reviewed by Nikolas.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=5996
     6        SVG <view> is unimplemented
     7
     8        Testcases for each possible viewSpec fragment and a test that
     9        uses all fragments.
     10
     11        * svg/custom/linking-a-03-b-all-expected.checksum: Added.
     12        * svg/custom/linking-a-03-b-all-expected.png: Added.
     13        * svg/custom/linking-a-03-b-all-expected.txt: Added.
     14        * svg/custom/linking-a-03-b-all.svg: Added.
     15        * svg/custom/linking-a-03-b-preserveAspectRatio-expected.checksum: Added.
     16        * svg/custom/linking-a-03-b-preserveAspectRatio-expected.png: Added.
     17        * svg/custom/linking-a-03-b-preserveAspectRatio-expected.txt: Added.
     18        * svg/custom/linking-a-03-b-preserveAspectRatio.svg: Added.
     19        * svg/custom/linking-a-03-b-transform-expected.checksum: Added.
     20        * svg/custom/linking-a-03-b-transform-expected.png: Added.
     21        * svg/custom/linking-a-03-b-transform-expected.txt: Added.
     22        * svg/custom/linking-a-03-b-transform.svg: Added.
     23        * svg/custom/linking-a-03-b-viewBox-expected.checksum: Added.
     24        * svg/custom/linking-a-03-b-viewBox-expected.png: Added.
     25        * svg/custom/linking-a-03-b-viewBox-expected.txt: Added.
     26        * svg/custom/linking-a-03-b-viewBox-transform-expected.checksum: Added.
     27        * svg/custom/linking-a-03-b-viewBox-transform-expected.png: Added.
     28        * svg/custom/linking-a-03-b-viewBox-transform-expected.txt: Added.
     29        * svg/custom/linking-a-03-b-viewBox-transform.svg: Added.
     30        * svg/custom/linking-a-03-b-viewBox.svg: Added.
     31        * svg/custom/linking-a-03-b-viewTarget-expected.checksum: Added.
     32        * svg/custom/linking-a-03-b-viewTarget-expected.png: Added.
     33        * svg/custom/linking-a-03-b-viewTarget-expected.txt: Added.
     34        * svg/custom/linking-a-03-b-viewTarget.svg: Added.
     35        * svg/custom/linking-a-03-b-zoomAndPan-expected.checksum: Added.
     36        * svg/custom/linking-a-03-b-zoomAndPan-expected.png: Added.
     37        * svg/custom/linking-a-03-b-zoomAndPan-expected.txt: Added.
     38        * svg/custom/linking-a-03-b-zoomAndPan.svg: Added.
     39        * svg/custom/resources/linkingCircle-f.svg: Added.
     40
    1412007-07-16  Nikolas Zimmermann  <zimmermann@kde.org>
    242
  • branches/feature-branch/WebCore/ChangeLog

    r24320 r24349  
     12007-07-17  Rob Buis  <buis@kde.org>
     2
     3        Reviewed by Nikolas.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=5996
     6        SVG <view> is unimplemented
     7
     8        Implement <view> and refactor the code in the svg renderer container classes.
     9
     10        * WebCore.xcodeproj/project.pbxproj:
     11        * ksvg2/svg/SVGDocument.cpp:
     12        (WebCore::SVGDocument::zoomAndPanEnabled): Take into account currentView for zoom/pan
     13        * ksvg2/svg/SVGDocument.h:
     14        * ksvg2/svg/SVGFEImageElement.cpp:
     15        (WebCore::SVGFEImageElement::parseMappedAttribute):
     16        * ksvg2/svg/SVGFitToViewBox.cpp:
     17        (WebCore::SVGFitToViewBox::parseViewBox):
     18        (WebCore::SVGFitToViewBox::parseMappedAttribute):
     19        * ksvg2/svg/SVGFitToViewBox.h:
     20        * ksvg2/svg/SVGImageElement.cpp:
     21        (WebCore::SVGImageElement::parseMappedAttribute):
     22        * ksvg2/svg/SVGLocatable.h:
     23        * ksvg2/svg/SVGMarkerElement.cpp:
     24        (WebCore::SVGMarkerElement::createRenderer):
     25        (WebCore::SVGMarkerElement::notifyAttributeChange):
     26        * ksvg2/svg/SVGPreserveAspectRatio.cpp:
     27        (WebCore::SVGPreserveAspectRatio::parsePreserveAspectRatio):
     28        * ksvg2/svg/SVGPreserveAspectRatio.h:
     29        * ksvg2/svg/SVGSVGElement.cpp:
     30        (WebCore::SVGSVGElement::SVGSVGElement):
     31        (WebCore::SVGSVGElement::currentView):
     32        (WebCore::SVGSVGElement::parseMappedAttribute):
     33        (WebCore::SVGSVGElement::createRenderer):
     34        (WebCore::SVGSVGElement::viewBoxToViewTransform):
     35        (WebCore::SVGSVGElement::inheritViewAttributes):
     36        * ksvg2/svg/SVGSVGElement.h:
     37        * ksvg2/svg/SVGTransformable.cpp:
     38        (WebCore::SVGTransformable::parseTransformAttribute):
     39        * ksvg2/svg/SVGTransformable.h:
     40        * ksvg2/svg/SVGViewElement.cpp:
     41        (WebCore::SVGViewElement::parseMappedAttribute):
     42        * ksvg2/svg/SVGViewElement.h:
     43        * ksvg2/svg/SVGViewSpec.cpp: Added.
     44        (WebCore::SVGViewSpec::SVGViewSpec):
     45        (WebCore::SVGViewSpec::~SVGViewSpec):
     46        (WebCore::SVGViewSpec::setTransform):
     47        (WebCore::SVGViewSpec::setViewBoxString):
     48        (WebCore::SVGViewSpec::setPreserveAspectRatioString):
     49        (WebCore::SVGViewSpec::setViewTargetString):
     50        (WebCore::SVGViewSpec::viewTarget):
     51        (WebCore::SVGViewSpec::contextElement):
     52        (WebCore::):
     53        (WebCore::SVGViewSpec::parseViewSpec):
     54        * ksvg2/svg/SVGViewSpec.h: Added.
     55        (WebCore::SVGViewSpec::transform):
     56        (WebCore::SVGViewSpec::viewTargetString):
     57        * ksvg2/svg/SVGZoomAndPan.cpp:
     58        (WebCore::SVGZoomAndPan::parseMappedAttribute):
     59        (WebCore::):
     60        (WebCore::SVGZoomAndPan::parseZoomAndPan):
     61        * ksvg2/svg/SVGZoomAndPan.h:
     62        * loader/FrameLoader.cpp:
     63        (WebCore::FrameLoader::gotoAnchor):
     64        * page/Frame.cpp:
     65        (WebCore::Frame::setZoomFactor): do not zoom when it is disabled
     66        * rendering/RenderSVGContainer.cpp:
     67        (WebCore::RenderSVGContainer::RenderSVGContainer):
     68        (WebCore::RenderSVGContainer::paint):
     69        (WebCore::RenderSVGContainer::viewportTransform):
     70        * rendering/RenderSVGContainer.h:
     71        * rendering/RenderSVGRoot.cpp:
     72        (WebCore::RenderSVGRoot::RenderSVGRoot):
     73        (WebCore::RenderSVGRoot::applyContentTransforms):
     74        (WebCore::RenderSVGRoot::paint):
     75        (WebCore::RenderSVGRoot::absoluteTransform):
     76        (WebCore::RenderSVGRoot::localTransform):
     77        * rendering/RenderSVGRoot.h:
     78
    1792007-07-16  Nikolas Zimmermann  <zimmermann@kde.org>
    280
  • branches/feature-branch/WebCore/WebCore.xcodeproj/project.pbxproj

    r24169 r24349  
    22592259                AA31B5B40C1DFD1000AE7083 /* RenderSVGRoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA31B5B20C1DFD1000AE7083 /* RenderSVGRoot.cpp */; };
    22602260                AA31B5B50C1DFD1000AE7083 /* RenderSVGRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = AA31B5B30C1DFD1000AE7083 /* RenderSVGRoot.h */; };
     2261                AA4038900C4C0D8B00DB56DC /* SVGViewSpec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA40388E0C4C0D8B00DB56DC /* SVGViewSpec.cpp */; };
     2262                AA4038910C4C0D8B00DB56DC /* SVGViewSpec.h in Headers */ = {isa = PBXBuildFile; fileRef = AA40388F0C4C0D8B00DB56DC /* SVGViewSpec.h */; };
    22612263                AA4C3A760B2B1679002334A2 /* StyleElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA4C3A740B2B1679002334A2 /* StyleElement.cpp */; };
    22622264                AA4C3A770B2B1679002334A2 /* StyleElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AA4C3A750B2B1679002334A2 /* StyleElement.h */; };
     
    53965398                AA31B5B20C1DFD1000AE7083 /* RenderSVGRoot.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGRoot.cpp; sourceTree = "<group>"; };
    53975399                AA31B5B30C1DFD1000AE7083 /* RenderSVGRoot.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RenderSVGRoot.h; sourceTree = "<group>"; };
     5400                AA40388E0C4C0D8B00DB56DC /* SVGViewSpec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGViewSpec.cpp; sourceTree = "<group>"; };
     5401                AA40388F0C4C0D8B00DB56DC /* SVGViewSpec.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGViewSpec.h; sourceTree = "<group>"; };
    53985402                AA4C3A740B2B1679002334A2 /* StyleElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = StyleElement.cpp; sourceTree = "<group>"; };
    53995403                AA4C3A750B2B1679002334A2 /* StyleElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StyleElement.h; sourceTree = "<group>"; };
     
    84838487                        isa = PBXGroup;
    84848488                        children = (
     8489                                AA40388E0C4C0D8B00DB56DC /* SVGViewSpec.cpp */,
     8490                                AA40388F0C4C0D8B00DB56DC /* SVGViewSpec.h */,
    84858491                                A84942D80B64A9CA0069F00F /* ColorDistance.cpp */,
    84868492                                A84942D70B64A9CA0069F00F /* ColorDistance.h */,
     
    1146711473                                B223622E0C3AF0710008CA9B /* DOMSVGTextPathElement.h in Headers */,
    1146811474                                B223622F0C3AF0710008CA9B /* DOMSVGTextPathElementInternal.h in Headers */,
     11475                                AA4038910C4C0D8B00DB56DC /* SVGViewSpec.h in Headers */,
    1146911476                        );
    1147011477                        runOnlyForDeploymentPostprocessing = 0;
     
    1286612873                                B22362280C3AF04A0008CA9B /* JSSVGTextPathElement.cpp in Sources */,
    1286712874                                B2AE9B9D0C3AF27400F23F7F /* DOMSVGTextPathElement.mm in Sources */,
     12875                                AA4038900C4C0D8B00DB56DC /* SVGViewSpec.cpp in Sources */,
    1286812876                        );
    1286912877                        runOnlyForDeploymentPostprocessing = 0;
  • branches/feature-branch/WebCore/ksvg2/svg/SVGDocument.cpp

    r21895 r24349  
    3232#include "SVGNames.h"
    3333#include "SVGSVGElement.h"
     34#include "SVGViewSpec.h"
    3435#include "SVGZoomEvent.h"
    3536#include "SVGZoomAndPan.h"
     
    8081bool SVGDocument::zoomAndPanEnabled() const
    8182{
    82     if (rootElement())
    83         return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
     83    if (rootElement()) {
     84        if (rootElement()->useCurrentView()) {
     85            if (rootElement()->currentView())
     86                return rootElement()->currentView()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
     87        } else
     88            return rootElement()->zoomAndPan() == SVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY;
     89    }
    8490
    8591    return false;
  • branches/feature-branch/WebCore/ksvg2/svg/SVGDocument.h

    r21895 r24349  
    4444       
    4545        virtual PassRefPtr<Element> createElement(const String& tagName, ExceptionCode&);
    46        
     46
    4747        void dispatchZoomEvent(float prevScale, float newScale);
    4848        void dispatchScrollEvent();
    4949
    50         virtual bool zoomAndPanEnabled() const;
     50        bool zoomAndPanEnabled() const;
    5151
    5252        void startPan(const FloatPoint& start);
  • branches/feature-branch/WebCore/ksvg2/svg/SVGFEImageElement.cpp

    r24194 r24349  
    6060{
    6161    const String& value = attr->value();
    62     if (attr->name() == SVGNames::preserveAspectRatioAttr)
    63         preserveAspectRatioBaseValue()->parsePreserveAspectRatio(value);
    64     else {
     62    if (attr->name() == SVGNames::preserveAspectRatioAttr) {
     63        const UChar* c = value.characters();
     64        const UChar* end = c + value.length();
     65        preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
     66    } else {
    6567        if (SVGURIReference::parseMappedAttribute(attr)) {
    6668            if (!href().startsWith("#")) {
  • branches/feature-branch/WebCore/ksvg2/svg/SVGFitToViewBox.cpp

    r24194 r24349  
    4848ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(SVGFitToViewBox, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr.localName(), m_preserveAspectRatio.get())
    4949
    50 void SVGFitToViewBox::parseViewBox(const String& str)
     50bool SVGFitToViewBox::parseViewBox(const UChar*& c, const UChar* end, double& x, double& y, double& w, double& h, bool validate)
    5151{
    52     double x = 0, y = 0, w = 0, h = 0;
    53     const UChar* c = str.characters();
    54     const UChar* end = c + str.length();
    5552    Document* doc = contextElement()->document();
     53    String str(c, end - c);
    5654
    5755    skipOptionalSpaces(c, end);
    5856
    59     if (!(parseNumber(c, end, x) && parseNumber(c, end, y) &&
    60           parseNumber(c, end, w) && parseNumber(c, end, h, false))) {
     57    bool valid = (parseNumber(c, end, x) && parseNumber(c, end, y) &&
     58          parseNumber(c, end, w) && parseNumber(c, end, h, false));
     59    if (!validate)
     60        return true;
     61    if (!valid) {
    6162        doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
    62         return;
     63        return false;
    6364    }
    6465
    65     if (w < 0.0) // check that width is positive
     66    if (w < 0.0) { // check that width is positive
    6667        doc->accessSVGExtensions()->reportError("A negative value for ViewBox width is not allowed");
    67     else if (h < 0.0) // check that height is positive
     68        return false;
     69    } else if (h < 0.0) { // check that height is positive
    6870        doc->accessSVGExtensions()->reportError("A negative value for ViewBox height is not allowed");
    69     else {
     71        return false;
     72    } else {
    7073        skipOptionalSpaces(c, end);
    71         if (c < end) // nothing should come after the last, fourth number
     74        if (c < end) { // nothing should come after the last, fourth number
    7275            doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
    73         else
    74             setViewBoxBaseValue(FloatRect(x, y, w, h));
     76            return false;
     77        }
    7578    }
     79
     80    return true;
    7681}
    7782
     
    9095{
    9196    if (attr->name() == SVGNames::viewBoxAttr) {
    92         parseViewBox(attr->value());
     97        double x = 0, y = 0, w = 0, h = 0;
     98        const UChar* c = attr->value().characters();
     99        const UChar* end = c + attr->value().length();
     100        if (parseViewBox(c, end, x, y, w, h))
     101            setViewBoxBaseValue(FloatRect(x, y, w, h));
    93102        return true;
    94103    } else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
    95         preserveAspectRatioBaseValue()->parsePreserveAspectRatio(attr->value());
     104        const UChar* c = attr->value().characters();
     105        const UChar* end = c + attr->value().length();
     106        preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
    96107        return true;
    97108    }
  • branches/feature-branch/WebCore/ksvg2/svg/SVGFitToViewBox.h

    r19855 r24349  
    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
     
    3737
    3838        // 'SVGFitToViewBox' functions
    39         void parseViewBox(const String&);
    40         AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
     39        bool parseViewBox(const UChar*& start, const UChar* end, double& x, double& y, double& w, double& h, bool validate = true);
     40        virtual AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
    4141
    4242        bool parseMappedAttribute(MappedAttribute*);
  • branches/feature-branch/WebCore/ksvg2/svg/SVGImageElement.cpp

    r24194 r24349  
    7070    else if (attr->name() == SVGNames::yAttr)
    7171        setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
    72     else if (attr->name() == SVGNames::preserveAspectRatioAttr)
    73         preserveAspectRatioBaseValue()->parsePreserveAspectRatio(attr->value());
    74     else if (attr->name() == SVGNames::widthAttr) {
     72    else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
     73        const UChar* c = attr->value().characters();
     74        const UChar* end = c + attr->value().length();
     75        preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
     76    } else if (attr->name() == SVGNames::widthAttr) {
    7577        setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
    7678        addCSSProperty(attr, CSS_PROP_WIDTH, attr->value());
  • branches/feature-branch/WebCore/ksvg2/svg/SVGLocatable.h

    r19855 r24349  
    11/*
    22    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
    3                   2004, 2005 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    4949        AffineTransform getTransformToElement(SVGElement*, ExceptionCode&) const;
    5050
    51     protected:
    5251        static SVGElement* nearestViewportElement(const SVGStyledElement*);
    5352        static SVGElement* farthestViewportElement(const SVGStyledElement*);
     53
     54    protected:
    5455        static FloatRect getBBox(const SVGStyledElement*);
    5556        static AffineTransform getCTM(const SVGElement*);
  • branches/feature-branch/WebCore/ksvg2/svg/SVGMarkerElement.cpp

    r24194 r24349  
    137137{
    138138    RenderSVGContainer* markerContainer = new (arena) RenderSVGContainer(this);
    139     markerContainer->setViewBox(viewBox());
    140     markerContainer->setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType(preserveAspectRatio()->align()));
    141     markerContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
    142139    markerContainer->setDrawsContents(false); // Marker contents will be explicitly drawn.
    143140    return markerContainer;
     
    152149
    153150    // NOTE: This is a typical case, where proper "attributeChanged" usage would reduce the number of updates needed.
    154     if (markerContainer) {
    155         markerContainer->setViewBox(viewBox());
    156         markerContainer->setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType(preserveAspectRatio()->align()));
    157         markerContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
    158     }
     151    if (markerContainer)
     152        markerContainer->setNeedsLayout(true);
    159153
    160154    m_marker->invalidate();
  • branches/feature-branch/WebCore/ksvg2/svg/SVGPreserveAspectRatio.cpp

    r24194 r24349  
    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
     
    6262}
    6363
    64 void SVGPreserveAspectRatio::parsePreserveAspectRatio(const String& string)
     64bool SVGPreserveAspectRatio::parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate)
    6565{
    6666    SVGPreserveAspectRatioType align = SVG_PRESERVEASPECTRATIO_NONE;
    6767    SVGMeetOrSliceType meetOrSlice = SVG_MEETORSLICE_MEET;
    68 
    69     const UChar* currParam = string.characters();
    70     const UChar* end = currParam + string.length();
     68    bool ret = false;
    7169
    7270    if (!skipOptionalSpaces(currParam, end))
     
    150148    }
    151149
    152     if (end != currParam) {
     150    if (end != currParam && validate) {
    153151bail_out:
    154152        // FIXME: Should the two values be set to UNKNOWN instead?
    155153        align = SVG_PRESERVEASPECTRATIO_NONE;
    156154        meetOrSlice = SVG_MEETORSLICE_MEET;
    157     }
     155    } else
     156        ret = true;
    158157
    159158    if (m_align == align && m_meetOrSlice == meetOrSlice)
    160         return;
     159        return ret;
    161160
    162161    m_align = align;
    163162    m_meetOrSlice = meetOrSlice;
     163    return ret;
    164164}
    165165
  • branches/feature-branch/WebCore/ksvg2/svg/SVGPreserveAspectRatio.h

    r24194 r24349  
    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
    2828#include "Shared.h"
     29#include <PlatformString.h>
    2930
    3031namespace WebCore {
     
    7172
    7273        // Helper
    73         void parsePreserveAspectRatio(const String&);
     74        bool parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate = true);
    7475
    7576    protected:
  • branches/feature-branch/WebCore/ksvg2/svg/SVGSVGElement.cpp

    r24292 r24349  
    4141#include "SVGPreserveAspectRatio.h"
    4242#include "SVGTransform.h"
     43#include "SVGTransformList.h"
     44#include "SVGViewElement.h"
     45#include "SVGViewSpec.h"
    4346#include "SVGZoomEvent.h"
    4447#include "SelectionController.h"
     
    6568    , m_useCurrentView(false)
    6669    , m_timeScheduler(new TimeScheduler(doc))
     70    , m_viewSpec(0)
    6771{
    6872    setWidthBaseValue(SVGLength(this, LengthModeWidth, "100%"));
     
    151155{
    152156    m_useCurrentView = currentView;
     157}
     158
     159SVGViewSpec* SVGSVGElement::currentView() const
     160{
     161    if (!m_viewSpec)
     162        m_viewSpec = new SVGViewSpec(this);
     163
     164    return m_viewSpec;
    153165}
    154166
     
    226238            return;
    227239        if (SVGFitToViewBox::parseMappedAttribute(attr) && renderer()) {
    228             if (renderer()->isSVGContainer())
    229                 static_cast<RenderSVGContainer*>(renderer())->setViewBox(viewBox());
    230             else
    231                 static_cast<RenderSVGRoot*>(renderer())->setViewBox(viewBox());
     240            renderer()->setNeedsLayout(true);
    232241            return;
    233242        }
     
    362371RenderObject* SVGSVGElement::createRenderer(RenderArena* arena, RenderStyle*)
    363372{
    364     if (!parentNode()->isSVGElement()) {
    365         RenderSVGRoot* rootContainer = new (arena) RenderSVGRoot(this);
    366         // FIXME: All this setup should be done after attributesChanged, not here.
    367         rootContainer->setViewBox(viewBox());
    368         rootContainer->setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType(preserveAspectRatio()->align()));
    369         rootContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
    370         return rootContainer;
    371     } else  {
    372         RenderSVGContainer* rootContainer = new (arena) RenderSVGContainer(this);
    373 
    374         // FIXME: All this setup should be done after attributesChanged, not here.
    375         rootContainer->setViewBox(viewBox());
    376         rootContainer->setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType(preserveAspectRatio()->align()));
    377         rootContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
    378         return rootContainer;
    379     }
     373    // FIXME: All this setup should be done after attributesChanged, not here.
     374    if (!parentNode()->isSVGElement())
     375        return new (arena) RenderSVGRoot(this);
     376    else
     377        return new (arena) RenderSVGContainer(this);
    380378}
    381379
     
    437435}
    438436
     437AffineTransform SVGSVGElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const
     438{
     439    FloatRect viewBoxRect;
     440    if (useCurrentView()) {
     441        if (currentView()) // what if we should use it but it is not set?
     442            viewBoxRect = currentView()->viewBox();
     443    } else
     444        viewBoxRect = viewBox();
     445    if (!viewBoxRect.width() || !viewBoxRect.height())
     446        return AffineTransform();
     447
     448    AffineTransform ctm = preserveAspectRatio()->getCTM(viewBoxRect.x(),
     449            viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(),
     450            0, 0, viewWidth, viewHeight);
     451
     452    if (useCurrentView() && currentView())
     453        return currentView()->transform()->concatenate().matrix() * ctm;
     454
     455    return ctm;
     456}
     457
     458void SVGSVGElement::inheritViewAttributes(SVGViewElement* viewElement)
     459{
     460    setUseCurrentView(true);
     461    if (viewElement->hasAttribute(SVGNames::viewBoxAttr))
     462        currentView()->setViewBox(viewElement->viewBox());
     463    else
     464        currentView()->setViewBox(viewBox());
     465    if (viewElement->hasAttribute(SVGNames::preserveAspectRatioAttr)) {
     466        currentView()->preserveAspectRatio()->setAlign(viewElement->preserveAspectRatio()->align());
     467        currentView()->preserveAspectRatio()->setMeetOrSlice(viewElement->preserveAspectRatio()->meetOrSlice());
     468    } else {
     469        currentView()->preserveAspectRatio()->setAlign(preserveAspectRatio()->align());
     470        currentView()->preserveAspectRatio()->setMeetOrSlice(preserveAspectRatio()->meetOrSlice());
     471    }
     472    if (viewElement->hasAttribute(SVGNames::zoomAndPanAttr))
     473        currentView()->setZoomAndPan(viewElement->zoomAndPan());
     474    renderer()->setNeedsLayout(true);
     475}
     476
    439477}
    440478
  • branches/feature-branch/WebCore/ksvg2/svg/SVGSVGElement.h

    r23509 r24349  
    3838    class SVGLength;
    3939    class SVGTransform;
    40     class SVGLength;
     40    class SVGViewSpec;
     41    class SVGViewElement;
    4142    class TimeScheduler;
    4243    class SVGSVGElement : public SVGStyledLocatableElement,
     
    7273        void setUseCurrentView(bool currentView);
    7374
    74         // SVGViewSpec* currentView() const;
     75        SVGViewSpec* currentView() const;
    7576
    7677        float currentScale() const;
     
    123124        virtual void attributeChanged(Attribute*, bool preserveDecls = false);
    124125
     126        virtual AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
     127
     128        void inheritViewAttributes(SVGViewElement*);
     129
    125130    protected:
    126131        virtual const SVGElement* contextElement() const { return this; }
     
    145150        TimeScheduler* m_timeScheduler;
    146151        FloatPoint m_translation;
     152        mutable SVGViewSpec* m_viewSpec;
    147153    };
    148154
  • branches/feature-branch/WebCore/ksvg2/svg/SVGTransformable.cpp

    r22021 r24349  
    189189bool SVGTransformable::parseTransformAttribute(SVGTransformList* list, const AtomicString& transform)
    190190{
    191     const UChar* currTransform = transform.characters();
    192     const UChar* end = currTransform + transform.length();
    193 
     191    const UChar* start = transform.characters();
     192    const UChar* end = start + transform.length();
     193    return parseTransformAttribute(list, start, end);
     194}
     195
     196bool SVGTransformable::parseTransformAttribute(SVGTransformList* list, const UChar*& currTransform, const UChar* end)
     197{
    194198    bool delimParsed = false;
    195199    while (currTransform < end) {
  • branches/feature-branch/WebCore/ksvg2/svg/SVGTransformable.h

    r22021 r24349  
    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
     
    4646
    4747        static bool parseTransformAttribute(SVGTransformList*, const AtomicString& transform);
     48        static bool parseTransformAttribute(SVGTransformList*, const UChar*& ptr, const UChar* end);
    4849        static bool parseTransformValue(unsigned type, const UChar*& ptr, const UChar* end, SVGTransform&);
    4950        AffineTransform getCTM(const SVGElement*) const;
  • branches/feature-branch/WebCore/ksvg2/svg/SVGViewElement.cpp

    r21272 r24349  
    5959        viewTarget()->reset(attr->value());
    6060    else {
    61         if(SVGExternalResourcesRequired::parseMappedAttribute(attr)
     61        if (SVGExternalResourcesRequired::parseMappedAttribute(attr)
    6262           || SVGFitToViewBox::parseMappedAttribute(attr)
    6363           || SVGZoomAndPan::parseMappedAttribute(attr))
  • branches/feature-branch/WebCore/ksvg2/svg/SVGViewElement.h

    r19908 r24349  
    11/*
    22    Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
    3                   2004, 2005 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    3434    class SVGStringList;
    3535    class SVGViewElement : public SVGStyledElement,
    36                                public SVGExternalResourcesRequired,
    37                                public SVGFitToViewBox,
    38                                public SVGZoomAndPan
     36                           public SVGExternalResourcesRequired,
     37                           public SVGFitToViewBox,
     38                           public SVGZoomAndPan
    3939    {
    4040    public:
  • branches/feature-branch/WebCore/ksvg2/svg/SVGZoomAndPan.cpp

    r21272 r24349  
    2727#include "MappedAttribute.h"
    2828#include "SVGNames.h"
     29#include "SVGParserUtilities.h"
    2930
    3031namespace WebCore {
     
    5253{
    5354    if (attr->name() == SVGNames::zoomAndPanAttr) {
    54         if (attr->value() == "disable")
    55             setZoomAndPan(SVG_ZOOMANDPAN_DISABLE);
    56         else if (attr->value() == "magnify")
    57             setZoomAndPan(SVG_ZOOMANDPAN_MAGNIFY);
     55        const UChar* start = attr->value().characters();
     56        const UChar* end = start + attr->value().length();
     57        parseZoomAndPan(start, end);
    5858        return true;
    5959    }
    6060
    6161    return false;
     62}
     63
     64static const UChar disable[] =  {'d', 'i', 's', 'a', 'b', 'l', 'e'};
     65static const UChar magnify[] =  {'m', 'a', 'g', 'n', 'i', 'f', 'y'};
     66
     67bool SVGZoomAndPan::parseZoomAndPan(const UChar*& start, const UChar* end)
     68{
     69    if (skipString(start, end, disable, sizeof(disable) / sizeof(UChar)))
     70        setZoomAndPan(SVG_ZOOMANDPAN_DISABLE);
     71    else if (skipString(start, end, magnify, sizeof(magnify) / sizeof(UChar)))
     72        setZoomAndPan(SVG_ZOOMANDPAN_MAGNIFY);
     73    else
     74        return false;
     75
     76    return true;
    6277}
    6378
  • branches/feature-branch/WebCore/ksvg2/svg/SVGZoomAndPan.h

    r19855 r24349  
    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
     
    2525#if ENABLE(SVG)
    2626
     27#include "PlatformString.h"
     28
    2729namespace WebCore {
    2830
     
    4648        bool parseMappedAttribute(MappedAttribute*);
    4749
     50        bool parseZoomAndPan(const UChar*& start, const UChar* end);
     51
    4852    private:
    4953        unsigned short m_zoomAndPan;
  • branches/feature-branch/WebCore/loader/FrameLoader.cpp

    r23871 r24349  
    8282#include <kjs/object.h>
    8383
     84#if ENABLE(SVG)
     85#include "SVGDocument.h"
     86#include "SVGLocatable.h"
     87#include "SVGNames.h"
     88#include "SVGPreserveAspectRatio.h"
     89#include "SVGSVGElement.h"
     90#include "SVGViewElement.h"
     91#include "SVGViewSpec.h"
     92#endif
     93
    8494using KJS::UString;
    8595using KJS::JSLock;
     
    8898namespace WebCore {
    8999
     100using namespace SVGNames;
    90101using namespace HTMLNames;
    91102using namespace EventNames;
     
    13681379    if (!anchorNode)
    13691380        anchorNode = m_frame->document()->anchors()->namedItem(name, !m_frame->document()->inCompatMode());
     1381
     1382    if (m_frame->document()->isSVGDocument()) {
     1383        if (name.startsWith("xpointer(")) {
     1384            // We need to parse the xpointer reference here
     1385        } else if (name.startsWith("svgView(")) {
     1386            RefPtr<SVGSVGElement> svg = static_cast<SVGDocument*>(m_frame->document())->rootElement();
     1387            if (!svg->currentView()->parseViewSpec(name))
     1388                return false;
     1389            svg->setUseCurrentView(true);
     1390        } else {
     1391            if (anchorNode && anchorNode->hasTagName(SVGNames::viewTag)) {
     1392                RefPtr<SVGViewElement> viewElement = anchorNode->hasTagName(SVGNames::viewTag) ? static_cast<SVGViewElement*>(anchorNode) : 0;
     1393                if (viewElement.get()) {
     1394                    RefPtr<SVGSVGElement> svg = static_cast<SVGSVGElement*>(SVGLocatable::nearestViewportElement(viewElement.get()));
     1395                    svg->inheritViewAttributes(viewElement.get());
     1396                }
     1397            }
     1398        }
     1399        // FIXME: need to decide which <svg> to focus on, and zoom to that one
     1400        // FIXME: need to actually "highlight" the viewTarget(s)
     1401    }
    13701402
    13711403    m_frame->document()->setCSSTarget(anchorNode); // Setting to null will clear the current target.
  • branches/feature-branch/WebCore/page/Frame.cpp

    r21895 r24349  
    105105
    106106#if ENABLE(SVG)
    107 #include "SVGNames.h"
    108107#include "XLinkNames.h"
    109108#include "SVGDocument.h"
    110109#include "SVGDocumentExtensions.h"
     110#include "SVGNames.h"
    111111#endif
    112112
     
    683683      return;
    684684
     685#if ENABLE(SVG)
     686    if (d->m_doc && d->m_doc->isSVGDocument()) {
     687        if (!static_cast<SVGDocument*>(d->m_doc.get())->zoomAndPanEnabled())
     688            return;
     689        d->m_zoomFactor = percent;
     690        if (d->m_doc->renderer())
     691            d->m_doc->renderer()->repaint();
     692        return;
     693    }
     694#endif
    685695  d->m_zoomFactor = percent;
    686   if (d->m_doc) {
    687 #if ENABLE(SVG)
    688     if (d->m_doc->isSVGDocument()) {
    689          if (d->m_doc->renderer())
    690              d->m_doc->renderer()->repaint();
    691          return;
    692     }
    693 #endif
     696  if (d->m_doc)
    694697      d->m_doc->recalcStyle(Node::Force);
    695   }
    696698
    697699  for (Frame* child = tree()->firstChild(); child; child = child->tree()->nextSibling())
  • branches/feature-branch/WebCore/rendering/RenderSVGContainer.cpp

    r24292 r24349  
    3030#include "GraphicsContext.h"
    3131#include "RenderView.h"
     32#include "SVGFitToViewBox.h"
    3233#include "SVGLength.h"
    3334#include "SVGMarkerElement.h"
     
    4950    , m_height(0)
    5051    , m_drawsContents(true)
    51     , m_slice(false)
    5252{
    5353    setReplaced(true);
     
    357357    }
    358358
    359     if (!viewBox().isEmpty())
    360         paintInfo.context->concatCTM(viewportTransform());
     359    paintInfo.context->concatCTM(viewportTransform());
    361360
    362361    // default implementation. Just pass paint through to the children
     
    412411}
    413412
    414 void RenderSVGContainer::setViewBox(const FloatRect& viewBox)
    415 {
    416     m_viewBox = viewBox;
    417 
    418     if (style())
    419         setNeedsLayout(true);
    420 }
    421 
    422 FloatRect RenderSVGContainer::viewBox() const
    423 {
    424     return m_viewBox;
    425 }
    426 
    427 void RenderSVGContainer::setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType align)
    428 {
    429     m_align = align;
    430     if (style())
    431         setNeedsLayout(true);
    432 }
    433 
    434 SVGPreserveAspectRatio::SVGPreserveAspectRatioType RenderSVGContainer::align() const
    435 {
    436     return m_align;
    437 }
    438 
    439413AffineTransform RenderSVGContainer::viewportTransform() const
    440414{
    441     // FIXME: The method name is confusing, since it does not
    442     // do viewport translating anymore. Look into this while
    443     //  fixing bug 12207.
    444     if (!viewBox().isEmpty())
    445         return getAspectRatio(viewBox(), viewport());
    446 
    447     return AffineTransform();
     415    if (element()->hasTagName(SVGNames::svgTag)) {
     416        SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
     417        return svg->viewBoxToViewTransform(viewport().width(), viewport().height());
     418    } else if (element()->hasTagName(SVGNames::markerTag)) {
     419        SVGMarkerElement* marker = static_cast<SVGMarkerElement*>(element());
     420        return marker->viewBoxToViewTransform(viewport().width(), viewport().height());
     421    }
     422 
     423     return AffineTransform();
    448424}
    449425
     
    520496
    521497    return rect;
    522 }
    523 
    524 void RenderSVGContainer::setSlice(bool slice)
    525 {
    526     m_slice = slice;
    527 
    528     if (style())
    529         setNeedsLayout(true);
    530 }
    531 
    532 bool RenderSVGContainer::slice() const
    533 {
    534     return m_slice;
    535 }
    536 
    537 AffineTransform RenderSVGContainer::getAspectRatio(const FloatRect& logical, const FloatRect& physical) const
    538 {
    539     AffineTransform temp;
    540 
    541     float logicX = logical.x();
    542     float logicY = logical.y();
    543     float logicWidth = logical.width();
    544     float logicHeight = logical.height();
    545     float physWidth = physical.width();
    546     float physHeight = physical.height();
    547 
    548     float vpar = logicWidth / logicHeight;
    549     float svgar = physWidth / physHeight;
    550 
    551     if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
    552         temp.scale(physWidth / logicWidth, physHeight / logicHeight);
    553         temp.translate(-logicX, -logicY);
    554     } else if ((vpar < svgar && !slice()) || (vpar >= svgar && slice())) {
    555         temp.scale(physHeight / logicHeight, physHeight / logicHeight);
    556 
    557         if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX)
    558             temp.translate(-logicX, -logicY);
    559         else if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX)
    560             temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight) / 2, -logicY);
    561         else
    562             temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight), -logicY);
    563     } else {
    564         temp.scale(physWidth / logicWidth, physWidth / logicWidth);
    565 
    566         if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN)
    567             temp.translate(-logicX, -logicY);
    568         else if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID)
    569             temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth) / 2);
    570         else
    571             temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth));
    572     }
    573 
    574     return temp;
    575498}
    576499
  • branches/feature-branch/WebCore/rendering/RenderSVGContainer.h

    r24292 r24349  
    11/*
    22    Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
    3                   2004, 2005 Rob Buis <buis@kde.org>
     3                  2004, 2005, 2007 Rob Buis <buis@kde.org>
    44
    55    This file is part of the KDE project
     
    9292    FloatRect viewport() const;
    9393
    94     void setViewBox(const FloatRect&);
    95     FloatRect viewBox() const;
    96 
    97     void setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType);
    98     SVGPreserveAspectRatio::SVGPreserveAspectRatioType align() const;
    99 
    100     void setSlice(bool);
    101     bool slice() const;
    102    
    10394    AffineTransform viewportTransform() const;
    10495   
     
    110101    int calcReplacedHeight() const;
    111102
    112     AffineTransform getAspectRatio(const FloatRect& logical, const FloatRect& physical) const;
    113103    void applyContentTransforms(PaintInfo&);
    114104
     
    120110
    121111    bool m_drawsContents : 1;
    122     bool m_slice : 1;
    123112
    124113    AffineTransform m_matrix;
    125114   
    126115    FloatRect m_viewport;
    127     FloatRect m_viewBox;
    128     SVGPreserveAspectRatio::SVGPreserveAspectRatioType m_align;
    129116    IntRect m_absoluteBounds;
    130117};
  • branches/feature-branch/WebCore/rendering/RenderSVGRoot.cpp

    r24296 r24349  
    2828
    2929#include "GraphicsContext.h"
     30#include "RenderPath.h"
    3031#include "RenderView.h"
    3132#include "SVGLength.h"
     
    4243RenderSVGRoot::RenderSVGRoot(SVGStyledElement* node)
    4344    : RenderContainer(node)
    44     , m_slice(false)
    4545{
    4646    setReplaced(true);
     
    4949RenderSVGRoot::~RenderSVGRoot()
    5050{
    51 }
    52 
    53 AffineTransform RenderSVGRoot::localTransform() const
    54 {
    55     return m_matrix;
    56 }
    57 
    58 void RenderSVGRoot::setLocalTransform(const AffineTransform& matrix)
    59 {
    60     m_matrix = matrix;
    6151}
    6252
     
    142132    }
    143133
    144     if (!localTransform().isIdentity())
    145         paintInfo.context->concatCTM(localTransform());
    146 
    147134    paintInfo.context->concatCTM(AffineTransform().translate(svg->currentTranslate().x(), svg->currentTranslate().y()));
    148135}
     
    158145        calcViewport();
    159146
     147    SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
    160148    // A value of zero disables rendering of the element.
    161149    if (viewport().width() <= 0. || viewport().height() <= 0.)
     
    198186    }
    199187
    200     if (!viewBox().isEmpty())
    201         childPaintInfo.context->concatCTM(viewportTransform());
     188    paintInfo.context->concatCTM(svg->viewBoxToViewTransform(width(), height()));
    202189
    203190    RenderContainer::paint(childPaintInfo, 0, 0);
     
    239226        m_viewport = FloatRect(x, y, w, h);
    240227    }
    241 }
    242 
    243 void RenderSVGRoot::setViewBox(const FloatRect& viewBox)
    244 {
    245     m_viewBox = viewBox;
    246 
    247     if (style())
    248         setNeedsLayout(true);
    249 }
    250 
    251 FloatRect RenderSVGRoot::viewBox() const
    252 {
    253     return m_viewBox;
    254 }
    255 
    256 void RenderSVGRoot::setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType align)
    257 {
    258     m_align = align;
    259     if (style())
    260         setNeedsLayout(true);
    261 }
    262 
    263 SVGPreserveAspectRatio::SVGPreserveAspectRatioType RenderSVGRoot::align() const
    264 {
    265     return m_align;
    266 }
    267 
    268 AffineTransform RenderSVGRoot::viewportTransform() const
    269 {
    270     // FIXME: The method name is confusing, since it does not
    271     // do viewport translating anymore. Look into this while
    272     //  fixing bug 12207.
    273     if (!viewBox().isEmpty()) {
    274         FloatRect viewportRect = viewport();
    275         viewportRect = FloatRect(viewport().x(), viewport().y(), width(), height());
    276 
    277         return getAspectRatio(viewBox(), viewportRect);
    278     }
    279 
    280     return AffineTransform();
    281228}
    282229
     
    316263    ctm.translate(svg->currentTranslate().x(), svg->currentTranslate().y());
    317264    ctm.translate(viewport().x(), viewport().y());
    318     return viewportTransform() * ctm;
     265    return svg->viewBoxToViewTransform(width(), height()) * ctm;
    319266}
    320267
     
    359306}
    360307
    361 void RenderSVGRoot::setSlice(bool slice)
    362 {
    363     m_slice = slice;
    364 
    365     if (style())
    366         setNeedsLayout(true);
    367 }
    368 
    369 bool RenderSVGRoot::slice() const
    370 {
    371     return m_slice;
    372 }
    373 
    374 AffineTransform RenderSVGRoot::getAspectRatio(const FloatRect& logical, const FloatRect& physical) const
    375 {
    376     AffineTransform temp;
    377 
    378     float logicX = logical.x();
    379     float logicY = logical.y();
    380     float logicWidth = logical.width();
    381     float logicHeight = logical.height();
    382     float physWidth = physical.width();
    383     float physHeight = physical.height();
    384 
    385     float vpar = logicWidth / logicHeight;
    386     float svgar = physWidth / physHeight;
    387 
    388     if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
    389         temp.scale(physWidth / logicWidth, physHeight / logicHeight);
    390         temp.translate(-logicX, -logicY);
    391     } else if ((vpar < svgar && !slice()) || (vpar >= svgar && slice())) {
    392         temp.scale(physHeight / logicHeight, physHeight / logicHeight);
    393 
    394         if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX)
    395             temp.translate(-logicX, -logicY);
    396         else if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX)
    397             temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight) / 2, -logicY);
    398         else
    399             temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight), -logicY);
    400     } else {
    401         temp.scale(physWidth / logicWidth, physWidth / logicWidth);
    402 
    403         if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN)
    404             temp.translate(-logicX, -logicY);
    405         else if (align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID)
    406             temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth) / 2);
    407         else
    408             temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth));
    409     }
    410 
    411     return temp;
     308AffineTransform RenderSVGRoot::localTransform() const
     309{
     310    return AffineTransform();
    412311}
    413312
  • branches/feature-branch/WebCore/rendering/RenderSVGRoot.h

    r24292 r24349  
    2626#if ENABLE(SVG)
    2727#include "RenderContainer.h"
    28 #include "RenderPath.h"
    29 #include "SVGPreserveAspectRatio.h"
     28#include "FloatRect.h"
    3029
    3130namespace WebCore {
    3231
    33 class SVGElement;
     32class SVGStyledElement;
     33class AffineTransform;
    3434
    3535class RenderSVGRoot : public RenderContainer {
     
    5858   
    5959    virtual AffineTransform localTransform() const;
    60     void setLocalTransform(const AffineTransform&);
    6160   
    6261    FloatRect viewport() const;
    6362
    64     void setViewBox(const FloatRect&);
    65     FloatRect viewBox() const;
    66 
    67     void setAlign(SVGPreserveAspectRatio::SVGPreserveAspectRatioType);
    68     SVGPreserveAspectRatio::SVGPreserveAspectRatioType align() const;
    69 
    70     void setSlice(bool);
    71     bool slice() const;
    72    
    73     AffineTransform viewportTransform() const;
    74    
    7563    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
    7664   
    7765private:
    7866    void calcViewport();
    79     AffineTransform getAspectRatio(const FloatRect& logical, const FloatRect& physical) const;
    8067    void applyContentTransforms(PaintInfo&, int parentX, int parentY);
    8168
    82     bool m_slice : 1;
    83     AffineTransform m_matrix;
    84    
    8569    FloatRect m_viewport;
    86     FloatRect m_viewBox;
    87     SVGPreserveAspectRatio::SVGPreserveAspectRatioType m_align;
    8870    IntRect m_absoluteBounds;
    8971};
Note: See TracChangeset for help on using the changeset viewer.