Skip to content

Implement ResizeObserver's devicePixelContentBox - #60534

Draft
Ahmad-S792 wants to merge 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/Implement-ResizeObserver-s-devicePixelContentBox
Draft

Ahmad-S792 wants to merge 1 commit into
WebKit:mainfrom
Ahmad-S792:eng/Implement-ResizeObserver-s-devicePixelContentBox

Conversation

@Ahmad-S792

@Ahmad-S792 Ahmad-S792 commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

6d0dfe8

Implement ResizeObserver's devicePixelContentBox
https://bugs.webkit.org/show_bug.cgi?id=219005
rdar://71469186

Reviewed by NOBODY (OOPS!).

This patch aligns WebKit with Web Specification [1]:

[1] https://drafts.csswg.org/resize-observer/#dom-resizeobserverentry-devicepixelcontentboxsize

This implements the device-pixel-content-box size reporting on ResizeObserverEntry,
gated behind the ResizeObserverDevicePixelContentBoxEnabled testable feature flag.

This adds the devicePixelContentBoxSize attribute to ResizeObserverEntry which
reports the content box size in device pixel units (accounting for CSS zoom and
device pixel ratio but not browser zoom). The "device-pixel-content-box" value
is also added to ResizeObserverBoxOptions so observers can track changes at the
device pixel level.

Also fixes computeTargetLocation() to adjust padding values for CSS zoom so that
contentRect.top/left report correct CSS pixel values for zoomed elements.

For SVG elements, the bounding box is in user-space coordinates and does not
include CSS zoom, so the device pixel size computation multiplies by the
element's used zoom in addition to the device scale factor.

Computing the device-pixel-content-box is comparatively expensive: for a
RenderBox it needs the element's absolute position (localToAbsolute) to snap to
the device pixel grid. So it is only computed when needed. The per-frame change
detection in computeObservedSizes() only computes it when the observed box is
the device-pixel-content-box. For other observed boxes it is computed once in
ResizeObserver::gatherObservations(), for observations that are recorded for
delivery (layout is clean there), and stored alongside the other sizes so that
delivery just reads it, like borderBoxSize and contentBoxSize. It is skipped
entirely for native observers (e.g. the contain-intrinsic-size observer) and
when the setting is disabled, in which case ResizeObserverEntry also does not
allocate the devicePixelContentBoxSize array.

ResizeObservation::m_observedBox is moved before m_target so that it fits in the
padding after the reference count, keeping ResizeObservation at 48 bytes on 64-bit
platforms despite the larger BoxSizes.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/page/ResizeObservation.cpp:
(WebCore::ResizeObservation::ResizeObservation):
(WebCore::ResizeObservation::resetObservationSize):
(WebCore::ResizeObservation::computeDevicePixelContentBoxLogicalSize const):
(WebCore::ResizeObservation::computeObservedSizes const):
(WebCore::ResizeObservation::computeTargetLocation const):
(WebCore::ResizeObservation::devicePixelContentBoxSize const):
(WebCore::ResizeObservation::elementSizeChanged const):
(WebCore::operator<<):
* Source/WebCore/page/ResizeObservation.h:
* Source/WebCore/page/ResizeObserver.cpp:
(WebCore::ResizeObserver::gatherObservations):
(WebCore::ResizeObserver::deliverObservations):
(WebCore::ResizeObserver::exposesDevicePixelContentBoxSize):
* Source/WebCore/page/ResizeObserver.h:
* Source/WebCore/page/ResizeObserverBoxOptions.h:
* Source/WebCore/page/ResizeObserverBoxOptions.idl:
* Source/WebCore/page/ResizeObserverEntry.h:
(WebCore::ResizeObserverEntry::create):
(WebCore::ResizeObserverEntry::ResizeObserverEntry):
* Source/WebCore/page/ResizeObserverEntry.idl:

> Progressions & Clean-up:
* LayoutTests/TestExpectations: Unskipped tests
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/idlharness.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe-019-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe-020-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/zoom-expected.txt:
* LayoutTests//imported/w3c/web-platform-tests/resize-observer/svg-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/resize-observer/svg-expected.txt: Removed.

> Adjustments:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/devicepixel2.html: Updated to use `reftest-wait`
to avoid flakiness / timing issue.

6d0dfe8

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ❌ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ❌ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
❌ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🧪 jsc-wpe
✅ 🧪 jsc-x86-64 ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-AS-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-wk2-stress ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@Ahmad-S792
Ahmad-S792 requested a review from cdumez as a code owner March 13, 2026 04:11
@Ahmad-S792 Ahmad-S792 self-assigned this Mar 13, 2026
@Ahmad-S792 Ahmad-S792 added the DOM For bugs specific to XML/HTML DOM elements (including parsing). label Mar 13, 2026
@Ahmad-S792
Ahmad-S792 marked this pull request as draft March 13, 2026 04:12
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 680a62c to 3c4881b Compare March 13, 2026 06:51
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #85795 (680a62c)

❌ Found 1 failing file with 4 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #85813 (3c4881b)

❌ Found 1 failing file with 4 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

iOS Safer C++ Build #4130 (3c4881b)

