mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1225412 Part 1 - Make AsyncEventDispatcher cancelable. r=smaug
Also I found that mBubbles are not initialized in the constructor in AsyncEventDispatcher.cpp. I initialized those bool member variables directly. MozReview-Commit-ID: FiU4NKGJjU9 --HG-- extra : rebase_source : 1bcd5808b442eb726763602525977bc064ecc0ee
This commit is contained in:
parent
8e434d1c10
commit
e112dca692
@ -23,7 +23,6 @@ using namespace dom;
|
||||
AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
||||
WidgetEvent& aEvent)
|
||||
: mTarget(aTarget)
|
||||
, mOnlyChromeDispatch(false)
|
||||
{
|
||||
MOZ_ASSERT(mTarget);
|
||||
RefPtr<Event> event =
|
||||
@ -37,6 +36,9 @@ AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
||||
NS_IMETHODIMP
|
||||
AsyncEventDispatcher::Run()
|
||||
{
|
||||
if (mCanceled) {
|
||||
return NS_OK;
|
||||
}
|
||||
RefPtr<Event> event = mEvent ? mEvent->InternalDOMEvent() : nullptr;
|
||||
if (!event) {
|
||||
event = NS_NewDOMEvent(mTarget, nullptr, nullptr);
|
||||
@ -52,6 +54,13 @@ AsyncEventDispatcher::Run()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AsyncEventDispatcher::Cancel()
|
||||
{
|
||||
mCanceled = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
AsyncEventDispatcher::PostDOMEvent()
|
||||
{
|
||||
|
@ -19,13 +19,13 @@ class nsINode;
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
|
||||
* Use AsyncEventDispatcher to fire a DOM event that requires safe a stable DOM.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class AsyncEventDispatcher : public nsRunnable
|
||||
|
||||
class AsyncEventDispatcher : public nsCancelableRunnable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@ -48,29 +48,28 @@ public:
|
||||
: mTarget(aTarget)
|
||||
, mEventType(aEventType)
|
||||
, mBubbles(aBubbles)
|
||||
, mOnlyChromeDispatch(false)
|
||||
{
|
||||
}
|
||||
|
||||
AsyncEventDispatcher(dom::EventTarget* aTarget, nsIDOMEvent* aEvent)
|
||||
: mTarget(aTarget)
|
||||
, mEvent(aEvent)
|
||||
, mBubbles(false)
|
||||
, mOnlyChromeDispatch(false)
|
||||
{
|
||||
}
|
||||
|
||||
AsyncEventDispatcher(dom::EventTarget* aTarget, WidgetEvent& aEvent);
|
||||
|
||||
NS_IMETHOD Run() override;
|
||||
NS_IMETHOD Cancel() override;
|
||||
nsresult PostDOMEvent();
|
||||
void RunDOMEventWhenSafe();
|
||||
|
||||
nsCOMPtr<dom::EventTarget> mTarget;
|
||||
nsCOMPtr<nsIDOMEvent> mEvent;
|
||||
nsString mEventType;
|
||||
bool mBubbles;
|
||||
bool mOnlyChromeDispatch;
|
||||
bool mBubbles = false;
|
||||
bool mOnlyChromeDispatch = false;
|
||||
bool mCanceled = false;
|
||||
};
|
||||
|
||||
class LoadBlockingAsyncEventDispatcher final : public AsyncEventDispatcher
|
||||
@ -96,7 +95,7 @@ public:
|
||||
mBlockedDoc->BlockOnload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~LoadBlockingAsyncEventDispatcher();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user