Bug 982602 Rename ns(LoadBlocking)AsyncDOMEvent to mozilla::(LoadBlocking)AsyncEventDispatcher r=smaug

--HG--
rename : dom/events/nsAsyncDOMEvent.cpp => dom/events/AsyncEventDispatcher.cpp
rename : dom/events/nsAsyncDOMEvent.h => dom/events/AsyncEventDispatcher.h
This commit is contained in:
Masayuki Nakano 2014-03-17 15:56:54 +09:00
parent 39a8082f47
commit 03e2114412
27 changed files with 270 additions and 237 deletions

View File

@ -25,7 +25,6 @@
#include "nsNodeUtils.h"
#include "nsTextNode.h"
#include "mozAutoDocUpdate.h"
#include "nsAsyncDOMEvent.h"
#include "nsWrapperCacheInlines.h"
nsIAttribute::nsIAttribute(nsDOMAttributeMap* aAttrMap,

View File

@ -48,6 +48,7 @@
#include "nsDOMString.h"
#include "nsIScriptSecurityManager.h"
#include "nsIDOMMutationEvent.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/InternalMutationEvent.h"
@ -99,7 +100,6 @@
#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
#include "nsCSSRuleProcessor.h"
#include "nsRuleProcessorData.h"
#include "nsAsyncDOMEvent.h"
#include "nsTextNode.h"
#ifdef MOZ_XUL
@ -1946,7 +1946,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
mutation.mAttrChange = aModType;
mozAutoSubtreeModified subtree(OwnerDoc(), this);
(new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
}
return NS_OK;
@ -2131,7 +2131,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
mutation.mAttrChange = nsIDOMMutationEvent::REMOVAL;
mozAutoSubtreeModified subtree(OwnerDoc(), this);
(new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
}
return NS_OK;
@ -2618,12 +2618,12 @@ Element::MozRequestFullScreen()
NS_LITERAL_CSTRING("DOM"), OwnerDoc(),
nsContentUtils::eDOM_PROPERTIES,
error);
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(OwnerDoc(),
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(OwnerDoc(),
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
asyncDispatcher->PostDOMEvent();
return;
}

View File

@ -17,6 +17,7 @@
#include "mozilla/dom/FragmentOrElement.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/dom/Attr.h"
#include "nsDOMAttributeMap.h"
@ -99,7 +100,6 @@
#include "ChildIterator.h"
#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
#include "nsRuleProcessorData.h"
#include "nsAsyncDOMEvent.h"
#include "nsTextNode.h"
#include "mozilla/dom/NodeListBinding.h"
#include "mozilla/dom/UndoManager.h"
@ -1123,7 +1123,7 @@ FragmentOrElement::FireNodeInserted(nsIDocument* aDoc,
mutation.mRelatedNode = do_QueryInterface(aParent);
mozAutoSubtreeModified subtree(aDoc, aParent);
(new nsAsyncDOMEvent(childContent, mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(childContent, mutation))->RunDOMEventWhenSafe();
}
}
}

View File

