Commit graph

777 commits

Author SHA1 Message Date
Ziran Sun
16b12dc7c0 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
9a6efb43a1 Backed out changeset d3fec9e5f456 (bug 1856539) for causing bustage on nsFrameTraversal.cpp CLOSED TREE 2023-11-16 16:05:55 +02:00
Ziran Sun
93786f9857 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
1c46fcbbca Backed out changeset bc6c5c88423b (bug 1856539) for bustages on nsFrameTraversal.cpp . CLOSED TREE 2023-11-16 00:44:04 +02:00
Ziran Sun
3dc8d2660f 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
e8ebc4a45a 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
b15e060876 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
d7d11c73c3 Backed out changeset 4267cbd5b7f5 (bug 1856539) for causing bustages in nsFocusManager.cpp 2023-11-14 12:38:50 +02:00
Ziran Sun
dacdf12e6a 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
c458754592 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
03c8c72db9 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
2b666100c0 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
Markus Stange
004448219f Bug 1843484 - Use EventTarget* instead of nsISupports* in some nsFocusManager methods. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D186978
2023-08-28 23:38:43 +00:00
Markus Stange
d89c20090c Bug 1843484 - Use EventTarget* instead of nsISupports* for the event target parameter of the EventDispatcher::Dispatch methods. r=smaug
This saves a few QueryInterface calls on the hot path.

Differential Revision: https://phabricator.services.mozilla.com/D186977
2023-08-28 23:38:43 +00:00
Markus Stange
3d20b7df6c Bug 1843484 - Use EventTarget* instead of nsISupports* for the event target parameter of the nsContentUtils::Dispatch methods. r=smaug
This saves a few queryInterface calls on the hot path.

Differential Revision: https://phabricator.services.mozilla.com/D186976
2023-08-28 23:38:42 +00:00
Logan Rosen
ee75c733c7 Bug 1091187 - remove unused arguments and check from UpdateCommands r=dom-core,webidl,masayuki,smaug
Differential Revision: https://phabricator.services.mozilla.com/D185385
2023-08-10 04:09:08 +00:00
Peter Van der Beken
9fba1d5220 Bug 1846277 - Remove nsGlobalWindow.h. r=dom-core,necko-reviewers,jesup,farre
Differential Revision: https://phabricator.services.mozilla.com/D184973
2023-08-02 20:41:48 +00:00
Emilio Cobos Álvarez
f66db6e37f Bug 1842679 - Consistently scroll to center for focus. r=dlrobertson
Differential Revision: https://phabricator.services.mozilla.com/D183512
2023-07-16 21:27:22 +00:00
Masayuki Nakano
143d2e34c5 Bug 1841689 - Make nsFocusManager::ContentRemoved let IMEStateManager of focus change when focused element is removed from the tree r=emilio
When an element in the shadow DOM of UA widget of `<input>` gets focus,
`IMEStateManger` let know the element instead of `<input>`.  Then, when
`HTMLInputElement` destroys the shadow DOM at changing type attribute,
`IMEStateManager` may not let know the focus change until `TextEditor`
is created.  Then, `IMEContentObserver` is created by `UpdateIMEState`
notification from `EditorBase::PostCreateInternal`, but
`TextControlState::GetIMEContentObserver()` fails to check whether it's
observed by an `IMEContentObserver` instance (*1).  Therefore,
`TextControlState` fails to notify `IMEContentObserver` of the value change
while `TextEditor` is not ready (*2).  Then, `IMEContentObserver` will let
IME know only a selection change without text change.  Therefore,
`ContentCacheInChild` will get invalid data due to outdated `mText` value
and latest `mSelection` value (*3).

For solving this issue, this patch makes `nsFocusManager::ContentRemoved`
let `IMEStateManager` know the focus change synchronously because `TextEditor`
may be initialized for some API calls of `HTMLInputElement` before
`nsFocusManager` handles the focus change.

