diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 742df2c96d4f..cac6d1db11ed 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -3149,8 +3149,8 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal, #endif } +mozilla::dom::DocGroup* Document::GetDocGroup() const { #ifdef DEBUG -void Document::AssertDocGroupMatchesKey() const { // Sanity check that we have an up-to-date and accurate docgroup if (mDocGroup) { nsAutoCString docGroupKey; @@ -3162,9 +3162,11 @@ void Document::AssertDocGroupMatchesKey() const { } // XXX: Check that the TabGroup is correct as well! } -} #endif + return mDocGroup; +} + nsresult Document::Dispatch(TaskCategory aCategory, already_AddRefed&& aRunnable) { // Note that this method may be called off the main thread. @@ -7332,8 +7334,7 @@ void Document::FlushPendingNotifications(mozilla::ChangesToFlush aFlush) { // affect style, we need to promote a style flush on ourself to a // layout flush on our parent, since we need our container to be the // correct size to determine the correct style. - if (StyleOrLayoutObservablyDependsOnParentDocumentLayout() && - IsSafeToFlush()) { + if (mParentDocument && IsSafeToFlush()) { mozilla::ChangesToFlush parentFlush = aFlush; if (flushType >= FlushType::Style) { parentFlush.mFlushType = std::max(FlushType::Layout, flushType); diff --git a/dom/base/Document.h b/dom/base/Document.h index 837dae91ceaa..2dcffdacd122 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -2406,6 +2406,7 @@ class Document : public nsINode, nsAtom* aAttrName, const nsAString& aAttrValue) const; + /** * To batch DOMSubtreeModified, document needs to be informed when * a mutation event might be dispatched, even if the event isn't actually @@ -3496,30 +3497,7 @@ class Document : public nsINode, void ReportHasScrollLinkedEffect(); bool HasScrollLinkedEffect() const { return mHasScrollLinkedEffect; } -#ifdef DEBUG - void AssertDocGroupMatchesKey() const; -#endif - - DocGroup* GetDocGroup() const { -#ifdef DEBUG - AssertDocGroupMatchesKey(); -#endif - return mDocGroup; - } - - /** - * If we're a sub-document, the parent document's layout can affect our style - * and layout (due to the viewport size, viewport units, media queries...). - * - * This function returns true if our parent document and our child document - * can observe each other. If they cannot, then we don't need to synchronously - * update the parent document layout every time the child document may need - * up-to-date layout information. - */ - bool StyleOrLayoutObservablyDependsOnParentDocumentLayout() const { - return GetParentDocument() && - GetDocGroup() == GetParentDocument()->GetDocGroup(); - } + DocGroup* GetDocGroup() const; void AddIntersectionObserver(DOMIntersectionObserver* aObserver) { MOZ_ASSERT(!mIntersectionObservers.Contains(aObserver), diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index ac52bd57bd61..88d80391eff6 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -7366,12 +7366,16 @@ void nsGlobalWindowOuter::FlushPendingNotifications(FlushType aType) { } void nsGlobalWindowOuter::EnsureSizeAndPositionUpToDate() { - // If we're a subframe, make sure our size is up to date. Make sure to go - // through the document chain rather than the window chain to not flush on - // detached iframes, see bug 1545516. - if (mDoc && mDoc->StyleOrLayoutObservablyDependsOnParentDocumentLayout()) { - RefPtr parent = mDoc->GetParentDocument(); - parent->FlushPendingNotifications(FlushType::Layout); + // If we're a subframe, make sure our size is up to date. It's OK that this + // crosses the content/chrome boundary, since chrome can have pending reflows + // too. + // + // Make sure to go through the document chain rather than the window chain to + // not flush on detached iframes, see bug 1545516. + if (mDoc) { + if (RefPtr parent = mDoc->GetParentDocument()) { + parent->FlushPendingNotifications(FlushType::Layout); + } } } diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 2d3da636a37c..fb644a64db73 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -785,8 +785,7 @@ bool nsComputedDOMStyle::NeedsToFlush() const { Document* doc = mElement->OwnerDoc(); // If parent document is there, also needs to check if there is some change // that needs to flush this document (e.g. size change for iframe). - while (doc->StyleOrLayoutObservablyDependsOnParentDocumentLayout()) { - Document* parentDocument = doc->GetParentDocument(); + while (Document* parentDocument = doc->GetParentDocument()) { Element* element = parentDocument->FindContentForSubDocument(doc); if (ElementNeedsRestyle(element, nullptr)) { return true;