@ -40,9 +40,9 @@
#include "nsDOMClassInfo.h"
#include "nsCxPusher.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/EventListenerManager.h"
#include "nsAsyncDOMEvent.h"
#include "nsIDOMNodeFilter.h"
#include "nsIDOMStyleSheet.h"
@ -3981,9 +3981,10 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
cssSheet, __VA_ARGS__); \
event->SetTrusted(true); \
event->SetTarget(this); \
nsRefPtr<nsAsyncDOMEvent> asyncEvent = new nsAsyncDOMEvent(this, event); \
asyncEvent->mDispatchChromeOnly = true; \
asyncEvent->PostDOMEvent(); \
nsRefPtr<AsyncEventDispatcher> asyncDispatcher = \
new AsyncEventDispatcher(this, event); \
asyncDispatcher->mDispatchChromeOnly = true; \
asyncDispatcher->PostDOMEvent(); \
} while (0);
void
@ -8567,12 +8568,12 @@ nsDocument::UnblockOnload(bool aFireSync)
// event to indicate that the SVG should be considered fully loaded.
// Because scripting is disabled on SVG-as-image documents, this event
// is not accessible to content authors. (See bug 837135.)
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(this,
NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
false,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this,
NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
false,
false);
asyncDispatcher->PostDOMEvent();
}
}
}
@ -8750,12 +8751,12 @@ NotifyPageHide(nsIDocument* aDocument, void* aData)
static void
DispatchFullScreenChange(nsIDocument* aTarget)
{
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(aTarget,
NS_LITERAL_STRING("mozfullscreenchange"),
true,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(aTarget,
NS_LITERAL_STRING("mozfullscreenchange"),
true,
false);
asyncDispatcher->PostDOMEvent();
}
void
@ -8908,7 +8909,8 @@ nsDocument::MutationEventDispatched(nsINode* aTarget)
int32_t realTargetCount = realTargets.Count();
for (int32_t k = 0; k < realTargetCount; ++k) {
InternalMutationEvent mutation(true, NS_MUTATION_SUBTREEMODIFIED);
(new nsAsyncDOMEvent(realTargets[k], mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(realTargets[k], mutation))->
RunDOMEventWhenSafe();
}
}
}
@ -9071,11 +9073,10 @@ nsDocument::SetReadyStateInternal(ReadyState rs)
mLoadingTimeStamp = mozilla::TimeStamp::Now();
}
nsRefPtr<nsAsyncDOMEvent> plevent =
new nsAsyncDOMEvent(this, NS_LITERAL_STRING("readystatechange"), false, false);
if (plevent) {
plevent->RunDOMEventWhenSafe();
}
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("readystatechange"),
false, false);
asyncDispatcher->RunDOMEventWhenSafe();
}
NS_IMETHODIMP
@ -10671,12 +10672,12 @@ nsDocument::RestorePreviousFullScreenState()
if (!nsContentUtils::HaveEqualPrincipals(fullScreenDoc, doc) ||
(!nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen") &&
!static_cast<nsDocument*>(doc)->mIsApprovedForFullscreen)) {
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(doc,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(doc,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
asyncDispatcher->PostDOMEvent();
}
}
@ -10760,12 +10761,12 @@ LogFullScreenDenied(bool aLogFailure, const char* aMessage, nsIDocument* aDoc)
if (!aLogFailure) {
return;
}
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(aDoc,
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(aDoc,
NS_LITERAL_STRING("mozfullscreenerror"),
true,
false);
asyncDispatcher->PostDOMEvent();
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("DOM"), aDoc,
nsContentUtils::eDOM_PROPERTIES,
@ -11121,12 +11122,12 @@ nsDocument::RequestFullScreen(Element* aElement,
// session.
if (!mIsApprovedForFullscreen ||
!nsContentUtils::HaveEqualPrincipals(previousFullscreenDoc, this)) {
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(this,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this,
NS_LITERAL_STRING("MozEnteredDomFullscreen"),
true,
true);
asyncDispatcher->PostDOMEvent();
}
#ifdef DEBUG
@ -11278,12 +11279,12 @@ DispatchPointerLockChange(nsIDocument* aTarget)
return;
}
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(aTarget,
NS_LITERAL_STRING("mozpointerlockchange"),
true,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(aTarget,
NS_LITERAL_STRING("mozpointerlockchange"),
true,
false);
asyncDispatcher->PostDOMEvent();
}
static void
@ -11293,12 +11294,12 @@ DispatchPointerLockError(nsIDocument* aTarget)
return;
}
nsRefPtr<nsAsyncDOMEvent> e =
new nsAsyncDOMEvent(aTarget,
NS_LITERAL_STRING("mozpointerlockerror"),
true,
false);
e->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(aTarget,
NS_LITERAL_STRING("mozpointerlockerror"),
true,
false);
asyncDispatcher->PostDOMEvent();
}
mozilla::StaticRefPtr<nsPointerLockPermissionRequest> gPendingPointerLockRequest;

