Commit Graph
106 Commits
Author SHA1 Message Date
Hiroyuki Ikezoe e382b3875f Bug 2045994 - Factor out ProcessSnapOverflow. r=ajakobi
Differential Revision: https://phabricator.services.mozilla.com/D305491
2026-06-09 20:26:37 +00:00
Hiroyuki Ikezoe 97000af18d Bug 2045994 - Check m[X|Y]RangeWiderThanSnapport > mSnapportSize.[width|height] outside of the iteration. r=ajakobi
It will avoid unnecessary interations.

Differential Revision: https://phabricator.services.mozilla.com/D305490
2026-06-09 20:26:34 +00:00
serge-sans-paille c7033d0d67 Bug 2030936 - Activate clang-tidy's performance-for-range-copy check r=sylvestre,tschuster,media-playback-reviewers,webrtc-reviewers,firefox-style-system-reviewers,layout-reviewers,janerik,padenot,bwc,emilio,alwu
And apply the auto-fix from the linter. Note that we exclude RefPtr from
the check as it plays badly with our CanRunScriptChecker's linter.

We also explicitly silent warning for loops on nsTObserverArray, as their
iterator is designed to support invalidation.

Differential Revision: https://phabricator.services.mozilla.com/D293497
2026-05-20 06:51:32 +00:00
Hiroyuki Ikezoe 709b884469 Bug 2019482 - Post pending re-snap on ancestor scroll containers when focused content is inside a nested scroll container snap target. r=botond
Per spec, snap positions only affect the nearest ancestor scroll
container, so re-snapping is normally only triggered on that container.
However, if a snap target contains the focused element, ancestor scroll
containers of that snap target may also need to re-snap.

Differential Revision: https://phabricator.services.mozilla.com/D296592
2026-05-14 10:14:16 +00:00
Hiroyuki Ikezoe 378d410be4 Bug 2019482 - Prefer snap target that contains the focused element when multiple targets are aligned. r=botond
Add a new WPT (prefer-element-having-focused-element.html) since no
existing test covered this case. It verifies that a snap target
containing a focused non-snap element takes priority over other
aligned snap targets.

Differential Revision: https://phabricator.services.mozilla.com/D296591
2026-05-14 10:14:12 +00:00
Hiroyuki Ikezoe 15fed97a99 Bug 1880436 - Implement step 4.3 of the multiple-aligned-snap-areas algorithm. r=botond
Per https://drafts.csswg.org/css-scroll-snap-1/#multiple-aligned-snap-areas
step 4.3: for each box in the candidate set, remove any box that is an
ancestor of that box. This ensures the innermost (most-descendant) snap
target is preferred over its ancestors during resnap.

Uses nsContentUtils::ContentIsFlattenedTreeDescendantOf to check ancestry
in the flat tree, which matches how CSS layout traverses the element tree.

Differential Revision: https://phabricator.services.mozilla.com/D296585
2026-05-14 05:01:34 +00:00
Botond Ballo 6fb2f71b9e Bug 2037224 - Use operator<< to print an array of snap targets. r=ajakobi
This uses the existing operator<< overload for nsTArray, which in turn
makes use of the overload for SnapTarget or SnapTarget* as needed.

Differential Revision: https://phabricator.services.mozilla.com/D298649
2026-05-06 22:30:26 +00:00
Botond Ballo a79862924d Bug 2037224 - Use operator<< to print a single SnapTarget. r=ajakobi
Differential Revision: https://phabricator.services.mozilla.com/D298647
2026-05-06 22:30:21 +00:00
Botond Ballo 654e3ea3c3 Bug 2037224 - Use nsAutoCString as the return type of ScrollSnapUtils::SnapTarget. r=ajakobi
This localizes the conversion from UTF-16 into the helper for
a single snap target.

Note that NS_LossyConvertUTF16toASCII derives from nsAutoCString
and adds no state, so it's safe to slice to nsAutoCString.

