VOOZH about

URL: https://phabricator.services.mozilla.com/D303899

⇱ ⚙ D303899 Bug 2035573 - Start focus navigation from selection if it is a descendant of focused element. r=#dom-core


Bug 2035573 - Start focus navigation from selection if it is a descendant of focused element. r=#dom-core
AcceptedPublic

Authored by ltenenbaum on Mon, Jun 1, 8:31 PM.
Referenced Files
F72886678: D303899.1781748701.diff
Wed, Jun 17, 2:11 AM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM
Unknown Object (File)
Tue, Jun 16, 9:41 PM

Diff Detail

Event Timeline

phab-bot published this revision for review.Mon, Jun 1, 8:31 PM
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
dom/base/Document.h
5353

We have to keep track of whether the selection or focus was set more recently, because if the selection is set and then an ancestor is focused, focus navigation should start from the focused ancestor (but if it happens the other way around, it should start from the selection).

dom/base/nsFocusManager.cpp
2517–2522

There is a test which fails without this because it's doing some focus navigation while the window is defocused. Which isn't normally possible to do AFAIK but might as well add this check.

2849

I think it maybe makes more sense to do this before running focus event listeners. Otherwise, some tests fail because they call inside the focusin listener which causes unexpected behavior (old starting point is still set).

3854

e.g. the "Backwards focus navigation should not be stuck when starting point is inside focused element but before any other focusable areas" test I added fails without this.

vhilla requested changes to this revision.Tue, Jun 2, 4:49 PM
vhilla added inline comments.
dom/base/nsFocusManager.cpp
2517–2522

Which test?

dom/base/nsFocusManager.h
588

I think it's confusing that exists with that name and is labeled with #sequential-focus-navigation-starting-point, but then we're adding a similarly named , as well as having to determine that spec concept. From the spec, would be responsible for tracking the starting point set through a click, while we do this in the method through the selection. But the method also considers the currently focused area, which the spec does in the sequential focus algorithm.

Chrome seems to call at various points like and . Could we also rely only on ? That seems closer to spec.

testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-starting-point.html
176

Should this test / these subtests be tentative?

https://html.spec.whatwg.org/#sequential-focus-navigation-starting-point

setting on click is optional. Or maybe setting is could be made normative.

This revision now requires changes to proceed.Tue, Jun 2, 4:49 PM
ltenenbaum updated this revision to Diff 1289650.
ltenenbaum marked an inline comment as done.
dom/base/nsFocusManager.cpp
2517–2522

This one here: https://searchfox.org/firefox-main/rev/e28b34ab33dbf49364999070168cbb7e11e8e5bd/browser/components/aboutlogins/tests/browser/browser_tabKeyNav.js#114
In the last iteration of the loop there, it presses tab while the last element in the DOM is focused, so the window gets defocused (which probably wasn't intentional, so maybe it's worth fixing that test). I think it probably makes sense not to do this when leaving the document anyways, though I don't think it would actually cause any real problems in practice.

dom/base/nsFocusManager.h
588

Yes I agree that it's confusing, and it would be nicer to handle everything in one place. The only problem is that updating the starting point when an element is removed is a bit expensive, so it would be better not to do that in the more common case where can get it from the focused element or selection instead. Maybe it's clearer if we rename this to .

testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-starting-point.html
176

In fact, the only place it's required to be set is during certain navigations, but all browsers currently set it on click AFAIK. Still, maybe it's best to make this tentative.

Comment Actions

Code analysis found 1 defect in diff 1289650:

  • 1 build error found by clang-tidy
IMPORTANT: Found 1 defect (error level) that must be fixed before landing.