View File

@ -57,7 +57,6 @@
#include "nsLayoutUtils.h"
#include "nsView.h"
#include "nsAsyncDOMEvent.h"
#include "nsIURI.h"
#include "nsIURL.h"
@ -76,6 +75,7 @@
#include "AppProcessChecker.h"
#include "ContentParent.h"
#include "TabParent.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/Preferences.h"
#include "mozilla/unused.h"
@ -375,12 +375,14 @@ nsFrameLoader::LoadFrame()
void
nsFrameLoader::FireErrorEvent()
{
if (mOwnerContent) {
nsRefPtr<nsAsyncDOMEvent> event =
new nsLoadBlockingAsyncDOMEvent(mOwnerContent, NS_LITERAL_STRING("error"),
false, false);
event->PostDOMEvent();
if (!mOwnerContent) {
return;
}
nsRefPtr<AsyncEventDispatcher > loadBlockingAsyncDispatcher =
new LoadBlockingAsyncEventDispatcher(mOwnerContent,
NS_LITERAL_STRING("error"),
false, false);
loadBlockingAsyncDispatcher->PostDOMEvent();
}
NS_IMETHODIMP

View File

@ -11,6 +11,7 @@
#include "mozilla/DebugOnly.h"
#include "nsGenericDOMDataNode.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ShadowRoot.h"
@ -32,7 +33,6 @@
#include "nsBindingManager.h"
#include "nsCCUncollectableMarker.h"
#include "mozAutoDocUpdate.h"
#include "nsAsyncDOMEvent.h"
#include "pldhash.h"
#include "prprf.h"
@ -387,7 +387,7 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
}
mozAutoSubtreeModified subtree(OwnerDoc(), this);
(new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
}
}

View File

@ -13,6 +13,7 @@
#include "AccessCheck.h"
#include "jsapi.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/CORSMode.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/InternalMutationEvent.h"
@ -22,7 +23,6 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/ShadowRoot.h"
#include "nsAsyncDOMEvent.h"
#include "nsAttrValueOrString.h"
#include "nsBindingManager.h"
#include "nsCCUncollectableMarker.h"
@ -1442,7 +1442,7 @@ nsINode::doInsertChildAt(nsIContent* aKid, uint32_t aIndex,
mutation.mRelatedNode = do_QueryInterface(this);
mozAutoSubtreeModified subtree(OwnerDoc(), this);
(new nsAsyncDOMEvent(aKid, mutation))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(aKid, mutation))->RunDOMEventWhenSafe();
}
}

View File

@ -26,7 +26,6 @@
#include "imgRequestProxy.h"
#include "nsThreadUtils.h"
#include "nsNetUtil.h"
#include "nsAsyncDOMEvent.h"
#include "nsImageFrame.h"
#include "nsIPresShell.h"
@ -45,6 +44,7 @@
#include "nsSVGEffects.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScriptSettings.h"
@ -1039,10 +1039,10 @@ nsImageLoadingContent::FireEvent(const nsAString& aEventType)
nsCOMPtr<nsINode> thisNode = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
nsRefPtr<nsAsyncDOMEvent> event =
new nsLoadBlockingAsyncDOMEvent(thisNode, aEventType, false, false);
event->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> loadBlockingAsyncDispatcher =
new LoadBlockingAsyncEventDispatcher(thisNode, aEventType, false, false);
loadBlockingAsyncDispatcher->PostDOMEvent();
return NS_OK;
}

View File

@ -18,7 +18,6 @@
#include "mozilla/gfx/Rect.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "nsAsyncDOMEvent.h"
#include "nsAttrValueInlines.h"
#include "nsContentUtils.h"
#include "nsDisplayList.h"

View File