❌ Found 1 failing file with 4 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Mar 15, 2026
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 3c4881b to 0b23e33 Compare March 15, 2026 12:22
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 0b23e33 to 6088cb3 Compare March 15, 2026 12:26
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 6088cb3 to ef07cca Compare March 15, 2026 12:57
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 15, 2026
auto contentBoxLogicalSize = box->contentBoxLogicalSize();
Ref document = box->document();
auto deviceScaleFactor = document->deviceScaleFactor();
auto absoluteContentBoxOrigin = box->localToAbsolute(FloatPoint(box->contentBoxLocation()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is expensive, and you're doing this even when ResizeObserverDevicePixelContentBoxEnabled is disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I wanted to get your input before doing further changes. Hence, I kept it in draft till now. Please share feedback, so I can address them one by one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smfr - Changed approach, now it is gated with settings enablement and also in separate function and computed lazily (matching Blink).

@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Jul 12, 2026
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from ef07cca to 697a866 Compare July 12, 2026 08:56
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

iOS Safer C++ Build #39154 (697a866)

❌ Found 52 failing files with 1027 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 12, 2026
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #120218 (697a866)

❌ Found 54 failing files with 1060 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Jul 15, 2026
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 697a866 to 01aba5c Compare July 15, 2026 08:12
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 15, 2026
https://bugs.webkit.org/show_bug.cgi?id=219005
rdar://71469186

Reviewed by NOBODY (OOPS!).

This patch aligns WebKit with Web Specification [1]:

[1] https://drafts.csswg.org/resize-observer/#dom-resizeobserverentry-devicepixelcontentboxsize

This implements the device-pixel-content-box size reporting on ResizeObserverEntry,
gated behind the ResizeObserverDevicePixelContentBoxEnabled testable feature flag.

This adds the devicePixelContentBoxSize attribute to ResizeObserverEntry which
reports the content box size in device pixel units (accounting for CSS zoom and
device pixel ratio but not browser zoom). The "device-pixel-content-box" value
is also added to ResizeObserverBoxOptions so observers can track changes at the
device pixel level.

Also fixes computeTargetLocation() to adjust padding values for CSS zoom so that
contentRect.top/left report correct CSS pixel values for zoomed elements.

For SVG elements, the bounding box is in user-space coordinates and does not
include CSS zoom, so the device pixel size computation multiplies by the
element's used zoom in addition to the device scale factor.

Computing the device-pixel-content-box is comparatively expensive: for a
RenderBox it needs the element's absolute position (localToAbsolute) to snap to
the device pixel grid. So it is only computed when needed. The per-frame change
detection in computeObservedSizes() only computes it when the observed box is
the device-pixel-content-box. For other observed boxes it is computed once in
ResizeObserver::gatherObservations(), for observations that are recorded for
delivery (layout is clean there), and stored alongside the other sizes so that
delivery just reads it, like borderBoxSize and contentBoxSize. It is skipped
entirely for native observers (e.g. the contain-intrinsic-size observer) and
when the setting is disabled, in which case ResizeObserverEntry also does not
allocate the devicePixelContentBoxSize array.

ResizeObservation::m_observedBox is moved before m_target so that it fits in the
padding after the reference count, keeping ResizeObservation at 48 bytes on 64-bit
platforms despite the larger BoxSizes.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/page/ResizeObservation.cpp:
(WebCore::ResizeObservation::ResizeObservation):
(WebCore::ResizeObservation::resetObservationSize):
(WebCore::ResizeObservation::computeDevicePixelContentBoxLogicalSize const):
(WebCore::ResizeObservation::computeObservedSizes const):
(WebCore::ResizeObservation::computeTargetLocation const):
(WebCore::ResizeObservation::devicePixelContentBoxSize const):
(WebCore::ResizeObservation::elementSizeChanged const):
(WebCore::operator<<):
* Source/WebCore/page/ResizeObservation.h:
* Source/WebCore/page/ResizeObserver.cpp:
(WebCore::ResizeObserver::gatherObservations):
(WebCore::ResizeObserver::deliverObservations):
(WebCore::ResizeObserver::exposesDevicePixelContentBoxSize):
* Source/WebCore/page/ResizeObserver.h:
* Source/WebCore/page/ResizeObserverBoxOptions.h:
* Source/WebCore/page/ResizeObserverBoxOptions.idl:
* Source/WebCore/page/ResizeObserverEntry.h:
(WebCore::ResizeObserverEntry::create):
(WebCore::ResizeObserverEntry::ResizeObserverEntry):
* Source/WebCore/page/ResizeObserverEntry.idl:

> Progressions & Clean-up:
* LayoutTests/TestExpectations: Unskipped tests
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/idlharness.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe-019-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe-020-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/zoom-expected.txt:
* LayoutTests//imported/w3c/web-platform-tests/resize-observer/svg-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/resize-observer/svg-expected.txt: Removed.

> Adjustments:
* LayoutTests/imported/w3c/web-platform-tests/resize-observer/devicepixel2.html: Updated to use `reftest-wait`
to avoid flakiness / timing issue.
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Oct 9, 2026
@Ahmad-S792
Ahmad-S792 force-pushed the eng/Implement-ResizeObserver-s-devicePixelContentBox branch from 01aba5c to 6d0dfe8 Compare October 9, 2026 20:04
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DOM For bugs specific to XML/HTML DOM elements (including parsing). merging-blocked Applied to prevent a change from being merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants