зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1546578 - part 5: Make EditorCommand implement nsIControllerCommand::IsCommandEnabled() and call internal IsCommandEnabled() method which return bool directly r=m_kato
This patch makes `EditorCommand` implement `nsIControllerCommand::IsCommandEnabled()` and then, makes it call internal `IsCommandEnabled()` method which returns `bool` directly and takes `TextEditor` instead. This makes each implementation really simpler. Differential Revision: https://phabricator.services.mozilla.com/D28687 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
dc5aeff4d8
Коммит
2c962c8575
|
@ -37,32 +37,31 @@ namespace mozilla {
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(EditorCommand, nsIControllerCommand)
|
NS_IMPL_ISUPPORTS(EditorCommand, nsIControllerCommand)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
EditorCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
|
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
||||||
|
if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aIsEnabled)) {
|
||||||
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
||||||
|
TextEditor* textEditor = editor ? editor->AsTextEditor() : nullptr;
|
||||||
|
*aIsEnabled = IsCommandEnabled(aCommandName, textEditor);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* mozilla::UndoCommand
|
* mozilla::UndoCommand
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
StaticRefPtr<UndoCommand> UndoCommand::sInstance;
|
StaticRefPtr<UndoCommand> UndoCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool UndoCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
UndoCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable() && aTextEditor->CanUndo();
|
||||||
*aIsEnabled = false;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanUndo();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -99,26 +98,12 @@ UndoCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<RedoCommand> RedoCommand::sInstance;
|
StaticRefPtr<RedoCommand> RedoCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool RedoCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
RedoCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable() && aTextEditor->CanRedo();
|
||||||
*aIsEnabled = false;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanRedo();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -155,26 +140,12 @@ RedoCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<CutCommand> CutCommand::sInstance;
|
StaticRefPtr<CutCommand> CutCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool CutCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
CutCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable() && aTextEditor->CanCut();
|
||||||
*aIsEnabled = false;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanCut();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -209,22 +180,12 @@ CutCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<CutOrDeleteCommand> CutOrDeleteCommand::sInstance;
|
StaticRefPtr<CutOrDeleteCommand> CutOrDeleteCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool CutOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
CutOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->IsSelectionEditable();
|
||||||
if (!editor) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -270,21 +231,12 @@ CutOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<CopyCommand> CopyCommand::sInstance;
|
StaticRefPtr<CopyCommand> CopyCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool CopyCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
CopyCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->CanCopy();
|
||||||
if (!editor) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->CanCopy();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -320,23 +272,12 @@ CopyCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<CopyOrDeleteCommand> CopyOrDeleteCommand::sInstance;
|
StaticRefPtr<CopyOrDeleteCommand> CopyOrDeleteCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool CopyOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
CopyOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable();
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -382,26 +323,13 @@ CopyOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<PasteCommand> PasteCommand::sInstance;
|
StaticRefPtr<PasteCommand> PasteCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool PasteCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
PasteCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable() &&
|
||||||
*aIsEnabled = false;
|
aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -439,27 +367,13 @@ PasteCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<PasteTransferableCommand> PasteTransferableCommand::sInstance;
|
StaticRefPtr<PasteTransferableCommand> PasteTransferableCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool PasteTransferableCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
PasteTransferableCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return aTextEditor->IsSelectionEditable() &&
|
||||||
*aIsEnabled = false;
|
aTextEditor->CanPasteTransferable(nullptr);
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanPasteTransferable(nullptr);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -533,22 +447,12 @@ PasteTransferableCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<SwitchTextDirectionCommand> SwitchTextDirectionCommand::sInstance;
|
StaticRefPtr<SwitchTextDirectionCommand> SwitchTextDirectionCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool SwitchTextDirectionCommand::IsCommandEnabled(
|
||||||
SwitchTextDirectionCommand::IsCommandEnabled(const char* aCommandName,
|
const char* aCommandName, TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->IsSelectionEditable();
|
||||||
if (!editor) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -587,32 +491,20 @@ SwitchTextDirectionCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<DeleteCommand> DeleteCommand::sInstance;
|
StaticRefPtr<DeleteCommand> DeleteCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool DeleteCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
DeleteCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) {
|
if (!aTextEditor) {
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
return false;
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*aIsEnabled = false;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
|
|
||||||
// We can generally delete whenever the selection is editable. However,
|
// We can generally delete whenever the selection is editable. However,
|
||||||
// cmd_delete doesn't make sense if the selection is collapsed because it's
|
// cmd_delete doesn't make sense if the selection is collapsed because it's
|
||||||
// directionless, which is the same condition under which we can't cut.
|
// directionless, which is the same condition under which we can't cut.
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
bool isEnabled = aTextEditor->IsSelectionEditable();
|
||||||
|
|
||||||
if (!nsCRT::strcmp("cmd_delete", aCommandName) && *aIsEnabled) {
|
if (!nsCRT::strcmp("cmd_delete", aCommandName) && isEnabled) {
|
||||||
*aIsEnabled = textEditor->CanDelete();
|
return aTextEditor->CanDelete();
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -678,32 +570,20 @@ DeleteCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<SelectAllCommand> SelectAllCommand::sInstance;
|
StaticRefPtr<SelectAllCommand> SelectAllCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool SelectAllCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
SelectAllCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
|
||||||
bool* aIsEnabled) {
|
|
||||||
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
// You can always select all, unless the selection is editable,
|
// You can always select all, unless the selection is editable,
|
||||||
// and the editable region is empty!
|
// and the editable region is empty!
|
||||||
*aIsEnabled = true;
|
if (!aTextEditor) {
|
||||||
|
return true;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can select all if there is an editor which is non-empty
|
// You can select all if there is an editor which is non-empty
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
bool isEmpty = false;
|
bool isEmpty = false;
|
||||||
rv = textEditor->IsEmpty(&isEmpty);
|
if (NS_WARN_IF(NS_FAILED(aTextEditor->IsEmpty(&isEmpty)))) {
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
return false;
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
*aIsEnabled = !isEmpty;
|
return !isEmpty;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -740,20 +620,12 @@ SelectAllCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<SelectionMoveCommands> SelectionMoveCommands::sInstance;
|
StaticRefPtr<SelectionMoveCommands> SelectionMoveCommands::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool SelectionMoveCommands::IsCommandEnabled(const char* aCommandName,
|
||||||
SelectionMoveCommands::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
return aTextEditor->IsSelectionEditable();
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct ScrollCommand {
|
static const struct ScrollCommand {
|
||||||
|
@ -886,22 +758,12 @@ SelectionMoveCommands::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<InsertPlaintextCommand> InsertPlaintextCommand::sInstance;
|
StaticRefPtr<InsertPlaintextCommand> InsertPlaintextCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool InsertPlaintextCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
InsertPlaintextCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->IsSelectionEditable();
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -977,23 +839,12 @@ InsertPlaintextCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<InsertParagraphCommand> InsertParagraphCommand::sInstance;
|
StaticRefPtr<InsertParagraphCommand> InsertParagraphCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool InsertParagraphCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
InsertParagraphCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->IsSelectionEditable();
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1037,23 +888,12 @@ InsertParagraphCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<InsertLineBreakCommand> InsertLineBreakCommand::sInstance;
|
StaticRefPtr<InsertLineBreakCommand> InsertLineBreakCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool InsertLineBreakCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
InsertLineBreakCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
return aTextEditor->IsSelectionEditable();
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
*aIsEnabled = false;
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
*aIsEnabled = textEditor->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1097,27 +937,13 @@ InsertLineBreakCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<PasteQuotationCommand> PasteQuotationCommand::sInstance;
|
StaticRefPtr<PasteQuotationCommand> PasteQuotationCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool PasteQuotationCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
PasteQuotationCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aCommandRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aIsEnabled) {
|
return false;
|
||||||
if (NS_WARN_IF(!aIsEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
}
|
||||||
|
return !aTextEditor->IsSingleLineEditor() &&
|
||||||
*aIsEnabled = false;
|
aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
|
||||||
MOZ_ASSERT(textEditor);
|
|
||||||
if (textEditor->IsSingleLineEditor()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*aIsEnabled = textEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -18,6 +18,7 @@ class nsICommandParams;
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
class HTMLEditor;
|
class HTMLEditor;
|
||||||
|
class TextEditor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a base class for commands registered with the editor controller.
|
* This is a base class for commands registered with the editor controller.
|
||||||
|
@ -29,6 +30,15 @@ class EditorCommand : public nsIControllerCommand {
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIControllerCommand methods. Use EditorCommand specific methods instead
|
||||||
|
// for internal use.
|
||||||
|
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
|
||||||
|
nsISupports* aCommandRefCon,
|
||||||
|
bool* aIsEnabled) final;
|
||||||
|
|
||||||
|
virtual bool IsCommandEnabled(const char* aCommandName,
|
||||||
|
TextEditor* aTextEditor) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EditorCommand() = default;
|
EditorCommand() = default;
|
||||||
virtual ~EditorCommand() = default;
|
virtual ~EditorCommand() = default;
|
||||||
|
@ -36,9 +46,9 @@ class EditorCommand : public nsIControllerCommand {
|
||||||
|
|
||||||
#define NS_DECL_EDITOR_COMMAND_METHODS(_cmd) \
|
#define NS_DECL_EDITOR_COMMAND_METHODS(_cmd) \
|
||||||
public: \
|
public: \
|
||||||
NS_IMETHOD IsCommandEnabled(const char* aCommandName, \
|
virtual bool IsCommandEnabled(const char* aCommandName, \
|
||||||
nsISupports* aCommandRefCon, bool* aIsEnabled) \
|
TextEditor* aTextEditor) const final; \
|
||||||
final; \
|
using EditorCommand::IsCommandEnabled; \
|
||||||
MOZ_CAN_RUN_SCRIPT \
|
MOZ_CAN_RUN_SCRIPT \
|
||||||
NS_IMETHOD DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) \
|
NS_IMETHOD DoCommand(const char* aCommandName, nsISupports* aCommandRefCon) \
|
||||||
final; \
|
final; \
|
||||||
|
|
|
@ -54,32 +54,19 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY // XXX Needs to change nsIControllerCommand.idl
|
||||||
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom>
|
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom>
|
||||||
StateUpdatingCommandBase::sTagNameTable;
|
StateUpdatingCommandBase::sTagNameTable;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool StateUpdatingCommandBase::IsCommandEnabled(const char* aCommandName,
|
||||||
StateUpdatingCommandBase::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
TextEditor* textEditor = editor->AsTextEditor();
|
if (!aTextEditor->IsSelectionEditable()) {
|
||||||
if (!textEditor) {
|
return false;
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
if (!textEditor->IsSelectionEditable()) {
|
if (!strcmp(aCommandName, "cmd_absPos")) {
|
||||||
*outCmdEnabled = false;
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
||||||
return NS_OK;
|
return htmlEditor && htmlEditor->IsAbsolutePositionEditorEnabled();
|
||||||
}
|
}
|
||||||
if (!nsCRT::strcmp(aCommandName, "cmd_absPos")) {
|
return true;
|
||||||
HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
|
|
||||||
*outCmdEnabled =
|
|
||||||
htmlEditor && htmlEditor->IsAbsolutePositionEditorEnabled();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
*outCmdEnabled = true;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -132,27 +119,20 @@ StateUpdatingCommandBase::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<PasteNoFormattingCommand> PasteNoFormattingCommand::sInstance;
|
StaticRefPtr<PasteNoFormattingCommand> PasteNoFormattingCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool PasteNoFormattingCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
PasteNoFormattingCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This command is only implemented by nsIHTMLEditor, since
|
// This command is only implemented by nsIHTMLEditor, since
|
||||||
// pasting in a plaintext editor automatically only supplies
|
// pasting in a plaintext editor automatically only supplies
|
||||||
// "unformatted" text
|
// "unformatted" text
|
||||||
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
||||||
if (NS_WARN_IF(!htmlEditor)) {
|
if (!htmlEditor) {
|
||||||
return NS_ERROR_FAILURE;
|
return false;
|
||||||
}
|
}
|
||||||
*outCmdEnabled = htmlEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
return htmlEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -419,35 +399,29 @@ nsresult ListItemCommand::ToggleState(nsAtom* aTagName,
|
||||||
|
|
||||||
StaticRefPtr<RemoveListCommand> RemoveListCommand::sInstance;
|
StaticRefPtr<RemoveListCommand> RemoveListCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool RemoveListCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
RemoveListCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon, bool* outCmdEnabled) {
|
if (!aTextEditor) {
|
||||||
*outCmdEnabled = false;
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
if (!aTextEditor->IsSelectionEditable()) {
|
||||||
MOZ_ASSERT(editorBase);
|
return false;
|
||||||
|
|
||||||
if (!editorBase->IsSelectionEditable()) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is enabled if we are in any list type
|
// It is enabled if we are in any list type
|
||||||
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
||||||
if (NS_WARN_IF(!htmlEditor)) {
|
if (NS_WARN_IF(!htmlEditor)) {
|
||||||
return NS_ERROR_FAILURE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bMixed;
|
bool bMixed;
|
||||||
nsAutoString localName;
|
nsAutoString localName;
|
||||||
nsresult rv = GetListState(MOZ_KnownLive(htmlEditor), &bMixed, localName);
|
nsresult rv = GetListState(MOZ_KnownLive(htmlEditor), &bMixed, localName);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return false;
|
||||||
*outCmdEnabled = bMixed || !localName.IsEmpty();
|
}
|
||||||
return NS_OK;
|
return bMixed || !localName.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -486,18 +460,12 @@ RemoveListCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<IndentCommand> IndentCommand::sInstance;
|
StaticRefPtr<IndentCommand> IndentCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool IndentCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
IndentCommand::IsCommandEnabled(const char* aCommandName, nsISupports* refCon,
|
TextEditor* aTextEditor) const {
|
||||||
bool* outCmdEnabled) {
|
if (!aTextEditor) {
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
return false;
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
return aTextEditor->IsSelectionEditable();
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -538,18 +506,12 @@ IndentCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<OutdentCommand> OutdentCommand::sInstance;
|
StaticRefPtr<OutdentCommand> OutdentCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool OutdentCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
OutdentCommand::IsCommandEnabled(const char* aCommandName, nsISupports* refCon,
|
TextEditor* aTextEditor) const {
|
||||||
bool* outCmdEnabled) {
|
if (!aTextEditor) {
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
return false;
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
return aTextEditor->IsSelectionEditable();
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -589,20 +551,13 @@ OutdentCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
* mozilla::MultiStateCommandBase
|
* mozilla::MultiStateCommandBase
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool MultiStateCommandBase::IsCommandEnabled(const char* aCommandName,
|
||||||
MultiStateCommandBase::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
// should be disabled sometimes, like if the current selection is an image
|
// should be disabled sometimes, like if the current selection is an image
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
return aTextEditor->IsSelectionEditable();
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1059,33 +1014,23 @@ nsresult AbsolutePositioningCommand::ToggleState(nsAtom* aTagName,
|
||||||
|
|
||||||
StaticRefPtr<DecreaseZIndexCommand> DecreaseZIndexCommand::sInstance;
|
StaticRefPtr<DecreaseZIndexCommand> DecreaseZIndexCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool DecreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
DecreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aOutCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aRefCon);
|
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
||||||
if (NS_WARN_IF(!htmlEditor)) {
|
if (!htmlEditor) {
|
||||||
return NS_ERROR_FAILURE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
||||||
*aOutCmdEnabled = false;
|
return false;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Element> positionedElement = htmlEditor->GetPositionedElement();
|
RefPtr<Element> positionedElement = htmlEditor->GetPositionedElement();
|
||||||
if (!positionedElement) {
|
if (!positionedElement) {
|
||||||
*aOutCmdEnabled = false;
|
return false;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
return htmlEditor->GetZIndex(*positionedElement) > 0;
|
||||||
int32_t z = htmlEditor->GetZIndex(*positionedElement);
|
|
||||||
*aOutCmdEnabled = (z > 0);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1128,26 +1073,19 @@ DecreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<IncreaseZIndexCommand> IncreaseZIndexCommand::sInstance;
|
StaticRefPtr<IncreaseZIndexCommand> IncreaseZIndexCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool IncreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
IncreaseZIndexCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* aRefCon,
|
if (!aTextEditor) {
|
||||||
bool* aOutCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aRefCon);
|
|
||||||
if (NS_WARN_IF(!editor)) {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
|
||||||
if (NS_WARN_IF(!htmlEditor)) {
|
if (!htmlEditor) {
|
||||||
return NS_ERROR_FAILURE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
if (!htmlEditor->IsAbsolutePositionEditorEnabled()) {
|
||||||
*aOutCmdEnabled = false;
|
return false;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
return !!htmlEditor->GetPositionedElement();
|
||||||
*aOutCmdEnabled = !!htmlEditor->GetPositionedElement();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1190,20 +1128,13 @@ IncreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<RemoveStylesCommand> RemoveStylesCommand::sInstance;
|
StaticRefPtr<RemoveStylesCommand> RemoveStylesCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool RemoveStylesCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
RemoveStylesCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
// test if we have any styles?
|
// test if we have any styles?
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
return aTextEditor->IsSelectionEditable();
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1241,20 +1172,13 @@ RemoveStylesCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<IncreaseFontSizeCommand> IncreaseFontSizeCommand::sInstance;
|
StaticRefPtr<IncreaseFontSizeCommand> IncreaseFontSizeCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool IncreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
IncreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
// test if we are at max size?
|
// test if we are at max size?
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
return aTextEditor->IsSelectionEditable();
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1293,20 +1217,13 @@ IncreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<DecreaseFontSizeCommand> DecreaseFontSizeCommand::sInstance;
|
StaticRefPtr<DecreaseFontSizeCommand> DecreaseFontSizeCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool DecreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
DecreaseFontSizeCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
if (!aTextEditor) {
|
||||||
bool* outCmdEnabled) {
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
// test if we are at min size?
|
// test if we are at min size?
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
return aTextEditor->IsSelectionEditable();
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1345,19 +1262,12 @@ DecreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<InsertHTMLCommand> InsertHTMLCommand::sInstance;
|
StaticRefPtr<InsertHTMLCommand> InsertHTMLCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool InsertHTMLCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
InsertHTMLCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon, bool* outCmdEnabled) {
|
if (!aTextEditor) {
|
||||||
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
return aTextEditor->IsSelectionEditable();
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1423,19 +1333,12 @@ InsertHTMLCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
StaticRefPtr<InsertTagCommand> InsertTagCommand::sInstance;
|
StaticRefPtr<InsertTagCommand> InsertTagCommand::sInstance;
|
||||||
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> InsertTagCommand::sTagNameTable;
|
nsRefPtrHashtable<nsCharPtrHashKey, nsAtom> InsertTagCommand::sTagNameTable;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool InsertTagCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
InsertTagCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon, bool* outCmdEnabled) {
|
if (!aTextEditor) {
|
||||||
NS_ENSURE_ARG_POINTER(outCmdEnabled);
|
return false;
|
||||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
|
|
||||||
if (!editor) {
|
|
||||||
*outCmdEnabled = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
mozilla::EditorBase* editorBase = editor->AsEditorBase();
|
return aTextEditor->IsSelectionEditable();
|
||||||
MOZ_ASSERT(editorBase);
|
|
||||||
*outCmdEnabled = editorBase->IsSelectionEditable();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// corresponding STATE_ATTRIBUTE is: src (img) and href (a)
|
// corresponding STATE_ATTRIBUTE is: src (img) and href (a)
|
||||||
|
|
|
@ -46,17 +46,10 @@ namespace mozilla {
|
||||||
|
|
||||||
StaticRefPtr<SetDocumentStateCommand> SetDocumentStateCommand::sInstance;
|
StaticRefPtr<SetDocumentStateCommand> SetDocumentStateCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool SetDocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
SetDocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
|
||||||
bool* outCmdEnabled) {
|
|
||||||
if (NS_WARN_IF(!outCmdEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
// These commands are always enabled
|
// These commands are always enabled
|
||||||
*outCmdEnabled = true;
|
return true;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -448,17 +441,10 @@ SetDocumentStateCommand::GetCommandStateParams(const char* aCommandName,
|
||||||
|
|
||||||
StaticRefPtr<DocumentStateCommand> DocumentStateCommand::sInstance;
|
StaticRefPtr<DocumentStateCommand> DocumentStateCommand::sInstance;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
bool DocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
||||||
DocumentStateCommand::IsCommandEnabled(const char* aCommandName,
|
TextEditor* aTextEditor) const {
|
||||||
nsISupports* refCon,
|
|
||||||
bool* outCmdEnabled) {
|
|
||||||
if (NS_WARN_IF(!outCmdEnabled)) {
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always return false to discourage callers from using DoCommand()
|
// Always return false to discourage callers from using DoCommand()
|
||||||
*outCmdEnabled = false;
|
return false;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
Загрузка…
Ссылка в новой задаче