Bug 1456588 part 5. Store an Element as the focused content in the focus manager. r=enndeakin
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 26 Apr 2018 10:37:47 -0400
changeset 415784 b64df38f5117a598d9036cbdf367acdb212ea23e
parent 415783 e419e7f9947999ecd704e45ef5e4525191bbf48e
child 415785 f240cf49fff8832d31b77334aff826113dd31d59
push id33910
push usershindli@mozilla.com
push dateThu, 26 Apr 2018 21:39:52 +0000
treeherdermozilla-central@63a0e2f626fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1456588 part 5. Store an Element as the focused content in the focus manager. r=enndeakin
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -1364,17 +1364,17 @@ nsFocusManager::SetFocusInner(Element* a
   LOGCONTENT("Shift Focus: %s", contentToFocus.get());
   LOGFOCUS((" Flags: %x Current Window: %p New Window: %p Current Element: %p",
            aFlags, mFocusedWindow.get(), newWindow.get(), mFocusedContent.get()));
   LOGFOCUS((" In Active Window: %d In Focused Window: %d SendFocus: %d",
            isElementInActiveWindow, isElementInFocusedWindow, sendFocusEvent));
   if (sendFocusEvent) {
-    nsCOMPtr<nsIContent> oldFocusedContent = mFocusedContent;
+    RefPtr<Element> oldFocusedContent = mFocusedContent;
     // return if blurring fails or the focus changes during the blur
     if (mFocusedWindow) {
       // if the focus is being moved to another element in the same document,
       // or to a descendant, pass the existing window to Blur so that the
       // current node in the existing window is cleared. If moving to a
       // window elsewhere, we want to maintain the current node in the
       // window but still blur it.
       bool currentIsSameOrAncestor = IsSameOrAncestor(mFocusedWindow, newWindow);
@@ -1654,17 +1654,17 @@ nsFocusManager::Blur(nsPIDOMWindowOuter*
                      nsPIDOMWindowOuter* aAncestorWindowToFocus,
                      bool aIsLeavingDocument,
                      bool aAdjustWidgets,
                      nsIContent* aContentToFocus)
   LOGFOCUS(("<<Blur begin>>"));
   // hold a reference to the focused content, which may be null
-  nsCOMPtr<nsIContent> content = mFocusedContent;
+  RefPtr<Element> content = mFocusedContent;
   if (content) {
     if (!content->IsInComposedDoc()) {
       mFocusedContent = nullptr;
       return true;
     if (content == mFirstBlurEvent)
       return true;
--- a/dom/base/nsFocusManager.h
+++ b/dom/base/nsFocusManager.h
@@ -10,16 +10,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIFocusManager.h"
 #include "nsIObserver.h"
 #include "nsIWidget.h"
 #include "nsWeakReference.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/RefPtr.h"
 #define FOCUSMETHOD_MASK 0xF000
 #define FOCUSMANAGER_CONTRACTID "@mozilla.org/focus-manager;1"
 class nsIContent;
 class nsIDocShellTreeItem;
@@ -58,20 +59,20 @@ public:
    * Retrieve the single focus manager.
   static nsFocusManager* GetFocusManager() { return sInstance; }
    * A faster version of nsIFocusManager::GetFocusedElement, returning a
-   * raw nsIContent pointer (instead of having AddRef-ed nsIDOMElement
+   * raw Element pointer (instead of having AddRef-ed nsIDOMElement
    * pointer filled in to an out-parameter).
-  nsIContent* GetFocusedContent() { return mFocusedContent; }
+  mozilla::dom::Element* GetFocusedContent() { return mFocusedContent; }
    * Returns true if aContent currently has focus.
   bool IsFocused(nsIContent* aContent);
    * Return a focused window. Version of nsIFocusManager::GetFocusedWindow.
@@ -94,19 +95,19 @@ public:
     SetMouseButtonHandlingDocument(nsIDocument* aDocument)
     nsCOMPtr<nsIDocument> handlingDocument = mMouseButtonEventHandlingDocument;
     mMouseButtonEventHandlingDocument = aDocument;
     return handlingDocument.forget();
-  void NeedsFlushBeforeEventHandling(nsIContent* aContent)
+  void NeedsFlushBeforeEventHandling(mozilla::dom::Element* aElement)
-    if (mFocusedContent == aContent) {
+    if (mFocusedContent == aElement) {
       mEventHandlingNeedsFlush = true;
   bool CanSkipFocus(nsIContent* aContent);
   void FlushBeforeEventHandlingIfNeeded(nsIContent* aContent)
@@ -639,17 +640,17 @@ private:
   // the child or top-level window that is currently focused. This window will
   // either be the same window as mActiveWindow or a descendant of it.
   // Except during shutdown use SetFocusedWindowInternal to set mFocusedWindow!
   nsCOMPtr<nsPIDOMWindowOuter> mFocusedWindow;
   // the currently focused content, which is always inside mFocusedWindow. This
   // is a cached copy of the mFocusedWindow's current content. This may be null
   // if no content is focused.
-  nsCOMPtr<nsIContent> mFocusedContent;
+  RefPtr<mozilla::dom::Element> mFocusedContent;
   // these fields store a content node temporarily while it is being focused
   // or blurred to ensure that a recursive call doesn't refire the same event.
   // They will always be cleared afterwards.
   nsCOMPtr<nsIContent> mFirstBlurEvent;
   nsCOMPtr<nsIContent> mFirstFocusEvent;
   // keep track of a window while it is being lowered