forked from mirrors/gecko-dev
Bug 1867042 - Don't force PresShell initialization from ResizeObserver handling. r=fredw
This is unfortunately somewhat hard to test, because paint suppression is not really quite observable by the page. This makes sure that we don't report resize observations etc until the page has been laid out for other reasons. Differential Revision: https://phabricator.services.mozilla.com/D194910
This commit is contained in:
parent
44caba5c0c
commit
6d7d4024d9
3 changed files with 18 additions and 21 deletions
|
|
@ -17148,7 +17148,8 @@ void Document::ScheduleResizeObserversNotification() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FlushLayoutForWholeBrowsingContextTree(Document& aDoc) {
|
static void FlushLayoutForWholeBrowsingContextTree(Document& aDoc) {
|
||||||
if (BrowsingContext* bc = aDoc.GetBrowsingContext()) {
|
BrowsingContext* bc = aDoc.GetBrowsingContext();
|
||||||
|
if (bc && bc->GetExtantDocument() == &aDoc) {
|
||||||
RefPtr<BrowsingContext> top = bc->Top();
|
RefPtr<BrowsingContext> top = bc->Top();
|
||||||
top->PreOrderWalk([](BrowsingContext* aCur) {
|
top->PreOrderWalk([](BrowsingContext* aCur) {
|
||||||
if (Document* doc = aCur->GetExtantDocument()) {
|
if (Document* doc = aCur->GetExtantDocument()) {
|
||||||
|
|
@ -17156,18 +17157,12 @@ static void FlushLayoutForWholeBrowsingContextTree(Document& aDoc) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If there is no browsing context, we just flush this document itself.
|
// If there is no browsing context, or we're not the current document of the
|
||||||
|
// browsing context, then we just flush this document itself.
|
||||||
aDoc.FlushPendingNotifications(FlushType::Layout);
|
aDoc.FlushPendingNotifications(FlushType::Layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::HasContentVisibilityAutoElements() const {
|
|
||||||
if (PresShell* presShell = GetPresShell()) {
|
|
||||||
return presShell->HasContentVisibilityAutoFrames();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Document::DetermineProximityToViewportAndNotifyResizeObservers() {
|
void Document::DetermineProximityToViewportAndNotifyResizeObservers() {
|
||||||
uint32_t shallowestTargetDepth = 0;
|
uint32_t shallowestTargetDepth = 0;
|
||||||
bool initialResetOfScrolledIntoViewFlagsDone = false;
|
bool initialResetOfScrolledIntoViewFlagsDone = false;
|
||||||
|
|
|
||||||
|
|
@ -3755,10 +3755,6 @@ class Document : public nsINode,
|
||||||
* Returns whether there is any ResizeObserver that has skipped observations.
|
* Returns whether there is any ResizeObserver that has skipped observations.
|
||||||
*/
|
*/
|
||||||
bool HasAnySkippedResizeObservations() const;
|
bool HasAnySkippedResizeObservations() const;
|
||||||
/**
|
|
||||||
* Returns whether the document contains any content-visibility: auto element.
|
|
||||||
*/
|
|
||||||
bool HasContentVisibilityAutoElements() const;
|
|
||||||
/**
|
/**
|
||||||
* Determine proximity to viewport for content-visibility: auto elements and
|
* Determine proximity to viewport for content-visibility: auto elements and
|
||||||
* notify resize observers.
|
* notify resize observers.
|
||||||
|
|
|
||||||
|
|
@ -2251,17 +2251,23 @@ void nsRefreshDriver::DetermineProximityToViewportAndNotifyResizeObservers() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ShouldCollect = [](const Document* aDocument) {
|
||||||
|
PresShell* ps = aDocument->GetPresShell();
|
||||||
|
if (!ps || !ps->DidInitialize()) {
|
||||||
|
// If there's no shell or it didn't initialize, then we'll run this code
|
||||||
|
// when the pres shell does the initial reflow.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return ps->HasContentVisibilityAutoFrames() ||
|
||||||
|
aDocument->HasResizeObservers();
|
||||||
|
};
|
||||||
|
|
||||||
AutoTArray<RefPtr<Document>, 32> documents;
|
AutoTArray<RefPtr<Document>, 32> documents;
|
||||||
if (mPresContext->Document()->HasResizeObservers() ||
|
if (ShouldCollect(mPresContext->Document())) {
|
||||||
mPresContext->Document()->HasContentVisibilityAutoElements()) {
|
|
||||||
documents.AppendElement(mPresContext->Document());
|
documents.AppendElement(mPresContext->Document());
|
||||||
}
|
}
|
||||||
|
mPresContext->Document()->CollectDescendantDocuments(documents,
|
||||||
mPresContext->Document()->CollectDescendantDocuments(
|
ShouldCollect);
|
||||||
documents, [](const Document* document) -> bool {
|
|
||||||
return document->HasResizeObservers() ||
|
|
||||||
document->HasContentVisibilityAutoElements();
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const RefPtr<Document>& doc : documents) {
|
for (const RefPtr<Document>& doc : documents) {
|
||||||
MOZ_KnownLive(doc)->DetermineProximityToViewportAndNotifyResizeObservers();
|
MOZ_KnownLive(doc)->DetermineProximityToViewportAndNotifyResizeObservers();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue