[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/khtml-blaze
From:       Viacheslav Tokarev <tsjoker () GMAIL ! COM>
Date:       2008-08-20 18:12:50
Message-ID: 1219255970.118820.4372.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 850050 by vtokarev:

Now execute scripts in xhtml/svg documents immediately. Not after parsing whole \
document


 M  +1 -2      svg/SVGNames.cpp  
 M  +1 -2      svg/SVGNames.h  
 M  +7 -7      svg/XLinkNames.cpp  
 M  +2 -0      svg/XLinkNames.h  
 M  +9 -1      svg/generateSVGNames.py  
 M  +55 -77    xml/xml_tokenizer.cpp  
 M  +6 -3      xml/xml_tokenizer.h  


--- branches/work/khtml-blaze/svg/SVGNames.cpp #850049:850050
@@ -333,8 +333,7 @@
         QualifiedName zAttr = QualifiedName("", "z", "");
         QualifiedName zoomAndPanAttr = QualifiedName("", "zoomAndPan", "");
     }
-    namespace HTMLNames
-    {
+    namespace HTMLNames {
         QualifiedName classAttr = QualifiedName("", "class", "");
     }
 }
--- branches/work/khtml-blaze/svg/SVGNames.h #850049:850050
@@ -336,8 +336,7 @@
         extern QualifiedName zAttr;
         extern QualifiedName zoomAndPanAttr;
     }
-    namespace HTMLNames
-    {
+    namespace HTMLNames {
         extern QualifiedName classAttr;
     }
 }
--- branches/work/khtml-blaze/svg/XLinkNames.cpp #850049:850050
@@ -4,12 +4,12 @@
 
 namespace WebCore {
     namespace XLinkNames {
-        QualifiedName actuateAttr = QualifiedName("", "actuate", "");
-        QualifiedName arcroleAttr = QualifiedName("", "arcrole", "");
-        QualifiedName hrefAttr = QualifiedName("", "href", "");
-        QualifiedName roleAttr = QualifiedName("", "role", "");
-        QualifiedName showAttr = QualifiedName("", "show", "");
-        QualifiedName titleAttr = QualifiedName("", "title", "");
-        QualifiedName typeAttr = QualifiedName("", "type", "");
+        QualifiedName actuateAttr = QualifiedName("", "actuate", xlinkNamespace);
+        QualifiedName arcroleAttr = QualifiedName("", "arcrole", xlinkNamespace);
+        QualifiedName hrefAttr = QualifiedName("", "href", xlinkNamespace);
+        QualifiedName roleAttr = QualifiedName("", "role", xlinkNamespace);
+        QualifiedName showAttr = QualifiedName("", "show", xlinkNamespace);
+        QualifiedName titleAttr = QualifiedName("", "title", xlinkNamespace);
+        QualifiedName typeAttr = QualifiedName("", "type", xlinkNamespace);
     }
 }
--- branches/work/khtml-blaze/svg/XLinkNames.h #850049:850050
@@ -3,6 +3,8 @@
 
 #include "xml/Document.h"
 