Differential Revision: https://phabricator.services.mozilla.com/D298646
2026-05-06 22:30:19 +00:00
Alex Jakobi f8570cc19e Bug 2033899 - Log SnapTargets for ScrollSnap r=botond
Differential Revision: https://phabricator.services.mozilla.com/D297360
2026-05-05 15:14:03 +00:00
Alex Jakobi 0fd2cbfbdf Bug 2019490 - Prefer target element for multiple aligned snap areas r=hiro,layout-reviewers,botond
Differential Revision: https://phabricator.services.mozilla.com/D284961
2026-04-30 07:06:53 +00:00
Hiroyuki Ikezoe 039bffdfce Bug 2020226 - Handle writing-mode properly on re-snap. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D293390
2026-04-16 04:18:55 +00:00
Lando 35ce57c04d Bug 2020227: apply code formatting via Lando
# ignore-this-changeset
2026-04-11 07:27:36 +00:00
Hiroyuki Ikezoe dbcf56e064 Bug 2020227 - Prefer the block-axis snap target for both axes when the inline and block re-snap candidate sets are disjoint. r=botond
When re-snapping after a layout change, we build separate candidate sets
for the inline (X) and block (Y) axes from the previously snapped targets,
using mIdsOnX and mIdsOnY respectively.

This implements step 5 of spec section 6.2.1: if the inline and block sets
are overlapping, both are replaced with their intersection. If the sets are
disjoint, the block-axis set takes precedence and determines the snap
position for both axes.

Differential Revision: https://phabricator.services.mozilla.com/D285438
2026-04-11 07:27:19 +00:00
Hiroyuki Ikezoe 1875516aee Bug 2020227 - Ignore snap points outside of the viewport while collecting last snap target ids for the next re-snapping. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D288312
2026-04-11 07:27:16 +00:00
Botond Ballo ff836f7ed7 Bug 2029830 - Avoid using generic lambdas with ForEachValidTargetFor. r=hiro,layout-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D292268
2026-04-07 00:33:40 +00:00
Sylvestre Ledru 55481ac4b5 Bug 2023419 - Remove Emacs/Vim modelines from layout/ r=emilio,firefox-style-system-reviewers,layout-reviewers
replaced by .editorconfig

Differential Revision: https://phabricator.services.mozilla.com/D287852
2026-03-17 12:05:43 +00:00
rperta 80d8075443 Revert "Bug 2020227 - Allow the previous snap target elements even if it was for the other axis. r=botond" for causing mochitest related failures at browser_spinner_keynav.js
This reverts commit 3a4fb3b8e8.
2026-03-13 11:31:40 +00:00
Hiroyuki Ikezoe 3a4fb3b8e8 Bug 2020227 - Allow the previous snap target elements even if it was for the other axis. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D285438
2026-03-13 10:12:38 +00:00
Dan Robertson f01d95ea56 Bug 1753188 - Mousewheel scrolls without a snap target should scroll to the destination. r=hiro,layout-reviewers
Mousewheel scrolls on a axis of a scroll container with a scroll-snap-type of
proximity should have the scroll target of the intended destination
instead of the scroll start if no snap target is found.

Differential Revision: https://phabricator.services.mozilla.com/D270173
2026-01-14 15:43:06 +00:00
Hiroyuki Ikezoe 34c2c1c21e Bug 1978946 - Do not set any snap target id for candidate snap points on elements larger than the snapport size. r=botond
In Gecko scroll snap id is a raw pointer of each snap target element. So
if the snap target element is larger than the snapport and once after
we snapped to a point inside element but the point is away from the
element's `scroll-snap-align` point, the snap id forces us to snap to
the element's `scroll-snap-align` point when we try to re-snap.

Differential Revision: https://phabricator.services.mozilla.com/D258498
2025-07-26 00:00:14 +00:00
Emilio Cobos Álvarez a8a2311474 Bug 1976457 - Sort includes in layout/. r=janv,dshin
Interesting bit is layout/.clang-format, the rest is all automated.

Differential Revision: https://phabricator.services.mozilla.com/D256616
2025-07-09 13:24:00 +00:00
Hiroyuki Ikezoe 51fc6df674 Bug 1934118 - Tweak the returned value of GetSnapPointForDestination. r=dlrobertson
Since bug 1922904, GetSnapPointForDestination had returned an ineligible
snap point.

For exmaple, given that there's a scroll container only wants to snap
horizontally and there are 3 snap target points, (0, 0), (100, 0) and
(200,0).  Then if the user tries to scroll vertically to (0, 100), the
function returned (0, 0) as a valid snap position for the vertical scroll
operation. With this change the function now returns (0, 100) so that
the user can scroll vertically to the correct position.

Differential Revision: https://phabricator.services.mozilla.com/D231058
2024-12-16 01:44:45 +00:00
Butkovits Atila f072b1ba84 Backed out changeset 34a32a58c71c (bug 1934118) for causing failures at test_group_scroll_snap.html. 2024-12-14 00:35:21 +02:00
Hiroyuki Ikezoe e722fa8b98 Bug 1934118 - Tweak the returned value of GetSnapPointForDestination. r=dlrobertson
Since bug 1922904, GetSnapPointForDestination had returned an ineligible
snap point.

