Commit Graph

815 Commits

Author SHA1 Message Date
Masayuki Nakano
87b520e2b3 Bug 1872300 - Make nsFocusManager::ContentRemoved() call HTMLEditor::FinalizeSelection() after the removal ends r=emilio
`HTMLEditor::FinalizeSelection()` resets the caret and `nsCaret` schedules to
paint itself with the new state.  If editing host is being removed, it's already
been removed from the child chain of its parent but it still knows the parent.
Additionally, `nsCaret` may still keep storing the removing editing host as the
content.  In such case, we try to look for the line edge from the removing
editing host and fails to compute the index in its parent node for considering
the caret geometry.  For avoiding to compute it in the unstable period,
`nsFocusManager::ContentRemoved()` should call `HTMLEditor::FinalizeSelection()`
after the removal ends.

Differential Revision: https://phabricator.services.mozilla.com/D219845
2024-08-24 10:14:30 +00:00
Sean Feng
1341b819e2 Bug 1863246 - Make the page that enters BFCache not asking the parent process to update the active browsing context r=peterv,dom-core
Currently, when a page enters BFCache, it updates the parent process
for the active BC; however, the page that is about to show will do the
same. These two operations are triggered in different processes with
different active id, they are racy and problematic.

This patch fixes the above issue by not updating the parent process
when a page enters BFCache.

This only applies to BFCacheInParent is enabled.

Differential Revision: https://phabricator.services.mozilla.com/D215818
2024-08-14 19:48:17 +00:00
Sean Feng
d8731be12c Bug 1901689 - Ensure ancestors' focus are updated correctly when the focus moves from the nested iframe to a non-focusable top-level document element r=smaug
In Gecko, the correct way of updating ancestors' focus is to adjust
the focus of the child document first, and then propagate that
to ancestors' chain.

This patch fixes a case where the focus of the ancestors are not
updated/cleared correctly when the focus moves from the nested
iframe to a non-focusable element in the top-level document.

Differential Revision: https://phabricator.services.mozilla.com/D218224
2024-08-06 17:08:04 +00:00
Emilio Cobos Álvarez
a44b49af0b Bug 1910698 - Add a struct to represent JS caller location and more general warning source location. r=smaug,necko-reviewers,anti-tracking-reviewers,dom-storage-reviewers,pbz,kershaw,janv
Use it liberally across the tree. This could be cleaned up even more in the future.

Differential Revision: https://phabricator.services.mozilla.com/D218114
2024-08-01 17:12:48 +00:00
Masayuki Nakano
d58e2a77d9 Bug 1669016 - Make nsFocusManager::DetermineElementToMoveFocus look for next tabbable content from next/previous element at selection r=NeilDeakin
`nsFocusManager::DetermineElementToMoveFocus` starts to look for next tabbable
element from start boundary for first selection range if there is no focused
element in the document.  This means that if there is only one focusable element
and `Selection` is collapsed at the only focusable element, it won't move
focus to any element because it does not make the start element focused.

Chrome does not honor `Selection` to move focus unless `Selection` is starts
from a `Text`.  Therefore, I think that we don't need to take care of web-compat
to fix this bug.

This patch makes that the method move focus to the start element first if it's
focusable if there is no focused element.  This behavior matches with the
focus move by a caret move.  So I think that this may make users feel consistent
behavior with arrow keys and `Tab` key in the caret browsing mode.

Differential Revision: https://phabricator.services.mozilla.com/D215903
2024-07-23 00:47:18 +00:00
Sean Feng
29b914a072 Bug 1902561 - Make F6 or Control+Tab takes the focus to the first focusable element in scope for Chrome document r=smaug
This is to miminc the behaviour in
https://searchfox.org/mozilla-central/rev/cb1060f7b4581e6c2d30f1accc84c7d807132d82/dom/base/nsFocusManager.cpp#4550-4561

Differential Revision: https://phabricator.services.mozilla.com/D214629
2024-07-02 16:44:37 +00:00
Sean Feng
d87c07d20b Bug 1824155 - Ensure focused browsing context is blurred when an OOP window is focused r=edgar,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D211432
2024-05-28 21:23:25 +00:00
Stanca Serban
ee46889e4e Backed out changeset c1fdd0149a3b (bug 1824155) for causing linting opt failures. CLOSED TREE 2024-05-28 23:37:26 +03:00
Sean Feng
1f5eeeb51a Bug 1824155 - Ensure focused browsing context is blurred when an OOP window is focused r=edgar,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D211432
2024-05-28 19:56:56 +00:00
Emilio Cobos Álvarez
bf22d33f87 Bug 1895208 - Refactor IsFocusable checks to take flags rather than bool arguments. r=smaug
This doesn't change behavior on its own, but it's likely we want to make
the tab focusability more complicated in bug 1895184, and this will make
changes to this area less painful.

