From 78ac3dcdb4203a9b946d5c5d77846fea316b5853 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 9 Mar 2018 06:41:30 +0900 Subject: [PATCH] Bug 1442817 - Add another variant of nsDocument::FlushPendingNotifications which are able to skip to flushing throttled animations. r=birtles,emilio MozReview-Commit-ID: BZ9yAoAmWBB --HG-- extra : rebase_source : 4f240b042992b3f13f296ce932c0d9795407932f --- dom/base/nsDocument.cpp | 28 +++++++++++++++++++--------- dom/base/nsIDocument.h | 8 ++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 1bfe97aec3ef..88f3aea3b625 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7579,6 +7579,15 @@ nsIDocument::CreateEvent(const nsAString& aEventType, CallerType aCallerType, void nsIDocument::FlushPendingNotifications(FlushType aType) { + mozilla::ChangesToFlush flush(aType, aType >= FlushType::Style); + FlushPendingNotifications(flush); +} + +void +nsIDocument::FlushPendingNotifications(mozilla::ChangesToFlush aFlush) +{ + FlushType flushType = aFlush.mFlushType; + nsDocumentOnStack dos(this); // We need to flush the sink for non-HTML documents (because the XML @@ -7588,7 +7597,7 @@ nsIDocument::FlushPendingNotifications(FlushType aType) // part if we have no presshell or if it's already done an initial // reflow. if ((!IsHTMLDocument() || - (aType > FlushType::ContentAndNotify && mPresShell && + (flushType > FlushType::ContentAndNotify && mPresShell && !mPresShell->DidInitialize())) && (mParser || mWeakSink)) { nsCOMPtr sink; @@ -7602,14 +7611,14 @@ nsIDocument::FlushPendingNotifications(FlushType aType) } // Determine if it is safe to flush the sink notifications // by determining if it safe to flush all the presshells. - if (sink && (aType == FlushType::Content || IsSafeToFlush())) { - sink->FlushPendingNotifications(aType); + if (sink && (flushType == FlushType::Content || IsSafeToFlush())) { + sink->FlushPendingNotifications(flushType); } } // Should we be flushing pending binding constructors in here? - if (aType <= FlushType::ContentAndNotify) { + if (flushType <= FlushType::ContentAndNotify) { // Nothing to do here return; } @@ -7624,14 +7633,15 @@ nsIDocument::FlushPendingNotifications(FlushType aType) // layout flush on our parent, since we need our container to be the // correct size to determine the correct style. if (mParentDocument && IsSafeToFlush()) { - FlushType parentType = aType; - if (aType >= FlushType::Style) - parentType = std::max(FlushType::Layout, aType); - mParentDocument->FlushPendingNotifications(parentType); + mozilla::ChangesToFlush parentFlush = aFlush; + if (flushType >= FlushType::Style) { + parentFlush.mFlushType = std::max(FlushType::Layout, flushType); + } + mParentDocument->FlushPendingNotifications(parentFlush); } if (nsIPresShell* shell = GetShell()) { - shell->FlushPendingNotifications(aType); + shell->FlushPendingNotifications(aFlush); } } diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 817ecadefd08..ab2640f764a1 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1737,6 +1737,14 @@ public: */ void FlushPendingNotifications(mozilla::FlushType aType); + /** + * Another variant of the above FlushPendingNotifications. This function + * takes a ChangesToFlush to specify whether throttled animations are flushed + * or not. + * If in doublt, use the above FlushPendingNotifications. + */ + void FlushPendingNotifications(mozilla::ChangesToFlush aFlush); + /** * Calls FlushPendingNotifications on any external resources this document * has. If this document has no external resources or is an external resource