For exmaple, given that there's a scroll container only wants to snap
horizontally and there are 3 snap target points, (0, 0), (100, 0) and
(200,0).  Then if the user tries to scroll vertically to (0, 100), the
function returned (0, 0) as a valid snap position for the vertical scroll
operation. With this change the function now returns (0, 100) so that
the user can scroll vertically to the correct position.

Differential Revision: https://phabricator.services.mozilla.com/D231058
2024-12-13 02:30:55 +00:00
Norisz Fay 4844a5c706 Backed out changeset a3870f21337b (bug 1934118) for causing mochitest failure on test_group_scroll_snap.html CLOSED TREE 2024-12-13 03:15:35 +02:00
Hiroyuki Ikezoe 55818926f1 Bug 1934118 - Tweak the returned value of GetSnapPointForDestination. r=dlrobertson
Since bug 1922904, GetSnapPointForDestination had returned an ineligible
snap point.

For exmaple, given that there's a scroll container only wants to snap
horizontally and there are 3 snap target points, (0, 0), (100, 0) and
(200,0).  Then if the user tries to scroll vertically to (0, 100), the
function returned (0, 0) as a valid snap position for the vertical scroll
operation. With this change the function now returns (0, 100) so that
the user can scroll vertically to the correct position.

Differential Revision: https://phabricator.services.mozilla.com/D231058
2024-12-12 21:44:10 +00:00
Hiroyuki Ikezoe e38ad9d39d Bug 1922904 - Fix bug 1780701 in a different approach. r=botond
In bug 1780701, we changed ScrollSnapUtils::GetSnapPointForDestination not to
return a valid SnapDestination if the snap position is equal to the original
scroll destination. But it has a bad side-effect on wheel scrolling.

While wheel scrolling, there are multiple wheel inputs comming from OS, in every
wheel input we do use the destination of the animation running at that moment
[1].  So if in the first wheel input we created a smooth animation for snapping
to the SnapDestination, and then in the second wheel input
GetSnapPointForDestination doesn't return any valid SnapDestination so that the
smooth animation is clobbered [2].

To avoid this bad side-effect, we do skip scroll snapping in the call site,
ScrollContainerFrame::ScrollSnap, if the snap position equals to the original
scroll destination.

[1] https://searchfox.org/mozilla-central/rev/53e8dfd81c32f1ab275516406ec06a68136aaef0/gfx/layers/apz/src/AsyncPanZoomController.cpp#2585-2586
[2] https://searchfox.org/mozilla-central/rev/53e8dfd81c32f1ab275516406ec06a68136aaef0/gfx/layers/apz/src/AsyncPanZoomController.cpp#2603

Differential Revision: https://phabricator.services.mozilla.com/D227409
2024-11-02 06:37:14 +00:00
Goloman Adrian 9d883be990 Backed out changeset 5b6fb5d517d3 (bug 1922904) for causing wpt failures at prefer-targeted-element-positioned.html. CLOSED TREE 2024-11-02 06:23:09 +02:00
Hiroyuki Ikezoe 7ba69c6d21 Bug 1922904 - Fix bug 1780701 in a different approach. r=botond
In bug 1780701, we changed ScrollSnapUtils::GetSnapPointForDestination not to
return a valid SnapDestination if the snap position is equal to the original
scroll destination. But it has a bad side-effect on wheel scrolling.

While wheel scrolling, there are multiple wheel inputs comming from OS, in every
wheel input we do use the destination of the animation running at that moment
[1].  So if in the first wheel input we created a smooth animation for snapping
to the SnapDestination, and then in the second wheel input
GetSnapPointForDestination doesn't return any valid SnapDestination so that the
smooth animation is clobbered [2].

To avoid this bad side-effect, we do skip scroll snapping in the call site,
ScrollContainerFrame::ScrollSnap, if the snap position equals to the original
scroll destination.

[1] https://searchfox.org/mozilla-central/rev/53e8dfd81c32f1ab275516406ec06a68136aaef0/gfx/layers/apz/src/AsyncPanZoomController.cpp#2585-2586
[2] https://searchfox.org/mozilla-central/rev/53e8dfd81c32f1ab275516406ec06a68136aaef0/gfx/layers/apz/src/AsyncPanZoomController.cpp#2603