@ -1056,14 +1056,14 @@ void
HTMLFormElement::PostPasswordEvent()
{
// Don't fire another add event if we have a pending add event.
if (mFormPasswordEvent.get()) {
if (mFormPasswordEventDispatcher.get()) {
return;
}
nsRefPtr<FormPasswordEvent> event =
new FormPasswordEvent(this, NS_LITERAL_STRING("DOMFormHasPassword"));
mFormPasswordEvent = event;
event->PostDOMEvent();
mFormPasswordEventDispatcher =
new FormPasswordEventDispatcher(this,
NS_LITERAL_STRING("DOMFormHasPassword"));
mFormPasswordEventDispatcher->PostDOMEvent();
}
// This function return true if the element, once appended, is the last one in

View File

@ -6,6 +6,7 @@
#ifndef mozilla_dom_HTMLFormElement_h
#define mozilla_dom_HTMLFormElement_h
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsIForm.h"
@ -20,7 +21,6 @@
#include "nsInterfaceHashtable.h"
#include "nsRefPtrHashtable.h"
#include "nsDataHashtable.h"
#include "nsAsyncDOMEvent.h"
#include "jsfriendapi.h" // For js::ExpandoAndGeneration
class nsIMutableArray;
@ -409,24 +409,24 @@ protected:
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void PostPasswordEvent();
void EventHandled() { mFormPasswordEvent = nullptr; }
void EventHandled() { mFormPasswordEventDispatcher = nullptr; }
class FormPasswordEvent : public nsAsyncDOMEvent
class FormPasswordEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
{
public:
FormPasswordEvent(HTMLFormElement* aEventNode,
const nsAString& aEventType)
: nsAsyncDOMEvent(aEventNode, aEventType, true, true)
FormPasswordEventDispatcher(HTMLFormElement* aEventNode,
const nsAString& aEventType)
: AsyncEventDispatcher(aEventNode, aEventType, true, true)
{}
NS_IMETHOD Run() MOZ_OVERRIDE
{
static_cast<HTMLFormElement*>(mEventNode.get())->EventHandled();
return nsAsyncDOMEvent::Run();
return AsyncEventDispatcher::Run();
}
};
nsRefPtr<FormPasswordEvent> mFormPasswordEvent;
nsRefPtr<FormPasswordEventDispatcher> mFormPasswordEventDispatcher;
class RemoveElementRunnable;
friend class RemoveElementRunnable;

View File

@ -6,9 +6,9 @@
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/Date.h"
#include "nsAsyncDOMEvent.h"
#include "nsAttrValueInlines.h"
#include "nsIDOMHTMLInputElement.h"
@ -3576,9 +3576,9 @@ HTMLInputElement::CancelRangeThumbDrag(bool aIsForUserEvent)
if (frame) {
frame->UpdateForValueChange();
}
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(this, NS_LITERAL_STRING("input"), true, false);
event->RunDOMEventWhenSafe();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("input"), true, false);
asyncDispatcher->RunDOMEventWhenSafe();
}
}
@ -5077,9 +5077,10 @@ HTMLInputElement::SetSelectionRange(int32_t aSelectionStart,
aRv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
if (!aRv.Failed()) {
aRv = textControlFrame->ScrollSelectionIntoView();
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(this, NS_LITERAL_STRING("select"), true, false);
event->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("select"),
true, false);
asyncDispatcher->PostDOMEvent();
}
}
}

View File

@ -6,10 +6,10 @@
#include "mozilla/dom/HTMLLinkElement.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/HTMLLinkElementBinding.h"
#include "mozilla/MemoryReporting.h"
#include "nsAsyncDOMEvent.h"
#include "nsContentUtils.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
@ -226,11 +226,11 @@ HTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc,
strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH)
return;
nsRefPtr<nsAsyncDOMEvent> event = new nsAsyncDOMEvent(this, aEventName, true,
true);
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, aEventName, true, true);
// Always run async in order to avoid running script when the content
// sink isn't expecting it.
event->PostDOMEvent();
asyncDispatcher->PostDOMEvent();
}
nsresult

View File

