Changeset 36699 in webkit


Ignore:
Timestamp:
Sep 19, 2008 8:33:43 PM (16 years ago)
Author:
Nikolas Zimmermann
Message:

Reviewed by Antti & Eric.

Fixes: https://bugs.webkit.org/show_bug.cgi?id=20372

Finish HTMLScriptElement / SVGScriptElement unification.
SVG <script> support is complete now, full SVGLoad event
respecting the influence of the externalResourcesRequired attribute
as well as SVGError event support. All other features shared with HTML.

Tests: fast/dom/HTMLScriptElement/script-reexecution.html

svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading.svg
svg/dom/SVGScriptElement/script-load-and-error-events.svg
svg/dom/SVGScriptElement/script-reexecution.svg
svg/dom/SVGScriptElement/script-set-href.svg

Location:
trunk
Files:
39 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r36687 r36699  
     12008-09-19  Nikolas Zimmermann  <zimmermann@kde.org>
     2
     3        Reviewed by Antti & Eric.
     4
     5        Fixes: https://bugs.webkit.org/show_bug.cgi?id=20372
     6
     7        Add new test fast/dom/HTMLScriptElement/script-reexecution.html, verifying that
     8        appending a <script>, removing and reappending doesn't reexecute the script.
     9
     10        Fix obvious errors in tests contained in fast/dom/HTMLScriptElement/.
     11        Use these tests as skeleton for a series of SVGScriptElement tests.
     12        Especially tests SVG's SVGLoad/SVGError event support, as well as the
     13        influence of externalResourcesRequired attribute.
     14
     15        * fast/dom/HTMLScriptElement/resources/script-reexecution-pass.js: Added.
     16        * fast/dom/HTMLScriptElement/script-load-events.html:
     17        * fast/dom/HTMLScriptElement/script-reexecution-expected.txt: Added.
     18        * fast/dom/HTMLScriptElement/script-reexecution.html: Added.
     19        * fast/dom/HTMLScriptElement/script-set-src.html:
     20        * platform/mac/svg/dom/SVGScriptElement: Added.
     21        * platform/mac/svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading-expected.checksum: Added.
     22        * platform/mac/svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading-expected.png: Added.
     23        * platform/mac/svg/dom/SVGScriptElement/script-load-and-error-events-expected.checksum: Added.
     24        * platform/mac/svg/dom/SVGScriptElement/script-load-and-error-events-expected.png: Added.
     25        * platform/mac/svg/dom/SVGScriptElement/script-reexecution-expected.checksum: Added.
     26        * platform/mac/svg/dom/SVGScriptElement/script-reexecution-expected.png: Added.
     27        * platform/mac/svg/dom/SVGScriptElement/script-set-href-expected.checksum: Added.
     28        * platform/mac/svg/dom/SVGScriptElement/script-set-href-expected.png: Added.
     29        * svg/dom/SVGScriptElement: Added.
     30        * svg/dom/SVGScriptElement/resources: Added.
     31        * svg/dom/SVGScriptElement/resources/script-load.js: Added.
     32        * svg/dom/SVGScriptElement/resources/script-load2.js: Added.
     33        * svg/dom/SVGScriptElement/resources/script-load3.js: Added.
     34        * svg/dom/SVGScriptElement/resources/script-load4.js: Added.
     35        * svg/dom/SVGScriptElement/resources/script-reexecution.js: Added.
     36        * svg/dom/SVGScriptElement/resources/script-set-href-p1fail.js: Added.
     37        * svg/dom/SVGScriptElement/resources/script-set-href-p2fail.js: Added.
     38        * svg/dom/SVGScriptElement/resources/script-set-href-p3pass.js: Added.
     39        * svg/dom/SVGScriptElement/resources/script-set-href-p4pass.js: Added.
     40        * svg/dom/SVGScriptElement/resources/script-set-href-p5fail.js: Added.
     41        * svg/dom/SVGScriptElement/resources/script-set-href-p5pass.js: Added.
     42        * svg/dom/SVGScriptElement/resources/script-set-href-p6pass.js: Added.
     43        * svg/dom/SVGScriptElement/resources/script-set-href-p7pass.js: Added.
     44        * svg/dom/SVGScriptElement/resources/script-set-href-p8pass.js: Added.
     45        * svg/dom/SVGScriptElement/resources/script-set-href-p9failAfter.js: Added.
     46        * svg/dom/SVGScriptElement/resources/script-set-href-p9failBefore.js: Added.
     47        * svg/dom/SVGScriptElement/resources/script-set-href-p9pass.js: Added.
     48        * svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading-expected.txt: Added.
     49        * svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading.svg: Added.
     50        * svg/dom/SVGScriptElement/script-load-and-error-events-expected.txt: Added.
     51        * svg/dom/SVGScriptElement/script-load-and-error-events.svg: Added.
     52        * svg/dom/SVGScriptElement/script-reexecution-expected.txt: Added.
     53        * svg/dom/SVGScriptElement/script-reexecution.svg: Added.
     54        * svg/dom/SVGScriptElement/script-set-href-expected.txt: Added.
     55        * svg/dom/SVGScriptElement/script-set-href.svg: Added.
     56
    1572008-09-19  Chris Marrin  <cmarrin@apple.com>
    258
  • trunk/LayoutTests/fast/dom/HTMLScriptElement/script-load-events.html

    r30238 r36699  
    6464<script type="text/javascript" onload="loaded(1)" onerror="erred(1)" src="resources/certainlydoesnotexist.js"></script>
    6565<script type="text/javascript" onload="loaded(2)" onerror="erred(2)" src="resources/script-load.js"></script>
    66 <script type="text/javascript" onload="loaded(3)" onerror="erred(3)" src="resources/script-load.js"></script>
     66<script type="text/javascript" onload="loaded(3)" onerror="erred(3)" src="resources/script-load.js"/>
    6767<script type="text/javascript">
    6868    document.write('<script type="text/javascript" onload="loaded(4)" onerror="erred(4)" src="resources/script-load.js"></script'+'>');
  • trunk/LayoutTests/fast/dom/HTMLScriptElement/script-set-src.html

    r21591 r36699  
    3131    var e3 = document.createElement( "script" );
    3232    e3.type  = "text/javascript";
    33     e3.src = "resources/script-set-src-p8failBefore.js";
     33    e3.src = "resources/script-set-src-p9failBefore.js";
    3434    e3.src = "resources/script-set-src-p9pass.js";
    3535    document.getElementsByTagName("head")[0].appendChild(e3);
     
    4444<script type="text/javascript" id="s5" src="resources/script-set-src-p5pass.js"></script>
    4545<script type="text/javascript" id="s3"></script>
    46 <script type="text/javascript" id="s4"></script>
     46<script type="text/javascript" id="s4"/>
    4747<script type="text/javascript" id="s6"></script>
    4848</head>
  • trunk/WebCore/ChangeLog

    r36698 r36699  
     12008-09-19  Nikolas Zimmermann  <zimmermann@kde.org>
     2
     3        Reviewed by Antti & Eric.
     4
     5        Fixes: https://bugs.webkit.org/show_bug.cgi?id=20372
     6
     7        Finish HTMLScriptElement / SVGScriptElement unification.
     8        SVG <script> support is complete now, full SVGLoad event
     9        respecting the influence of the externalResourcesRequired attribute
     10        as well as SVGError event support. All other features shared with HTML.
     11
     12        Tests: fast/dom/HTMLScriptElement/script-reexecution.html
     13               svg/dom/SVGScriptElement/script-change-externalResourcesRequired-while-loading.svg
     14               svg/dom/SVGScriptElement/script-load-and-error-events.svg
     15               svg/dom/SVGScriptElement/script-reexecution.svg
     16               svg/dom/SVGScriptElement/script-set-href.svg
     17
     18        * dom/ScriptElement.cpp:
     19        (WebCore::ScriptElementData::ScriptElementData):
     20        (WebCore::ScriptElementData::requestScript):
     21        * dom/ScriptElement.h:
     22        (WebCore::ScriptElementData::haveFiredLoadEvent):
     23        (WebCore::ScriptElementData::setHaveFiredLoadEvent):
     24        * dom/XMLTokenizer.cpp:
     25        (WebCore::XMLTokenizer::notifyFinished):
     26        * html/HTMLScriptElement.cpp:
     27        (WebCore::HTMLScriptElement::dispatchLoadEvent):
     28        * svg/SVGScriptElement.cpp:
     29        (WebCore::SVGScriptElement::setCreatedByParser):
     30        (WebCore::SVGScriptElement::parseMappedAttribute):
     31        (WebCore::SVGScriptElement::svgAttributeChanged):
     32        (WebCore::SVGScriptElement::insertedIntoDocument):
     33        (WebCore::SVGScriptElement::removedFromDocument):
     34        (WebCore::SVGScriptElement::childrenChanged):
     35        (WebCore::SVGScriptElement::isURLAttribute):
     36        (WebCore::SVGScriptElement::finishParsingChildren):
     37        (WebCore::SVGScriptElement::type):
     38        (WebCore::SVGScriptElement::setType):
     39        (WebCore::SVGScriptElement::haveLoadedRequiredResources):
     40        (WebCore::SVGScriptElement::dispatchLoadEvent):
     41        (WebCore::SVGScriptElement::dispatchErrorEvent):
     42        * svg/SVGScriptElement.h:
     43
    1442008-09-19  Dan Bernstein  <mitz@apple.com>
    245
  • trunk/WebCore/dom/ScriptElement.cpp

    r35744 r36699  
    119119    , m_createdByParser(false)
    120120    , m_evaluated(false)
     121    , m_firedLoad(false)
    121122{
    122123    ASSERT(m_scriptElement);
     
    141142    ASSERT(!m_cachedScript);
    142143    m_cachedScript = document->docLoader()->requestScript(sourceUrl, scriptCharset());
     144
     145    // m_createdByParser is never reset - always resied at the initial value set while parsing.
     146    // m_evaluated is left untouched as well to avoid script reexecution, if a <script> element
     147    // is removed and reappended to the document.
     148    m_firedLoad = false;
    143149
    144150    if (m_cachedScript) {
  • trunk/WebCore/dom/ScriptElement.h

    r36109 r36699  
    7171    bool createdByParser() const { return m_createdByParser; }
    7272    void setCreatedByParser(bool value) { m_createdByParser = value; }
     73    bool haveFiredLoadEvent() const { return m_firedLoad; }
     74    void setHaveFiredLoadEvent(bool firedLoad) { m_firedLoad = firedLoad; }
    7375
    7476    void requestScript(const String& sourceUrl);
     
    8587    bool m_createdByParser;
    8688    bool m_evaluated;
     89    bool m_firedLoad;
    8790};
    8891
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r36630 r36699  
    3434#include "DocumentFragment.h"
    3535#include "DocumentType.h"
    36 #include "EventNames.h"
    3736#include "Frame.h"
    3837#include "FrameLoader.h"
     
    6564namespace WebCore {
    6665
    67 using namespace EventNames;
    68 
    6966const int maxErrors = 25;
    7067
     
    318315    RefPtr<Element> e = m_scriptElement;
    319316    m_scriptElement = 0;
    320    
     317
     318    ScriptElement* scriptElement = castToScriptElement(e.get());
     319    ASSERT(scriptElement);
     320
    321321    if (errorOccurred)
    322         EventTargetNodeCast(e.get())->dispatchEventForType(errorEvent, true, false);
     322        scriptElement->dispatchErrorEvent();
    323323    else {
    324324        m_view->frame()->loader()->executeScript(cachedScriptUrl, 1, scriptSource);
    325         EventTargetNodeCast(e.get())->dispatchEventForType(loadEvent, false, false);
     325        scriptElement->dispatchLoadEvent();
    326326    }
    327327   
  • trunk/WebCore/html/HTMLScriptElement.cpp

    r36466 r36699  
    215215void HTMLScriptElement::dispatchLoadEvent()
    216216{
     217    ASSERT(!m_data.haveFiredLoadEvent());
     218    m_data.setHaveFiredLoadEvent(true);
     219
    217220    dispatchEventForType(loadEvent, false, false);
    218221}
  • trunk/WebCore/svg/SVGScriptElement.cpp

    r35744 r36699  
    2525#if ENABLE(SVG)
    2626#include "SVGScriptElement.h"
     27
     28#include "EventNames.h"
    2729#include "SVGNames.h"
    2830
     
    4143}
    4244
    43 String SVGScriptElement::type() const
    44 {
    45     return m_type;
    46 }
    47 
    48 void SVGScriptElement::setType(const String& type)
    49 {
    50     m_type = type;
     45void SVGScriptElement::setCreatedByParser(bool createdByParser)
     46{
     47    m_data.setCreatedByParser(createdByParser);
    5148}
    5249
     
    5855void SVGScriptElement::parseMappedAttribute(MappedAttribute* attr)
    5956{
    60     if (attr->name() == SVGNames::typeAttr)
     57    const QualifiedName& attrName = attr->name();
     58
     59    if (attrName == SVGNames::typeAttr)
    6160        setType(attr->value());
    6261    else {
     
    7069}
    7170
     71void SVGScriptElement::svgAttributeChanged(const QualifiedName& attrName)
     72{
     73    SVGElement::svgAttributeChanged(attrName);
     74
     75    if (SVGURIReference::isKnownAttribute(attrName))
     76        handleSourceAttribute(m_data, href());
     77    else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
     78        // Handle dynamic updates of the 'externalResourcesRequired' attribute. Only possible case: changing from 'true' to 'false'
     79        // causes an immediate dispatch of the SVGLoad event. If the attribute value was 'false' before inserting the script element
     80        // in the document, the SVGLoad event has already been dispatched.
     81        if (!externalResourcesRequiredBaseValue() && !m_data.haveFiredLoadEvent() && !m_data.createdByParser()) {
     82            m_data.setHaveFiredLoadEvent(true);
     83            ASSERT(haveLoadedRequiredResources());
     84
     85            sendSVGLoadEventIfPossible();
     86        }
     87    }
     88}
     89
     90void SVGScriptElement::insertedIntoDocument()
     91{
     92    SVGElement::insertedIntoDocument();
     93    ScriptElement::insertedIntoDocument(m_data, sourceAttributeValue());
     94
     95    if (m_data.createdByParser())
     96        return;
     97
     98    // Eventually send SVGLoad event now for the dynamically inserted script element
     99    if (!externalResourcesRequiredBaseValue()) {
     100        m_data.setHaveFiredLoadEvent(true);
     101        sendSVGLoadEventIfPossible();
     102    }
     103}
     104
     105void SVGScriptElement::removedFromDocument()
     106{
     107    SVGElement::removedFromDocument();
     108    ScriptElement::removedFromDocument(m_data);
     109}
     110
     111void SVGScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
     112{
     113    ScriptElement::childrenChanged(m_data);
     114    SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     115}
     116
     117bool SVGScriptElement::isURLAttribute(Attribute* attr) const
     118{
     119    return attr->name() == sourceAttributeValue();
     120}
     121
     122void SVGScriptElement::finishParsingChildren()
     123{
     124    ScriptElement::finishParsingChildren(m_data, sourceAttributeValue());
     125    SVGElement::finishParsingChildren();
     126
     127    // A SVGLoad event has been fired by SVGElement::finishParsingChildren.
     128    if (!externalResourcesRequiredBaseValue())
     129        m_data.setHaveFiredLoadEvent(true);
     130}
     131
     132String SVGScriptElement::type() const
     133{
     134    return m_type;
     135}
     136
     137void SVGScriptElement::setType(const String& type)
     138{
     139    m_type = type;
     140}
     141
    72142void SVGScriptElement::getSubresourceAttributeStrings(Vector<String>& urls) const
    73143{
     
    75145}
    76146
     147bool SVGScriptElement::haveLoadedRequiredResources()
     148{
     149    return !externalResourcesRequiredBaseValue() || m_data.haveFiredLoadEvent();
     150}
     151
    77152String SVGScriptElement::sourceAttributeValue() const
    78153{
     
    97172void SVGScriptElement::dispatchLoadEvent()
    98173{
    99     // TODO!
    100     // dispatchSVGEvent(loadEvent, false, false);
     174    bool externalResourcesRequired = externalResourcesRequiredBaseValue();
     175
     176    if (m_data.createdByParser())
     177        ASSERT(externalResourcesRequired != m_data.haveFiredLoadEvent());
     178    else if (m_data.haveFiredLoadEvent()) {
     179        // If we've already fired an load event and externalResourcesRequired is set to 'true'
     180        // externalResourcesRequired has been modified while loading the <script>. Don't dispatch twice.
     181        if (externalResourcesRequired)
     182            return;
     183    }
     184
     185    // HTML and SVG differ completly in the 'onload' event handling of <script> elements.
     186    // HTML fires the 'load' event after it sucessfully loaded a remote resource, otherwhise an error event.
     187    // SVG fires the SVGLoad event immediately after parsing the <script> element, if externalResourcesRequired
     188    // is set to 'false', otherwhise it dispatches the 'SVGLoad' event just after loading the remote resource.
     189    if (externalResourcesRequired) {
     190        ASSERT(!m_data.haveFiredLoadEvent());
     191
     192        // Dispatch SVGLoad event
     193        m_data.setHaveFiredLoadEvent(true);
     194        ASSERT(haveLoadedRequiredResources());
     195
     196        sendSVGLoadEventIfPossible();
     197    }
    101198}
    102199
    103200void SVGScriptElement::dispatchErrorEvent()
    104201{
    105     // TODO!
    106     // dispatchSVGEvent(errorEvent, true, false);
    107 }
     202    dispatchEventForType(EventNames::errorEvent, true, false);
     203}
     204
    108205}
    109206
  • trunk/WebCore/svg/SVGScriptElement.h

    r35744 r36699  
    4040        virtual ~SVGScriptElement();
    4141
    42         void setCreatedByParser(bool) { }
     42        void setCreatedByParser(bool);
    4343        virtual String scriptContent() const;
     44
     45        virtual void parseMappedAttribute(MappedAttribute*);
     46        virtual void insertedIntoDocument();
     47        virtual void removedFromDocument();
     48        virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
     49
     50        virtual void svgAttributeChanged(const QualifiedName&);
     51        virtual bool isURLAttribute(Attribute*) const;
     52        virtual void finishParsingChildren();
    4453
    4554        String type() const;
    4655        void setType(const String&);
    4756
    48         virtual void parseMappedAttribute(MappedAttribute *attr);
    4957        virtual void getSubresourceAttributeStrings(Vector<String>&) const;
    5058
    5159    protected:
    5260        virtual const SVGElement* contextElement() const { return this; }
     61        virtual bool haveLoadedRequiredResources();
    5362
    5463        virtual String sourceAttributeValue() const;
Note: See TracChangeset for help on using the changeset viewer.