Bug 1421351 - Queue chrome-only scrollend event in refresh driver scroll event queue instead of firing immediately. r=kats

MozReview-Commit-ID: KVQ5kp1t7NW

--HG--
extra : rebase_source : f8daa82c692c94a9a2f5d2f88987b3d0d10d7bbb
This commit is contained in:
Mike Conley 2017-11-28 13:09:56 -05:00
parent 74915a3cf3
commit 741c01cd43
2 changed files with 47 additions and 2 deletions

View File

@ -2107,6 +2107,9 @@ ScrollFrameHelper::~ScrollFrameHelper()
if (mScrollEvent) {
mScrollEvent->Revoke();
}
if (mScrollEndEvent) {
mScrollEndEvent->Revoke();
}
}
/*
@ -2186,7 +2189,7 @@ ScrollFrameHelper::CompleteAsyncScroll(const nsRect &aRange, nsAtom* aOrigin)
// We are done scrolling, set our destination to wherever we actually ended
// up scrolling to.
mDestination = GetScrollPosition();
FireScrollEndEvent();
PostScrollEndEvent();
}
bool
@ -4422,10 +4425,25 @@ ScrollFrameHelper::FireScrollPortEvent()
mOuter->PresContext(), &event);
}
void
ScrollFrameHelper::PostScrollEndEvent()
{
if (mScrollEndEvent) {
return;
}
// The ScrollEndEvent constructor registers itself with the refresh driver.
mScrollEndEvent = new ScrollEndEvent(this);
}
void
ScrollFrameHelper::FireScrollEndEvent()
{
MOZ_ASSERT(mOuter->GetContent());
MOZ_ASSERT(mScrollEndEvent);
mScrollEndEvent->Revoke();
mScrollEndEvent = nullptr;
nsContentUtils::DispatchEventOnlyToChrome(mOuter->GetContent()->OwnerDoc(),
mOuter->GetContent(),
NS_LITERAL_STRING("scrollend"),
@ -4821,6 +4839,22 @@ ScrollFrameHelper::ScrollEvent::Run()
return NS_OK;
}
ScrollFrameHelper::ScrollEndEvent::ScrollEndEvent(ScrollFrameHelper* aHelper)
: Runnable("ScrollFrameHelper::ScrollEndEvent")
, mHelper(aHelper)
{
mHelper->mOuter->PresContext()->RefreshDriver()->PostScrollEvent(this);
}
NS_IMETHODIMP
ScrollFrameHelper::ScrollEndEvent::Run()
{
if (mHelper) {
mHelper->FireScrollEndEvent();
}
return NS_OK;
}
void
ScrollFrameHelper::FireScrollEvent()
{

View File

@ -69,6 +69,7 @@ public:
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter);
nsresult FireScrollPortEvent();
void PostScrollEndEvent();
void FireScrollEndEvent();
void PostOverflowEvent();
using PostDestroyData = nsIFrame::PostDestroyData;
@ -131,6 +132,15 @@ public:
ScrollFrameHelper* mHelper;
};
class ScrollEndEvent : public Runnable {
public:
NS_DECL_NSIRUNNABLE
explicit ScrollEndEvent(ScrollFrameHelper* aHelper);
void Revoke() { mHelper = nullptr; }
private:
ScrollFrameHelper* mHelper;
};
class AsyncScrollPortEvent : public Runnable {
public:
NS_DECL_NSIRUNNABLE
@ -402,7 +412,7 @@ public:
void SetTransformingByAPZ(bool aTransforming) {
if (mTransformingByAPZ && !aTransforming) {
FireScrollEndEvent();
PostScrollEndEvent();
}
mTransformingByAPZ = aTransforming;
if (!mozilla::css::TextOverflow::HasClippedOverflow(mOuter)) {
@ -495,6 +505,7 @@ public:
nsCOMPtr<nsIContent> mResizerContent;
RefPtr<ScrollEvent> mScrollEvent;
RefPtr<ScrollEndEvent> mScrollEndEvent;
nsRevocableEventPtr<AsyncScrollPortEvent> mAsyncScrollPortEvent;
nsRevocableEventPtr<ScrolledAreaEvent> mScrolledAreaEvent;
nsIFrame* mHScrollbarBox;