2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
#include "EditorCommands.h"
|
2014-12-02 08:07:42 +03:00
|
|
|
|
2014-11-22 18:33:36 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2017-01-05 09:54:02 +03:00
|
|
|
#include "mozilla/FlushType.h"
|
2020-04-27 06:36:57 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2019-05-21 10:44:39 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/MozPromise.h" // for mozilla::detail::Any
|
2016-08-21 16:33:07 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2019-04-27 10:35:56 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2017-08-04 14:41:20 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2018-07-10 14:04:21 +03:00
|
|
|
#include "nsCommandParams.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIClipboard.h"
|
2019-04-27 10:35:56 +03:00
|
|
|
#include "nsIEditingSession.h"
|
2019-06-10 13:27:07 +03:00
|
|
|
#include "nsIPrincipal.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
#include "nsISelectionController.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsAString.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsISupports;
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
#define STATE_ENABLED "state_enabled"
|
2019-05-21 10:44:39 +03:00
|
|
|
#define STATE_ATTRIBUTE "state_attribute"
|
2002-11-13 02:30:29 +03:00
|
|
|
#define STATE_DATA "state_data"
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
namespace mozilla {
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2019-05-24 07:48:46 +03:00
|
|
|
using detail::Any;
|
2019-05-21 10:44:39 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
2019-04-26 06:20:02 +03:00
|
|
|
* mozilla::EditorCommand
|
2016-06-24 05:45:22 +03:00
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_IMPL_ISUPPORTS(EditorCommand, nsIControllerCommand)
|
2016-06-24 05:45:22 +03:00
|
|
|
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_IMETHODIMP EditorCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled) {
|
2019-04-26 16:11:24 +03:00
|
|
|
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;
|
2019-04-30 07:24:49 +03:00
|
|
|
*aIsEnabled = IsCommandEnabled(GetInternalCommand(aCommandName),
|
|
|
|
MOZ_KnownLive(textEditor));
|
2019-04-26 16:11:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_IMETHODIMP EditorCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon) {
|
2019-04-26 17:00:47 +03:00
|
|
|
if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aCommandRefCon)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult rv = DoCommand(GetInternalCommand(aCommandName),
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-04-26 17:00:47 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommand()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_IMETHODIMP EditorCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon) {
|
2019-04-26 18:32:06 +03:00
|
|
|
if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aCommandRefCon)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2019-05-21 10:44:39 +03:00
|
|
|
nsCommandParams* params = aParams ? aParams->AsCommandParams() : nullptr;
|
2019-05-21 10:47:51 +03:00
|
|
|
Command command = GetInternalCommand(aCommandName, params);
|
2019-05-21 10:44:11 +03:00
|
|
|
EditorCommandParamType paramType = EditorCommand::GetParamType(command);
|
|
|
|
if (paramType == EditorCommandParamType::None) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = DoCommandParam(
|
|
|
|
command, MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:44:39 +03:00
|
|
|
if (Any(paramType & EditorCommandParamType::Bool)) {
|
|
|
|
if (Any(paramType & EditorCommandParamType::StateAttribute)) {
|
|
|
|
Maybe<bool> boolParam = Nothing();
|
|
|
|
if (params) {
|
|
|
|
ErrorResult error;
|
|
|
|
boolParam = Some(params->GetBool(STATE_ATTRIBUTE, error));
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = DoCommandParam(
|
|
|
|
command, boolParam, MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:44:39 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected state for bool");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:47 +03:00
|
|
|
// Special case for MultiStateCommandBase. It allows both CString and String
|
|
|
|
// in STATE_ATTRIBUTE and CString is preferred.
|
|
|
|
if (Any(paramType & EditorCommandParamType::CString) &&
|
|
|
|
Any(paramType & EditorCommandParamType::String)) {
|
|
|
|
if (!params) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
DoCommandParam(command, VoidString(),
|
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from "
|
|
|
|
"nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (Any(paramType & EditorCommandParamType::StateAttribute)) {
|
|
|
|
nsCString cStringParam;
|
|
|
|
nsresult rv = params->GetCString(STATE_ATTRIBUTE, cStringParam);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_ConvertUTF8toUTF16 stringParam(cStringParam);
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
DoCommandParam(command, stringParam,
|
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from "
|
|
|
|
"nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsString stringParam;
|
|
|
|
DebugOnly<nsresult> rvIgnored =
|
|
|
|
params->GetString(STATE_ATTRIBUTE, stringParam);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
|
|
|
"Failed to get string from STATE_ATTRIBUTE");
|
|
|
|
rv = DoCommandParam(command, stringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from "
|
|
|
|
"nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected state for CString/String");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:22 +03:00
|
|
|
if (Any(paramType & EditorCommandParamType::CString)) {
|
|
|
|
if (!params) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
DoCommandParam(command, VoidCString(),
|
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:45:22 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (Any(paramType & EditorCommandParamType::StateAttribute)) {
|
|
|
|
nsCString cStringParam;
|
|
|
|
nsresult rv = params->GetCString(STATE_ATTRIBUTE, cStringParam);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = DoCommandParam(command, cStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:45:22 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected state for CString");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
if (Any(paramType & EditorCommandParamType::String)) {
|
|
|
|
if (!params) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
DoCommandParam(command, VoidString(),
|
|
|
|
MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsString stringParam;
|
|
|
|
if (Any(paramType & EditorCommandParamType::StateAttribute)) {
|
|
|
|
nsresult rv = params->GetString(STATE_ATTRIBUTE, stringParam);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else if (Any(paramType & EditorCommandParamType::StateData)) {
|
|
|
|
nsresult rv = params->GetString(STATE_DATA, stringParam);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected state for String");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = DoCommandParam(
|
|
|
|
command, stringParam, MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:49 +03:00
|
|
|
if (Any(paramType & EditorCommandParamType::Transferable)) {
|
|
|
|
nsCOMPtr<nsITransferable> transferable;
|
|
|
|
if (params) {
|
|
|
|
nsCOMPtr<nsISupports> supports = params->GetISupports("transferable");
|
|
|
|
transferable = do_QueryInterface(supports);
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = DoCommandParam(
|
|
|
|
command, transferable, MOZ_KnownLive(*editor->AsTextEditor()), nullptr);
|
2019-05-21 10:47:49 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"Failed to do command from nsIControllerCommand::DoCommandParams()");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected param type");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2019-04-26 18:32:06 +03:00
|
|
|
}
|
|
|
|
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_IMETHODIMP EditorCommand::GetCommandStateParams(
|
|
|
|
const char* aCommandName, nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon) {
|
2019-04-27 10:35:56 +03:00
|
|
|
if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor) {
|
2019-04-30 07:24:49 +03:00
|
|
|
return GetCommandStateParams(GetInternalCommand(aCommandName),
|
|
|
|
MOZ_KnownLive(*aParams->AsCommandParams()),
|
|
|
|
MOZ_KnownLive(editor->AsTextEditor()),
|
|
|
|
nullptr);
|
2019-04-27 10:35:56 +03:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditingSession> editingSession =
|
|
|
|
do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editingSession) {
|
2019-04-30 07:24:49 +03:00
|
|
|
return GetCommandStateParams(GetInternalCommand(aCommandName),
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_KnownLive(*aParams->AsCommandParams()),
|
2019-04-27 10:35:56 +03:00
|
|
|
nullptr, editingSession);
|
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
return GetCommandStateParams(GetInternalCommand(aCommandName),
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_KnownLive(*aParams->AsCommandParams()),
|
2019-04-27 10:35:56 +03:00
|
|
|
nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::UndoCommand
|
|
|
|
******************************************************************************/
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<UndoCommand> UndoCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool UndoCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable() && aTextEditor->CanUndo();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult UndoCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
nsresult rv = aTextEditor.UndoAsAction(1, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::UndoAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult UndoCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::RedoCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<RedoCommand> RedoCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool RedoCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable() && aTextEditor->CanRedo();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult RedoCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
nsresult rv = aTextEditor.RedoAsAction(1, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::RedoAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult RedoCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CutCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<CutCommand> CutCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool CutCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-07-29 09:21:42 +03:00
|
|
|
return aTextEditor->IsSelectionEditable() &&
|
|
|
|
aTextEditor->IsCutCommandEnabled();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult CutCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
nsresult rv = aTextEditor.CutAsAction(aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::CutAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult CutCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CutOrDeleteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<CutOrDeleteCommand> CutOrDeleteCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool CutOrDeleteCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult CutOrDeleteCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
dom::Selection* selection = aTextEditor.GetSelection();
|
2018-05-08 20:52:39 +03:00
|
|
|
if (selection && selection->IsCollapsed()) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aTextEditor.DeleteSelectionAsAction(
|
|
|
|
nsIEditor::eNext, nsIEditor::eStrip, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2020-04-24 17:55:09 +03:00
|
|
|
"EditorBase::DeleteSelectionAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aTextEditor.CutAsAction(aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::CutAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult CutOrDeleteCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2001-02-16 00:51:25 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CopyCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<CopyCommand> CopyCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool CopyCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-07-29 09:21:42 +03:00
|
|
|
return aTextEditor->IsCopyCommandEnabled();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult CopyCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
// Shouldn't cause "beforeinput" event so that we don't need to specify
|
|
|
|
// the given principal.
|
2019-04-26 17:00:47 +03:00
|
|
|
return aTextEditor.Copy();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult CopyCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CopyOrDeleteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<CopyOrDeleteCommand> CopyOrDeleteCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool CopyOrDeleteCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult CopyOrDeleteCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
dom::Selection* selection = aTextEditor.GetSelection();
|
2018-05-08 20:52:39 +03:00
|
|
|
if (selection && selection->IsCollapsed()) {
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aTextEditor.DeleteSelectionAsAction(
|
|
|
|
nsIEditor::eNextWord, nsIEditor::eStrip, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2020-04-24 17:55:09 +03:00
|
|
|
"EditorBase::DeleteSelectionAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
// Shouldn't cause "beforeinput" event so that we don't need to specify
|
|
|
|
// the given principal.
|
|
|
|
nsresult rv = aTextEditor.Copy();
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::Copy() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult CopyOrDeleteCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
2001-02-16 00:51:25 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<PasteCommand> PasteCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool PasteCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable() &&
|
|
|
|
aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult PasteCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
nsresult rv = aTextEditor.PasteAsAction(nsIClipboard::kGlobalClipboard, true,
|
|
|
|
aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::PasteAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult PasteCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteTransferableCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<PasteTransferableCommand> PasteTransferableCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool PasteTransferableCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable() &&
|
|
|
|
aTextEditor->CanPasteTransferable(nullptr);
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult PasteTransferableCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2010-01-11 04:45:45 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:49 +03:00
|
|
|
nsresult PasteTransferableCommand::DoCommandParam(
|
|
|
|
Command aCommand, nsITransferable* aTransferableParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor, nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:47:49 +03:00
|
|
|
if (NS_WARN_IF(!aTransferableParam)) {
|
2019-04-26 18:32:06 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv =
|
|
|
|
aTextEditor.PasteTransferableAsAction(aTransferableParam, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"TextEditor::PasteTransferableAsAction() failed");
|
2019-05-21 10:47:49 +03:00
|
|
|
return rv;
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult PasteTransferableCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
if (NS_WARN_IF(!aTextEditor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2010-01-11 04:45:45 +03:00
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsCOMPtr<nsISupports> supports = aParams.GetISupports("transferable");
|
2017-08-04 14:41:20 +03:00
|
|
|
if (NS_WARN_IF(!supports)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
trans = do_QueryInterface(supports);
|
|
|
|
if (NS_WARN_IF(!trans)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
|
|
|
aTextEditor->CanPasteTransferable(trans));
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SwitchTextDirectionCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<SwitchTextDirectionCommand> SwitchTextDirectionCommand::sInstance;
|
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
bool SwitchTextDirectionCommand::IsCommandEnabled(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, TextEditor* aTextEditor) const {
|
2019-04-26 16:11:24 +03:00
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2005-01-26 04:40:30 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult SwitchTextDirectionCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
nsresult rv = aTextEditor.ToggleTextDirectionAsAction(aPrincipal);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2020-03-10 07:34:15 +03:00
|
|
|
"EditorBase::ToggleTextDirectionAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2005-01-26 04:40:30 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult SwitchTextDirectionCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2005-01-26 04:40:30 +03:00
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::DeleteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<DeleteCommand> DeleteCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool DeleteCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2016-06-08 01:00:49 +03:00
|
|
|
}
|
2012-06-21 16:05:24 +04:00
|
|
|
// We can generally delete whenever the selection is editable. However,
|
|
|
|
// cmd_delete doesn't make sense if the selection is collapsed because it's
|
2019-07-29 09:21:14 +03:00
|
|
|
// directionless.
|
2019-04-26 16:11:24 +03:00
|
|
|
bool isEnabled = aTextEditor->IsSelectionEditable();
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
if (aCommand == Command::Delete && isEnabled) {
|
2019-07-29 09:21:14 +03:00
|
|
|
return aTextEditor->CanDeleteSelection();
|
2012-06-21 16:05:24 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return isEnabled;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult DeleteCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2000-02-16 04:33:03 +03:00
|
|
|
nsIEditor::EDirection deleteDir = nsIEditor::eNone;
|
2019-04-30 07:24:49 +03:00
|
|
|
switch (aCommand) {
|
|
|
|
case Command::Delete:
|
|
|
|
// Really this should probably be eNone, but it only makes a difference
|
|
|
|
// if the selection is collapsed, and then this command is disabled. So
|
|
|
|
// let's keep it as it always was to avoid breaking things.
|
|
|
|
deleteDir = nsIEditor::ePrevious;
|
|
|
|
break;
|
|
|
|
case Command::DeleteCharForward:
|
|
|
|
deleteDir = nsIEditor::eNext;
|
|
|
|
break;
|
|
|
|
case Command::DeleteCharBackward:
|
|
|
|
deleteDir = nsIEditor::ePrevious;
|
|
|
|
break;
|
|
|
|
case Command::DeleteWordBackward:
|
|
|
|
deleteDir = nsIEditor::ePreviousWord;
|
|
|
|
break;
|
|
|
|
case Command::DeleteWordForward:
|
|
|
|
deleteDir = nsIEditor::eNextWord;
|
|
|
|
break;
|
|
|
|
case Command::DeleteToBeginningOfLine:
|
|
|
|
deleteDir = nsIEditor::eToBeginningOfLine;
|
|
|
|
break;
|
|
|
|
case Command::DeleteToEndOfLine:
|
|
|
|
deleteDir = nsIEditor::eToEndOfLine;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unrecognized nsDeleteCommand");
|
2012-06-21 16:05:24 +04:00
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = aTextEditor.DeleteSelectionAsAction(
|
|
|
|
deleteDir, nsIEditor::eStrip, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2020-04-24 17:55:09 +03:00
|
|
|
"EditorBase::DeleteSelectionAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult DeleteCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SelectAllCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<SelectAllCommand> SelectAllCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool SelectAllCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
2010-11-16 23:45:49 +03:00
|
|
|
// You can always select all, unless the selection is editable,
|
|
|
|
// and the editable region is empty!
|
2019-04-26 16:11:24 +03:00
|
|
|
if (!aTextEditor) {
|
|
|
|
return true;
|
2010-11-16 23:45:49 +03:00
|
|
|
}
|
2011-09-24 01:44:53 +04:00
|
|
|
|
2017-08-04 14:41:20 +03:00
|
|
|
// You can select all if there is an editor which is non-empty
|
2019-09-17 09:58:06 +03:00
|
|
|
return !aTextEditor->IsEmpty();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SelectAllCommand::DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
|
|
|
// Shouldn't cause "beforeinput" event so that we don't need to specify
|
|
|
|
// aPrincipal.
|
2020-03-10 07:34:15 +03:00
|
|
|
nsresult rv = aTextEditor.SelectAll();
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SelectAll() failed");
|
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult SelectAllCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SelectionMoveCommands
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<SelectionMoveCommands> SelectionMoveCommands::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool SelectionMoveCommands::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
static const struct ScrollCommand {
|
2019-04-30 07:24:49 +03:00
|
|
|
Command mReverseScroll;
|
|
|
|
Command mForwardScroll;
|
2014-11-22 17:39:04 +03:00
|
|
|
nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
|
2019-04-30 07:24:49 +03:00
|
|
|
} scrollCommands[] = {{Command::ScrollTop, Command::ScrollBottom,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::CompleteScroll},
|
2019-04-30 07:24:49 +03:00
|
|
|
{Command::ScrollPageUp, Command::ScrollPageDown,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollPage},
|
2019-04-30 07:24:49 +03:00
|
|
|
{Command::ScrollLineUp, Command::ScrollLineDown,
|
2014-11-22 17:39:04 +03:00
|
|
|
&nsISelectionController::ScrollLine}};
|
|
|
|
|
|
|
|
static const struct MoveCommand {
|
2019-04-30 07:24:49 +03:00
|
|
|
Command mReverseMove;
|
|
|
|
Command mForwardMove;
|
|
|
|
Command mReverseSelect;
|
|
|
|
Command mForwardSelect;
|
2014-11-22 17:39:04 +03:00
|
|
|
nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool);
|
|
|
|
} moveCommands[] = {
|
2019-04-30 07:24:49 +03:00
|
|
|
{Command::CharPrevious, Command::CharNext, Command::SelectCharPrevious,
|
|
|
|
Command::SelectCharNext, &nsISelectionController::CharacterMove},
|
|
|
|
{Command::LinePrevious, Command::LineNext, Command::SelectLinePrevious,
|
|
|
|
Command::SelectLineNext, &nsISelectionController::LineMove},
|
|
|
|
{Command::WordPrevious, Command::WordNext, Command::SelectWordPrevious,
|
|
|
|
Command::SelectWordNext, &nsISelectionController::WordMove},
|
|
|
|
{Command::BeginLine, Command::EndLine, Command::SelectBeginLine,
|
|
|
|
Command::SelectEndLine, &nsISelectionController::IntraLineMove},
|
|
|
|
{Command::MovePageUp, Command::MovePageDown, Command::SelectPageUp,
|
|
|
|
Command::SelectPageDown, &nsISelectionController::PageMove},
|
|
|
|
{Command::MoveTop, Command::MoveBottom, Command::SelectTop,
|
|
|
|
Command::SelectBottom, &nsISelectionController::CompleteMove}};
|
2014-11-22 17:39:04 +03:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
static const struct PhysicalCommand {
|
2019-04-30 07:24:49 +03:00
|
|
|
Command mMove;
|
|
|
|
Command mSelect;
|
2014-11-22 17:39:04 +03:00
|
|
|
int16_t direction;
|
|
|
|
int16_t amount;
|
|
|
|
} physicalCommands[] = {
|
2019-04-30 07:24:49 +03:00
|
|
|
{Command::MoveLeft, Command::SelectLeft, nsISelectionController::MOVE_LEFT,
|
|
|
|
0},
|
|
|
|
{Command::MoveRight, Command::SelectRight,
|
|
|
|
nsISelectionController::MOVE_RIGHT, 0},
|
|
|
|
{Command::MoveUp, Command::SelectUp, nsISelectionController::MOVE_UP, 0},
|
|
|
|
{Command::MoveDown, Command::SelectDown, nsISelectionController::MOVE_DOWN,
|
|
|
|
0},
|
|
|
|
{Command::MoveLeft2, Command::SelectLeft2,
|
|
|
|
nsISelectionController::MOVE_LEFT, 1},
|
|
|
|
{Command::MoveRight2, Command::SelectRight2,
|
|
|
|
nsISelectionController::MOVE_RIGHT, 1},
|
|
|
|
{Command::MoveUp2, Command::SelectUp2, nsISelectionController::MOVE_UP, 1},
|
|
|
|
{Command::MoveDown2, Command::SelectDown2,
|
|
|
|
nsISelectionController::MOVE_DOWN, 1}};
|
|
|
|
|
|
|
|
nsresult SelectionMoveCommands::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2020-04-27 06:36:57 +03:00
|
|
|
RefPtr<dom::Document> document = aTextEditor.GetDocument();
|
2019-04-26 17:00:47 +03:00
|
|
|
if (document) {
|
2010-08-05 22:39:39 +04:00
|
|
|
// Most of the commands below (possibly all of them) need layout to
|
|
|
|
// be up to date.
|
2019-04-26 17:00:47 +03:00
|
|
|
document->FlushPendingNotifications(FlushType::Layout);
|
2010-08-05 22:39:39 +04:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:41:20 +03:00
|
|
|
nsCOMPtr<nsISelectionController> selectionController =
|
2019-04-26 17:00:47 +03:00
|
|
|
aTextEditor.GetSelectionController();
|
2017-08-04 14:41:20 +03:00
|
|
|
if (NS_WARN_IF(!selectionController)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// scroll commands
|
2019-04-26 17:00:47 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(scrollCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const ScrollCommand& cmd = scrollCommands[i];
|
2019-04-30 07:24:49 +03:00
|
|
|
if (aCommand == cmd.mReverseScroll) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.scroll))(false);
|
2019-04-30 07:24:49 +03:00
|
|
|
}
|
|
|
|
if (aCommand == cmd.mForwardScroll) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.scroll))(true);
|
2014-11-22 17:39:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// caret movement/selection commands
|
2019-04-26 17:00:47 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(moveCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const MoveCommand& cmd = moveCommands[i];
|
2019-04-30 07:24:49 +03:00
|
|
|
if (aCommand == cmd.mReverseMove) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.move))(false, false);
|
2019-04-30 07:24:49 +03:00
|
|
|
}
|
|
|
|
if (aCommand == cmd.mForwardMove) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.move))(true, false);
|
2019-04-30 07:24:49 +03:00
|
|
|
}
|
|
|
|
if (aCommand == cmd.mReverseSelect) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.move))(false, true);
|
2019-04-30 07:24:49 +03:00
|
|
|
}
|
|
|
|
if (aCommand == cmd.mForwardSelect) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return (selectionController->*(cmd.move))(true, true);
|
2014-11-22 17:39:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// physical-direction movement/selection
|
2019-04-26 17:00:47 +03:00
|
|
|
for (size_t i = 0; i < ArrayLength(physicalCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const PhysicalCommand& cmd = physicalCommands[i];
|
2019-04-30 07:24:49 +03:00
|
|
|
if (aCommand == cmd.mMove) {
|
2020-03-10 07:34:15 +03:00
|
|
|
nsresult rv =
|
|
|
|
selectionController->PhysicalMove(cmd.direction, cmd.amount, false);
|
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"nsISelectionController::PhysicalMove() failed to move caret");
|
|
|
|
return rv;
|
2019-04-30 07:24:49 +03:00
|
|
|
}
|
|
|
|
if (aCommand == cmd.mSelect) {
|
2020-03-10 07:34:15 +03:00
|
|
|
nsresult rv =
|
|
|
|
selectionController->PhysicalMove(cmd.direction, cmd.amount, true);
|
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
NS_SUCCEEDED(rv),
|
|
|
|
"nsISelectionController::PhysicalMove() failed to select");
|
|
|
|
return rv;
|
2014-11-22 17:39:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult SelectionMoveCommands::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-02-02 17:30:00 +03:00
|
|
|
}
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InsertPlaintextCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<InsertPlaintextCommand> InsertPlaintextCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool InsertPlaintextCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2017-08-04 14:41:20 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult InsertPlaintextCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2018-04-16 17:43:36 +03:00
|
|
|
// XXX InsertTextAsAction() is not same as OnInputText(). However, other
|
|
|
|
// commands to insert line break or paragraph separator use OnInput*().
|
|
|
|
// According to the semantics of those methods, using *AsAction() is
|
|
|
|
// better, however, this may not cause two or more placeholder
|
|
|
|
// transactions to the top transaction since its name may not be
|
|
|
|
// nsGkAtoms::TypingTxnName.
|
2020-03-10 07:34:15 +03:00
|
|
|
DebugOnly<nsresult> rvIgnored =
|
2019-06-10 13:27:07 +03:00
|
|
|
aTextEditor.InsertTextAsAction(EmptyString(), aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
|
|
|
"EditorBase::InsertTextAsAction() failed, but ignored");
|
2018-04-16 17:43:36 +03:00
|
|
|
return NS_OK;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult InsertPlaintextCommand::DoCommandParam(
|
|
|
|
Command aCommand, const nsAString& aStringParam, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:45:55 +03:00
|
|
|
if (NS_WARN_IF(aStringParam.IsVoid())) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2018-04-16 17:43:36 +03:00
|
|
|
// XXX InsertTextAsAction() is not same as OnInputText(). However, other
|
|
|
|
// commands to insert line break or paragraph separator use OnInput*().
|
|
|
|
// According to the semantics of those methods, using *AsAction() is
|
|
|
|
// better, however, this may not cause two or more placeholder
|
|
|
|
// transactions to the top transaction since its name may not be
|
|
|
|
// nsGkAtoms::TypingTxnName.
|
2020-03-10 07:34:15 +03:00
|
|
|
DebugOnly<nsresult> rvIgnored =
|
2019-06-10 13:27:07 +03:00
|
|
|
aTextEditor.InsertTextAsAction(aStringParam, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
|
|
|
"EditorBase::InsertTextAsAction() failed, but ignored");
|
2018-04-16 17:43:36 +03:00
|
|
|
return NS_OK;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertPlaintextCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InsertParagraphCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<InsertParagraphCommand> InsertParagraphCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool InsertParagraphCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
2019-06-10 13:27:07 +03:00
|
|
|
if (!aTextEditor || !aTextEditor->AsHTMLEditor()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult InsertParagraphCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2018-11-03 07:19:22 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_OK; // Do nothing for now.
|
|
|
|
}
|
2019-09-03 06:59:11 +03:00
|
|
|
nsresult rv =
|
|
|
|
MOZ_KnownLive(htmlEditor)->InsertParagraphSeparatorAsAction(aPrincipal);
|
2019-06-10 13:27:07 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
2020-03-10 07:34:15 +03:00
|
|
|
"HTMLEditor::InsertParagraphSeparatorAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertParagraphCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InsertLineBreakCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<InsertLineBreakCommand> InsertLineBreakCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool InsertLineBreakCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
2019-06-10 13:27:07 +03:00
|
|
|
if (!aTextEditor || !aTextEditor->AsHTMLEditor()) {
|
2019-04-26 16:11:24 +03:00
|
|
|
return false;
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return aTextEditor->IsSelectionEditable();
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult InsertLineBreakCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
|
2018-04-16 17:43:36 +03:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult rv = MOZ_KnownLive(htmlEditor)->InsertLineBreakAsAction(aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"HTMLEditor::InsertLineBreakAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2016-08-21 16:33:07 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult InsertLineBreakCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
return aParams.SetBool(STATE_ENABLED,
|
2019-04-30 07:24:49 +03:00
|
|
|
IsCommandEnabled(aCommand, aTextEditor));
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteQuotationCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-04-15 10:49:46 +03:00
|
|
|
StaticRefPtr<PasteQuotationCommand> PasteQuotationCommand::sInstance;
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
bool PasteQuotationCommand::IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const {
|
|
|
|
if (!aTextEditor) {
|
|
|
|
return false;
|
2003-10-10 23:02:28 +04:00
|
|
|
}
|
2019-04-26 16:11:24 +03:00
|
|
|
return !aTextEditor->IsSingleLineEditor() &&
|
|
|
|
aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard);
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
nsresult PasteQuotationCommand::DoCommand(Command aCommand,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-04-26 17:00:47 +03:00
|
|
|
nsresult rv = aTextEditor.PasteAsQuotationAsAction(
|
2019-06-10 13:27:07 +03:00
|
|
|
nsIClipboard::kGlobalClipboard, true, aPrincipal);
|
2020-03-10 07:34:15 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"TextEditor::PasteAsQuotationAsAction() failed");
|
2019-06-10 13:27:07 +03:00
|
|
|
return rv;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
nsresult PasteQuotationCommand::GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
2019-04-27 10:35:56 +03:00
|
|
|
nsIEditingSession* aEditingSession) const {
|
|
|
|
if (!aTextEditor) {
|
2017-08-04 14:41:20 +03:00
|
|
|
return NS_OK;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
2019-04-27 10:35:56 +03:00
|
|
|
aParams.SetBool(STATE_ENABLED,
|
|
|
|
aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard));
|
2002-11-13 02:30:29 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-06-24 05:45:22 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|