Differential Revision: https://phabricator.services.mozilla.com/D227409
2024-11-01 22:23:07 +00:00
Ting-Yu Lin 76523f97b1 Bug 1896516 Part 6 - Remove nsIScrollableFrame usages in nsLayoutUtils. r=layout-reviewers,emilio
Convert `nsIScrollableFrame` to `ScrollContainerFrame` for all the APIs in
nsLayoutUtils, and then adapt other callers until everything compiles.

In `nsLayoutUtils::CalculateBasicFrameMetrics()`'s documentation,
s/ComputeFrameMetrics/ComputeScrollMetadata/ because the method was renamed in
https://hg.mozilla.org/mozilla-central/rev/cb2023f50288

Differential Revision: https://phabricator.services.mozilla.com/D211493
2024-05-30 06:32:20 +00:00
Sebastian Hengst bf4dfe53f8 Backed out 15 changesets (bug 1896516) for causing scrolling crashes on macOS. a=backout
Backed out changeset fd6904338812 (bug 1896516)
Backed out changeset 2977ff81a23e (bug 1896516)
Backed out changeset c8a6b0e526d6 (bug 1896516)
Backed out changeset 3c06f22da72b (bug 1896516)
Backed out changeset f63b0c4335fe (bug 1896516)
Backed out changeset 6f7ab8adfa6e (bug 1896516)
Backed out changeset 997c9249dbed (bug 1896516)
Backed out changeset c964fccd5180 (bug 1896516)
Backed out changeset 7b481b747b7a (bug 1896516)
Backed out changeset 42e1bbe0ecb6 (bug 1896516)
Backed out changeset 717dac08b607 (bug 1896516)
Backed out changeset 2f0817331dbe (bug 1896516)
Backed out changeset b765169a7a8f (bug 1896516)
Backed out changeset a2d37b98273c (bug 1896516)
Backed out changeset ea9ecb543e66 (bug 1896516)
2024-05-29 11:22:52 +02:00
Ting-Yu Lin 16b24f6c41 Bug 1896516 Part 6 - Remove nsIScrollableFrame usages in nsLayoutUtils. r=layout-reviewers,emilio
Convert `nsIScrollableFrame` to `ScrollContainerFrame` for all the APIs in
nsLayoutUtils, and then adapt other callers until everything compiles.

In `nsLayoutUtils::CalculateBasicFrameMetrics()`'s documentation,
s/ComputeFrameMetrics/ComputeScrollMetadata/ because the method was renamed in
https://hg.mozilla.org/mozilla-central/rev/cb2023f50288

Differential Revision: https://phabricator.services.mozilla.com/D211493
2024-05-28 04:46:18 +00:00
Hiroyuki Ikezoe b817697873 Bug 1768393 - Filter out snap candidates if snapping to the point makes the snap area outside of the snapport. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D184342
2023-09-12 01:33:19 +00:00
Hiroyuki Ikezoe 9053d93cc3 Bug 1768393 - Make SnapPosition inherit from ScrollSnapInfo::SnapTarget. r=botond
We will need the snap area, (i.e. SnapTarget::mSnapArea) in SnapPosition to tell
whether the snap area is visible or not if we snap to a candidate snap position.

Though SnapPosition::mPosition is redundant, it's equivalent to either
SnapTarget::mSnapPoint.mX or SnapTarget::mSnapPoint.mY, if we omit it, we need
another variable representing the axis of SnapPosition.

Differential Revision: https://phabricator.services.mozilla.com/D184341
2023-09-12 01:33:19 +00:00
Hiroyuki Ikezoe 961ed566fc Bug 1768393 - Support multiple SnapPositions in CandidateTracker. r=botond
It's possible that multiple snap target elements are located at the same
position in one axis but at different position in the other axis. We need to
keep track of them respectively in each CandidateTracker.

Differential Revision: https://phabricator.services.mozilla.com/D184339
2023-09-12 01:33:19 +00:00
Hiroyuki Ikezoe e3d7522940 Bug 1768393 - Drop mBestEdge initialization. r=botond
We can refer mEdgeFound whether mBestEdge has been set or not.

Differential Revision: https://phabricator.services.mozilla.com/D184338
2023-09-12 01:33:18 +00:00
Hiroyuki Ikezoe 29fa70a4b8 Bug 1768393 - Introduce SnapPoint to wrap a pair of Maybe<nscoord>. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D184337
2023-09-12 01:33:18 +00:00
Hiroyuki Ikezoe 425f5fbdce Bug 1768393 - Change mSecondBestEdge type to nscoord. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D184336
2023-09-12 01:33:18 +00:00
Hiroyuki Ikezoe 2fb362302c Bug 1768393 - Use the snap position on the axis only if the scroll snap strictness is not none to tell whether the given snap position is inside the scrollport or not. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D184335
2023-09-12 01:33:18 +00:00
Hiroyuki Ikezoe 58719ebd7f Bug 1768393 - Rename mozilla::SnapTarget to mozilla::SnapDestination. r=botond
It was confusing with ScrollSnapInfo::SnapTarget.

