Bug 1791759 - Add support for content-visibility: auto r=emilio
This change adds support for `content-visibilty: auto` as well as showing and hiding content based on the relevancy of the content as defined in the specification. Changes to relevancy are handled by triggering updates in a set of `content-visibility: auto` frames stored in PresShell at the appropriate time in the document lifecycle. Some tests are now failing due to this feature exposing the failures, but they will be fixed in later changes. This change is a reland of an earlier version that properly updates intrinsic sizes and triggers an update of remembered size for the purposes of contain-intrinsic-size when content relevancy changes. Co-authored-by: Jihye Hong <jihye@igalia.com> Differential Revision: https://phabricator.services.mozilla.com/D159693
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "nsRefreshDriver.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/StaticPrefs_layout.h"
|
||||
#include "mozilla/ServoBindings.h"
|
||||
#include "mozilla/dom/BrowserChild.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
@@ -150,6 +151,20 @@ static void LazyLoadCallback(
|
||||
}
|
||||
}
|
||||
|
||||
static void ContentVisibilityCallback(
|
||||
const Sequence<OwningNonNull<DOMIntersectionObserverEntry>>& aEntries) {
|
||||
for (const auto& entry : aEntries) {
|
||||
entry->Target()->SetVisibleForContentVisibility(entry->IsIntersecting());
|
||||
|
||||
if (RefPtr<Document> doc = entry->Target()->GetComposedDoc()) {
|
||||
if (RefPtr<PresShell> presShell = doc->GetPresShell()) {
|
||||
presShell->ScheduleContentRelevancyUpdate(
|
||||
ContentRelevancyReason::Visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static LengthPercentage PrefMargin(float aValue, bool aIsPercentage) {
|
||||
return aIsPercentage ? LengthPercentage::FromPercentage(aValue / 100.0f)
|
||||
: LengthPercentage::FromPixels(aValue);
|
||||
@@ -182,6 +197,25 @@ DOMIntersectionObserver::CreateLazyLoadObserver(Document& aDocument) {
|
||||
return observer.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMIntersectionObserver>
|
||||
DOMIntersectionObserver::CreateContentVisibilityObserver(Document& aDocument) {
|
||||
RefPtr<DOMIntersectionObserver> observer =
|
||||
new DOMIntersectionObserver(aDocument, ContentVisibilityCallback);
|
||||
|
||||
observer->mThresholds.AppendElement(0.0f);
|
||||
|
||||
auto margin = LengthPercentage::FromPercentage(
|
||||
StaticPrefs::layout_css_content_visibility_relevant_content_margin() /
|
||||
100.0f);
|
||||
|
||||
observer->mRootMargin.Get(eSideTop) = margin;
|
||||
observer->mRootMargin.Get(eSideRight) = margin;
|
||||
observer->mRootMargin.Get(eSideBottom) = margin;
|
||||
observer->mRootMargin.Get(eSideLeft) = margin;
|
||||
|
||||
return observer.forget();
|
||||
}
|
||||
|
||||
bool DOMIntersectionObserver::SetRootMargin(const nsACString& aString) {
|
||||
return Servo_IntersectionObserverRootMargin_Parse(&aString, &mRootMargin);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user