2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 21:18:28 +04:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-04-06 04:44:15 +04:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
2013-04-06 04:44:15 +04:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::AsyncEventDispatcher
|
|
|
|
******************************************************************************/
|
2011-05-09 23:33:03 +04:00
|
|
|
|
2014-05-14 13:48:37 +04:00
|
|
|
AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
2014-03-17 10:56:54 +04:00
|
|
|
WidgetEvent& aEvent)
|
2014-05-14 13:48:37 +04:00
|
|
|
: mTarget(aTarget)
|
2015-05-26 01:04:38 +03:00
|
|
|
, mOnlyChromeDispatch(false)
|
2011-05-09 23:33:03 +04:00
|
|
|
{
|
2014-05-14 13:48:37 +04:00
|
|
|
MOZ_ASSERT(mTarget);
|
2015-08-12 14:39:31 +03:00
|
|
|
nsRefPtr<Event> event =
|
|
|
|
EventDispatcher::CreateEvent(aTarget, nullptr, &aEvent, EmptyString());
|
|
|
|
mEvent = do_QueryInterface(event);
|
2011-05-09 23:33:03 +04:00
|
|
|
NS_ASSERTION(mEvent, "Should never fail to create an event");
|
2012-06-11 03:44:50 +04:00
|
|
|
mEvent->DuplicatePrivateData();
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->SetTrusted(aEvent.mFlags.mIsTrusted);
|
2011-05-09 23:33:03 +04:00
|
|
|
}
|
2005-07-28 21:18:28 +04:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
AsyncEventDispatcher::Run()
|
2005-07-28 21:18:28 +04:00
|
|
|
{
|
2015-08-12 14:39:31 +03:00
|
|
|
nsRefPtr<Event> event = mEvent ? mEvent->InternalDOMEvent() : nullptr;
|
2015-05-26 01:04:38 +03:00
|
|
|
if (!event) {
|
2015-08-12 14:39:31 +03:00
|
|
|
event = NS_NewDOMEvent(mTarget, nullptr, nullptr);
|
2015-05-26 01:04:38 +03:00
|
|
|
nsresult rv = event->InitEvent(mEventType, mBubbles, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
event->SetTrusted(true);
|
2005-07-28 21:18:28 +04:00
|
|
|
}
|
2015-05-26 01:04:38 +03:00
|
|
|
if (mOnlyChromeDispatch) {
|
2015-08-12 14:39:31 +03:00
|
|
|
MOZ_ASSERT(event->IsTrusted());
|
2015-05-26 01:04:38 +03:00
|
|
|
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
|
|
|
|
}
|
|
|
|
bool dummy;
|
|
|
|
mTarget->DispatchEvent(event, &dummy);
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
2005-07-28 21:18:28 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
nsresult
|
|
|
|
AsyncEventDispatcher::PostDOMEvent()
|
2005-07-28 21:18:28 +04:00
|
|
|
{
|
2014-05-14 13:48:37 +04:00
|
|
|
nsRefPtr<AsyncEventDispatcher> ensureDeletionWhenFailing = this;
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_DispatchToCurrentThread(this);
|
2005-07-28 21:18:28 +04:00
|
|
|
}
|
2008-04-11 21:29:06 +04:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
void
|
|
|
|
AsyncEventDispatcher::RunDOMEventWhenSafe()
|
2008-04-11 21:29:06 +04:00
|
|
|
{
|
2014-05-14 13:48:37 +04:00
|
|
|
nsRefPtr<AsyncEventDispatcher> ensureDeletionWhenFailing = this;
|
2011-05-09 23:33:03 +04:00
|
|
|
nsContentUtils::AddScriptRunner(this);
|
2008-04-11 21:29:06 +04:00
|
|
|
}
|
2010-02-25 05:45:43 +03:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::LoadBlockingAsyncEventDispatcher
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
LoadBlockingAsyncEventDispatcher::~LoadBlockingAsyncEventDispatcher()
|
2010-02-25 05:45:43 +03:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mBlockedDoc->UnblockOnload(true);
|
2010-02-25 05:45:43 +03:00
|
|
|
}
|
|
|
|
}
|
2014-03-17 10:56:54 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|