Issue #2135 - Implement sequential focus navigation for shadow DOM

This covers the following:
Bug 1413834	Implement sequential focus navigation regarding shadow DOM
> Bug 1430020	Let sequential focus navigation in shadow DOM enter iframes
> Bug 1430701	Handle focus navigation on frameless shadow hosts in light DOM
> Bug 1430692	Handle focus navigation on NAC in shadow DOM
> Bug 1453693	Ensure sequential focus navigation works in Shadow DOM and add some tests
> Bug 1466581	Handle sequential focus also in nested shadow DOM
> Bug 1481079	Shadow DOM hosts should be focusable
> Bug 1507101	Use StyleChildrenIterator instead of custom frame tree walking code to handle NAC inside shadow dom
> Bug 1512043	Ensure traverse all nodes owned by the top level shadow host
> Bug 1512457	Fix various cases that focus navigation doesn't work well with frameless shadow host
> Bug 1513141	Really minor nsFocusManager cleanup
> Bug 1519090	Keyboard focus is trapped inside <slot>
> Bug 1528034	Make IsHostOrSlot null-safe
> Bug 1544826	Wrong focus navigation behavior when the root element is a shadow root
>> Bug 1500273	Ensure backward focus navigation works in Shadow DOM
This commit is contained in:
FranklinDM 2023-03-04 02:18:40 +08:00 committed by roytam1
commit 56193120c5
7 changed files with 1712 additions and 98 deletions

View file

@ -384,6 +384,91 @@ protected:
int32_t aType, bool aNoParentTraversal,
nsIContent** aNextContent);
/**
* Returns scope owner of aContent.
* A scope owner is either a document root, shadow host, or slot.
*/
nsIContent* FindOwner(nsIContent* aContent);
/**
* Retrieve the next tabbable element in scope owned by aOwner, using
* focusability and tabindex to determine the tab order.
*
* aOwner is the owner of scope to search in.
*
* aStartContent is the starting point for this call of this method.
*
* aOriginalStartContent is the initial starting point for sequential
* navigation.
*
* aForward should be true for forward navigation or false for backward
* navigation.
*
* aCurrentTabIndex is the current tabindex.
*
* aIgnoreTabIndex to ignore the current tabindex and find the element
* irrespective or the tab index.
*
* aForDocumentNavigation informs whether we're navigating only through
* documents.
*
* aSkipOwner to skip owner while searching. The flag is set when caller is
* |GetNextTabbableContent| in order to let caller handle owner.
*
* NOTE:
* Consider the method searches downwards in flattened subtree
* rooted at aOwner.
*/
nsIContent* GetNextTabbableContentInScope(nsIContent* aOwner,
nsIContent* aStartContent,
nsIContent* aOriginalStartContent,
bool aForward,
int32_t aCurrentTabIndex,
bool aIgnoreTabIndex,
bool aForDocumentNavigation,
bool aSkipOwner);
/**
* Retrieve the next tabbable element in scope including aStartContent
* and the scope's ancestor scopes, using focusability and tabindex to
* determine the tab order.
*
* aStartOwner is the scope owner of the aStartContent.
*
* aStartContent an in/out paremeter. It as input is the starting point
* for this call of this method; as output it is the shadow host in
* light DOM if the next tabbable element is not found in shadow DOM,
* in order to continue searching in light DOM.
*
* aOriginalStartContent is the initial starting point for sequential
* navigation.
*
* aForward should be true for forward navigation or false for backward
* navigation.
*
* aCurrentTabIndex returns tab index of shadow host in light DOM if the
* next tabbable element is not found in shadow DOM, in order to continue
* searching in light DOM.
*
* aIgnoreTabIndex to ignore the current tabindex and find the element
* irrespective or the tab index.
*
* aForDocumentNavigation informs whether we're navigating only through
* documents.
*
* NOTE:
* Consider the method searches upwards in all shadow host- or slot-rooted
* flattened subtrees that contains aStartContent as non-root, except
* the flattened subtree rooted at shadow host in light DOM.
*/
nsIContent* GetNextTabbableContentInAncestorScopes(nsIContent* aStartOwner,
nsIContent** aStartContent,
nsIContent* aOriginalStartContent,
bool aForward,
int32_t* aCurrentTabIndex,
bool aIgnoreTabIndex,
bool aForDocumentNavigation);
/**
* Retrieve the next tabbable element within a document, using focusability
* and tabindex to determine the tab order. The element is returned in
@ -503,6 +588,16 @@ private:
void SetFocusedWindowInternal(nsPIDOMWindowOuter* aWindow);
bool TryDocumentNavigation(nsIContent* aCurrentContent,
bool* aCheckSubDocument,
nsIContent** aResultContent);
bool TryToMoveFocusToSubDocument(nsIContent* aCurrentContent,
nsIContent* aOriginalStartContent,
bool aForward,
bool aForDocumentNavigation,
nsIContent** aResultContent);
// the currently active and front-most top-most window
nsCOMPtr<nsPIDOMWindowOuter> mActiveWindow;