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

--HG--
extra : rebase_source : 09e87fab64bc3e8a00300bc3109e45a1b8c8b797
This commit is contained in:
Masayuki Nakano 2017-08-07 14:43:50 +09:00
Родитель 9ee491b79f
Коммит 9114d3d55d
1 изменённых файлов: 22 добавлений и 25 удалений

Просмотреть файл

@ -84,12 +84,11 @@
#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"
@ -2613,9 +2612,8 @@ nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement)
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)) {
@ -2626,8 +2624,8 @@ nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement)
}
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
rv = editor->GetInlineSpellChecker(false,
getter_AddRefs(spellChecker));
rv = htmlEditor->GetInlineSpellChecker(false,
getter_AddRefs(spellChecker));
NS_ENSURE_SUCCESS_VOID(rv);
if (spellChecker) {
@ -2774,17 +2772,12 @@ nsHTMLDocument::EditingStateChanged()
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.
@ -2802,7 +2795,7 @@ nsHTMLDocument::EditingStateChanged()
bool updateState = false;
bool spellRecheckAll = false;
bool putOffToRemoveScriptBlockerUntilModifyingEditingState = false;
nsCOMPtr<nsIEditor> editor;
htmlEditor = nullptr;
{
EditingState oldState = mEditingState;
@ -2886,14 +2879,15 @@ nsHTMLDocument::EditingStateChanged()
}
// 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) {
@ -2945,18 +2939,21 @@ nsHTMLDocument::EditingStateChanged()
// 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;
}