2005-07-28 17:18:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 17:18:28 +00:00
|
|
|
|
2011-12-17 06:02:05 +00:00
|
|
|
#ifndef nsAsyncDOMEvent_h___
|
|
|
|
#define nsAsyncDOMEvent_h___
|
2005-07-28 17:18:28 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2009-03-06 18:12:20 +00:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
2005-07-28 17:18:28 +00:00
|
|
|
#include "nsString.h"
|
2010-02-25 02:45:43 +00:00
|
|
|
#include "nsIDocument.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2005-07-28 17:18:28 +00:00
|
|
|
/**
|
2011-12-17 06:02:05 +00:00
|
|
|
* Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
|
2005-07-28 17:18:28 +00: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-17 06:02:05 +00:00
|
|
|
class nsAsyncDOMEvent : public nsRunnable {
|
2006-05-10 17:30:15 +00:00
|
|
|
public:
|
2011-12-17 06:02:05 +00:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
|
|
|
|
bool aBubbles, bool aDispatchChromeOnly)
|
2009-03-06 18:12:20 +00:00
|
|
|
: mEventNode(aEventNode), mEventType(aEventType),
|
2010-02-25 02:45:43 +00:00
|
|
|
mBubbles(aBubbles),
|
2009-03-06 18:12:20 +00:00
|
|
|
mDispatchChromeOnly(aDispatchChromeOnly)
|
2005-07-28 17:18:28 +00:00
|
|
|
{ }
|
2007-12-11 08:18:04 +00:00
|
|
|
|
2011-12-17 06:02:05 +00:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
|
2011-10-17 14:59:28 +00:00
|
|
|
: mEventNode(aEventNode), mEvent(aEvent), mDispatchChromeOnly(false)
|
2007-12-11 08:18:04 +00:00
|
|
|
{ }
|
|
|
|
|
2011-12-17 06:02:05 +00:00
|
|
|
nsAsyncDOMEvent(nsINode *aEventNode, nsEvent &aEvent);
|
2011-05-09 19:33:03 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_IMETHOD Run();
|
2005-07-28 17:18:28 +00:00
|
|
|
nsresult PostDOMEvent();
|
2011-05-09 19:33:03 +00:00
|
|
|
void RunDOMEventWhenSafe();
|
2005-07-28 17:18:28 +00:00
|
|
|
|
2009-03-06 18:12:20 +00:00
|
|
|
nsCOMPtr<nsINode> mEventNode;
|
2007-12-11 08:18:04 +00:00
|
|
|
nsCOMPtr<nsIDOMEvent> mEvent;
|
|
|
|
nsString mEventType;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mBubbles;
|
|
|
|
bool mDispatchChromeOnly;
|
2010-02-25 02:45:43 +00:00
|
|
|
};
|
|
|
|
|
2011-12-17 06:02:42 +00:00
|
|
|
class nsLoadBlockingAsyncDOMEvent : public nsAsyncDOMEvent {
|
2010-02-25 02:45:43 +00:00
|
|
|
public:
|
2011-12-17 06:02:42 +00:00
|
|
|
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
|
|
|
|
bool aBubbles, bool aDispatchChromeOnly)
|
2011-12-17 06:02:05 +00:00
|
|
|
: nsAsyncDOMEvent(aEventNode, aEventType, aBubbles, aDispatchChromeOnly),
|
2011-10-18 10:53:36 +00:00
|
|
|
mBlockedDoc(aEventNode->OwnerDoc())
|
2010-02-25 02:45:43 +00:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
|
|
|
mBlockedDoc->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 06:02:42 +00:00
|
|
|
nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
|
2011-12-17 06:02:05 +00:00
|
|
|
: nsAsyncDOMEvent(aEventNode, aEvent),
|
2011-10-18 10:53:36 +00:00
|
|
|
mBlockedDoc(aEventNode->OwnerDoc())
|
2010-02-25 02:45:43 +00:00
|
|
|
{
|
|
|
|
if (mBlockedDoc) {
|
|
|
|
mBlockedDoc->BlockOnload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 06:02:42 +00:00
|
|
|
~nsLoadBlockingAsyncDOMEvent();
|
2010-02-25 02:45:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> mBlockedDoc;
|
2005-07-28 17:18:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|