You can run this analysis locally with:

  • (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1289650.

Comment Actions

Thanks for renaming !

Looks good to me, though I only have a superficial understanding of focus handling.


I see the reporter states

<dialog> should [...] respect window.getSelection(), unless it has tabindex="-1".

and this change doesn't have this opt-out. I don't see Safari honoring that either. Seems fine to me, but maybe worth clarifying in the bug that we won't have that opt-out.

dom/base/nsFocusManager.cpp
2517–2522

Thanks. It's not clear to me yet why this is needed, but I'm also not familiar enough with this.

The test moves focus to the browser, then moves focus backwards. Manually, this works fine with and without this change. Without this, the test succeeds initially, but then gets stuck some back navigations later at an input element. Strange.

3537–3548

Unless there is a reason not to?

3642

So this is the originally focused content, but only if we do . And skip refers to later where .
Maybe add a comment or split it into and some bool?

3854

I'm unsure about this.

Looking at the spec and subtest, the sequential focus navigation starting point is the click position. Direction is backward, selection mechanism should be DOM. Either way I think the spec returns the div, not the button. The focusing steps have an early return and would do nothing. The spec likely gets stuck too, perhaps moving focus counts as "the user indicates that it should be moved". Maybe we should file an issue for that.

Effectively, what I'm wondering is whether we should first show a focus ring around the div before moving focus to the button. Safari does so, but gets stuck on the div. Chrome shows a focus ring on shift and then moves to the button on shift tab.

ltenenbaum marked 2 inline comments as done.
dom/base/nsFocusManager.cpp
2517–2522

Yeah, what's happening is that this check here is failing, so is called but not . I suppose we could clear the previously-focused content in instead to fix this, but I don't think that's actually necessary.

3537–3548

Oh yes thanks, I don't know how I missed that method :)

3642

Hmm maybe actually it's fine to always skip the focused content, that would simplify this a bit. I will run it through try though to be sure…

3854

Yeah, probably it's worth filing a spec issue about this: https://github.com/whatwg/html/issues/12514
You're right that we could also solve this by not showing the focus ring until shift+tab is pressed, though we'd also need to set when we do show the focus ring… This way keeps the current behavior, but I could go either way

3860

Probably this check isn't necessary, but with how complicated is, I wouldn't be surprised if there is some strange case where it returns the start content, and it's probably best not to hang if that happens

Comment Actions

Code analysis found 1 defect in diff 1290917:

  • 1 build error found by clang-tidy
IMPORTANT: Found 1 defect (error level) that must be fixed before landing.

You can run this analysis locally with:

  • (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1290917.

Comment Actions

Looks good, thanks!

dom/base/nsFocusManager.cpp
990–991

Nit: maybe check first.

This revision is now accepted and ready to land.Thu, Jun 4, 8:37 AM
Comment Actions

This revision requires a Testing Policy Project Tag to be set before landing. Please apply one of , , , , . Tip: this Firefox add-on makes it easy!

ltenenbaum marked an inline comment as done.
ltenenbaum added inline comments.
dom/base/nsFocusManager.cpp
3851

Hmm actually this should compare against , rather than just checking the element state, since shadow hosts have even if it is something inside of it that is focused.

3860

Oh in fact, it does return the starting content in certain cases such as radio groups or having only one focusable element on the page. So probably best to just remove that assertion.

Comment Actions

Code analysis found 1 defect in diff 1292401:

  • 1 build error found by clang-tidy
IMPORTANT: Found 1 defect (error level) that must be fixed before landing.

You can run this analysis locally with:

  • (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1292401.

Comment Actions

Code analysis found 1 defect in diff 1292414:

  • 1 build error found by clang-tidy
IMPORTANT: Found 1 defect (error level) that must be fixed before landing.

You can run this analysis locally with:

  • (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1292414.

This revision is now accepted and ready to land.Thu, Jun 4, 10:12 PM
Comment Actions

Ah okay, I think the problem with the test was just that still pauses execution

This revision is now accepted and ready to land.Thu, Jun 11, 3:23 PM
This revision is now accepted and ready to land.Tue, Jun 16, 4:45 PM

Revision Contents

PathSize
dom/
base/
35 lines
23 lines
3 lines
13 lines
150 lines
events/
2 lines
layout/
base/
5 lines
testing/
web-platform/
tests/
html/
interaction/
focus/
sequential-focus-navigation-starting-point.html
43 lines
CommitTreeParentsAuthorSummaryDate
359a0e10694baeb4abbe5e51Leo Tenenbaum
Bug 2035573 - Start focus navigation from selection if it is a descendant of… (Show More…)

Diff 1301207

dom/base/Document.h

Loading...

dom/base/Document.cpp

Loading...

dom/base/Selection.cpp

Loading...

dom/base/nsFocusManager.h

Loading...

dom/base/nsFocusManager.cpp

Loading...

dom/events/NavigateEvent.cpp

Loading...

layout/base/PresShell.cpp

Loading...

testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-starting-point.html

Loading...

testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-starting-point.tentative.html

Loading...