Changeset 18652 in webkit


Ignore:
Timestamp:
Jan 7, 2007 8:47:24 AM (17 years ago)
Author:
rwlbuis
Message:

Reviewed by weinig.

http://bugs.webkit.org/show_bug.cgi?id=10362
SVG needs to support SVGError events and some form of "error state"
Report SVG warnings and errors on (JS) console.
Expose line and column number getters in Tokenizer in
order to display them with the error message.

Location:
trunk/WebCore
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r18651 r18652  
     12007-01-07  Rob Buis  <buis@kde.org>
     2
     3        Reviewed by weinig.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=10362
     6        SVG needs to support SVGError events and some form of "error state"
     7
     8        Report SVG warnings and errors on (JS) console.
     9        Expose line and column number getters in Tokenizer in
     10        order to display them with the error message.
     11
     12        * dom/XMLTokenizer.cpp:
     13        * dom/XMLTokenizer.h:
     14        (WebCore::Tokenizer::lineNumber):
     15        (WebCore::Tokenizer::columnNumber):
     16        * html/HTMLTokenizer.h:
     17        (WebCore::HTMLTokenizer::lineNumber):
     18        (WebCore::HTMLTokenizer::columnNumber):
     19        * ksvg2/misc/SVGDocumentExtensions.cpp:
     20        (WebCore::SVGDocumentExtensions::reportWarning):
     21        (WebCore::SVGDocumentExtensions::reportError):
     22        * ksvg2/misc/SVGDocumentExtensions.h:
     23        * ksvg2/svg/SVGCircleElement.cpp:
     24        (WebCore::SVGCircleElement::parseMappedAttribute):
     25        * ksvg2/svg/SVGElement.h:
     26        * ksvg2/svg/SVGEllipseElement.cpp:
     27        (WebCore::SVGEllipseElement::parseMappedAttribute):
     28        * ksvg2/svg/SVGFitToViewBox.cpp:
     29        (WebCore::SVGFitToViewBox::parseViewBox):
     30        * ksvg2/svg/SVGFitToViewBox.h:
     31        * ksvg2/svg/SVGImageElement.cpp:
     32        (WebCore::SVGImageElement::parseMappedAttribute):
     33        * ksvg2/svg/SVGParserUtilities.cpp:
     34        (WebCore::SVGPolyParser::parsePoints):
     35        * ksvg2/svg/SVGParserUtilities.h:
     36        * ksvg2/svg/SVGPathElement.cpp:
     37        (WebCore::SVGPathElement::parseMappedAttribute):
     38        * ksvg2/svg/SVGPatternElement.cpp:
     39        (WebCore::SVGPatternElement::parseMappedAttribute):
     40        * ksvg2/svg/SVGPolyElement.cpp:
     41        (WebCore::SVGPolyElement::parseMappedAttribute):
     42        * ksvg2/svg/SVGRadialGradientElement.cpp:
     43        (WebCore::SVGRadialGradientElement::parseMappedAttribute):
     44        * ksvg2/svg/SVGRectElement.cpp:
     45        (WebCore::SVGRectElement::parseMappedAttribute):
     46        * ksvg2/svg/SVGSVGElement.cpp:
     47        (WebCore::SVGSVGElement::parseMappedAttribute):
     48        * ksvg2/svg/SVGTextContentElement.cpp:
     49        (WebCore::SVGTextContentElement::parseMappedAttribute):
     50        * ksvg2/svg/SVGUseElement.cpp:
     51        (WebCore::SVGUseElement::parseMappedAttribute):
     52
    1532007-01-07  Nikolas Zimmermann  <zimmermann@kde.org>
    254
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r18218 r18652  
    114114    virtual bool wellFormed() const { return !m_sawError; }
    115115
     116    int lineNumber() const;
     117    int columnNumber() const;
     118
    116119private:
    117120    void initializeParserContext();
    118121    void setCurrentNode(Node*);
    119 
    120     int lineNumber() const;
    121     int columnNumber() const;
    122122
    123123    void insertErrorMessageBlock();
  • trunk/WebCore/dom/XMLTokenizer.h

    r17860 r18652  
    6666    virtual bool wellFormed() const { return true; }
    6767
     68    virtual int lineNumber() const { return -1; }
     69    virtual int columnNumber() const { return -1; }
     70
    6871protected:
    6972    // The tokenizer has buffers, so parsing may continue even after
  • trunk/WebCore/html/HTMLTokenizer.h

    r16245 r18652  
    9494    virtual bool processingData() const;
    9595    virtual int executingScript() const { return m_executingScript; }
     96
     97    virtual int lineNumber() const { return lineno; }
     98    virtual int columnNumber() const { return 1; }
    9699
    97100private:
  • trunk/WebCore/ksvg2/misc/SVGDocumentExtensions.cpp

    r18521 r18652  
    22    Copyright (C) 2006 Apple Computer, Inc.
    33                  2006 Nikolas Zimmermann <zimmermann@kde.org>
     4                  2007 Rob Buis <buis@kde.org>
    45
    56    This file is part of the WebKit project
     
    2627#include "SVGDocumentExtensions.h"
    2728
     29#include "AtomicString.h"
     30#include "Chrome.h"
    2831#include "Document.h"
    2932#include "EventListener.h"
    3033#include "Frame.h"
     34#include "FrameLoader.h"
     35#include "Page.h"
     36#include "SVGSVGElement.h"
    3137#include "TimeScheduler.h"
    32 #include "AtomicString.h"
     38#include "XMLTokenizer.h"
    3339#include "kjs_proxy.h"
    34 #include "SVGSVGElement.h"
    3540
    3641namespace WebCore {
     
    8893}
    8994
     95void SVGDocumentExtensions::reportWarning(const String& message)
     96{
     97    if (Page* page = m_doc->frame()->page()) {
     98        page->chrome()->addMessageToConsole("Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
     99    }
     100}
     101
     102void SVGDocumentExtensions::reportError(const String& message)
     103{
     104    if (Page* page = m_doc->frame()->page()) {
     105        page->chrome()->addMessageToConsole("Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
     106    }
     107}
     108
    90109void SVGDocumentExtensions::addPendingResource(const AtomicString& id, SVGStyledElement* obj)
    91110{
  • trunk/WebCore/ksvg2/misc/SVGDocumentExtensions.h

    r18521 r18652  
    6161    void unpauseAnimations();
    6262
     63    void reportWarning(const String&);
     64    void reportError(const String&);
     65
    6366private:
    6467    Document* m_doc; // weak reference
  • trunk/WebCore/ksvg2/svg/SVGCircleElement.cpp

    r18268 r18652  
    5757    else if (attr->name() == SVGNames::cyAttr)
    5858        setCyBaseValue(SVGLength(this, LengthModeHeight, value));
    59     else if (attr->name() == SVGNames::rAttr)
     59    else if (attr->name() == SVGNames::rAttr) {
    6060        setRBaseValue(SVGLength(this, LengthModeOther, value));
    61     else {
     61        if (r().value() < 0.0)
     62            document()->accessSVGExtensions()->reportError("A negative value for circle <r> is not allowed");
     63    } else {
    6264        if (SVGTests::parseMappedAttribute(attr))
    6365            return;
  • trunk/WebCore/ksvg2/svg/SVGElement.h

    r18217 r18652  
    174174
    175175namespace WebCore {
    176     class DocumentPtr;
    177176    class Ecma;
    178177    class SVGPreserveAspectRatio;
  • trunk/WebCore/ksvg2/svg/SVGEllipseElement.cpp

    r18268 r18652  
    6060    else if (attr->name() == SVGNames::cyAttr)
    6161        setCyBaseValue(SVGLength(this, LengthModeHeight, value));
    62     else if (attr->name() == SVGNames::rxAttr)
     62    else if (attr->name() == SVGNames::rxAttr) {
    6363        setRxBaseValue(SVGLength(this, LengthModeWidth, value));
    64     else if (attr->name() == SVGNames::ryAttr)
     64        if (rx().value() < 0.0)
     65            document()->accessSVGExtensions()->reportError("A negative value for ellipse <rx> is not allowed");
     66    } else if (attr->name() == SVGNames::ryAttr) {
    6567        setRyBaseValue(SVGLength(this, LengthModeHeight, value));
    66     else {
     68        if (ry().value() < 0.0)
     69            document()->accessSVGExtensions()->reportError("A negative value for ellipse <ry> is not allowed");
     70    } else {
    6771        if (SVGTests::parseMappedAttribute(attr))
    6872            return;
  • trunk/WebCore/ksvg2/svg/SVGFitToViewBox.cpp

    r18478 r18652  
    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#include "SVGFitToViewBox.h"
    2626
     27#include "AffineTransform.h"
    2728#include "FloatRect.h"
     29#include "SVGDocumentExtensions.h"
    2830#include "SVGNames.h"
    2931#include "SVGParserUtilities.h"
    3032#include "SVGPreserveAspectRatio.h"
    31 #include "SVGSVGElement.h"
    3233#include "StringImpl.h"
    3334
     
    5253    const UChar* c = str.characters();
    5354    const UChar* end = c + str.length();
     55    Document* doc = contextElement()->document();
    5456
    5557    skipOptionalSpaces(c, end);
    5658
    57     if (!parseNumber(c, end, x))
    58         goto bail_out;
     59    if (!(parseNumber(c, end, x) && parseNumber(c, end, y) &&
     60          parseNumber(c, end, w) && parseNumber(c, end, h, false))) {
     61        doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
     62        return;
     63    }
    5964
    60     if (!parseNumber(c, end, y))
    61         goto bail_out;
    62 
    63     if (!parseNumber(c, end, w) || w < 0.0) // check that width is positive
    64         goto bail_out;
    65 
    66     if (!parseNumber(c, end, h, false) || h < 0.0) // check that height is positive
    67         goto bail_out;
    68 
    69     skipOptionalSpaces(c, end);
    70 
    71     if (c < end) // nothing should come after the last, fourth number
    72         goto bail_out;
    73 
    74     setViewBoxBaseValue(FloatRect(x, y, w, h));
    75     return;
    76 
    77 bail_out:;
    78     // FIXME: Per the spec we are supposed to set the document into an "error state" here.
     65    if (w < 0.0) // check that width is positive
     66        doc->accessSVGExtensions()->reportError("A negative value for ViewBox width is not allowed");
     67    else if (h < 0.0) // check that height is positive
     68        doc->accessSVGExtensions()->reportError("A negative value for ViewBox height is not allowed");
     69    else {
     70        skipOptionalSpaces(c, end);
     71        if (c < end) // nothing should come after the last, fourth number
     72            doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
     73        else
     74            setViewBoxBaseValue(FloatRect(x, y, w, h));
     75    }
    7976}
    8077
  • trunk/WebCore/ksvg2/svg/SVGFitToViewBox.h

    r18177 r18652  
    2121*/
    2222
    23 #ifndef KSVG_SVGFitToViewBoxImpl_H
    24 #define KSVG_SVGFitToViewBoxImpl_H
     23#ifndef SVGFitToViewBox_H
     24#define SVGFitToViewBox_H
    2525#ifdef SVG_SUPPORT
    2626
     
    2828
    2929namespace WebCore {
    30     class Attribute;
    3130    class AffineTransform;
    3231    class SVGPreserveAspectRatio;
    33     class StringImpl;
    3432
    3533    class SVGFitToViewBox {
     
    5553
    5654#endif // SVG_SUPPORT
    57 #endif // KSVG_SVGFitToViewBoxImpl_H
     55#endif // SVGFitToViewBox_H
    5856
    5957// vim:ts=4:noet
  • trunk/WebCore/ksvg2/svg/SVGImageElement.cpp

    r18428 r18652  
    7676        setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
    7777        addCSSProperty(attr, CSS_PROP_WIDTH, value);
     78        if (width().value() < 0.0)
     79            document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
    7880    } else if (attr->name() == SVGNames::heightAttr) {
    7981        setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
    8082        addCSSProperty(attr, CSS_PROP_HEIGHT, value);
     83        if (height().value() < 0.0)
     84            document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed");
    8185    } else {
    8286        if (SVGTests::parseMappedAttribute(attr))
  • trunk/WebCore/ksvg2/svg/SVGParserUtilities.cpp

    r18489 r18652  
    110110}
    111111
    112 void SVGPolyParser::parsePoints(const String& s) const
     112bool SVGPolyParser::parsePoints(const String& s) const
    113113{
    114114    if (s.isEmpty())
    115         return;
     115        return true;
    116116    const UChar* cur = s.characters();
    117117    const UChar* end = cur + s.length();
     
    123123        double xPos = 0;
    124124        if (!parseNumber(cur, end, xPos))
    125             break;
     125           return false;
    126126
    127127        double yPos = 0;
    128128        if (!parseNumber(cur, end, yPos))
    129             break;
     129            return false;
    130130
    131131        svgPolyTo(xPos, yPos, segmentNum++);
  • trunk/WebCore/ksvg2/svg/SVGParserUtilities.h

    r18489 r18652  
    7070    public:
    7171        virtual ~SVGPolyParser() { }
    72         void parsePoints(const String &points) const;
     72        bool parsePoints(const String& points) const;
    7373
    7474    protected:
     
    9191    public:
    9292        virtual ~SVGPathParser() { }
    93         bool parseSVG(const String &d, bool process = false);
     93        bool parseSVG(const String& d, bool process = false);
    9494
    9595    protected:
     
    105105        virtual void svgClosePath() = 0;
    106106    private:
    107         void calculateArc(bool relative, double &curx, double &cury, double angle, double x, double y, double r1, double r2, bool largeArcFlag, bool sweepFlag);
     107        void calculateArc(bool relative, double& curx, double& cury, double angle, double x, double y, double r1, double r2, bool largeArcFlag, bool sweepFlag);
    108108    };
    109109
  • trunk/WebCore/ksvg2/svg/SVGPathElement.cpp

    r18518 r18652  
    269269void SVGPathElement::parseMappedAttribute(MappedAttribute* attr)
    270270{
     271    const AtomicString& value = attr->value();
    271272    if (attr->name() == SVGNames::dAttr) {
    272273        ExceptionCode ec;
    273274        pathSegList()->clear(ec);
    274         if (!parseSVG(attr->value(), true))
    275             pathSegList()->clear(ec);
     275        if (!parseSVG(value, true))
     276            document()->accessSVGExtensions()->reportError("Problem parsing d=\"" + value + "\"");
     277    } else if (attr->name() == SVGNames::pathLengthAttr) {
     278        m_pathLength = value.toDouble();
     279        if (m_pathLength < 0.0)
     280            document()->accessSVGExtensions()->reportError("A negative value for path attribute <pathLength> is not allowed");
    276281    } else {
    277282        if (SVGTests::parseMappedAttribute(attr))
  • trunk/WebCore/ksvg2/svg/SVGPatternElement.cpp

    r18641 r18652  
    100100    else if (attr->name() == SVGNames::yAttr)
    101101        setYBaseValue(SVGLength(this, LengthModeHeight, value));
    102     else if (attr->name() == SVGNames::widthAttr)
     102    else if (attr->name() == SVGNames::widthAttr) {
    103103        setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
    104     else if (attr->name() == SVGNames::heightAttr)
     104        if (width().value() < 0.0)
     105            document()->accessSVGExtensions()->reportError("A negative value for pattern attribute <width> is not allowed");
     106    } else if (attr->name() == SVGNames::heightAttr) {
    105107        setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
    106     else {
     108        if (width().value() < 0.0)
     109            document()->accessSVGExtensions()->reportError("A negative value for pattern attribute <height> is not allowed");
     110    } else {
    107111        if (SVGURIReference::parseMappedAttribute(attr))
    108112            return;
  • trunk/WebCore/ksvg2/svg/SVGPolyElement.cpp

    r18489 r18652  
    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
     
    6363void SVGPolyElement::parseMappedAttribute(MappedAttribute* attr)
    6464{
     65    const AtomicString& value = attr->value();
    6566    if (attr->name() == SVGNames::pointsAttr) {
    6667        ExceptionCode ec = 0;
    6768        points()->clear(ec);
    68         parsePoints(attr->value());
     69        if (!parsePoints(value) && !m_ignoreAttributeChanges)
     70            document()->accessSVGExtensions()->reportError("Problem parsing points=\"" + value + "\"");
    6971    } else {
    7072        if (SVGTests::parseMappedAttribute(attr))
  • trunk/WebCore/ksvg2/svg/SVGRadialGradientElement.cpp

    r18521 r18652  
    6868    else if (attr->name() == SVGNames::cyAttr)
    6969        setCyBaseValue(SVGLength(this, LengthModeHeight, value));
    70     else if (attr->name() == SVGNames::rAttr)
     70    else if (attr->name() == SVGNames::rAttr) {
    7171        setRBaseValue(SVGLength(this, LengthModeOther, value));
    72     else if (attr->name() == SVGNames::fxAttr)
     72        if (r().value() < 0.0)
     73            document()->accessSVGExtensions()->reportError("A negative value for radial gradient radius <r> is not allowed");
     74    } else if (attr->name() == SVGNames::fxAttr)
    7375        setFxBaseValue(SVGLength(this, LengthModeWidth, value));
    7476    else if (attr->name() == SVGNames::fyAttr)
  • trunk/WebCore/ksvg2/svg/SVGRectElement.cpp

    r18268 r18652  
    6262    else if (attr->name() == SVGNames::yAttr)
    6363        setYBaseValue(SVGLength(this, LengthModeHeight, value));
    64     else if (attr->name() == SVGNames::rxAttr)
    65          setRxBaseValue(SVGLength(this, LengthModeWidth, value));
    66     else if (attr->name() == SVGNames::ryAttr)
    67          setRyBaseValue(SVGLength(this, LengthModeHeight, value));
    68     else if (attr->name() == SVGNames::widthAttr)
     64    else if (attr->name() == SVGNames::rxAttr) {
     65        setRxBaseValue(SVGLength(this, LengthModeWidth, value));
     66            document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed");
     67    } else if (attr->name() == SVGNames::ryAttr) {
     68        setRyBaseValue(SVGLength(this, LengthModeHeight, value));
     69        if (ry().value() < 0.0)
     70            document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
     71    } else if (attr->name() == SVGNames::widthAttr) {
    6972        setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
    70     else if (attr->name() == SVGNames::heightAttr)
     73        if (width().value() < 0.0)
     74            document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
     75    } else if (attr->name() == SVGNames::heightAttr) {
    7176        setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
    72     else {
     77        if (height().value() < 0.0)
     78            document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
     79    } else {
    7380        if (SVGTests::parseMappedAttribute(attr))
    7481            return;
  • trunk/WebCore/ksvg2/svg/SVGSVGElement.cpp

    r18524 r18652  
    197197        setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
    198198        addCSSProperty(attr, CSS_PROP_WIDTH, value);
     199        if (width().value() < 0.0)
     200            document()->accessSVGExtensions()->reportError("A negative value for svg attribute <width> is not allowed");
    199201    } else if (attr->name() == SVGNames::heightAttr) {
    200202        setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
    201203        addCSSProperty(attr, CSS_PROP_HEIGHT, value);
     204        if (height().value() < 0.0)
     205            document()->accessSVGExtensions()->reportError("A negative value for svg attribute <height> is not allowed");
    202206    } else {
    203207        if (SVGTests::parseMappedAttribute(attr))
  • trunk/WebCore/ksvg2/svg/SVGTextContentElement.cpp

    r18268 r18652  
    9595void SVGTextContentElement::parseMappedAttribute(MappedAttribute* attr)
    9696{
     97    const AtomicString& value = attr->value();
    9798    //if (attr->name() == SVGNames::lengthAdjustAttr)
    9899    //    setXBaseValue(SVGLength(this, LengthModeWidth, value));
    99100    //else
    100     {
     101    if (attr->name() == SVGNames::textLengthAttr) {
     102        setTextLengthBaseValue(SVGLength(this, LengthModeOther, value));
     103        if (textLength().value() < 0.0)
     104            document()->accessSVGExtensions()->reportError("A negative value for text attribute <textLength> is not allowed");
     105    } else {
    101106        if (SVGTests::parseMappedAttribute(attr))
    102107            return;
  • trunk/WebCore/ksvg2/svg/SVGUseElement.cpp

    r18643 r18652  
    6767    else if (attr->name() == SVGNames::yAttr)
    6868        setYBaseValue(SVGLength(this, LengthModeHeight, value));
    69     else if (attr->name() == SVGNames::widthAttr)
     69    else if (attr->name() == SVGNames::widthAttr) {
    7070        setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
    71     else if (attr->name() == SVGNames::heightAttr)
     71        if (width().value() < 0.0)
     72            document()->accessSVGExtensions()->reportError("A negative value for use attribute <width> is not allowed");
     73    } else if (attr->name() == SVGNames::heightAttr) {
    7274        setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
    73     else {
     75        if (height().value() < 0.0)
     76            document()->accessSVGExtensions()->reportError("A negative value for use attribute <height> is not allowed");
     77    } else {
    7478        if (SVGTests::parseMappedAttribute(attr))
    7579            return;
Note: See TracChangeset for help on using the changeset viewer.