@ -3,11 +3,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/dom/HTMLMetaElement.h"
#include "mozilla/dom/HTMLMetaElementBinding.h"
#include "nsStyleConsts.h"
#include "nsAsyncDOMEvent.h"
#include "nsContentUtils.h"
#include "nsStyleConsts.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
@ -83,9 +83,9 @@ HTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc,
if (!aDoc)
return;
nsRefPtr<nsAsyncDOMEvent> event = new nsAsyncDOMEvent(this, aEventName, true,
true);
event->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, aEventName, true, true);
asyncDispatcher->PostDOMEvent();
}
JSObject*

View File

@ -7,6 +7,7 @@
#include "mozilla/dom/HTMLTextAreaElement.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/HTMLTextAreaElementBinding.h"
#include "mozilla/MouseEvents.h"
@ -887,9 +888,10 @@ HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart,
rv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
if (NS_SUCCEEDED(rv)) {
rv = textControlFrame->ScrollSelectionIntoView();
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(this, NS_LITERAL_STRING("select"), true, false);
event->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("select"),
true, false);
asyncDispatcher->PostDOMEvent();
}
}
}

View File

@ -83,7 +83,6 @@
#include "mozilla/dom/Element.h"
#include "HTMLFieldSetElement.h"
#include "HTMLMenuElement.h"
#include "nsAsyncDOMEvent.h"
#include "nsDOMMutationObserver.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/FromParser.h"

View File

@ -75,7 +75,6 @@
#include "nsContentList.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/MouseEvents.h"
#include "nsAsyncDOMEvent.h"
#include "nsIDOMMutationEvent.h"
#include "nsPIDOMWindow.h"
#include "nsJSPrincipals.h"

View File

@ -3,19 +3,26 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsAsyncDOMEvent.h"
#include "nsIDOMEvent.h"
#include "nsContentUtils.h"
#include "nsEventDispatcher.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/EventTarget.h"
#include "nsContentUtils.h"
#include "nsEventDispatcher.h"
#include "nsIDOMEvent.h"
using namespace mozilla;
using namespace mozilla::dom;
namespace mozilla {
nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode* aEventNode, WidgetEvent& aEvent)
: mEventNode(aEventNode), mDispatchChromeOnly(false)
using namespace dom;
/******************************************************************************
* mozilla::AsyncEventDispatcher
******************************************************************************/
AsyncEventDispatcher::AsyncEventDispatcher(nsINode* aEventNode,
WidgetEvent& aEvent)
: mEventNode(aEventNode)
, mDispatchChromeOnly(false)
{
MOZ_ASSERT(mEventNode);
nsEventDispatcher::CreateEvent(aEventNode, nullptr, &aEvent, EmptyString(),
@ -25,7 +32,8 @@ nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode* aEventNode, WidgetEvent& aEvent)
mEvent->SetTrusted(aEvent.mFlags.mIsTrusted);
}
NS_IMETHODIMP nsAsyncDOMEvent::Run()
NS_IMETHODIMP
AsyncEventDispatcher::Run()
{
if (mEvent) {
if (mDispatchChromeOnly) {
@ -62,19 +70,27 @@ NS_IMETHODIMP nsAsyncDOMEvent::Run()
return NS_OK;
}
nsresult nsAsyncDOMEvent::PostDOMEvent()
nsresult
AsyncEventDispatcher::PostDOMEvent()
{
return NS_DispatchToCurrentThread(this);
}
void nsAsyncDOMEvent::RunDOMEventWhenSafe()
void
AsyncEventDispatcher::RunDOMEventWhenSafe()
{
nsContentUtils::AddScriptRunner(this);
}
nsLoadBlockingAsyncDOMEvent::~nsLoadBlockingAsyncDOMEvent()
/******************************************************************************
* mozilla::LoadBlockingAsyncEventDispatcher
******************************************************************************/
LoadBlockingAsyncEventDispatcher::~LoadBlockingAsyncEventDispatcher()
{
if (mBlockedDoc) {
mBlockedDoc->UnblockOnload(true);
}
}
} // namespace mozilla

View File

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_AsyncEventDispatcher_h_
#define mozilla_AsyncEventDispatcher_h_
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDOMEvent.h"
#include "nsINode.h"
#include "nsString.h"
#include "nsThreadUtils.h"
namespace mozilla {
/**
* Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
* For example, you may need to fire an event from within layout, but
* want to ensure that the event handler doesn't mutate the DOM at
* the wrong time, in order to avoid resulting instability.
*/
class AsyncEventDispatcher : public nsRunnable
{
public:
AsyncEventDispatcher(nsINode* aEventNode, const nsAString& aEventType,
bool aBubbles, bool aDispatchChromeOnly)
: mEventNode(aEventNode)
, mEventType(aEventType)
, mBubbles(aBubbles)
, mDispatchChromeOnly(aDispatchChromeOnly)
{
}
AsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
: mEventNode(aEventNode)
, mEvent(aEvent)
, mDispatchChromeOnly(false)
{
}
AsyncEventDispatcher(nsINode* aEventNode, WidgetEvent& aEvent);
NS_IMETHOD Run() MOZ_OVERRIDE;
nsresult PostDOMEvent();
void RunDOMEventWhenSafe();
nsCOMPtr<nsINode> mEventNode;
nsCOMPtr<nsIDOMEvent> mEvent;
nsString mEventType;
bool mBubbles;
bool mDispatchChromeOnly;
};
class LoadBlockingAsyncEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
{
public:
LoadBlockingAsyncEventDispatcher(nsINode* aEventNode,
const nsAString& aEventType,
bool aBubbles, bool aDispatchChromeOnly)
: AsyncEventDispatcher(aEventNode, aEventType,
aBubbles, aDispatchChromeOnly)
, mBlockedDoc(aEventNode->OwnerDoc())
{
if (mBlockedDoc) {
mBlockedDoc->BlockOnload();
}
}
LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
: AsyncEventDispatcher(aEventNode, aEvent)
, mBlockedDoc(aEventNode->OwnerDoc())
{
if (mBlockedDoc) {
mBlockedDoc->BlockOnload();
}
}
~LoadBlockingAsyncEventDispatcher();
private:
nsCOMPtr<nsIDocument> mBlockedDoc;
};
} // namespace mozilla
#endif // mozilla_AsyncEventDispatcher_h_

View File

@ -6,10 +6,10 @@
#include "ContentEventHandler.h"
#include "IMEContentObserver.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/dom/Element.h"
#include "nsAutoPtr.h"
#include "nsAsyncDOMEvent.h"
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
#include "nsIAtom.h"
@ -95,8 +95,8 @@ IMEContentObserver::Init(nsIWidget* aWidget,
if (IMEStateManager::IsTestingIME()) {
nsIDocument* doc = aPresContext->Document();
(new nsAsyncDOMEvent(doc, NS_LITERAL_STRING("MozIMEFocusIn"),
false, false))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusIn"),
false, false))->RunDOMEventWhenSafe();
}
aWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS));
@ -149,8 +149,8 @@ IMEContentObserver::Destroy()
if (mRootContent) {
if (IMEStateManager::IsTestingIME() && mEditableNode) {
nsIDocument* doc = mEditableNode->OwnerDoc();
(new nsAsyncDOMEvent(doc, NS_LITERAL_STRING("MozIMEFocusOut"),
false, false))->RunDOMEventWhenSafe();
(new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusOut"),
false, false))->RunDOMEventWhenSafe();
}
mWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
}

View File

@ -14,7 +14,6 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'content_events'
EXPORTS += [
'nsAsyncDOMEvent.h',
'nsDOMEventTargetHelper.h',
'nsDOMKeyNameList.h',
'nsEventDispatcher.h',
@ -26,6 +25,7 @@ EXPORTS += [
]
EXPORTS.mozilla += [
'AsyncEventDispatcher.h',
'EventListenerManager.h',
'IMEStateManager.h',
'InternalMutationEvent.h',
@ -67,6 +67,7 @@ if CONFIG['MOZ_WEBSPEECH']:
UNIFIED_SOURCES += [
'AnimationEvent.cpp',
'AsyncEventDispatcher.cpp',
'BeforeUnloadEvent.cpp',
'ClipboardEvent.cpp',
'CommandEvent.cpp',
@ -90,7 +91,6 @@ UNIFIED_SOURCES += [
'MutationEvent.cpp',
'NotifyAudioAvailableEvent.cpp',
'NotifyPaintEvent.cpp',
'nsAsyncDOMEvent.cpp',
'nsDOMEventTargetHelper.cpp',
'nsEventDispatcher.cpp',
'nsJSEventListener.cpp',

View File

@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsAsyncDOMEvent_h___
#define nsAsyncDOMEvent_h___
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsThreadUtils.h"
#include "nsINode.h"
#include "nsIDOMEvent.h"
#include "nsString.h"
#include "nsIDocument.h"
/**
* Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
* For example, you may need to fire an event from within layout, but
* want to ensure that the event handler doesn't mutate the DOM at
* the wrong time, in order to avoid resulting instability.
*/
class nsAsyncDOMEvent : public nsRunnable {
public:
nsAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
bool aBubbles, bool aDispatchChromeOnly)
: mEventNode(aEventNode), mEventType(aEventType),
mBubbles(aBubbles),
mDispatchChromeOnly(aDispatchChromeOnly)
{ }
nsAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
: mEventNode(aEventNode), mEvent(aEvent), mDispatchChromeOnly(false)
{ }
nsAsyncDOMEvent(nsINode* aEventNode, mozilla::WidgetEvent& aEvent);
NS_IMETHOD Run() MOZ_OVERRIDE;
nsresult PostDOMEvent();
void RunDOMEventWhenSafe();
nsCOMPtr<nsINode> mEventNode;
nsCOMPtr<nsIDOMEvent> mEvent;
nsString mEventType;
bool mBubbles;
bool mDispatchChromeOnly;
};
class nsLoadBlockingAsyncDOMEvent : public nsAsyncDOMEvent {
public:
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
bool aBubbles, bool aDispatchChromeOnly)
: nsAsyncDOMEvent(aEventNode, aEventType, aBubbles, aDispatchChromeOnly),
mBlockedDoc(aEventNode->OwnerDoc())
{
if (mBlockedDoc) {
mBlockedDoc->BlockOnload();
}
}
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
: nsAsyncDOMEvent(aEventNode, aEvent),
mBlockedDoc(aEventNode->OwnerDoc())
{
if (mBlockedDoc) {
mBlockedDoc->BlockOnload();
}
}
~nsLoadBlockingAsyncDOMEvent();
nsCOMPtr<nsIDocument> mBlockedDoc;
};
#endif

View File

@ -32,11 +32,11 @@
#include "nsLayoutUtils.h"
#include "nsDisplayList.h"
#include "nsITheme.h"
#include "nsAsyncDOMEvent.h"
#include "nsRenderingContext.h"
#include "mozilla/Likely.h"
#include <algorithm>
#include "nsTextNode.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/unused.h"
@ -1552,8 +1552,8 @@ void nsComboboxControlFrame::FireValueChangeEvent()
{
// Fire ValueChange event to indicate data value of combo box has changed
nsContentUtils::AddScriptRunner(
new nsAsyncDOMEvent(mContent, NS_LITERAL_STRING("ValueChange"), true,
false));
new AsyncEventDispatcher(mContent, NS_LITERAL_STRING("ValueChange"), true,
false));
}
void

View File

@ -25,7 +25,6 @@
#include "nsViewManager.h"
#include "nsIScrollableFrame.h"
#include "nsPresContext.h"
#include "nsAsyncDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIPresShell.h"
#include "prlog.h"
@ -78,6 +77,7 @@
#include "nsRegion.h"
#include "nsIFrameInlines.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
@ -2443,10 +2443,10 @@ nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent)
nsIContent* target = aContent ? aContent : mContent;
if (target) {
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(target, aDOMEventName, true, false);
if (NS_FAILED(event->PostDOMEvent()))
NS_WARNING("Failed to dispatch nsAsyncDOMEvent");
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(target, aDOMEventName, true, false);
DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch");
}
}

