зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
8e434d1c10
Коммит
e112dca692
|
@ -23,7 +23,6 @@ using namespace dom;
|
||||||
AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
||||||
WidgetEvent& aEvent)
|
WidgetEvent& aEvent)
|
||||||
: mTarget(aTarget)
|
: mTarget(aTarget)
|
||||||
, mOnlyChromeDispatch(false)
|
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mTarget);
|
MOZ_ASSERT(mTarget);
|
||||||
RefPtr<Event> event =
|
RefPtr<Event> event =
|
||||||
|
@ -37,6 +36,9 @@ AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
AsyncEventDispatcher::Run()
|
AsyncEventDispatcher::Run()
|
||||||
{
|
{
|
||||||
|
if (mCanceled) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
RefPtr<Event> event = mEvent ? mEvent->InternalDOMEvent() : nullptr;
|
RefPtr<Event> event = mEvent ? mEvent->InternalDOMEvent() : nullptr;
|
||||||
if (!event) {
|
if (!event) {
|
||||||
event = NS_NewDOMEvent(mTarget, nullptr, nullptr);
|
event = NS_NewDOMEvent(mTarget, nullptr, nullptr);
|
||||||
|
@ -52,6 +54,13 @@ AsyncEventDispatcher::Run()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
AsyncEventDispatcher::Cancel()
|
||||||
|
{
|
||||||
|
mCanceled = true;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
AsyncEventDispatcher::PostDOMEvent()
|
AsyncEventDispatcher::PostDOMEvent()
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,13 +19,13 @@ class nsINode;
|
||||||
namespace mozilla {
|
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
|
* 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
|
* want to ensure that the event handler doesn't mutate the DOM at
|
||||||
* the wrong time, in order to avoid resulting instability.
|
* the wrong time, in order to avoid resulting instability.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AsyncEventDispatcher : public nsRunnable
|
class AsyncEventDispatcher : public nsCancelableRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -48,29 +48,28 @@ public:
|
||||||
: mTarget(aTarget)
|
: mTarget(aTarget)
|
||||||
, mEventType(aEventType)
|
, mEventType(aEventType)
|
||||||
, mBubbles(aBubbles)
|
, mBubbles(aBubbles)
|
||||||
, mOnlyChromeDispatch(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncEventDispatcher(dom::EventTarget* aTarget, nsIDOMEvent* aEvent)
|
AsyncEventDispatcher(dom::EventTarget* aTarget, nsIDOMEvent* aEvent)
|
||||||
: mTarget(aTarget)
|
: mTarget(aTarget)
|
||||||
, mEvent(aEvent)
|
, mEvent(aEvent)
|
||||||
, mBubbles(false)
|
|
||||||
, mOnlyChromeDispatch(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncEventDispatcher(dom::EventTarget* aTarget, WidgetEvent& aEvent);
|
AsyncEventDispatcher(dom::EventTarget* aTarget, WidgetEvent& aEvent);
|
||||||
|
|
||||||
NS_IMETHOD Run() override;
|
NS_IMETHOD Run() override;
|
||||||
|
NS_IMETHOD Cancel() override;
|
||||||
nsresult PostDOMEvent();
|
nsresult PostDOMEvent();
|
||||||
void RunDOMEventWhenSafe();
|
void RunDOMEventWhenSafe();
|
||||||
|
|
||||||
nsCOMPtr<dom::EventTarget> mTarget;
|
nsCOMPtr<dom::EventTarget> mTarget;
|
||||||
nsCOMPtr<nsIDOMEvent> mEvent;
|
nsCOMPtr<nsIDOMEvent> mEvent;
|
||||||
nsString mEventType;
|
nsString mEventType;
|
||||||
bool mBubbles;
|
bool mBubbles = false;
|
||||||
bool mOnlyChromeDispatch;
|
bool mOnlyChromeDispatch = false;
|
||||||
|
bool mCanceled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoadBlockingAsyncEventDispatcher final : public AsyncEventDispatcher
|
class LoadBlockingAsyncEventDispatcher final : public AsyncEventDispatcher
|
||||||
|
@ -96,7 +95,7 @@ public:
|
||||||
mBlockedDoc->BlockOnload();
|
mBlockedDoc->BlockOnload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~LoadBlockingAsyncEventDispatcher();
|
~LoadBlockingAsyncEventDispatcher();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче