Fix LayoutShift attribution data to use CSS pixels #55329
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The LayoutShift API was returning attribution data (currentRect and
prevRect) in physical pixels instead of CSS pixels. This makes the Layout
Instability API inconsistent with other layout-related APIs, which all use
CSS pixels.
With the current behavior, consumers of this API are required to manually
convert the attribution data using devicePixelRatio to make the coordinates
relative to the viewport.
Previously, on a display with device pixel ratio 2.0, a 100x100 CSS pixel
element positioned at (50, 50) would be reported as 200x200 at (100, 100)
in the attribution data. After this fix, it correctly reports as 100x100
at (50, 50) CSS pixels, matching the actual element position and size as
seen by web developers.
The layout shift scores themselves remain unaffected as they are calculated
using the impact fraction (shifted area relative to viewport) multiplied
by the distance fraction (movement distance relative to viewport dimensions).
Only the attribution data reporting to the Performance API is corrected.
Bug: 399058544
Change-Id: Ib8109c12eaf1c1a2e5648edbc39ef97111431494
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6624567
Reviewed-by: Manuel Rego <[email protected]>
Reviewed-by: Michal Mocny <[email protected]>
Commit-Queue: Manuel Rego <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1527545}