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
--- 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)