1. https://searchfox.org/mozilla-central/rev/1bcef85eb36da6de8fab890bc724e214dde68ecb/dom/html/TextControlState.cpp#3055
2. https://searchfox.org/mozilla-central/rev/1bcef85eb36da6de8fab890bc724e214dde68ecb/dom/html/TextControlState.cpp#2959
3. https://searchfox.org/mozilla-central/rev/1bcef85eb36da6de8fab890bc724e214dde68ecb/widget/ContentCache.cpp#54

Differential Revision: https://phabricator.services.mozilla.com/D183080
2023-07-14 00:30:25 +00:00
Emilio Cobos Álvarez
54832f0e4b Bug 1843277 - Remove nsContentUtils::HasPluginWithUncontrolledEventDispatch. r=peterv
Always false.

Differential Revision: https://phabricator.services.mozilla.com/D183495
2023-07-13 14:35:12 +00:00
Dan Robertson
1cbb3aa1ce Bug 1818126: Use WhereToScroll::Center when tab scrolling. r=hiro,credential-management-reviewers,sgalich
When scrolling the next element into view for a tab scroll, scroll the
element to the center.

Differential Revision: https://phabricator.services.mozilla.com/D182930
2023-07-12 13:20:09 +00:00
Emilio Cobos Álvarez
4cc6758558 Bug 1839922 - Remove usage of {Has,Get}Attr(kNameSpaceID_None, ..). r=edgar
We have more readable and faster versions (that just omit the namespace
arg).

Mostly done via sed, with a couple helpers to use the faster lookups
where possible.

Differential Revision: https://phabricator.services.mozilla.com/D181795
2023-06-23 10:01:32 +00:00
Masayuki Nakano
25c9325b7a Bug 1820470 - Make nsFocusManager::Focus not keep updating focus state if another window gets focus or focusing element is moved to another document r=NeilDeakin,smaug
It may dispatch `focus` event to the document node or the DOM window first.
Then, the web app may set another window focused or may move the focusing
element to another document.  In these cases, the method should not keep
handling it.  And unfortunately, it's hard to keep setting focus to the
focusing element after it's moved to another document because it'll cause
dispatching another `focus` event on the new document and window even if we
call itself recursively.  Then, it could cause infinite loop.  As far as
I've checked the behavior in Chrome for Windows, Chrome does not keep setting
focus.  Thus, we can just stop moving focus in the case.

Differential Revision: https://phabricator.services.mozilla.com/D175845
2023-04-25 03:24:32 +00:00
Masayuki Nakano
e4a81444c1 Bug 1807495 - part 1: Make Document notify HTMLEditor and IMEStateManager of pseudo focus change when editing state of focused editing host or document is changed r=smaug,m_kato
`IMEStateManager` basically runs at focus change.  However, when `designMode`
is set to `"off"` or focused editing host becomes non-editable (removing
`contenteditable` attribute or `contenteditable` attribute is set to `false`),
IME may be disabled without a focus change.  Therefore, `Document` needs to
notify `IMEStateManager` of the timing.

Additionally, `nsFocusManager` does not change focus when focused element
becomes not focusable (bug 1807597).  Therefore, `Document` needs to kick
`focus` or `blur` event handler of `HTMLEditor` when active editing host
becomes not editable.

However, if an ancestor of focused element becomes editable, I think that
`HTMLEditor` does not work well without focus move because it computes
editing host with current editing state in a lot of places, but `Selection`
and `nsFocusManager::GetFocusedElement` keeps working with previous focused
element which is now a editable child of editing host.  Therefore, this patch
marks them as `todo` in the new tests.

Differential Revision: https://phabricator.services.mozilla.com/D171196
2023-04-11 23:26:03 +00:00
Emilio Cobos Álvarez
e393d547a6 Bug 1823984 - Remove chrome-only special-case in CanSkipFocus. r=smaug
This seems to be XBL leftovers per bug 1366517. Let's try to remove it?

Differential Revision: https://phabricator.services.mozilla.com/D173322
2023-03-23 21:15:40 +00:00
Emilio Cobos Álvarez
39aeca9d9c Bug 1449669 - Remove IsNodeOfType. r=longsonr
Depends on D172893

