fix(dom/base/Element): Clear focus when the active element is hidden draft
authorSorin Davidoi <sorin.davidoi@gmail.com>
Sat, 10 Feb 2018 13:44:18 +0100
changeset 753523 a78881eaedd4244c8ecce946abcb8569c21d3166
parent 753522 a8e153c55eeee93a11e87d325fb20c644421036f
child 753524 f84c7a94ab47dd1aa61949981a1bb964ddb325b9
push id98577
push userbmo:sorin.davidoi@gmail.com
push dateSat, 10 Feb 2018 13:40:06 +0000
milestone60.0a1
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.
dom/base/Element.cpp
--- 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()) {