Bug 1589027 - Fix object.tabIndex should return 0 by default; r=smaug

The spec change HTMLObjectElement tabIndex default to 0, but `test_object_plugin_nav.html` will fail due to HTMLObjectElement’s sequence focus and .focus() rely on default tabIndex. In this patch I separate the logic to not rely on default tabIndex for HTMLObjectElement's plugin type and align the spec.

Differential Revision: https://phabricator.services.mozilla.com/D50801
This commit is contained in:
John Dai
2019-10-28 15:50:59 +00:00
parent 2ed94eb548
commit 09f058f5a9
6 changed files with 25 additions and 41 deletions

View File

@@ -276,17 +276,6 @@ nsresult HTMLObjectElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
return NS_OK;
}
bool HTMLObjectElement::IsFocusableForTabIndex() {
Document* doc = GetComposedDoc();
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
return false;
}
return IsEditableRoot() ||
((Type() == eType_Document || Type() == eType_FakePlugin) &&
nsContentUtils::IsSubDocumentTabbable(this));
}
bool HTMLObjectElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
int32_t* aTabIndex) {
// TODO: this should probably be managed directly by IsHTMLFocusable.
@@ -294,38 +283,45 @@ bool HTMLObjectElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
Document* doc = GetComposedDoc();
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
if (aTabIndex) {
*aTabIndex = TabIndex();
*aTabIndex = -1;
}
*aIsFocusable = false;
return false;
}
const nsAttrValue* attrVal = mAttrs.GetAttr(nsGkAtoms::tabindex);
bool isFocusable = attrVal && attrVal->Type() == nsAttrValue::eInteger;
// Has plugin content: let the plugin decide what to do in terms of
// internal focus from mouse clicks
if (Type() == eType_Plugin) {
if (aTabIndex) {
*aTabIndex = isFocusable ? attrVal->GetIntegerValue() : -1;
}
*aIsFocusable = true;
return false;
}
// This method doesn't call nsGenericHTMLFormElement intentionally.
// TODO: It should probably be changed when bug 597242 will be fixed.
if (Type() == eType_Plugin || IsEditableRoot() ||
if (IsEditableRoot() ||
((Type() == eType_Document || Type() == eType_FakePlugin) &&
nsContentUtils::IsSubDocumentTabbable(this))) {
// Has plugin content: let the plugin decide what to do in terms of
// internal focus from mouse clicks
if (aTabIndex) {
*aTabIndex = TabIndex();
*aTabIndex = isFocusable ? attrVal->GetIntegerValue() : 0;
}
*aIsFocusable = true;
return false;
}
// TODO: this should probably be managed directly by IsHTMLFocusable.
// See bug 597242.
const nsAttrValue* attrVal = mAttrs.GetAttr(nsGkAtoms::tabindex);
*aIsFocusable = attrVal && attrVal->Type() == nsAttrValue::eInteger;
if (aTabIndex && *aIsFocusable) {
if (aTabIndex && isFocusable) {
*aTabIndex = attrVal->GetIntegerValue();
*aIsFocusable = true;
}
return false;
@@ -372,9 +368,7 @@ HTMLObjectElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
return aFormSubmission->AddNameValuePair(name, value);
}
int32_t HTMLObjectElement::TabIndexDefault() {
return IsFocusableForTabIndex() ? 0 : -1;
}
int32_t HTMLObjectElement::TabIndexDefault() { return 0; }
Nullable<WindowProxyHolder> HTMLObjectElement::GetContentWindow(
nsIPrincipal& aSubjectPrincipal) {