Bug 1351275: Move style flush observer logic to nsIPresShell, and align layout observing code. r=bholley

MozReview-Commit-ID: 2oUTNfTS4Ku
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez
2017-03-29 15:41:11 +02:00
parent e6f1a62f0d
commit f6d2513b77
5 changed files with 53 additions and 37 deletions

View File

@@ -466,7 +466,7 @@ struct nsCallbackEventRequest
// ----------------------------------------------------------------------------
#define ASSERT_REFLOW_SCHEDULED_STATE() \
NS_ASSERTION(mReflowScheduled == \
NS_ASSERTION(ObservingLayoutFlushes() == \
GetPresContext()->RefreshDriver()-> \
IsLayoutFlushObserver(this), "Unexpected state")
@@ -794,11 +794,12 @@ nsIPresShell::nsIPresShell()
, mFrozen(false)
, mIsFirstPaint(false)
, mObservesMutationsForPrint(false)
, mReflowScheduled(false)
, mSuppressInterruptibleReflows(false)
, mScrollPositionClampingScrollPortSizeSet(false)
, mNeedLayoutFlush(true)
, mNeedStyleFlush(true)
, mObservingStyleFlushes(false)
, mObservingLayoutFlushes(false)
, mNeedThrottledAnimationFlush(true)
, mPresShellId(0)
, mFontSizeInflationEmPerLine(0)
@@ -1827,7 +1828,7 @@ PresShell::Initialize(nscoord aWidth, nscoord aHeight)
FrameNeedsReflow(rootFrame, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
NS_ASSERTION(mDirtyRoots.Contains(rootFrame),
"Should be in mDirtyRoots now");
NS_ASSERTION(mReflowScheduled, "Why no reflow scheduled?");
NS_ASSERTION(mObservingLayoutFlushes, "Why no reflow scheduled?");
}
// Restore our root scroll position now if we're getting here after EndLoad
@@ -2864,9 +2865,9 @@ PresShell::CancelAllPendingReflows()
{
mDirtyRoots.Clear();
if (mReflowScheduled) {
if (mObservingLayoutFlushes) {
GetPresContext()->RefreshDriver()->RemoveLayoutFlushObserver(this);
mReflowScheduled = false;
mObservingLayoutFlushes = false;
}
ASSERT_REFLOW_SCHEDULED_STATE();
@@ -9080,8 +9081,8 @@ void
PresShell::MaybeScheduleReflow()
{
ASSERT_REFLOW_SCHEDULED_STATE();
if (mReflowScheduled || mIsDestroying || mIsReflowing ||
mDirtyRoots.Length() == 0)
if (mObservingLayoutFlushes || mIsDestroying || mIsReflowing ||
mDirtyRoots.IsEmpty())
return;
if (!mPresContext->HasPendingInterrupt() || !ScheduleReflowOffTimer()) {
@@ -9094,13 +9095,8 @@ PresShell::MaybeScheduleReflow()
void
PresShell::ScheduleReflow()
{
NS_PRECONDITION(!mReflowScheduled, "Why are we trying to schedule a reflow?");
ASSERT_REFLOW_SCHEDULED_STATE();
if (GetPresContext()->RefreshDriver()->AddLayoutFlushObserver(this)) {
mReflowScheduled = true;
}
DoObserveLayoutFlushes();
ASSERT_REFLOW_SCHEDULED_STATE();
}
@@ -9175,7 +9171,7 @@ PresShell::sReflowContinueCallback(nsITimer* aTimer, void* aPresShell)
bool
PresShell::ScheduleReflowOffTimer()
{
NS_PRECONDITION(!mReflowScheduled, "Shouldn't get here");
NS_PRECONDITION(!mObservingLayoutFlushes, "Shouldn't get here");
ASSERT_REFLOW_SCHEDULED_STATE();
if (!mReflowContinueTimer) {
@@ -9732,6 +9728,22 @@ nsIPresShell::RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver)
return true;
}
void
nsIPresShell::DoObserveStyleFlushes()
{
MOZ_ASSERT(!ObservingStyleFlushes());
mObservingStyleFlushes =
mPresContext->RefreshDriver()->AddStyleFlushObserver(this);
}
void
nsIPresShell::DoObserveLayoutFlushes()
{
MOZ_ASSERT(!ObservingLayoutFlushes());
mObservingLayoutFlushes =
mPresContext->RefreshDriver()->AddLayoutFlushObserver(this);
}
//------------------------------------------------------
// End of protected and private methods on the PresShell
//------------------------------------------------------