dom/events/AsyncEventDispatcher.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/AsyncEventDispatcher.h"
michael@0 7 #include "mozilla/BasicEvents.h"
michael@0 8 #include "mozilla/EventDispatcher.h"
michael@0 9 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
michael@0 10 #include "mozilla/dom/EventTarget.h"
michael@0 11 #include "nsContentUtils.h"
michael@0 12 #include "nsIDOMEvent.h"
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15
michael@0 16 using namespace dom;
michael@0 17
michael@0 18 /******************************************************************************
michael@0 19 * mozilla::AsyncEventDispatcher
michael@0 20 ******************************************************************************/
michael@0 21
michael@0 22 AsyncEventDispatcher::AsyncEventDispatcher(nsINode* aEventNode,
michael@0 23 WidgetEvent& aEvent)
michael@0 24 : mEventNode(aEventNode)
michael@0 25 , mDispatchChromeOnly(false)
michael@0 26 {
michael@0 27 MOZ_ASSERT(mEventNode);
michael@0 28 EventDispatcher::CreateEvent(aEventNode, nullptr, &aEvent, EmptyString(),
michael@0 29 getter_AddRefs(mEvent));
michael@0 30 NS_ASSERTION(mEvent, "Should never fail to create an event");
michael@0 31 mEvent->DuplicatePrivateData();
michael@0 32 mEvent->SetTrusted(aEvent.mFlags.mIsTrusted);
michael@0 33 }
michael@0 34
michael@0 35 NS_IMETHODIMP
michael@0 36 AsyncEventDispatcher::Run()
michael@0 37 {
michael@0 38 if (mEvent) {
michael@0 39 if (mDispatchChromeOnly) {
michael@0 40 MOZ_ASSERT(mEvent->InternalDOMEvent()->IsTrusted());
michael@0 41
michael@0 42 nsCOMPtr<nsIDocument> ownerDoc = mEventNode->OwnerDoc();
michael@0 43 nsPIDOMWindow* window = ownerDoc->GetWindow();
michael@0 44 if (!window) {
michael@0 45 return NS_ERROR_INVALID_ARG;
michael@0 46 }
michael@0 47
michael@0 48 nsCOMPtr<EventTarget> target = window->GetParentTarget();
michael@0 49 if (!target) {
michael@0 50 return NS_ERROR_INVALID_ARG;
michael@0 51 }
michael@0 52 EventDispatcher::DispatchDOMEvent(target, nullptr, mEvent,
michael@0 53 nullptr, nullptr);
michael@0 54 } else {
michael@0 55 nsCOMPtr<EventTarget> target = mEventNode.get();
michael@0 56 bool defaultActionEnabled; // This is not used because the caller is async
michael@0 57 target->DispatchEvent(mEvent, &defaultActionEnabled);
michael@0 58 }
michael@0 59 } else {
michael@0 60 nsIDocument* doc = mEventNode->OwnerDoc();
michael@0 61 if (mDispatchChromeOnly) {
michael@0 62 nsContentUtils::DispatchChromeEvent(doc, mEventNode, mEventType,
michael@0 63 mBubbles, false);
michael@0 64 } else {
michael@0 65 nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
michael@0 66 mBubbles, false);
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 return NS_OK;
michael@0 71 }
michael@0 72
michael@0 73 nsresult
michael@0 74 AsyncEventDispatcher::PostDOMEvent()
michael@0 75 {
michael@0 76 return NS_DispatchToCurrentThread(this);
michael@0 77 }
michael@0 78
michael@0 79 void
michael@0 80 AsyncEventDispatcher::RunDOMEventWhenSafe()
michael@0 81 {
michael@0 82 nsContentUtils::AddScriptRunner(this);
michael@0 83 }
michael@0 84
michael@0 85 /******************************************************************************
michael@0 86 * mozilla::LoadBlockingAsyncEventDispatcher
michael@0 87 ******************************************************************************/
michael@0 88
michael@0 89 LoadBlockingAsyncEventDispatcher::~LoadBlockingAsyncEventDispatcher()
michael@0 90 {
michael@0 91 if (mBlockedDoc) {
michael@0 92 mBlockedDoc->UnblockOnload(true);
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 } // namespace mozilla

mercurial