Bug 1792217 - Let last remembered size take all fragments into account regardless of pref. r=emilio

ResizeObserver only handles multiple fragments when the preference
dom.resize_observer.support_fragments is true.
That's because this experimental behavior may have compat problems.

But the last remembered size uses an internal ResizeObserver,
so changing the signature of the callback is not a problem.

Differential Revision: https://phabricator.services.mozilla.com/D158034
This commit is contained in:
Oriol Brufau 2022-09-23 23:41:34 +00:00
parent f88d2cb267
commit 70bc1e8b84
3 changed files with 11 additions and 8 deletions

View file

@ -74,7 +74,8 @@ static nsSize GetContentRectSize(const nsIFrame& aFrame) {
* https://www.w3.org/TR/resize-observer-1/#calculate-box-size
*/
static AutoTArray<LogicalPixelSize, 1> CalculateBoxSize(
Element* aTarget, ResizeObserverBoxOptions aBox) {
Element* aTarget, ResizeObserverBoxOptions aBox,
const ResizeObserver& aObserver) {
nsIFrame* frame = aTarget->GetPrimaryFrame();
if (!frame) {
@ -157,7 +158,8 @@ static AutoTArray<LogicalPixelSize, 1> CalculateBoxSize(
}
return CSSPixel::FromAppUnits(GetContentRectSize(*aFrame)).ToUnknownSize();
};
if (!StaticPrefs::dom_resize_observer_support_fragments()) {
if (!StaticPrefs::dom_resize_observer_support_fragments() &&
!aObserver.HasNativeCallback()) {
return {LogicalPixelSize(frame->GetWritingMode(), GetFrameSize(frame))};
}
AutoTArray<LogicalPixelSize, 1> size;
@ -213,7 +215,8 @@ bool ResizeObservation::IsActive() const {
return false;
}
return mLastReportedSize != CalculateBoxSize(mTarget, mObservedBox);
return mLastReportedSize !=
CalculateBoxSize(mTarget, mObservedBox, *mObserver);
}
void ResizeObservation::UpdateLastReportedSize(
@ -397,11 +400,11 @@ uint32_t ResizeObserver::BroadcastActiveObservations() {
Element* target = observation->Target();
auto borderBoxSize =
CalculateBoxSize(target, ResizeObserverBoxOptions::Border_box);
CalculateBoxSize(target, ResizeObserverBoxOptions::Border_box, *this);
auto contentBoxSize =
CalculateBoxSize(target, ResizeObserverBoxOptions::Content_box);
CalculateBoxSize(target, ResizeObserverBoxOptions::Content_box, *this);
auto devicePixelContentBoxSize = CalculateBoxSize(
target, ResizeObserverBoxOptions::Device_pixel_content_box);
target, ResizeObserverBoxOptions::Device_pixel_content_box, *this);
RefPtr<ResizeObserverEntry> entry =
new ResizeObserverEntry(mOwner, *target, borderBoxSize, contentBoxSize,
devicePixelContentBoxSize);

View file

@ -179,7 +179,7 @@ class ResizeObserver final : public nsISupports, public nsWrapperCache {
/**
* Returns whether this is an internal ResizeObserver with a native callback.
*/
bool HasNativeCallback() { return mCallback.is<NativeCallback>(); }
bool HasNativeCallback() const { return mCallback.is<NativeCallback>(); }
/**
* Invoke the callback function in JavaScript for all active observations

View file

@ -1 +1 @@
prefs: [layout.css.content-visibility.enabled:true, dom.resize_observer.support_fragments:true]
prefs: [layout.css.content-visibility.enabled:true]