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
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
#include "nsAsyncDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
2008-04-11 10:29:06 -07:00
|
|
|
#include "nsContentUtils.h"
|
2011-05-09 12:33:03 -07:00
|
|
|
#include "nsEventDispatcher.h"
|
2013-03-27 11:15:58 -07:00
|
|
|
#include "nsDOMEvent.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2013-04-05 17:44:15 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
using namespace mozilla;
|
2013-04-05 17:44:15 -07:00
|
|
|
using namespace mozilla::dom;
|
2011-05-09 12:33:03 -07:00
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode* aEventNode, WidgetEvent& aEvent)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mEventNode(aEventNode), mDispatchChromeOnly(false)
|
2011-05-09 12:33:03 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
MOZ_ASSERT(mEventNode);
|
|
|
|
nsEventDispatcher::CreateEvent(aEventNode, nullptr, &aEvent, EmptyString(),
|
2011-05-09 12:33:03 -07:00
|
|
|
getter_AddRefs(mEvent));
|
|
|
|
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
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
NS_IMETHODIMP nsAsyncDOMEvent::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;
|
|
|
|
}
|
|
|
|
nsEventDispatcher::DispatchDOMEvent(target, nullptr, mEvent,
|
|
|
|
nullptr, nullptr);
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
nsresult nsAsyncDOMEvent::PostDOMEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_DispatchToCurrentThread(this);
|
|
|
|
}
|
2008-04-11 10:29:06 -07:00
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
void nsAsyncDOMEvent::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
|
|
|
|
2011-12-16 22:02:42 -08:00
|
|
|
nsLoadBlockingAsyncDOMEvent::~nsLoadBlockingAsyncDOMEvent()
|
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
|
|
|
}
|
|
|
|
}
|