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:
Emilio Cobos Álvarez 2023-11-28 22:27:59 +00:00
parent 44caba5c0c
commit 6d7d4024d9
3 changed files with 18 additions and 21 deletions

View file

@ -17148,7 +17148,8 @@ void Document::ScheduleResizeObserversNotification() const {
}
static void FlushLayoutForWholeBrowsingContextTree(Document& aDoc) {
if (BrowsingContext* bc = aDoc.GetBrowsingContext()) {
BrowsingContext* bc = aDoc.GetBrowsingContext();
if (bc && bc->GetExtantDocument() == &aDoc) {
RefPtr<BrowsingContext> top = bc->Top();
top->PreOrderWalk([](BrowsingContext* aCur) {
if (Document* doc = aCur->GetExtantDocument()) {
@ -17156,18 +17157,12 @@ static void FlushLayoutForWholeBrowsingContextTree(Document& aDoc) {
}
});
} 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);
}
}
bool Document::HasContentVisibilityAutoElements() const {
if (PresShell* presShell = GetPresShell()) {
return presShell->HasContentVisibilityAutoFrames();
}
return false;
}
void Document::DetermineProximityToViewportAndNotifyResizeObservers() {
uint32_t shallowestTargetDepth = 0;
bool initialResetOfScrolledIntoViewFlagsDone = false;

View file

@ -3755,10 +3755,6 @@ class Document : public nsINode,
* Returns whether there is any ResizeObserver that has skipped observations.
*/
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
* notify resize observers.

View file

@ -2251,17 +2251,23 @@ void nsRefreshDriver::DetermineProximityToViewportAndNotifyResizeObservers() {
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;
if (mPresContext->Document()->HasResizeObservers() ||
mPresContext->Document()->HasContentVisibilityAutoElements()) {
if (ShouldCollect(mPresContext->Document())) {
documents.AppendElement(mPresContext->Document());
}
mPresContext->Document()->CollectDescendantDocuments(
documents, [](const Document* document) -> bool {
return document->HasResizeObservers() ||
document->HasContentVisibilityAutoElements();
});
mPresContext->Document()->CollectDescendantDocuments(documents,
ShouldCollect);
for (const RefPtr<Document>& doc : documents) {
MOZ_KnownLive(doc)->DetermineProximityToViewportAndNotifyResizeObservers();