Differential Revision: https://phabricator.services.mozilla.com/D172894
2023-03-17 19:22:14 +00:00
Edgar Chen
5860c73273 Bug 1814597; r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D171401
2023-03-14 20:15:41 +00:00
Sean Feng
40ee61069d Bug 1801761 - Generate focus actionId in SetFocusInner rather than relying on the caller to provide it r=emilio,hsivonen
This fixes an issue where Element::Focus triggered another focus
event and caused the initial focus event failed to be executed.

Differential Revision: https://phabricator.services.mozilla.com/D163156
2023-02-15 20:08:37 +00:00
Csoregi Natalia
fc752aa9f0 Backed out 7 changesets (bug 1444491, bug 1801761) for causing failures on autofocus-attribute.svg. CLOSED TREE
Backed out changeset 1cee414009cb (bug 1444491)
Backed out changeset 30f786b79191 (bug 1444491)
Backed out changeset ce06375518a7 (bug 1801761)
Backed out changeset 64c8bb293e5c (bug 1444491)
Backed out changeset 94aa0ce630f2 (bug 1444491)
Backed out changeset 80010eabc0c1 (bug 1444491)
Backed out changeset 7d8da1f44177 (bug 1444491)
2023-02-15 19:03:59 +02:00
Sean Feng
daed0147e7 Bug 1801761 - Generate focus actionId in SetFocusInner rather than relying on the caller to provide it r=emilio,hsivonen
This fixes an issue where Element::Focus triggered another focus
event and caused the initial focus event failed to be executed.

Differential Revision: https://phabricator.services.mozilla.com/D163156
2023-02-15 14:13:41 +00:00
Emilio Cobos Álvarez
eb724d197c Bug 1812041 - Don't deactivate main browser when moving focus to datetime picker panel. r=emilio,mconley,kcochrane
Ensuring that the date input within a main browser is not loosing focus when its associate date picker panel is opened and that the focus is udpated accordingly when it is closed (main part of the patch was crafted by Emilio, tests are added by ayeddi).

Differential Revision: https://phabricator.services.mozilla.com/D167698
2023-02-14 17:52:12 +00:00
Sean Feng
22a0614ff1 Bug 1816002 - Factor out the get-the-focusable-area step from FlushAndCheckIfFocusable r=emilio
FlushAndCheckIfFocusable does a few things in the same function, however
I'd like to reuse the area and shadow dom checks from it for the
autofocus algorithm work. Generally they are useful for checking if a
non-focusable element can be focused.

Differential Revision: https://phabricator.services.mozilla.com/D168399
2023-02-13 14:24:06 +00:00
Emilio Cobos Álvarez
7465d49826 Bug 1815526 - Make sure to clean up :focus-visible as well as :focus for shadow hosts. r=smaug
This is supposed to be cleaned up by the datetime widget in:

  https://searchfox.org/mozilla-central/rev/188d0f76a73e0671d12e744a71e9f5701668cc37/toolkit/content/widgets/datetimebox.js#600,623

But that may never happen if we tear down the widget before via a type
change, and we don't quite want to unconditionally unfocus when tearing
down (we might want to close the picker, but that's a separate issue).

Make sure to always unset :focus-visible as well from shadow roots to
fix it, and add exhaustive tests.

Differential Revision: https://phabricator.services.mozilla.com/D169099
2023-02-07 19:09:06 +00:00
Emilio Cobos Álvarez
19d036b807 Bug 1815430 - nsFocusManager::GetRedirectedFocus is dead code. r=smaug
No implementation of nsIDOMXULMenuListElement returns an input field
(this is menulist.js and autocomplete-input.js).

It seems autocomplete-input used to do this, but it got refactored to
extend HTMLInputElement instead, so this code can all go.

Differential Revision: https://phabricator.services.mozilla.com/D169066
2023-02-07 13:47:48 +00:00
Emilio Cobos Álvarez
9e530f224a Bug 1811834 - Clean up nsWidgetInitData. r=cmartin,geckoview-reviewers,calu
Move it to the mozilla::widget namespace.

Use enum classes for transparency, popup type, popup level, etc.

Mostly automated with sed, but there were a few manual changes required
as well in windows code because they relied on Atomic<TransparencyMode>
working (which now doesn't because TransparencyMode is 1 byte instead of
4 bytes).

Differential Revision: https://phabricator.services.mozilla.com/D167537
2023-01-23 23:58:41 +00:00
Emilio Cobos Álvarez
113c1d0d8a Bug 1792057 - Make sure to focus inner text field when creating / rebuilding edit fields in datetime widget. r=smaug
The blur is a regression from bug 1740989, but it's really uncovering a
regression from bug 1729342, sorta. Before that, we used to focus the
inner text field on rebuild via focusInnerTextBox().

One could argue that the focus fixup rule should really deal with this,
but I guess since content can't really unattach shadow DOM, it's less of
a general issue and more of an implementation detail.

The test uncovers another pre-existing issue (switching from date ->
test was also broken, and we left a bogus ElementState::FOCUS state in
the element).

Differential Revision: https://phabricator.services.mozilla.com/D158167
2023-01-11 22:16:38 +00:00
Martin Robinson
281ff8ade5 Bug 1791759 - Add support for content-visibility: auto r=emilio
This change adds support for `content-visibilty: auto` as well as
showing and hiding content based on the relevancy of the content as
defined in the specification. Changes to relevancy are handled by
triggering updates in a set of `content-visibility: auto` frames stored
in PresShell at the appropriate time in the document lifecycle.

Some tests are now failing due to this feature exposing the failures,
but they will be fixed in later changes.

This change is a reland of an earlier version that properly updates
intrinsic sizes and triggers an update of remembered size for the
purposes of contain-intrinsic-size when content relevancy changes.

Co-authored-by: Jihye Hong <jihye@igalia.com>

Differential Revision: https://phabricator.services.mozilla.com/D159693
2022-11-30 18:00:27 +00:00
Marian-Vasile Laza
f4d4ce0e21 Backed out changeset c428c3ad7725 (bug 1791759) for causing wpt failures on auto-012.html. CLOSED TREE 2022-11-28 13:31:05 +02:00
Martin Robinson
e26b2a32b9 Bug 1791759 - Add support for content-visibility: auto r=emilio
This change adds support for `content-visibilty: auto` as well as
showing and hiding content based on the relevancy of the content as
defined in the specification. Changes to relevancy are handled by
triggering updates in a set of `content-visibility: auto` frames stored
in PresShell at the appropriate time in the document lifecycle.

Some tests are now failing due to this feature exposing the failures,
but they will be fixed in later changes.

Co-authored-by: Jihye Hong <jihye@igalia.com>

Differential Revision: https://phabricator.services.mozilla.com/D159693
2022-11-28 09:53:06 +00:00
Emilio Cobos Álvarez
486040e135 Bug 1801094 - Clean-up a bit WhereToScroll. r=layout-reviewers,credential-management-reviewers,sgalich,dshin
This doesn't change behavior, but clarifies a bit the naming to match
the scrollIntoView() API. Also makes the name generic (rather than
Top/Left/etc), since for scrollIntoView we want to make the axes be
logical.

That will be done in bug 1789464 (probably via an extra ScrollFlag).

Differential Revision: https://phabricator.services.mozilla.com/D162286
2022-11-18 10:02:23 +00:00
Masayuki Nakano
f22596686b Bug 1795620 - Make it work better to activate/inactivate checkboxes and radio buttons like the other browsers r=smaug
First, the test compares `document.querySelector(":active")` and a checkbox or
a radio button.  However, Gecko activates ancestor elements too.  Therefore,
Gecko returns `<html>` element or `null` for the selector.  However, this is
an issue of CSS pseudo class compatibility which is **not** scope of the test.
Therefore, this patch makes it compare `document.querySelector("input:active")`
and a checkbox or a radio button instead.

Next, Gecko does not activate checkboxes and radio buttons when user presses
the space key, but the other browsers do it.  Therefore, this patch makes
`HTMLInputElement::PostHandleEvent` do it and
`EventStateManager::PostHandleEvent` clear it at `keyup` of the space key.

Next, Gecko does not inactive active elements when it gets lost focus.
Therefore, this patch makes `nsFocusManager::NotifyFocusStateChange` do it
like the other browsers.

Finally, with manual testing of draft patches, I found some issues of
inactivating them when they are activated by `<label>`s.  Therefore, I add new
tests in a separate file.  Note that Chrome fails only in the cases testing
`<input type="radio">` with `<label>`.

Differential Revision: https://phabricator.services.mozilla.com/D160494
2022-11-11 13:55:14 +00:00
Sean Feng
c6d5b35934 Bug 1741936 - Implement focus delegate algorithm r=emilio
Spec: https://html.spec.whatwg.org/multipage/interaction.html#focus-delegate

Differential Revision: https://phabricator.services.mozilla.com/D153689
2022-10-14 01:20:08 +00:00
Emilio Cobos Álvarez
b9e8672893 Bug 1794777 - Make elementIsFocusable not lie with ShadowRoot.delegatesFocus and an already-focused element. r=smaug
FlushAndCheckIfFocusable was returning false, when the real thing that's
going on is that the element _is_ focusable, but it's already focused.

Improve handling of FlushAndCheckIfFocusable elsewhere, though I don't
think that can change behavior since we get the delegated focus at that
point already. Still seems like the right thing to do.

Differential Revision: https://phabricator.services.mozilla.com/D158935
2022-10-12 10:35:58 +00:00
Csoregi Natalia
510661b9f3 Backed out changeset 4edc81a94eaa (bug 1792057) for causing multiple failures. CLOSED TREE 2022-10-05 21:53:02 +03:00
Emilio Cobos Álvarez
5d6bc39dcf Bug 1792057 - Make sure to focus inner text field when creating / rebuilding edit fields in datetime widget. r=smaug
The blur is a regression from bug 1740989, but it's really uncovering a
regression from bug 1729342, sorta. Before that, we used to focus the
inner text field on rebuild via focusInnerTextBox().

One could argue that the focus fixup rule should really deal with this,
but I guess since content can't really unattach shadow DOM, it's less of
a general issue and more of an implementation detail.

The test uncovers another pre-existing issue (switching from date ->
test was also broken, and we left a bogus ElementState::FOCUS state in
the element).

Differential Revision: https://phabricator.services.mozilla.com/D158167
2022-10-05 17:31:51 +00:00
Emilio Cobos Álvarez
bc80c6bba9 Bug 1689816 - Flush style in moveFocus. r=smaug
This is callable from JS, and nothing guarantees that style has been
updated properly before. Without this, my previous patch causes failures
in browser/base/content/test/tabdialogs/browser_tabdialogbox_focus.js,
because the nsDeckFrame used to listen to attribute changes
synchronously and now it's style-based, so if you moveFocus right after
revealing it we'd end up with the wrong answer.

Differential Revision: https://phabricator.services.mozilla.com/D157886
2022-09-22 18:10:50 +00:00
Emilio Cobos Álvarez
e3d2060438 Bug 1740989 - Implement focus fixup rule. r=smaug
This implements the proposal in the linked spec issue, and makes
it nightly-only pending resolution + edits.

Differential Revision: https://phabricator.services.mozilla.com/D155970
2022-09-01 11:28:47 +00:00
Iulian Moraru
c4572532eb Backed out changeset d8f983951128 (bug 1740989) for causing mochitest-chrome failures on test_modal_prompts.html. CLOSED TREE 2022-09-01 01:03:29 +03:00
Emilio Cobos Álvarez
c5ffe23435 Bug 1740989 - Implement focus fixup rule. r=smaug
This implements the proposal in the linked spec issue, and makes
it nightly-only pending resolution + edits.

Differential Revision: https://phabricator.services.mozilla.com/D155970
2022-08-31 17:10:17 +00:00
Emilio Cobos Álvarez
c84f2d6726 Bug 1765083 - Introduce FocusOptions.focusVisible. r=smaug,pip-reviewers
As per:

 * https://github.com/whatwg/html/issues/7830
 * https://github.com/whatwg/html/pull/8087

Replace the internal preventFocusRing with the new flag.

Differential Revision: https://phabricator.services.mozilla.com/D151326
2022-07-11 22:04:34 +00:00