Bug 1388001 - part4: nsHTMLDocument should treat editor as HTMLEditor r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 07 Aug 2017 14:43:50 +0900
changeset 645253 d88b02100a93daebfb5f8bda29aa7c4fc89c10c4
parent 645252 66f01a988d5849b226f373a80ef127ebe65036cc
child 645258 68226981d224969b8f193c425d0feea63b5d3798
push id73718
push usermasayuki@d-toybox.com
push dateSat, 12 Aug 2017 02:58:16 +0000
reviewerssmaug
bugs1388001
milestone57.0a1
Bug 1388001 - part4: nsHTMLDocument should treat editor as HTMLEditor r?smaug nsHTMLDocument retrieves its associated editor from nsIEditingSession and nsIDocShell. So, both of them have methods returning HTMLEditor*. Therefore, nsHTMLDocument should treat all of them as HTMLEditor. MozReview-Commit-ID: 5zPH708Vev3
dom/html/nsHTMLDocument.cpp
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -79,22 +79,21 @@
 #include "nsArrayUtils.h"
 #include "nsIEffectiveTLDService.h"
 
 //AHMED 12-2
 #include "nsBidiUtils.h"
 
 #include "mozilla/dom/FallbackEncoding.h"
 #include "mozilla/Encoding.h"
+#include "mozilla/HTMLEditor.h"
 #include "mozilla/LoadInfo.h"
 #include "nsIEditingSession.h"
-#include "nsIEditor.h"
 #include "nsNodeInfoManager.h"
 #include "nsIPlaintextEditor.h"
-#include "nsIHTMLEditor.h"
 #include "nsIEditorStyleSheets.h"
 #include "nsIInlineSpellChecker.h"
 #include "nsRange.h"
 #include "mozAutoDocUpdate.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsHtml5Module.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Preferences.h"
@@ -2608,31 +2607,30 @@ nsHTMLDocument::DeferredContentEditableC
       nsPIDOMWindowOuter *window = GetWindow();
       if (!window)
         return;
 
       nsIDocShell *docshell = window->GetDocShell();
       if (!docshell)
         return;
 
-      nsCOMPtr<nsIEditor> editor;
-      docshell->GetEditor(getter_AddRefs(editor));
-      if (editor) {
+      RefPtr<HTMLEditor> htmlEditor = docshell->GetHTMLEditor();
+      if (htmlEditor) {
         RefPtr<nsRange> range = new nsRange(aElement);
         rv = range->SelectNode(node);
         if (NS_FAILED(rv)) {
           // The node might be detached from the document at this point,
           // which would cause this call to fail.  In this case, we can
           // safely ignore the contenteditable count change.
           return;
         }
 
         nsCOMPtr<nsIInlineSpellChecker> spellChecker;
-        rv = editor->GetInlineSpellChecker(false,
-                                           getter_AddRefs(spellChecker));
+        rv = htmlEditor->GetInlineSpellChecker(false,
+                                               getter_AddRefs(spellChecker));
         NS_ENSURE_SUCCESS_VOID(rv);
 
         if (spellChecker) {
           rv = spellChecker->SpellCheckRange(range);
         }
       }
     }
   }
@@ -2769,27 +2767,22 @@ nsHTMLDocument::EditingStateChanged()
   nsIDocShell *docshell = window->GetDocShell();
   if (!docshell)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIEditingSession> editSession;
   nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIEditor> existingEditor;
-  editSession->GetEditorForWindow(window, getter_AddRefs(existingEditor));
-  if (existingEditor) {
+  RefPtr<HTMLEditor> htmlEditor = editSession->GetHTMLEditorForWindow(window);
+  if (htmlEditor) {
     // We might already have an editor if it was set up for mail, let's see
     // if this is actually the case.
-#ifdef DEBUG
-    nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(existingEditor);
-    MOZ_ASSERT(htmlEditor, "If we have an editor, it must be an HTML editor");
-#endif
     uint32_t flags = 0;
-    existingEditor->GetFlags(&flags);
+    htmlEditor->GetFlags(&flags);
     if (flags & nsIPlaintextEditor::eEditorMailMask) {
       // We already have a mail editor, then we should not attempt to create
       // another one.
       return NS_OK;
     }
   }
 
   if (!HasPresShell(window)) {
@@ -2797,17 +2790,17 @@ nsHTMLDocument::EditingStateChanged()
     // It's probably style=display:none.
     return NS_OK;
   }
 
   bool makeWindowEditable = mEditingState == eOff;
   bool updateState = false;
   bool spellRecheckAll = false;
   bool putOffToRemoveScriptBlockerUntilModifyingEditingState = false;
-  nsCOMPtr<nsIEditor> editor;
+  htmlEditor = nullptr;
 
   {
     EditingState oldState = mEditingState;
     nsAutoEditingState push(this, eSettingUp);
 
     nsCOMPtr<nsIPresShell> presShell = GetShell();
     NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
@@ -2881,24 +2874,25 @@ nsHTMLDocument::EditingStateChanged()
       // XXX This can cause flushing which can change the editing state, so make
       //     sure to avoid recursing.
       rv = editSession->MakeWindowEditable(window, "html", false, false,
                                            true);
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // XXX Need to call TearDownEditorOnWindow for all failures.
-    docshell->GetEditor(getter_AddRefs(editor));
-    if (!editor)
+    htmlEditor = docshell->GetHTMLEditor();
+    if (!htmlEditor) {
       return NS_ERROR_FAILURE;
+    }
 
     // If we're entering the design mode, put the selection at the beginning of
     // the document for compatibility reasons.
     if (designMode && oldState == eOff) {
-      editor->BeginningOfDocument();
+      htmlEditor->BeginningOfDocument();
     }
 
     if (putOffToRemoveScriptBlockerUntilModifyingEditingState) {
       nsContentUtils::AddScriptBlocker();
     }
   }
 
   mEditingState = newState;
@@ -2940,28 +2934,31 @@ nsHTMLDocument::EditingStateChanged()
 
   if (updateState) {
     nsAutoScriptBlocker scriptBlocker;
     NotifyEditableStateChange(this, this);
   }
 
   // Resync the editor's spellcheck state.
   if (spellRecheckAll) {
-    nsCOMPtr<nsISelectionController> selcon;
-    nsresult rv = editor->GetSelectionController(getter_AddRefs(selcon));
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsISelectionController> selectionController =
+      htmlEditor->GetSelectionController();
+    if (NS_WARN_IF(!selectionController)) {
+      return NS_ERROR_FAILURE;
+    }
 
     nsCOMPtr<nsISelection> spellCheckSelection;
-    rv = selcon->GetSelection(nsISelectionController::SELECTION_SPELLCHECK,
-                              getter_AddRefs(spellCheckSelection));
+    rv = selectionController->GetSelection(
+                                nsISelectionController::SELECTION_SPELLCHECK,
+                                getter_AddRefs(spellCheckSelection));
     if (NS_SUCCEEDED(rv)) {
       spellCheckSelection->RemoveAllRanges();
     }
   }
-  editor->SyncRealTimeSpell();
+  htmlEditor->SyncRealTimeSpell();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::SetDesignMode(const nsAString& aDesignMode)
 {
   ErrorResult rv;