+#define xlinkNamespace "http://www.w3.org/1999/xlink"
+
 namespace WebCore {
     namespace XLinkNames {
         extern QualifiedName actuateAttr;
--- branches/work/khtml-blaze/svg/generateSVGNames.py #850049:850050
@@ -34,6 +34,9 @@
 for i in attrsList:
     f.write(" " * 8 + "extern QualifiedName %sAttr;\n" % i.replace("-", "_"))
 f.write("    }\n")
+f.write("    namespace HTMLNames {\n")
+f.write("        extern QualifiedName classAttr;\n")
+f.write("    }\n")
 f.write("}\n")
 f.write("\n")
 f.write("#endif\n")
@@ -51,6 +54,9 @@
 for i in attrsList:
     f.write(" " * 8 + "QualifiedName %sAttr = QualifiedName(\"\", \"%s\", \"\");\n" \
% (i.replace("-", "_"), i))  f.write("    }\n")
+f.write("    namespace HTMLNames {\n")
+f.write("        QualifiedName classAttr = QualifiedName(\"\", \"class\", \"\");\n")
+f.write("    }\n")
 f.write("}\n")
 f.close()
 
@@ -74,6 +80,8 @@
 f.write("\n")
 f.write("#include \"xml/Document.h\"\n")
 f.write("\n")
+f.write("#define xlinkNamespace \"http://www.w3.org/1999/xlink\"\n")
+f.write("\n")
 f.write("namespace WebCore {\n")
 f.write("    namespace XLinkNames {\n")
 for i in xlinkAttrs:
@@ -92,7 +100,7 @@
 f.write("namespace WebCore {\n")
 f.write("    namespace XLinkNames {\n")
 for i in xlinkAttrs:
-    f.write(" " * 8 + "QualifiedName %sAttr = QualifiedName(\"\", \"%s\", \"\");\n" \
% (i.replace("-", "_"), i)) +    f.write(" " * 8 + "QualifiedName %sAttr = \
QualifiedName(\"\", \"%s\", xlinkNamespace);\n" % (i.replace("-", "_"), i))  \
f.write("    }\n")  f.write("}\n")
 f.close()
--- branches/work/khtml-blaze/xml/xml_tokenizer.cpp #850049:850050
@@ -39,13 +39,14 @@
 
 // SVG includes
 #include "svg/SVGScriptElement.h"
+#include "svg/XLinkNames.h"
 
 using namespace DOM;
 using namespace khtml;
 
 XMLIncrementalSource::XMLIncrementalSource()
     : QXmlInputSource(), m_pos( 0 ), m_unicode( 0 ),
-      m_finished( false )
+      m_finished( false ), m_paused( false )
 {
 }
 
@@ -58,7 +59,7 @@
 {
     if ( m_finished )
         return QXmlInputSource::EndOfDocument;
-    else if ( m_data.length() <= m_pos )
+    else if ( m_paused || m_data.length() <= m_pos )
         return QXmlInputSource::EndOfData;
     else
         return m_unicode[m_pos++];
@@ -239,6 +240,11 @@
     } else
         return false;
 
+    // if it's a script element then execute it immediately
+    if ((node->id() == ID_SCRIPT || node->id() == makeId(xhtmlNamespace, ID_SCRIPT)) \
|| (node->id() == WebCore::SVGNames::scriptTag.id())) { +        \
static_cast<XMLTokenizer*>(m_doc->tokenizer())->executeScript(node); +    }
+
     return true;
 }
 
@@ -392,7 +398,6 @@
     return true;
 }
 
-
 //------------------------------------------------------------------------------
 
 XMLTokenizer::XMLTokenizer(DOM::DocumentImpl *_doc, KHTMLView *_view)
@@ -515,96 +520,30 @@
 
         m_doc->recalcStyle( NodeImpl::Inherit );
         m_doc->updateRendering();
-
-        end();
     }
     else {
-        // Parsing was successful. Now locate all html <script> tags in the document \
                and execute them
-        // one by one
-        addScripts(m_doc);
-        m_scriptsIt = new QLinkedListIterator<ElementImpl*>(m_scripts);
-        executeScripts();
+        // All scripts have finished executing, so calculate the style for the \
document and close +        // the last element
+        m_doc->updateStyleSelector();
     }
 
-}
-
-void XMLTokenizer::addScripts(NodeImpl *n)
-{
-    // Recursively go through the entire document tree, looking for html <script> \
                tags. For each of these
-    // that is found, add it to the m_scripts list from which they will be executed
-
-    if (n->id() == ID_SCRIPT || n->id() == makeId(xhtmlNamespace, ID_SCRIPT)) {
-        m_scripts.append(static_cast<HTMLScriptElementImpl*>(n));
-    }
-
-    if (n->id() == WebCore::SVGNames::scriptTag.id()) {
-        m_scripts.append(static_cast<WebCore::SVGScriptElement*>(n));
-    }
-
-    NodeImpl *child;
-    for (child = n->firstChild(); child; child = child->nextSibling())
-        addScripts(child);
-}
-
-void XMLTokenizer::executeScripts()
-{
-    // Iterate through all of the html <script> tags in the document. For those that \
                have a src attribute,
-    // start loading the script and return (executeScripts() will be called again \
                once the script is loaded
-    // and continue where it left off). For scripts that don't have a src attribute, \
                execute the code
-    // inside the tag
-    while (m_scriptsIt->hasNext()) {
-        ElementImpl* script = m_scriptsIt->next();
-        DOMString scriptSrc = script->getAttribute(ATTR_SRC);
-        QString charset = script->getAttribute(ATTR_CHARSET).string();
-
-        if (!scriptSrc.isEmpty()) {
-            // we have a src attribute
-            m_cachedScript = m_doc->docLoader()->requestScript(scriptSrc, charset);
-            if (m_cachedScript) {
-                m_cachedScript->ref(this); // will call executeScripts() again if \
                already cached
-                return;
-            }
-        }
-        else {
-            // no src attribute - execute from contents of tag
-            QString scriptCode = "";
-            NodeImpl *child;
-            for (child = script->firstChild(); child; child = child->nextSibling()) \
                {
-                if ( ( child->nodeType() == Node::TEXT_NODE || child->nodeType() == \
                Node::CDATA_SECTION_NODE) &&
-                     static_cast<TextImpl*>(child)->string() )
-                    scriptCode += \
                QString::fromRawData(static_cast<TextImpl*>(child)->string()->s,
-                                                       \
                static_cast<TextImpl*>(child)->string()->l);
-            }
-            // the script cannot do document.write until we support incremental \
                parsing
-            // ### handle the case where the script deletes the node or redirects to
-            // another page, etc. (also in notifyFinished())
-            // ### the script may add another script node after this one which \
                should be executed
-            if (m_view) {
-                m_view->part()->executeScript(DOM::Node(), scriptCode);
-            }
-        }
-    }
-
-    // All scripts have finished executing, so calculate the style for the document \
                and close
-    // the last element
-    m_doc->updateStyleSelector();
-
     // We are now finished parsing
     end();
 }
 
 void XMLTokenizer::notifyFinished(CachedObject *finishedObj)
 {
-    // This is called when a script has finished loading that was requested from \
                executeScripts(). We execute
-    // the script, and then call executeScripts() again to continue iterating \
                through the list of scripts in
-    // the document
+    // This is called when a script has finished loading that was requested from \
executeScript(). We execute +    // the script, and then continue parsing of the \
document  if (finishedObj == m_cachedScript) {
         DOMString scriptSource = m_cachedScript->script();
         m_cachedScript->deref(this);
         m_cachedScript = 0;
         if (m_view)
             m_view->part()->executeScript(DOM::Node(), scriptSource.string());
-        executeScripts();
+        // should continue parsing here after we fetched and executed the script
+        m_source.setPaused(false);
+        m_reader.parseContinue();
     }
 }
 
