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
This commit is contained in:
Emilio Cobos Álvarez
2023-12-08 11:34:06 +00:00
parent c46be63470
commit 71e771518b
21 changed files with 140 additions and 246 deletions

View File

@@ -2286,6 +2286,8 @@ void nsGenericHTMLElement::Click(CallerType aCallerType) {
bool nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
int32_t* aTabIndex) {
MOZ_ASSERT(aIsFocusable);
MOZ_ASSERT(aTabIndex);
if (ShadowRoot* root = GetShadowRoot()) {
if (root->DelegatesFocus()) {
*aIsFocusable = false;
@@ -2293,23 +2295,17 @@ bool nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
}
}
Document* doc = GetComposedDoc();
if (!doc || IsInDesignMode()) {
if (!IsInComposedDoc() || IsInDesignMode()) {
// In designMode documents we only allow focusing the document.
if (aTabIndex) {
*aTabIndex = -1;
}
*aTabIndex = -1;
*aIsFocusable = false;
return true;
}
int32_t tabIndex = TabIndex();
*aTabIndex = TabIndex();
bool disabled = false;
bool disallowOverridingFocusability = true;
Maybe<int32_t> attrVal = GetTabIndexAttrValue();
if (IsEditingHost()) {
// Editable roots should always be focusable.
disallowOverridingFocusability = true;
@@ -2319,7 +2315,7 @@ bool nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
if (attrVal.isNothing()) {
// The default value for tabindex should be 0 for editable
// contentEditable roots.
tabIndex = 0;
*aTabIndex = 0;
}
} else {
disallowOverridingFocusability = false;
@@ -2327,18 +2323,13 @@ bool nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
// Just check for disabled attribute on form controls
disabled = IsDisabled();
if (disabled) {
tabIndex = -1;
*aTabIndex = -1;
}
}
if (aTabIndex) {
*aTabIndex = tabIndex;
}
// If a tabindex is specified at all, or the default tabindex is 0, we're
// focusable
*aIsFocusable = (tabIndex >= 0 || (!disabled && attrVal.isSome()));
// focusable.
*aIsFocusable = (*aTabIndex >= 0 || (!disabled && attrVal.isSome()));
return disallowOverridingFocusability;
}