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