Differential Revision: https://phabricator.services.mozilla.com/D209525
2024-05-06 21:54:37 +00:00
Emilio Cobos Álvarez
a705793753 Bug 1895229 - Remove nsIWebBrowserChromeFocus. r=hsivonen,dom-core
It's only implemented by BrowserChild, we can do this more directly.

Differential Revision: https://phabricator.services.mozilla.com/D209534
2024-05-06 11:30:34 +00:00
Emilio Cobos Álvarez
45b669a6a7 Bug 1036966 - Make accessibility.tabfocus default to 7 on macOS too. r=morgan,settings-reviewers,mac-reviewers,mstange
Stop supporting following the system preference, but keep macOS users
able to switch to just text controls (accessibility.tabfocus=1) in the
settings.

Change the meaning of the "Use the tab key to move focus between form
controls and links" checkbox in the Firefox settings, which was
introduced in bug 1628476 to override the system setting.

The intention, I think was that this checkbox being off resulted in
"follow the system" behavior, but that didn't quite happen due to a bug
in the preferences code (this[1] won't unset the pref, because of
this[2], which means we'll just return 0).

This patch changes it so that the checkbox instead always ignores the
system setting. There will no longer be a Firefox setting (neither in
the UI nor on about:config) that means "follow system setting".

This allows us to somewhat simplify the approach compared to the
previous patch in D196110, and keep the accessibility.tabfocus working
as the source of truth without a migration.

In the future, we can think of migrating accessibility.tabfocus to a
boolean pref, which would allow us to do the cleanups to the preferences
code that D196110 did.

[1]: https://searchfox.org/mozilla-central/rev/f1532761de0b60337e42c6c3f525288a523dabef/browser/components/preferences/main.js#2252
[2]: https://searchfox.org/mozilla-central/rev/f1532761de0b60337e42c6c3f525288a523dabef/toolkit/content/preferencesBindings.js#450,483

Differential Revision: https://phabricator.services.mozilla.com/D208602
2024-05-03 23:10:47 +00:00
Tamas Szentpeteri
453ac165cb Backed out changeset 644738c3ccfe (bug 1036966) for causing mochitest failures in test_tabindex.html. CLOSED TREE 2024-05-03 04:18:36 +03:00
Emilio Cobos Álvarez
87eeb156af Bug 1036966 - Make accessibility.tabfocus default to 7 on macOS too. r=morgan,settings-reviewers,mac-reviewers,mstange
Stop supporting following the system preference, but keep macOS users
able to switch to just text controls (accessibility.tabfocus=1) in the
settings.

Change the meaning of the "Use the tab key to move focus between form
controls and links" checkbox in the Firefox settings, which was
introduced in bug 1628476 to override the system setting.

The intention, I think was that this checkbox being off resulted in
"follow the system" behavior, but that didn't quite happen due to a bug
in the preferences code (this[1] won't unset the pref, because of
this[2], which means we'll just return 0).

This patch changes it so that the checkbox instead always ignores the
system setting. There will no longer be a Firefox setting (neither in
the UI nor on about:config) that means "follow system setting".

This allows us to somewhat simplify the approach compared to the
previous patch in D196110, and keep the accessibility.tabfocus working
as the source of truth without a migration.

In the future, we can think of migrating accessibility.tabfocus to a
boolean pref, which would allow us to do the cleanups to the preferences
code that D196110 did.

[1]: https://searchfox.org/mozilla-central/rev/f1532761de0b60337e42c6c3f525288a523dabef/browser/components/preferences/main.js#2252
[2]: https://searchfox.org/mozilla-central/rev/f1532761de0b60337e42c6c3f525288a523dabef/toolkit/content/preferencesBindings.js#450,483

Differential Revision: https://phabricator.services.mozilla.com/D208602
2024-05-02 22:19:53 +00:00
Ziran Sun
1229476ae0 Bug 1891934 - [popover] Handling focus naviagtion when invoker is not focusable. r=smaug
At popover navigation bug 1856539, we left the case that when invoker is not focusable to its default behaviour.
At https://github.com/web-platform-tests/wpt/pull/45391, it is suggested that we should another element next to
the invoker to focus.

Differential Revision: https://phabricator.services.mozilla.com/D207693
2024-05-02 08:51:13 +00:00
Tamas Szentpeteri
a9d1e792f2 Backed out changeset 977bf4319b43 (bug 1891934) for causing wpt failures in nsFocusManager.cpp. CLOSED TREE 2024-04-24 16:40:18 +03:00
Ziran Sun
8eea0c4e75 Bug 1891934 - [popover] Handling focus naviagtion when invoker is not focusable. r=smaug
At popover navigation bug 1856539, we left the case that when invoker is not focusable to its default behaviour.
At https://github.com/web-platform-tests/wpt/pull/45391, it is suggested that we should another element next to
the invoker to focus.

Differential Revision: https://phabricator.services.mozilla.com/D207693
2024-04-24 10:23:58 +00:00
Sean Feng
0f45ff8550 Bug 1884870: Clear ancestors' focus when child document loses the focus r=hsivonen,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D205135
2024-03-27 20:48:28 +00:00
Olli Pettay
3bca61d1e9 Bug 1887621 - Micro-optimize nsFocusManager::ContentRemoved, r=edgar
Differential Revision: https://phabricator.services.mozilla.com/D205551
2024-03-25 14:02:28 +00:00
Sean Feng
684a2f7a04 Bug 1483828 - [Part 4] Ensure KEY_F6 still works properly for chrome document navigation r=smaug
KEY_F6 has a special requirement for chrome document navigation
such that if the focus algorithm has reached to the end of the
top-level chrome document, it expects to focus first element of
this chrome document, because the root element of chrome document
is not focusable. This patch is to ensure this behaviour is still
working.

dom/tests/mochitest/chrome/test_focus_docnav.xhtml is used to test this.

Differential Revision: https://phabricator.services.mozilla.com/D200864
2024-03-04 14:16:32 +00:00
Sean Feng
d7254ccf1b Bug 1483828 - [Part 1] Disallow <tab> to move focus to root element r=smaug
Brings us on-par with Chrome and Safari

Differential Revision: https://phabricator.services.mozilla.com/D198436
2024-03-04 14:16:30 +00:00
Emilio Cobos Álvarez
3107f02299 Bug 1879607 - Rename nsINode::GetPreviousContent to nsINode::GetPrevNode. r=smaug
For parallelism with GetNextNode.

Differential Revision: https://phabricator.services.mozilla.com/D201264
2024-02-09 20:42:39 +00:00
Sean Feng
faf28dc59b Bug 1878753 - Fix focus gets incorrectly cleared by PresShell::FixUpFocus if the focus is on area element r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D200950
2024-02-08 16:35:02 +00:00
Emilio Cobos Álvarez
5a714b595c Bug 1875100 - Propagate top level activeness automatically to top descendants. r=nika,tabbrowser-reviewers,mconley,extension-reviewers,robwu,geckoview-reviewers,owlish,kaya
For that, opt in tabbrowser and the shopping sidebar to manual
activeness management.

Differential Revision: https://phabricator.services.mozilla.com/D198942
2024-02-07 10:58:15 +00:00
Cristian Tuns
77579088f3 Backed out changeset ecd780688279 (bug 1875100) for causing mochitest failures in test_suspend_media_by_inactive_docshell.html 2024-02-07 01:25:21 -05:00
Emilio Cobos Álvarez
a6a14d3ed6 Bug 1875100 - Propagate top level activeness automatically to top descendants. r=nika,tabbrowser-reviewers,mconley,extension-reviewers,robwu,geckoview-reviewers,owlish
For that, opt in tabbrowser and the shopping sidebar to manual
activeness management.

Differential Revision: https://phabricator.services.mozilla.com/D198942
2024-02-06 21:47:37 +00:00
Emilio Cobos Álvarez
8b123421cc Bug 1877672 - Simplify some uses of FunctionRef that now can use lambdas. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D200158
2024-02-02 19:21:20 +00:00
Emilio Cobos Álvarez
ca8e85e34b Bug 1877242 - Avoid some unnecessary refcounting churn when accessing parent-cross-chrome-boundary. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D199901
2024-01-30 23:24:43 +00:00
Masayuki Nakano
5e49db6103 Bug 1872301 - Make nsFocusManager::GetSelectionLocation never fail when found text node has no frame r=NeilDeakin
In the test case, `nsFocusManager::GetSelectionLocation` is called with
collapsed selection at end of the `<svg>` which ends with collapsible
white-spaces.  Therefore, it reaches the white-space only text node and it
does not have a primary frame due to invisible.

Previously, creating `nsFrameIterator` failed and then the method returned
error, but after bug 779684, `nsFrameIterator` constructor wants non-nullptr
frame avoiding crash.  Therefore, I added the `MOZ_ASSERT` there to get a
way to reproduce the case and now we got it.

I think that just removing `MOZ_ASSERT` and keeping returning error is not
correct. The text can be invisible with the other reasons and it does not
collapsed at end of invisible text, this does not return error.  Therefore,
this patch makes just returning the text in the case without error.

Differential Revision: https://phabricator.services.mozilla.com/D198128
2024-01-17 00:25:04 +00:00
Masayuki Nakano
2ac7025389 Bug 1872000 - Make nsFocusManager::GetSelectionLocation check whether the text frame is nullptr before creating nsFrameIterator r=emilio
See the comment in the bug, this is not a new crash.  The old factory method
did the null-check and returned.  Therefore, before using `MOZ_TRY`, calling
a method of `nsFrameIterator` with `nullptr` caused a crash.

I tried to reproduce this bug with creating empty text nodes or invisible
text nodes, but I couldn't reproduce this.  Therefore, this patch does not
contain crash tests.

Differential Revision: https://phabricator.services.mozilla.com/D197317
2023-12-27 07:48:25 +00:00
Masayuki Nakano
099c05f33c Bug 779684 - part 3: Make nsFrameIterator non-refcountable r=emilio
Nobody shares an instance of `nsFrameIterator`.  Therefore, we can make it
non-refcountable.  Additionally, `nsVisualIterator` is not required because
it overrides only 4 methods which are really simple.  So, once we merge it
into `nsFrameIterator`, we can allocate it in the stack.

Differential Revision: https://phabricator.services.mozilla.com/D197144
2023-12-24 06:01:19 +00:00
Masayuki Nakano
0c98adaa6f Bug 779684 - part 2: Get rid of nsFrameTraversal and nsIFrameTraversal r=emilio
The class is used only for creating `nsFrameIterator`, but it's unnecessary
so that we can get rid of it and its interface.

Differential Revision: https://phabricator.services.mozilla.com/D197143
2023-12-24 06:01:19 +00:00
Masayuki Nakano
ff15a98ea7 Bug 779684 - part 1: Get rid of nsIFrameEnumerator interface r=emilio
It's inherited only by `nsFrameIterator`, and `nsFrameIterator` can be declared
in a header file. So, the interface is not required and removing it can avoid
virtual calls.

Differential Revision: https://phabricator.services.mozilla.com/D197142
2023-12-24 06:01:19 +00:00
Stanca Serban
3651b1ac9c Backed out 3 changesets (bug 779684) for causing nsFrameIterator related mochitests failures.
Backed out changeset 8b92fb4e3f41 (bug 779684)
Backed out changeset f357b2287591 (bug 779684)
Backed out changeset 738fe6bbf913 (bug 779684)
2023-12-23 10:32:48 +02:00
Masayuki Nakano
bf4e6a40b9 Bug 779684 - part 3: Make nsFrameIterator non-refcountable r=emilio
Nobody shares an instance of `nsFrameIterator`.  Therefore, we can make it
non-refcountable.  Additionally, `nsVisualIterator` is not required because
it overrides only 4 methods which are really simple.  So, once we merge it
into `nsFrameIterator`, we can allocate it in the stack.

Differential Revision: https://phabricator.services.mozilla.com/D197144
2023-12-23 05:39:39 +00:00
Masayuki Nakano
dc9647c07e Bug 779684 - part 2: Get rid of nsFrameTraversal and nsIFrameTraversal r=emilio
The class is used only for creating `nsFrameIterator`, but it's unnecessary
so that we can get rid of it and its interface.

Differential Revision: https://phabricator.services.mozilla.com/D197143
2023-12-23 05:39:38 +00:00
Masayuki Nakano
8cc40d3b31 Bug 779684 - part 1: Get rid of nsIFrameEnumerator interface r=emilio
It's inherited only by `nsFrameIterator`, and `nsFrameIterator` can be declared
in a header file. So, the interface is not required and removing it can avoid
virtual calls.

Differential Revision: https://phabricator.services.mozilla.com/D197142
2023-12-23 05:39:38 +00:00
Emilio Cobos Álvarez
71e771518b Bug 1868552 - Refactor nsIContent::IsFocusable for clarity. r=masayuki
Make it be output-only, not having that confusing in-out tab-index
parameter that is special for XUL to become focusable with
-moz-user-focus: normal. Instead, do that explicitly in
nsIFrame::IsFocusable().

Also, call it IsFocusableWithoutStyle(), since that's what it is.

Differential Revision: https://phabricator.services.mozilla.com/D195644
2023-12-08 11:34:06 +00:00
Ziran Sun
bed8737ffd Bug 1856539 - Add focus navigation support for popover. r=emilio,smaug,edgar
This implements the focus behavior described in [1]:

 1. Moves focus from an invoking element to its invoked popover,
    regardless of where in the DOM that popover lives.
 2. Moves focus back to the next focusable element after the
    invoking element once focus leaves the invoked popover.
 3. Skips over an open invoked popover otherwise.

[1] https://html.spec.whatwg.org/#focus-navigation-scope-owner

Differential Revision: https://phabricator.services.mozilla.com/D190560
2023-11-16 15:25:54 +00:00
Norisz Fay
44ea06c342 Backed out changeset d3fec9e5f456 (bug 1856539) for causing bustage on nsFrameTraversal.cpp CLOSED TREE 2023-11-16 16:05:55 +02:00
Ziran Sun
cd63bb5e85 Bug 1856539 - Add focus navigation support for popover. r=emilio,smaug,edgar
This implements the focus behavior described in [1]:

 1. Moves focus from an invoking element to its invoked popover,
    regardless of where in the DOM that popover lives.
 2. Moves focus back to the next focusable element after the
    invoking element once focus leaves the invoked popover.
 3. Skips over an open invoked popover otherwise.

[1] https://html.spec.whatwg.org/#focus-navigation-scope-owner

Differential Revision: https://phabricator.services.mozilla.com/D190560
2023-11-16 10:57:14 +00:00
Narcis Beleuzu
3d36a651dc Backed out changeset bc6c5c88423b (bug 1856539) for bustages on nsFrameTraversal.cpp . CLOSED TREE 2023-11-16 00:44:04 +02:00
Ziran Sun
d5806368ef Bug 1856539 - Add focus navigation support for popover. r=emilio,smaug,edgar
This implements the focus behavior described in [1]:

 1. Moves focus from an invoking element to its invoked popover,
    regardless of where in the DOM that popover lives.
 2. Moves focus back to the next focusable element after the
    invoking element once focus leaves the invoked popover.
 3. Skips over an open invoked popover otherwise.

[1] https://html.spec.whatwg.org/#focus-navigation-scope-owner

Differential Revision: https://phabricator.services.mozilla.com/D190560
2023-11-15 18:51:36 +00:00
Sandor Molnar
f20c834438 Backed out changeset 58fc056d5652 (bug 1856539) for causing build bustages at layout/base/nsFrameTraversal.cpp CLOSED TREE 2023-11-15 18:09:47 +02:00
Ziran Sun
009a5623dd Bug 1856539 - Add focus navigation support for popover. r=emilio,smaug,edgar
This implements the focus behavior described in [1]:

 1. Moves focus from an invoking element to its invoked popover,
    regardless of where in the DOM that popover lives.
 2. Moves focus back to the next focusable element after the
    invoking element once focus leaves the invoked popover.
 3. Skips over an open invoked popover otherwise.

[1] https://html.spec.whatwg.org/#focus-navigation-scope-owner

Differential Revision: https://phabricator.services.mozilla.com/D190560
2023-11-15 09:46:35 +00:00
Noemi Erli
aff86dfd0c Backed out changeset 4267cbd5b7f5 (bug 1856539) for causing bustages in nsFocusManager.cpp 2023-11-14 12:38:50 +02:00
Ziran Sun
abb1cc1e1b Bug 1856539 - Add focus navigation support for popover. r=emilio,smaug,edgar
This implements the focus behavior described in [1]:

 1. Moves focus from an invoking element to its invoked popover,
    regardless of where in the DOM that popover lives.
 2. Moves focus back to the next focusable element after the
    invoking element once focus leaves the invoked popover.
 3. Skips over an open invoked popover otherwise.

[1] https://html.spec.whatwg.org/#focus-navigation-scope-owner

Differential Revision: https://phabricator.services.mozilla.com/D190560
2023-11-14 09:07:38 +00:00
Jan Varga
272327b326 Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D189226
2023-09-28 20:46:07 +00:00
pommicket
58155264eb Bug 1248186 - prevent focus loss at end of [contenteditable] r=masayuki
Adjust nsFocusManager::GetSelectionLocation so that
it never moves the selection outside of the "ancestor limiter".

Differential Revision: https://phabricator.services.mozilla.com/D186864
2023-09-26 07:45:20 +00:00
Emilio Cobos Álvarez
e76308530f Bug 1248186 - Preliminary clean-up of nsFocusManager::GetSelectionLocation. r=masayuki
This patch shouldn't change behavior. It just removes a lot of noise
from that function.

In particular, it simplifies various conditions that can't happen, like
startNode being a text-node but a form control at the same time, or a
text-node and the root element.

Differential Revision: https://phabricator.services.mozilla.com/D186964
2023-08-29 09:45:52 +00:00