Bug 712130 - Simplify focus stealing prevention for autofocus. r?bz draft
authordecltype <mozilla@decltype.org>
Fri, 12 Jan 2018 00:17:58 +0100
changeset 754879 40545f746541edb6ff49b4c9d783ca4fe8515d57
parent 754878 c5a5ee2f4a8aa2192e167e40a34acef3ef1c92e3
push id99026
push userbmo:mozilla@decltype.org
push dateWed, 14 Feb 2018 13:55:40 +0000
reviewersbz
bugs712130
milestone59.0a1
Bug 712130 - Simplify focus stealing prevention for autofocus. r?bz Remove redundant check already implied by earlier condition: If the focus manager's focused content is in our document, all parent windows including the root window must have their focused node set to non-null. MozReview-Commit-ID: CryGb6mfczK
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -10015,37 +10015,24 @@ public:
     nsCOMPtr<nsPIDOMWindowOuter> currentTopWindow =
       FindTopWindowForElement(mElement);
     if (currentTopWindow != mTopWindow) {
       // The element's top window changed from when the event was queued.
       // Don't take away focus from an unrelated window.
       return NS_OK;
     }
 
-    nsFocusManager* fm = nsFocusManager::GetFocusManager();
-    if (!fm) {
-      return NS_ERROR_NULL_POINTER;
-    }
-
-    nsIDocument* document = mElement->OwnerDoc();
-
     // Don't steal focus from the user.
     if (mTopWindow->GetFocusedNode()) {
       return NS_OK;
     }
 
-    // If something is focused in the same document, ignore autofocus.
-    if (!fm->GetFocusedContent() ||
-        fm->GetFocusedContent()->OwnerDoc() != document) {
-      mozilla::ErrorResult rv;
-      mElement->Focus(rv);
-      return rv.StealNSResult();
-    }
-
-    return NS_OK;
+    mozilla::ErrorResult rv;
+    mElement->Focus(rv);
+    return rv.StealNSResult();
   }
 private:
   nsCOMPtr<Element> mElement;
   nsCOMPtr<nsPIDOMWindowOuter> mTopWindow;
 };
 
 void
 nsDocument::SetAutoFocusElement(Element* aAutoFocusElement)