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
|
|
|
#ifndef nsAsyncDOMEvent_h___
|
|
|
|
#define nsAsyncDOMEvent_h___
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2009-03-06 10:12:20 -08:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
2010-02-24 18:45:43 -08:00
|
|
|
#include "nsIDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2011-12-16 22:02:05 -08:00
|
|
|
* Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
|
2007-03-22 10:30:00 -07:00
|
|
|
* For example, you may need to fire an event from within layout, but
|
|
|
|
* want to ensure that the event handler doesn't mutate the DOM at
|
|
|
|
* the wrong time, in order to avoid resulting instability.
|
|
|
|
*/
|
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
class nsAsyncDOMEvent : public nsRunnable {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2011-12-16 22:02:05 -08:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
|
|
|
|
bool aBubbles, bool aDispatchChromeOnly)
|
2009-03-06 10:12:20 -08:00
|
|
|
: mEventNode(aEventNode), mEventType(aEventType),
|
2010-02-24 18:45:43 -08:00
|
|
|
mBubbles(aBubbles),
|
2009-03-06 10:12:20 -08:00
|
|
|
mDispatchChromeOnly(aDispatchChromeOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{ }
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mEventNode(aEventNode), mEvent(aEvent), mDispatchChromeOnly(false)
|
2007-12-11 00:18:04 -08:00
|
|
|
{ }
|
|
|
|
|
2011-12-16 22:02:05 -08:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, nsEvent &aEvent);
|
2011-05-09 12:33:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD Run();
|
|
|
|
nsresult PostDOMEvent();
|
2011-05-09 12:33:03 -07:00
|
|
|
void RunDOMEventWhenSafe();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-06 10:12:20 -08:00
|
|
|
nsCOMPtr<nsINode> mEventNode;
|
2007-12-11 00:18:04 -08:00
|
|
|
nsCOMPtr<nsIDOMEvent> mEvent;
|
|
|
|
nsString mEventType;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mBubbles;
|
|
|
|
bool mDispatchChromeOnly;
|
2010-02-24 18:45:43 -08:00
|
|
|
};
|
|
|
|
|
2011-12-16 22:02:42 -08:00
|
|
|
class nsLoadBlockingAsyncDOMEvent : public nsAsyncDOMEvent {
|
2010-02-24 18:45:43 -08:00
|
|
|
public:
|
2011-12-16 22:02:42 -08:00
|
|
|
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
|
|
|
|
bool aBubbles, bool aDispatchChromeOnly)
|
2011-12-16 22:02:05 -08:00
|
|
|
: nsAsyncDOMEvent(aEventNode, aEventType, aBubbles, aDispatchChromeOnly),
|
2011-10-18 03:53:36 -07:00
|
|
|
mBlockedDoc(aEventNode->OwnerDoc())
|
2010-02-24 18:45:43 -08:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
|
|
|
mBlockedDoc->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 22:02:42 -08:00
|
|
|
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
|
2011-12-16 22:02:05 -08:00
|
|
|
: nsAsyncDOMEvent(aEventNode, aEvent),
|
2011-10-18 03:53:36 -07:00
|
|
|
mBlockedDoc(aEventNode->OwnerDoc())
|
2010-02-24 18:45:43 -08:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
|
|
|
mBlockedDoc->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 22:02:42 -08:00
|
|
|
~nsLoadBlockingAsyncDOMEvent();
|
2010-02-24 18:45:43 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> mBlockedDoc;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|