fix(dom/base/Element): Clear focus when the active element is hidden
This fixes a failing Web Platform Test (https://github.com/w3c/web-platform-tests/blob/009111410a1099e85d4027a679985975757ceb4d/html/editing/focus/processing-model/focus-fixup-rule-one-no-dialogs.html#L36). Wasn't sure where exactly to place this logic - it makes sense to me to be done before the attribute changed callback is called.
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -2724,16 +2724,24 @@ Element::SetAttrAndNotify(int32_t aNames
oldValue = nullptr;
}
} else {
// No need to conditionally assign null here. If there was no previously
// set value for the attribute, aOldValue will already be null.
oldValue = aOldValue;
}
+ if (aName == nsGkAtoms::hidden && HasAttr(kNameSpaceID_None, nsGkAtoms::hidden)) {
+ nsFocusManager *fm = nsFocusManager::GetFocusManager();
+
+ if (fm && fm->IsFocused(this)) {
+ fm->ClearFocus(OwnerDoc()->GetWindow());
+ }
+ }
+
if (aComposedDocument || HasFlag(NODE_FORCE_XBL_BINDINGS)) {
RefPtr<nsXBLBinding> binding = GetXBLBinding();
if (binding) {
binding->AttributeChanged(aName, aNamespaceID, false, aNotify);
}
}
if (CustomElementRegistry::IsCustomElementEnabled()) {