mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-29 14:32:55 +00:00
LibWeb: Fix incorrectly offset root intersection rectangle for Document
When the intersection root is a Document, we use the viewport itself as the root intersection rectangle. However, we should only use the size of the viewport and strip away the current scroll offset. This is important, as intersections are computed using viewport-relative element rects, so we're already in a coordinate system where (0, 0) is the top left of the scrolled viewport. This fixes an issue where IntersectionObservers would fire at entirely wrong scroll offsets. :^)
This commit is contained in:
parent
6cdb1f0415
commit
92bc3d200d
Notes:
sideshowbarker
2024-07-17 06:51:48 +09:00
Author: https://github.com/awesomekling
Commit: 92bc3d200d
Pull-request: https://github.com/SerenityOS/serenity/pull/19939
1 changed files with 4 additions and 1 deletions
|
@ -175,7 +175,10 @@ CSSPixelRect IntersectionObserver::root_intersection_rectangle() const
|
||||||
|
|
||||||
// Since the spec says that this is only reach if the document is fully active, that means it must have a browsing context.
|
// Since the spec says that this is only reach if the document is fully active, that means it must have a browsing context.
|
||||||
VERIFY(document->browsing_context());
|
VERIFY(document->browsing_context());
|
||||||
rect = document->browsing_context()->viewport_rect();
|
|
||||||
|
// NOTE: This rect is the *size* of the viewport. The viewport *offset* is not relevant,
|
||||||
|
// as intersections are computed using viewport-relative element rects.
|
||||||
|
rect = CSSPixelRect { CSSPixelPoint { 0, 0 }, document->browsing_context()->viewport_rect().size() };
|
||||||
} else {
|
} else {
|
||||||
VERIFY(intersection_root.has<JS::Handle<DOM::Element>>());
|
VERIFY(intersection_root.has<JS::Handle<DOM::Element>>());
|
||||||
auto element = intersection_root.get<JS::Handle<DOM::Element>>();
|
auto element = intersection_root.get<JS::Handle<DOM::Element>>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue