Bug 1387406 - part3: nsFocusManager should treat editor as HTMLEditor r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 07 Aug 2017 14:55:58 +0900
changeset 643906 d3cbadeaf0049975e0757fd8d7688ffd6a49b11e
parent 643905 71279f8f5269e0bd00293d88376aaa569a0564a7
child 643907 93b170cee6346fa246ce0adbb7530631d1c3fa16
push id73250
push usermasayuki@d-toybox.com
push dateThu, 10 Aug 2017 07:58:50 +0000
reviewerssmaug
bugs1387406
milestone57.0a1
Bug 1387406 - part3: nsFocusManager should treat editor as HTMLEditor r?smaug Editor treated by nsFocusManager is always HTMLEditor. So, it should treat the editor as is. MozReview-Commit-ID: Di1k2dlLodV
dom/base/nsFocusManager.cpp
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -10,17 +10,16 @@
 
 #include "AccessibleCaretEventHub.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsGkAtoms.h"
 #include "nsGlobalWindow.h"
 #include "nsContentUtils.h"
 #include "nsIContentParent.h"
 #include "nsIDocument.h"
-#include "nsIEditor.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMRange.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
@@ -49,16 +48,17 @@
 #include "nsNetUtil.h"
 
 #include "mozilla/ContentEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
+#include "mozilla/HTMLEditor.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Unused.h"
 #include <algorithm>
 
 #ifdef MOZ_XUL
@@ -852,28 +852,22 @@ nsFocusManager::ContentRemoved(nsIDocume
         }
       }
     }
 
     // Notify the editor in case we removed its ancestor limiter.
     if (content->IsEditable()) {
       nsCOMPtr<nsIDocShell> docShell = aDocument->GetDocShell();
       if (docShell) {
-        nsCOMPtr<nsIEditor> editor;
-        docShell->GetEditor(getter_AddRefs(editor));
-        if (editor) {
-          nsCOMPtr<nsISelection> s;
-          editor->GetSelection(getter_AddRefs(s));
-          nsCOMPtr<nsISelectionPrivate> selection = do_QueryInterface(s);
-          if (selection) {
-            nsCOMPtr<nsIContent> limiter;
-            selection->GetAncestorLimiter(getter_AddRefs(limiter));
-            if (limiter == content) {
-              editor->FinalizeSelection();
-            }
+        RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
+        if (htmlEditor) {
+          RefPtr<Selection> selection = htmlEditor->GetSelection();
+          if (selection && selection->GetFrameSelection() &&
+              content == selection->GetFrameSelection()->GetAncestorLimiter()) {
+            htmlEditor->FinalizeSelection();
           }
         }
       }
     }
 
     NotifyFocusStateChange(content, nullptr, shouldShowFocusRing, false);
   }