2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-04-05 17:44:15 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-03-16 23:56:54 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
2013-04-05 17:44:15 -07:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::AsyncEventDispatcher
|
|
|
|
******************************************************************************/
|
2011-05-09 12:33:03 -07:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
AsyncEventDispatcher::AsyncEventDispatcher(nsINode* aEventNode,
|
|
|
|
WidgetEvent& aEvent)
|
|
|
|
: mEventNode(aEventNode)
|
|
|
|
, mDispatchChromeOnly(false)
|
2011-05-09 12:33:03 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
MOZ_ASSERT(mEventNode);
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::CreateEvent(aEventNode, nullptr, &aEvent, EmptyString(),
|
|
|
|
getter_AddRefs(mEvent));
|
2011-05-09 12:33:03 -07:00
|
|
|
NS_ASSERTION(mEvent, "Should never fail to create an event");
|
2012-06-10 16:44:50 -07:00
|
|
|
mEvent->DuplicatePrivateData();
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->SetTrusted(aEvent.mFlags.mIsTrusted);
|
2011-05-09 12:33:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
AsyncEventDispatcher::Run()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-06 10:12:20 -08:00
|
|
|
if (mEvent) {
|
2013-03-27 11:15:58 -07:00
|
|
|
if (mDispatchChromeOnly) {
|
|
|
|
MOZ_ASSERT(mEvent->InternalDOMEvent()->IsTrusted());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> ownerDoc = mEventNode->OwnerDoc();
|
|
|
|
nsPIDOMWindow* window = ownerDoc->GetWindow();
|
|
|
|
if (!window) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:44:26 -07:00
|
|
|
nsCOMPtr<EventTarget> target = window->GetParentTarget();
|
2013-03-27 11:15:58 -07:00
|
|
|
if (!target) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::DispatchDOMEvent(target, nullptr, mEvent,
|
|
|
|
nullptr, nullptr);
|
2013-03-27 11:15:58 -07:00
|
|
|
} else {
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> target = mEventNode.get();
|
2013-03-27 11:15:58 -07:00
|
|
|
bool defaultActionEnabled; // This is not used because the caller is async
|
|
|
|
target->DispatchEvent(mEvent, &defaultActionEnabled);
|
|
|
|
}
|
2009-03-06 10:12:20 -08:00
|
|
|
} else {
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = mEventNode->OwnerDoc();
|
2011-10-18 04:19:44 -07:00
|
|
|
if (mDispatchChromeOnly) {
|
|
|
|
nsContentUtils::DispatchChromeEvent(doc, mEventNode, mEventType,
|
|
|
|
mBubbles, false);
|
|
|
|
} else {
|
|
|
|
nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
|
|
|
|
mBubbles, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
nsresult
|
|
|
|
AsyncEventDispatcher::PostDOMEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_DispatchToCurrentThread(this);
|
|
|
|
}
|
2008-04-11 10:29:06 -07:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
void
|
|
|
|
AsyncEventDispatcher::RunDOMEventWhenSafe()
|
2008-04-11 10:29:06 -07:00
|
|
|
{
|
2011-05-09 12:33:03 -07:00
|
|
|
nsContentUtils::AddScriptRunner(this);
|
2008-04-11 10:29:06 -07:00
|
|
|
}
|
2010-02-24 18:45:43 -08:00
|
|
|
|
2014-03-16 23:56:54 -07:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::LoadBlockingAsyncEventDispatcher
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
LoadBlockingAsyncEventDispatcher::~LoadBlockingAsyncEventDispatcher()
|
2010-02-24 18:45:43 -08:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mBlockedDoc->UnblockOnload(true);
|
2010-02-24 18:45:43 -08:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 23:56:54 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|