Re: [csswg-drafts] [cssom-view] Inconsistencies between partially offscreen scroll-into-view (#4778)

> Interestingly, it appears Firefox does avoid scrolling a partial element onscreen from focus. I'm going to make the same change in Blink but I'm having a hard time exactly determining Gecko's behavior. It looks like there's some kind of threshold too (10px onscreen is scrolled but 50px is not) but testing locally on Linux in FF73 I see focus() scrolls both axes into view whereas (using browserstack) on Windows/Mac it only scrolls the vertical axis. @emilio - can you help me understand what's going on here?

Focus does: https://searchfox.org/mozilla-central/rev/174f1195ec740e8f17223b48018f7e14e6d4e40e/dom/base/nsFocusManager.cpp#2180

`scrollIntoView` does: https://searchfox.org/mozilla-central/rev/174f1195ec740e8f17223b48018f7e14e6d4e40e/dom/base/Element.cpp#623

So `focus()` is effectively `scrollIntoView` passing `inline: "nearest", block: "nearest"`, and with `IfNotVisible` as the `WhenToScroll` parameter. That effectively uses the "line size" as threshold to determine whether you should actually scroll:

 * https://searchfox.org/mozilla-central/rev/174f1195ec740e8f17223b48018f7e14e6d4e40e/layout/base/PresShell.cpp#3243

Which is determined here:

 * https://searchfox.org/mozilla-central/rev/174f1195ec740e8f17223b48018f7e14e6d4e40e/layout/base/PresShell.cpp#3302
 * https://searchfox.org/mozilla-central/rev/174f1195ec740e8f17223b48018f7e14e6d4e40e/layout/generic/nsGfxScrollFrame.cpp#4412

Which effectively depends on font-size / line-height / font-metrics etc. I think that's what you're observing, and I don't particularly think that behavior is great.

It seems that flag is only used for focus related things, so `focus()` and scrolling form controls when auto-filling and focusing them. Blaming that flag it comes from: https://github.com/mozilla/gecko-dev/commit/f40d94ae94b1d7a1c69c43f1406c52f8934059fb (so pretty old code).

I haven't finished blaming the actual code using the flag and I have to run, but the line-size dependent behavior is already in https://searchfox.org/mozilla-central/rev/7ca5ac579cbcae7983ada5666cd06fe7e845960e/layout/base/nsPresShell.cpp#3995.

I'd be pretty happy of standardizing on something simpler if possible. Hope that helps.

-- 
GitHub Notification of comment by emilio
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4778#issuecomment-586489117 using your GitHub account

Received on Friday, 14 February 2020 21:58:17 UTC