View File

@ -9,6 +9,7 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Selection.h"
#include "nsIScriptGlobalObject.h"
#include "nsPIDOMWindow.h"
@ -19,7 +20,6 @@
#include "nsError.h"
#include "nsView.h"
#include "nsAsyncDOMEvent.h"
#include <algorithm>
// Print Options
@ -1858,7 +1858,7 @@ nsPrintEngine::FirePrintPreviewUpdateEvent()
// listener bound to this event and therefore no need to dispatch it.
if (mIsDoingPrintPreview && !mIsDoingPrinting) {
nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
(new nsAsyncDOMEvent(
(new AsyncEventDispatcher(
cv->GetDocument(), NS_LITERAL_STRING("printPreviewUpdate"), true, true)
)->RunDOMEventWhenSafe();
}

View File

@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
@ -23,7 +24,6 @@
#include "nsIContent.h"
#include "nsStyleContext.h"
#include "nsIBoxObject.h"
#include "nsAsyncDOMEvent.h"
#include "nsIDOMDataContainerEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMElement.h"
@ -4562,11 +4562,9 @@ nsTreeBodyFrame::FireRowCountChangedEvent(int32_t aIndex, int32_t aCount)
event->SetTrusted(true);
nsRefPtr<nsAsyncDOMEvent> plevent = new nsAsyncDOMEvent(content, event);
if (!plevent)
return;
plevent->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(content, event);
asyncDispatcher->PostDOMEvent();
}
void
@ -4644,9 +4642,9 @@ nsTreeBodyFrame::FireInvalidateEvent(int32_t aStartRowIdx, int32_t aEndRowIdx,
event->SetTrusted(true);
nsRefPtr<nsAsyncDOMEvent> plevent = new nsAsyncDOMEvent(content, event);
if (plevent)
plevent->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(content, event);
asyncDispatcher->PostDOMEvent();
}
#endif

View File

@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AsyncEventDispatcher.h"
#include "nsCOMPtr.h"
#include "nsTreeSelection.h"
#include "nsIBoxObject.h"
@ -14,11 +15,12 @@
#include "nsIContent.h"
#include "nsNameSpaceManager.h"
#include "nsGkAtoms.h"
#include "nsAsyncDOMEvent.h"
#include "nsEventDispatcher.h"
#include "nsAutoPtr.h"
#include "nsComponentManagerUtils.h"
using namespace mozilla;
// A helper class for managing our ranges of selection.
struct nsTreeRange
{
@ -650,11 +652,12 @@ NS_IMETHODIMP nsTreeSelection::SetCurrentIndex(int32_t aIndex)
NS_NAMED_LITERAL_STRING(DOMMenuItemActive, "DOMMenuItemActive");
NS_NAMED_LITERAL_STRING(DOMMenuItemInactive, "DOMMenuItemInactive");
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(treeDOMNode,
(aIndex != -1 ? DOMMenuItemActive : DOMMenuItemInactive),
true, false);
return event->PostDOMEvent();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(treeDOMNode,
(aIndex != -1 ? DOMMenuItemActive :
DOMMenuItemInactive),
true, false);
return asyncDispatcher->PostDOMEvent();
}
NS_IMETHODIMP nsTreeSelection::GetCurrentColumn(nsITreeColumn** aCurrentColumn)
@ -838,9 +841,9 @@ nsTreeSelection::FireOnSelectHandler()
nsCOMPtr<nsINode> node(do_QueryInterface(elt));
NS_ENSURE_STATE(node);
nsRefPtr<nsAsyncDOMEvent> event =
new nsAsyncDOMEvent(node, NS_LITERAL_STRING("select"), true, false);
event->RunDOMEventWhenSafe();
nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(node, NS_LITERAL_STRING("select"), true, false);
asyncDispatcher->RunDOMEventWhenSafe();
return NS_OK;
}