Differential Revision: https://phabricator.services.mozilla.com/D184334
2023-09-12 01:33:18 +00:00
Hiroyuki Ikezoe d3638ed8ac Bug 1768393 - Split out ScrollSnapInfo. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D184333
2023-09-12 01:33:17 +00:00
Hiroyuki Ikezoe 89d3983975 Bug 1766386 - Make scroll snap proximity threshold based on the snapport size rather than using a fixed preference value. r=dlrobertson
Now the threshold is `0.3*snapport size`, it's mostly same as WebKit [1].
A difference is WebKit's threshold is based on the scrollport size. Given that
if `scroll-padding` was specified due to a `position: fixed` element or some
such, using snapport size (i.e. offsetted by the scroll-padding) is more
reasonable than using scrollport size.

Note that Chrome uses 1/3 of the snapport size [2]. It will result scroll
positions having fractional parts. Once after we fixed our pixel alignment
issues (e.g., bug 1774315), we will change it in bug 1848574.

[1] https://searchfox.org/wubkat/rev/d1911bf073cc55fc8ca76bcee8b4783539e43c2e/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp#207-208
[2] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/page/scrolling/snap_coordinator.cc;l=23;drc=b678d9f0da19257d872a19e6291e3ae4bb2c404f

Differential Revision: https://phabricator.services.mozilla.com/D185873
2023-08-14 06:36:35 +00:00
Cristian Tuns 6bb5937964 Backed out changeset bdeed1276a35 (bug 1766386) for causing mochitest failures in helper_scroll_snap_resnap_after_async_scroll.html CLOSED TREE 2023-08-13 21:35:49 -04:00
Hiroyuki Ikezoe 66e9a802f5 Bug 1766386 - Make scroll snap proximity threshold based on the snapport size rather than using a fixed preference value. r=dlrobertson
Now the threshold is `0.3*snapport size`, it's mostly same as WebKit [1].
A difference is WebKit's threshold is based on the scrollport size. Given that
if `scroll-padding` was specified due to a `position: fixed` element or some
such, using snapport size (i.e. offsetted by the scroll-padding) is more
reasonable than using scrollport size.

Note that Chrome uses 1/3 of the snapport size [2]. It will result scroll
positions having fractional parts. Once after we fixed our pixel alignment
issues (e.g., bug 1774315), we will change it in bug 1848574.

[1] https://searchfox.org/wubkat/rev/d1911bf073cc55fc8ca76bcee8b4783539e43c2e/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp#207-208
[2] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/page/scrolling/snap_coordinator.cc;l=23;drc=b678d9f0da19257d872a19e6291e3ae4bb2c404f

Differential Revision: https://phabricator.services.mozilla.com/D185873
2023-08-14 00:25:31 +00:00
Hiroyuki Ikezoe 7e70b63cd3 Bug 1822433 - Snap to the scroll destination in the case of intended-end-position scroll operation if there's no snap target points. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D172627
2023-03-16 07:51:01 +00:00
Marian-Vasile Laza a8a6e33ea4 Backed out changeset de233af59c21 (bug 1822433) for wpt failures on scroll-snap-type-on-root-element.html. 2023-03-16 01:55:48 +02:00
Hiroyuki Ikezoe 6385d14e21 Bug 1822433 - Snap to the scroll destination in the case of intended-end-position scroll operation if there's no snap target points. r=botond
Differential Revision: https://phabricator.services.mozilla.com/D172627
2023-03-15 21:12:59 +00:00
Hiroyuki Ikezoe 072cdfbbd0 Bug 1791606 - Downgrade the assertion when we found multiple SnapTargets for the same focused content. r=emilio
The assertion is valid, but fixing it would be a bit of work (bug 1798240),
so now we degrade the assertion to make it harmless on fuzzers works.

Differential Revision: https://phabricator.services.mozilla.com/D160742
2022-10-31 22:58:12 +00:00
Emilio Cobos Álvarez 784307a8e2 Bug 1785310 - Remove mozilla/StaticPrefs_layout.h includes from other headers. r=dholbert
Adding layout prefs cause massive rebuilds because of this.

Differential Revision: https://phabricator.services.mozilla.com/D154928
2022-08-17 21:26:36 +00:00