[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.0/kdelibs/khtml
From: Maks Orlovich <maksim () kde ! org>
Date: 2008-01-17 7:53:10
Message-ID: 1200556390.896978.24288.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 762468 by orlovich:
For jQuery: support onload on script elements, so we can get past test 105.
Partial merge from WC, minus code duplication, plus comments.
One thing I am not sure of: do we want to do error event as well?
I am not a fan of 50% legacy, 50% proprietary events that bubble.
M +43 -7 html/html_headimpl.cpp
M +2 -0 html/html_headimpl.h
M +4 -1 misc/loader.cpp
M +1 -0 misc/loader.h
--- branches/KDE/4.0/kdelibs/khtml/html/html_headimpl.cpp #762467:762468
@@ -4,7 +4,7 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * (C) 2002-2003 Apple Computer, Inc.
+ * (C) 2003, 2004, 2005, 2006, 2007 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -26,6 +26,7 @@
#include "html/html_headimpl.h"
#include "html/html_documentimpl.h"
#include "xml/dom_textimpl.h"
+#include "xml/dom2_eventsimpl.h"
#include "khtmlview.h"
#include "khtml_part.h"
@@ -342,6 +343,31 @@
return ID_SCRIPT;
}
+void HTMLScriptElementImpl::parseAttribute(AttributeImpl *attr)
+{
+ switch(attr->id())
+ {
+ case ATTR_ONLOAD:
+ setHTMLEventListener(EventImpl::LOAD_EVENT,
+ getDocument()->createHTMLEventListener(attr->value().string(), "onload", this));
+ break;
+ case ATTR_SRC: {
+ // We want to evaluate scripts on src attr change when a fresh script element
+ // is inserted into document, and then has its source changed -after-.
+ // If the source is manipulated while we're outside the document,
+ // we'll only start doing things once we get insertedIntoDocument()
+ if (m_evaluated || m_cachedScript || m_createdByParser || !inDocument())
+ return;
+ DOMString url = attr->value();
+ if (!url.isEmpty())
+ loadFromUrl(url);
+ break;
+ }
+ default:
+ HTMLElementImpl::parseAttribute(attr);
+ }
+}
+
bool HTMLScriptElementImpl::isURLAttribute(AttributeImpl *attr) const
{
return attr->id() == ATTR_SRC;
@@ -356,6 +382,14 @@
evaluateScript(getDocument()->URL().url(), text());
}
+void HTMLScriptElementImpl::loadFromUrl(const DOMString &url)
+{
+ QString charset = getAttribute(ATTR_CHARSET).string();
+ m_cachedScript = getDocument()->docLoader()->requestScript(url, charset);
+ if (m_cachedScript)
+ m_cachedScript->ref(this);
+}
+
void HTMLScriptElementImpl::insertedIntoDocument()
{
HTMLElementImpl::insertedIntoDocument();
@@ -365,12 +399,9 @@
if (m_createdByParser)
return;
- QString url = getAttribute(ATTR_SRC).string();
+ DOMString url = getAttribute(ATTR_SRC).string();
if (!url.isEmpty()) {
- QString charset = getAttribute(ATTR_CHARSET).string();
- m_cachedScript = getDocument()->docLoader()->requestScript(DOMString(url), charset);
- if (m_cachedScript)
- m_cachedScript->ref(this);
+ loadFromUrl(url);
return;
}
@@ -403,7 +434,12 @@
cs->deref(this);
m_cachedScript = 0;
- evaluateScript(URL, script);
+ ref(); // Pin so we don't destroy oursleves.
+ if (!cs->hadError()) {
+ evaluateScript(URL, script);
+ dispatchHTMLEvent(EventImpl::LOAD_EVENT, false, false);
+ }
+ deref();
}
void HTMLScriptElementImpl::evaluateScript(const QString &URL, const DOMString &script)
--- branches/KDE/4.0/kdelibs/khtml/html/html_headimpl.h #762467:762468
@@ -139,6 +139,7 @@
HTMLScriptElementImpl(DocumentImpl *doc);
~HTMLScriptElementImpl();
+ virtual void parseAttribute(AttributeImpl *attr);
virtual void insertedIntoDocument();
virtual void removedFromDocument();
virtual void notifyFinished(khtml::CachedObject *finishedObj);
@@ -173,6 +174,7 @@
void setType(const DOMString &);
private:
+ void loadFromUrl(const DOMString &url);
khtml::CachedScript *m_cachedScript;
bool m_createdByParser;
bool m_evaluated;
--- branches/KDE/4.0/kdelibs/khtml/misc/loader.cpp #762467:762468
@@ -334,11 +334,13 @@
// load the file
Cache::loader()->load(dl, this, false);
m_loading = true;
+ m_hadError = false;
}
CachedScript::CachedScript(const DOMString &url, const QString &script_data)
: CachedObject(url, Script, KIO::CC_Verify, script_data.length())
{
+ m_hadError = false;
m_loading = false;
m_status = Persistent;
m_script = DOMString(script_data);
@@ -374,7 +376,8 @@
void CachedScript::error( int /*err*/, const char* /*text*/ )
{
- m_loading = false;
+ m_hadError = true;
+ m_loading = false;
checkNotify();
}
--- branches/KDE/4.0/kdelibs/khtml/misc/loader.h #762467:762468
@@ -134,6 +134,7 @@
int size() const { return m_size; }
bool isLoaded() const { return !m_loading; }
+ bool hadError() const { return m_hadError; }
bool free() const { return m_free; }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic