Bug 552938 - Implement the SVG load event in text/html, make the SVG load event in XML async and only supported on <svg>. r=dholbert, sr=roc.

--HG--
extra : rebase_source : 6b4eb0b424b328cbb7853d767c2552ed01abc519
This commit is contained in:
Henri Sivonen 2010-05-25 14:57:58 +03:00
Родитель 5ce39e0eab
Коммит 5ddfe2af08
11 изменённых файлов: 233 добавлений и 42 удалений

Просмотреть файл

@ -52,8 +52,6 @@
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsIDOMComment.h"
#include "nsIDOMCDATASection.h"
#include "nsDOMDocumentType.h"
@ -96,12 +94,11 @@
#include "nsNodeUtils.h"
#include "nsIScriptGlobalObject.h"
#include "nsIHTMLDocument.h"
#include "nsEventDispatcher.h"
#include "mozAutoDocUpdate.h"
#include "nsMimeTypes.h"
#ifdef MOZ_SVG
#include "nsGUIEvent.h"
#include "nsHtml5SVGLoadDispatcher.h"
#endif
// XXX Open Issues:
@ -1158,29 +1155,13 @@ nsXMLContentSink::HandleEndElement(const PRUnichar *aName,
DidAddContent();
#ifdef MOZ_SVG
if (mDocument &&
content->GetNameSpaceID() == kNameSpaceID_SVG &&
(
#ifdef MOZ_SMIL
content->Tag() == nsGkAtoms::svg ||
#endif
content->HasAttr(kNameSpaceID_None, nsGkAtoms::onload))) {
if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
content->Tag() == nsGkAtoms::svg) {
FlushTags();
nsEvent event(PR_TRUE, NS_SVG_LOAD);
event.eventStructType = NS_SVG_EVENT;
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
// Do we care about forcing presshell creation if it hasn't happened yet?
// That is, should this code flush or something? Does it really matter?
// For that matter, do we really want to try getting the prescontext? Does
// this event ever want one?
nsRefPtr<nsPresContext> ctx;
nsCOMPtr<nsIPresShell> shell = mDocument->GetPrimaryShell();
if (shell) {
ctx = shell->GetPresContext();
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(content);
if (NS_FAILED(NS_DispatchToMainThread(event))) {
NS_WARNING("failed to dispatch svg load dispatcher");
}
nsEventDispatcher::Dispatch(content, ctx, &event);
}
#endif

Просмотреть файл

@ -49,7 +49,7 @@ load 384637-1.svg
load 384728-1.svg
load 385246-1.svg
load 385246-2.svg
asserts(1) load 385840-1.svg # bug 385845
load 385840-1.svg
load 385852-1.svg
load 386475-1.xhtml
load 386566-1.svg

Просмотреть файл

@ -50,6 +50,12 @@ EXPORTS = \
nsHtml5Module.h \
$(NULL)
ifdef MOZ_SVG
EXPORTS += \
nsHtml5SVGLoadDispatcher.h \
$(NULL)
endif
CPPSRCS = \
nsHtml5Atoms.cpp \
nsHtml5Atom.cpp \
@ -77,6 +83,12 @@ CPPSRCS = \
nsHtml5SpeculativeLoad.cpp \
$(NULL)
ifdef MOZ_SVG
CPPSRCS += \
nsHtml5SVGLoadDispatcher.cpp \
$(NULL)
endif
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,66 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Henri Sivonen <hsivonen@iki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsHtml5SVGLoadDispatcher.h"
#include "nsPresContext.h"
#include "nsEventDispatcher.h"
#include "nsIPresShell.h"
nsHtml5SVGLoadDispatcher::nsHtml5SVGLoadDispatcher(nsIContent* aElement)
: mElement(aElement)
{
}
NS_IMETHODIMP
nsHtml5SVGLoadDispatcher::Run()
{
nsEvent event(PR_TRUE, NS_SVG_LOAD);
event.eventStructType = NS_SVG_EVENT;
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
// Do we care about forcing presshell creation if it hasn't happened yet?
// That is, should this code flush or something? Does it really matter?
// For that matter, do we really want to try getting the prescontext?
// Does this event ever want one?
nsRefPtr<nsPresContext> ctx;
nsCOMPtr<nsIPresShell> shell = mElement->GetOwnerDoc()->GetPrimaryShell();
if (shell) {
ctx = shell->GetPresContext();
}
nsEventDispatcher::Dispatch(mElement, ctx, &event);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,53 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Asynchronous SVG load event dispatching code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henri Sivonen <hsivonen@iki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsHtml5SVGLoadDispatcher_h_
#define nsHtml5SVGLoadDispatcher_h_
#include "nsThreadUtils.h"
#include "nsIContent.h"
class nsHtml5SVGLoadDispatcher : public nsRunnable
{
private:
nsCOMPtr<nsIContent> mElement;
public:
nsHtml5SVGLoadDispatcher(nsIContent* aElement);
NS_IMETHOD Run();
};
#endif // nsHtml5SVGLoadDispatcher_h_

Просмотреть файл

@ -486,24 +486,13 @@ nsHtml5TreeBuilder::elementPopped(PRInt32 aNamespace, nsIAtom* aName, nsIContent
return;
}
if (aNamespace == kNameSpaceID_SVG) {
#if 0
if (aElement->HasAttr(kNameSpaceID_None, nsHtml5Atoms::onload)) {
nsEvent event(PR_TRUE, NS_SVG_LOAD);
event.eventStructType = NS_SVG_EVENT;
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
// Do we care about forcing presshell creation if it hasn't happened yet?
// That is, should this code flush or something? Does it really matter?
// For that matter, do we really want to try getting the prescontext? Does
// this event ever want one?
nsRefPtr<nsPresContext> ctx;
nsCOMPtr<nsIPresShell> shell = parser->GetDocument()->GetPrimaryShell();
if (shell) {
ctx = shell->GetPresContext();
}
nsEventDispatcher::Dispatch(aElement, ctx, &event);
#ifdef MOZ_SVG
if (aName == nsHtml5Atoms::svg) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
NS_ASSERTION(treeOp, "Tree op allocation failed.");
treeOp->Init(eTreeOpSvgLoad, aElement);
}
#endif
// TODO soft flush the op queue every now and then
return;
}
// we now have only HTML

Просмотреть файл

@ -61,6 +61,10 @@
#include "nsIFormProcessor.h"
#include "nsIServiceManager.h"
#ifdef MOZ_SVG
#include "nsHtml5SVGLoadDispatcher.h"
#endif
static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
/**
@ -660,6 +664,16 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
sele->FreezeUriAsyncDefer();
return rv;
}
#ifdef MOZ_SVG
case eTreeOpSvgLoad: {
nsIContent* node = *(mOne.node);
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(node);
if (NS_FAILED(NS_DispatchToMainThread(event))) {
NS_WARNING("failed to dispatch svg load dispatcher");
}
return rv;
}
#endif
default: {
NS_NOTREACHED("Bogus tree op");
}

Просмотреть файл

@ -81,6 +81,9 @@ enum eHtml5TreeOperation {
eTreeOpStreamEnded,
eTreeOpSetStyleLineNumber,
eTreeOpSetScriptLineNumberAndFreeze,
#ifdef MOZ_SVG
eTreeOpSvgLoad,
#endif
eTreeOpStartLayout
};

Просмотреть файл

@ -61,6 +61,8 @@ _TEST_FILES = parser_datreader.js \
bug_502091_iframe.html \
test_compatmode.html \
invalidchar.xml \
test_bug552938.html \
test_bug552938-2.html \
$(NULL)
libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=552938
-->
<head>
<title>Test for Bug 552938</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload='runTest();'>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=552938">Mozilla Bug 552938</a>
<script>
var svgLoadFired = false;
</script>
<p id="display"></p>
<div id="content" style="display: none">
<svg>
<script>
document.getElementsByTagName("svg")[0].addEventListener("SVGLoad",
function() { svgLoadFired = true; }, false);
</script>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 552938 **/
function runTest() {
ok(svgLoadFired, "The SVG load event should have fired.");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=552938
-->
<head>
<title>Test for Bug 552938</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload='runTest();'>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=552938">Mozilla Bug 552938</a>
<script>
var svgLoadFired = false;
</script>
<p id="display"></p>
<div id="content" style="display: none">
<svg onload="svgLoadFired = true;"></svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 552938 **/
function runTest() {
ok(svgLoadFired, "The SVG load event should have fired.");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>