Bug 839103 - part 2 - enable chrome dispatching of nsIDOMEvents in nsAsyncDOMEvent; r=bz

This commit is contained in:
Nathan Froyd 2013-03-27 14:15:58 -04:00
parent b2aae26008
commit 6d6b3771e3

View File

@ -9,6 +9,7 @@
#include "nsContentUtils.h"
#include "nsEventDispatcher.h"
#include "nsGUIEvent.h"
#include "nsDOMEvent.h"
nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode *aEventNode, nsEvent &aEvent)
: mEventNode(aEventNode), mDispatchChromeOnly(false)
@ -24,10 +25,26 @@ nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode *aEventNode, nsEvent &aEvent)
NS_IMETHODIMP nsAsyncDOMEvent::Run()
{
if (mEvent) {
NS_ASSERTION(!mDispatchChromeOnly, "Can't do that");
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mEventNode);
bool defaultActionEnabled; // This is not used because the caller is async
target->DispatchEvent(mEvent, &defaultActionEnabled);
if (mDispatchChromeOnly) {
MOZ_ASSERT(mEvent->InternalDOMEvent()->IsTrusted());
nsCOMPtr<nsIDocument> ownerDoc = mEventNode->OwnerDoc();
nsPIDOMWindow* window = ownerDoc->GetWindow();
if (!window) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIDOMEventTarget> target = window->GetParentTarget();
if (!target) {
return NS_ERROR_INVALID_ARG;
}
nsEventDispatcher::DispatchDOMEvent(target, nullptr, mEvent,
nullptr, nullptr);
} else {
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mEventNode);
bool defaultActionEnabled; // This is not used because the caller is async
target->DispatchEvent(mEvent, &defaultActionEnabled);
}
} else {
nsIDocument* doc = mEventNode->OwnerDoc();
if (mDispatchChromeOnly) {