@@ -613,5 +552,44 @@
     return m_cachedScript != 0;
 }
 
+void XMLTokenizer::executeScript(NodeImpl* node)
+{
+    ElementImpl* script = static_cast<ElementImpl*>(node);
+    DOMString scriptSrc;
+    if (node->id() == WebCore::SVGNames::scriptTag.id())
+        scriptSrc = script->getAttribute(WebCore::XLinkNames::hrefAttr.id());
+    else
+        scriptSrc = script->getAttribute(ATTR_SRC);
+    QString charset = script->getAttribute(ATTR_CHARSET).string();
+
+    if (!scriptSrc.isEmpty()) {
+        // we have a src attribute
+        m_cachedScript = m_doc->docLoader()->requestScript(scriptSrc, charset);
+        // pause parsing until we got script
+        m_source.setPaused();
+        if (m_cachedScript) {
+            m_cachedScript->ref(this); // will call executeScripts() again if \
already cached +            return;
+        }
+    } else {
+        // no src attribute - execute from contents of tag
+        QString scriptCode = "";
+        NodeImpl *child;
+        for (child = script->firstChild(); child; child = child->nextSibling()) {
+            if ( ( child->nodeType() == Node::TEXT_NODE || child->nodeType() == \
Node::CDATA_SECTION_NODE) && +                static_cast<TextImpl*>(child)->string() \
) +                scriptCode += \
QString::fromRawData(static_cast<TextImpl*>(child)->string()->s, +                    \
static_cast<TextImpl*>(child)->string()->l); +            }
+        // the script cannot do document.write until we support incremental parsing
+        // ### handle the case where the script deletes the node or redirects to
+        // another page, etc. (also in notifyFinished())
+        // ### the script may add another script node after this one which should be \
executed +        if (m_view) {
+            m_view->part()->executeScript(DOM::Node(), scriptCode);
+        }
+    }
+}
+
 #include "xml_tokenizer.moc"
 
--- branches/work/khtml-blaze/xml/xml_tokenizer.h #850049:850050
@@ -150,11 +150,14 @@
     void appendXML( const QString& str );
     void setFinished( bool );
 
+    inline void setPaused(bool paused = true) { m_paused = paused; }
+
 private:
     QString      m_data;
     int          m_pos;
     const QChar *m_unicode;
     bool         m_finished;
+    bool         m_paused;
 };
 
 class XMLTokenizer : public Tokenizer, public khtml::CachedObjectClient
@@ -174,13 +177,13 @@
     virtual bool isWaitingForScripts() const;
     virtual bool isExecutingScript() const { return false; }
 
+    // executes script in place, if it contains src attribute wait before it's \
downloaded +    void executeScript(DOM::NodeImpl *n);
+
 protected:
     DOM::DocumentImpl *m_doc;
     KHTMLView *m_view;
 
-    void executeScripts();
-    void addScripts(DOM::NodeImpl *n);
-
     QLinkedList<DOM::ElementImpl*> m_scripts;
     QLinkedListIterator<DOM::ElementImpl*> *m_scriptsIt;
     khtml::CachedScript *m_cachedScript;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic