зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1319340 - part9: Make nsComposerDocumentCommands use concrete class when calling methods of editor r=m_kato
MozReview-Commit-ID: 15WBfUpfo6L --HG-- extra : rebase_source : 0e729ea9f2a37555836cca869ea1da4174895960
This commit is contained in:
Родитель
de893ee82e
Коммит
19dc3194d7
|
@ -5,6 +5,7 @@
|
|||
|
||||
|
||||
#include "mozilla/HTMLEditor.h" // for HTMLEditor
|
||||
#include "mozilla/TextEditor.h" // for TextEditor
|
||||
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
|
||||
#include "nsCRT.h" // for nsCRT
|
||||
#include "nsComposerCommands.h" // for nsSetDocumentOptionsCommand, etc
|
||||
|
@ -16,9 +17,6 @@
|
|||
#include "nsIDocument.h" // for nsIDocument
|
||||
#include "nsIEditingSession.h" // for nsIEditingSession, etc
|
||||
#include "nsIEditor.h" // for nsIEditor
|
||||
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
|
||||
#include "nsIHTMLInlineTableEditor.h" // for nsIHTMLInlineTableEditor
|
||||
#include "nsIHTMLObjectResizer.h" // for nsIHTMLObjectResizer
|
||||
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc
|
||||
#include "nsIPresShell.h" // for nsIPresShell
|
||||
#include "nsISelectionController.h" // for nsISelectionController
|
||||
|
@ -40,21 +38,18 @@ class nsISupports;
|
|||
|
||||
static
|
||||
nsresult
|
||||
GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult)
|
||||
GetPresContextFromEditor(TextEditor* aTextEditor, nsPresContext** aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aTextEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
*aResult = nullptr;
|
||||
NS_ENSURE_ARG_POINTER(aEditor);
|
||||
|
||||
nsCOMPtr<nsISelectionController> selCon;
|
||||
nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryInterface(selCon);
|
||||
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
||||
|
||||
NS_IF_ADDREF(*aResult = presShell->GetPresContext());
|
||||
nsCOMPtr<nsIPresShell> presShell = aTextEditor->GetPresShell();
|
||||
if (NS_WARN_IF(!presShell)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
RefPtr<nsPresContext> presContext = presShell->GetPresContext();
|
||||
presContext.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -65,11 +60,13 @@ nsSetDocumentOptionsCommand::IsCommandEnabled(const char * aCommandName,
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
||||
if (editor) {
|
||||
return editor->GetIsSelectionEditable(outCmdEnabled);
|
||||
if (!editor) {
|
||||
*outCmdEnabled = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*outCmdEnabled = false;
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
*outCmdEnabled = textEditor->IsSelectionEditable();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -88,10 +85,15 @@ nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName,
|
|||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
|
||||
RefPtr<nsPresContext> presContext;
|
||||
nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
|
||||
nsresult rv =
|
||||
GetPresContextFromEditor(textEditor, getter_AddRefs(presContext));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -126,7 +128,11 @@ nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
// The base editor owns most state info
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
|
||||
// Always get the enabled state
|
||||
bool outCmdEnabled = false;
|
||||
|
@ -136,7 +142,7 @@ nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
// get pres context
|
||||
RefPtr<nsPresContext> presContext;
|
||||
rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
|
||||
rv = GetPresContextFromEditor(textEditor, getter_AddRefs(presContext));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -198,7 +204,11 @@ nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
|
|||
nsISupports *refCon)
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
|
@ -211,10 +221,10 @@ nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (modified) {
|
||||
return editor->IncrementModificationCount(1);
|
||||
return textEditor->IncrementModificationCount(1);
|
||||
}
|
||||
|
||||
return editor->ResetModificationCount();
|
||||
return textEditor->ResetModificationCount();
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
|
||||
|
@ -224,50 +234,53 @@ nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
|
|||
NS_ENSURE_SUCCESS(rvRO, rvRO);
|
||||
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
textEditor->GetFlags(&flags);
|
||||
if (isReadOnly) {
|
||||
flags |= nsIPlaintextEditor::eEditorReadonlyMask;
|
||||
} else {
|
||||
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
|
||||
}
|
||||
|
||||
return editor->SetFlags(flags);
|
||||
return textEditor->SetFlags(flags);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool desireCSS;
|
||||
nsresult rvCSS = aParams->GetBooleanValue(STATE_ATTRIBUTE, &desireCSS);
|
||||
NS_ENSURE_SUCCESS(rvCSS, rvCSS);
|
||||
|
||||
return htmleditor->SetIsCSSEnabled(desireCSS);
|
||||
return htmlEditor->SetIsCSSEnabled(desireCSS);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool insertBrOnReturn;
|
||||
nsresult rvBR = aParams->GetBooleanValue(STATE_ATTRIBUTE,
|
||||
&insertBrOnReturn);
|
||||
NS_ENSURE_SUCCESS(rvBR, rvBR);
|
||||
|
||||
return htmleditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
|
||||
return htmlEditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_defaultParagraphSeparator")) {
|
||||
if (NS_WARN_IF(!aParams)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
auto htmlEditor = static_cast<HTMLEditor*>(editor.get());
|
||||
|
||||
nsXPIDLCString newValue;
|
||||
nsresult rv = aParams->GetCStringValue(STATE_ATTRIBUTE,
|
||||
|
@ -297,26 +310,30 @@ nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
|
|||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
|
||||
NS_ENSURE_SUCCESS(rvOR, rvOR);
|
||||
|
||||
return resizer->SetObjectResizingEnabled(enabled);
|
||||
return htmlEditor->SetObjectResizingEnabled(enabled);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
|
||||
NS_ENSURE_SUCCESS(rvOR, rvOR);
|
||||
|
||||
return editor->SetInlineTableEditingEnabled(enabled);
|
||||
return htmlEditor->SetInlineTableEditingEnabled(enabled);
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
@ -332,7 +349,11 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
// The base editor owns most state info
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
|
||||
// Always get the enabled state
|
||||
bool outCmdEnabled = false;
|
||||
|
@ -342,7 +363,7 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) {
|
||||
bool modified;
|
||||
rv = editor->GetDocumentModified(&modified);
|
||||
rv = textEditor->GetDocumentModified(&modified);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, modified);
|
||||
|
@ -350,30 +371,30 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
bool isReadOnly = flags & nsIPlaintextEditor::eEditorReadonlyMask;
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, isReadOnly);
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, textEditor->IsReadonly());
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool isCSS;
|
||||
htmleditor->GetIsCSSEnabled(&isCSS);
|
||||
htmlEditor->GetIsCSSEnabled(&isCSS);
|
||||
return aParams->SetBooleanValue(STATE_ALL, isCSS);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool createPOnReturn;
|
||||
htmleditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn);
|
||||
htmlEditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn);
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, !createPOnReturn);
|
||||
}
|
||||
|
||||
|
@ -381,11 +402,10 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
if (NS_WARN_IF(!aParams)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
|
||||
if (NS_WARN_IF(!editor)) {
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
auto htmlEditor = static_cast<HTMLEditor*>(editor.get());
|
||||
|
||||
switch (htmlEditor->GetDefaultParagraphSeparator()) {
|
||||
case ParagraphSeparator::div:
|
||||
|
@ -408,21 +428,25 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
resizer->GetObjectResizingEnabled(&enabled);
|
||||
htmlEditor->GetObjectResizingEnabled(&enabled);
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
|
||||
NS_ENSURE_ARG_POINTER(aParams);
|
||||
nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
|
||||
NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
|
||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
||||
if (NS_WARN_IF(!htmlEditor)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
editor->GetInlineTableEditingEnabled(&enabled);
|
||||
htmlEditor->GetInlineTableEditingEnabled(&enabled);
|
||||
return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
|
||||
}
|
||||
|
||||
|
@ -532,10 +556,10 @@ nsDocumentStateCommand::GetCommandStateParams(const char *aCommandName,
|
|||
if (!editor) {
|
||||
return NS_OK;
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
editor->GetDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
nsCOMPtr<nsIDocument> doc = textEditor->GetDocument();
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
||||
|
||||
nsIURI *uri = doc->GetDocumentURI();
|
||||
|
|
Загрузка…
Ссылка в новой задаче