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
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozFlushType.h"
|
2014-11-22 18:33:36 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-08-21 16:33:07 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
#include "nsCRT.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsICommandParams.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-02-16 04:33:03 +03:00
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsISelection.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"
|
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
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::EditorCommandBase
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
EditorCommandBase::EditorCommandBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(EditorCommandBase, nsIControllerCommand)
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::UndoCommand
|
|
|
|
******************************************************************************/
|
2000-02-16 04:33:03 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
UndoCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEnabled, isEditable = false;
|
2011-08-18 19:34:52 +04:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (isEditable)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanUndo(&isEnabled, aIsEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
UndoCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Undo(1);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
UndoCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
UndoCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
RedoCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEnabled, isEditable = false;
|
2011-08-18 19:34:52 +04:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (isEditable)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanRedo(&isEnabled, aIsEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
RedoCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Redo(1);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
RedoCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
RedoCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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::ClearUndoCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2003-05-09 22:21:00 +04:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
ClearUndoCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2014-11-25 00:08:00 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2003-05-09 22:21:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
ClearUndoCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2014-11-25 00:08:00 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
|
|
|
editor->EnableUndo(false); // Turning off undo clears undo/redo stacks.
|
|
|
|
editor->EnableUndo(true); // This re-enables undo/redo.
|
|
|
|
|
2003-05-09 22:21:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-11-25 00:08:00 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
ClearUndoCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2003-05-09 22:21:00 +04:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2003-05-09 22:21:00 +04:00
|
|
|
}
|
2014-11-25 00:08:00 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
ClearUndoCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2014-11-25 00:08:00 +03:00
|
|
|
{
|
2003-05-09 22:21:00 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enabled;
|
2016-06-24 05:45:22 +03:00
|
|
|
nsresult rv = IsCommandEnabled(aCommandName, aCommandRefCon, &enabled);
|
2003-05-09 22:21:00 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2003-05-09 22:21:00 +04:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CutCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable = false;
|
2011-08-18 19:34:52 +04:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (isEditable)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanCut(aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Cut();
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::CutOrDeleteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2001-02-16 00:51:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutOrDeleteCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2001-02-16 00:51:25 +03:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
2012-05-18 12:29:39 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
|
2012-05-18 15:32:20 +04:00
|
|
|
return editor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
return editor->Cut();
|
|
|
|
}
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutOrDeleteCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CutOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanCopy(aIsEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->Copy();
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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
|
|
|
|
******************************************************************************/
|
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2001-02-16 00:51:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyOrDeleteCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2001-02-16 00:51:25 +03:00
|
|
|
{
|
2001-04-05 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2001-02-16 00:51:25 +03:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
nsresult rv = editor->GetSelection(getter_AddRefs(selection));
|
2012-05-18 12:29:39 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
|
2012-05-18 15:32:20 +04:00
|
|
|
return editor->DeleteSelection(nsIEditor::eNextWord, nsIEditor::eStrip);
|
2001-02-16 00:51:25 +03:00
|
|
|
}
|
|
|
|
return editor->Copy();
|
|
|
|
}
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2001-02-16 00:51:25 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyOrDeleteCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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::CopyAndCollapseToEndCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-11-27 01:06:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyAndCollapseToEndCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2014-11-27 01:06:00 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2014-11-27 01:06:00 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanCopy(aIsEnabled);
|
2014-11-27 01:06:00 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2014-11-27 01:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyAndCollapseToEndCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2014-11-27 01:06:00 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor) {
|
|
|
|
nsresult rv = editor->Copy();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
rv = editor->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_SUCCEEDED(rv) && selection) {
|
|
|
|
selection->CollapseToEnd();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyAndCollapseToEndCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2014-11-27 01:06:00 +03:00
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
CopyAndCollapseToEndCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2014-11-27 01:06:00 +03:00
|
|
|
{
|
|
|
|
bool canUndo;
|
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable = false;
|
2011-08-18 19:34:52 +04:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (isEditable)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanPaste(nsIClipboard::kGlobalClipboard, aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2003-10-10 23:02:28 +04:00
|
|
|
return editor->Paste(nsIClipboard::kGlobalClipboard);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteTransferableCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteTransferableCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2010-01-11 04:45:45 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2010-01-11 04:45:45 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable = false;
|
2011-08-18 19:34:52 +04:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (isEditable)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanPasteTransferable(nullptr, aIsEnabled);
|
2011-08-17 21:28:03 +04:00
|
|
|
}
|
2010-01-11 04:45:45 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2010-01-11 04:45:45 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteTransferableCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2010-01-11 04:45:45 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteTransferableCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2010-01-11 04:45:45 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(supports, NS_ERROR_FAILURE);
|
2010-01-11 04:45:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
2010-01-11 04:45:45 +03:00
|
|
|
|
|
|
|
return editor->PasteTransferable(trans);
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteTransferableCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2010-01-11 04:45:45 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2010-01-11 04:45:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
|
|
|
|
if (supports) {
|
|
|
|
trans = do_QueryInterface(supports);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
2010-01-11 04:45:45 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canPaste;
|
2010-01-11 04:45:45 +03:00
|
|
|
nsresult rv = editor->CanPasteTransferable(trans, &canPaste);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canPaste);
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SwitchTextDirectionCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-01-26 04:40:30 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SwitchTextDirectionCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2005-01-26 04:40:30 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2005-01-26 04:40:30 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2005-01-26 04:40:30 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2005-01-26 04:40:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SwitchTextDirectionCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2005-01-26 04:40:30 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2005-01-26 04:40:30 +03:00
|
|
|
|
|
|
|
return editor->SwitchTextDirection();
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SwitchTextDirectionCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2005-01-26 04:40:30 +03:00
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SwitchTextDirectionCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2005-01-26 04:40:30 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canSwitchTextDirection = true;
|
2005-01-26 04:40:30 +03:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canSwitchTextDirection);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canSwitchTextDirection);
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::DeleteCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
DeleteCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2016-06-08 01:00:49 +03:00
|
|
|
if (!editor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
// directionless, which is the same condition under which we can't cut.
|
2016-06-24 05:45:22 +03:00
|
|
|
nsresult rv = editor->GetIsSelectionEditable(aIsEnabled);
|
2011-08-18 19:34:52 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-08-17 21:28:03 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
if (!nsCRT::strcmp("cmd_delete", aCommandName) && *aIsEnabled) {
|
|
|
|
rv = editor->CanDelete(aIsEnabled);
|
2012-06-21 16:05:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2003-06-30 18:56:22 +04:00
|
|
|
return NS_OK;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
DeleteCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2012-06-21 16:05:24 +04:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
nsIEditor::EDirection deleteDir = nsIEditor::eNone;
|
2012-06-21 16:05:24 +04:00
|
|
|
|
|
|
|
if (!nsCRT::strcmp("cmd_delete", aCommandName)) {
|
|
|
|
// 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.
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePrevious;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteCharForward", aCommandName)) {
|
2012-05-22 13:37:17 +04:00
|
|
|
deleteDir = nsIEditor::eNext;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteCharBackward", aCommandName)) {
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePrevious;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteWordBackward", aCommandName)) {
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::ePreviousWord;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteWordForward", aCommandName)) {
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eNextWord;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteToBeginningOfLine", aCommandName)) {
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eToBeginningOfLine;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else if (!nsCRT::strcmp("cmd_deleteToEndOfLine", aCommandName)) {
|
2000-02-16 04:33:03 +03:00
|
|
|
deleteDir = nsIEditor::eToEndOfLine;
|
2012-06-21 16:05:24 +04:00
|
|
|
} else {
|
2013-06-29 05:38:30 +04:00
|
|
|
MOZ_CRASH("Unrecognized nsDeleteCommand");
|
2012-06-21 16:05:24 +04:00
|
|
|
}
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2012-05-10 18:54:33 +04:00
|
|
|
return editor->DeleteSelection(deleteDir, nsIEditor::eStrip);
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
DeleteCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
DeleteCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SelectAllCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectAllCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2011-09-24 01:44:53 +04:00
|
|
|
nsresult rv = NS_OK;
|
2010-11-16 23:45:49 +03:00
|
|
|
// You can always select all, unless the selection is editable,
|
|
|
|
// and the editable region is empty!
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = true;
|
2011-12-30 21:42:04 +04:00
|
|
|
bool docIsEmpty;
|
2010-11-16 23:45:49 +03:00
|
|
|
|
2011-09-24 01:44:53 +04:00
|
|
|
// you can select all if there is an editor which is non-empty
|
2011-09-23 02:09:44 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-09-24 01:44:53 +04:00
|
|
|
if (editor) {
|
2011-12-30 21:42:04 +04:00
|
|
|
rv = editor->GetDocumentIsEmpty(&docIsEmpty);
|
2011-09-24 01:44:53 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = !docIsEmpty;
|
2010-11-16 23:45:49 +03:00
|
|
|
}
|
2011-09-24 01:44:53 +04:00
|
|
|
|
|
|
|
return rv;
|
2000-02-16 04:33:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectAllCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (editor)
|
|
|
|
return editor->SelectAll();
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectAllCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectAllCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::SelectionMoveCommands
|
|
|
|
******************************************************************************/
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectionMoveCommands::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2011-08-17 21:28:03 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2000-02-16 04:33:03 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
static const struct ScrollCommand {
|
|
|
|
const char *reverseScroll;
|
|
|
|
const char *forwardScroll;
|
|
|
|
nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
|
|
|
|
} scrollCommands[] = {
|
|
|
|
{ "cmd_scrollTop", "cmd_scrollBottom",
|
|
|
|
&nsISelectionController::CompleteScroll },
|
|
|
|
{ "cmd_scrollPageUp", "cmd_scrollPageDown",
|
|
|
|
&nsISelectionController::ScrollPage },
|
|
|
|
{ "cmd_scrollLineUp", "cmd_scrollLineDown",
|
|
|
|
&nsISelectionController::ScrollLine }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct MoveCommand {
|
|
|
|
const char *reverseMove;
|
|
|
|
const char *forwardMove;
|
|
|
|
const char *reverseSelect;
|
|
|
|
const char *forwardSelect;
|
|
|
|
nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool);
|
|
|
|
} moveCommands[] = {
|
|
|
|
{ "cmd_charPrevious", "cmd_charNext",
|
|
|
|
"cmd_selectCharPrevious", "cmd_selectCharNext",
|
|
|
|
&nsISelectionController::CharacterMove },
|
|
|
|
{ "cmd_linePrevious", "cmd_lineNext",
|
|
|
|
"cmd_selectLinePrevious", "cmd_selectLineNext",
|
|
|
|
&nsISelectionController::LineMove },
|
|
|
|
{ "cmd_wordPrevious", "cmd_wordNext",
|
|
|
|
"cmd_selectWordPrevious", "cmd_selectWordNext",
|
|
|
|
&nsISelectionController::WordMove },
|
|
|
|
{ "cmd_beginLine", "cmd_endLine",
|
|
|
|
"cmd_selectBeginLine", "cmd_selectEndLine",
|
|
|
|
&nsISelectionController::IntraLineMove },
|
|
|
|
{ "cmd_movePageUp", "cmd_movePageDown",
|
|
|
|
"cmd_selectPageUp", "cmd_selectPageDown",
|
|
|
|
&nsISelectionController::PageMove },
|
|
|
|
{ "cmd_moveTop", "cmd_moveBottom",
|
|
|
|
"cmd_selectTop", "cmd_selectBottom",
|
|
|
|
&nsISelectionController::CompleteMove }
|
|
|
|
};
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
static const struct PhysicalCommand {
|
|
|
|
const char *move;
|
|
|
|
const char *select;
|
|
|
|
int16_t direction;
|
|
|
|
int16_t amount;
|
|
|
|
} physicalCommands[] = {
|
|
|
|
{ "cmd_moveLeft", "cmd_selectLeft",
|
|
|
|
nsISelectionController::MOVE_LEFT, 0 },
|
|
|
|
{ "cmd_moveRight", "cmd_selectRight",
|
|
|
|
nsISelectionController::MOVE_RIGHT, 0 },
|
|
|
|
{ "cmd_moveUp", "cmd_selectUp",
|
|
|
|
nsISelectionController::MOVE_UP, 0 },
|
|
|
|
{ "cmd_moveDown", "cmd_selectDown",
|
|
|
|
nsISelectionController::MOVE_DOWN, 0 },
|
|
|
|
{ "cmd_moveLeft2", "cmd_selectLeft2",
|
|
|
|
nsISelectionController::MOVE_LEFT, 1 },
|
|
|
|
{ "cmd_moveRight2", "cmd_selectRight2",
|
|
|
|
nsISelectionController::MOVE_RIGHT, 1 },
|
|
|
|
{ "cmd_moveUp2", "cmd_selectUp2",
|
|
|
|
nsISelectionController::MOVE_UP, 1 },
|
|
|
|
{ "cmd_moveDown2", "cmd_selectDown2",
|
|
|
|
nsISelectionController::MOVE_DOWN, 1 }
|
|
|
|
};
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectionMoveCommands::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2000-02-16 04:33:03 +03:00
|
|
|
{
|
2003-06-30 18:56:22 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2010-08-05 22:39:39 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
|
|
|
// Most of the commands below (possibly all of them) need layout to
|
|
|
|
// be up to date.
|
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
2014-11-25 00:08:00 +03:00
|
|
|
nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont));
|
2010-06-18 00:44:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(selCont, NS_ERROR_FAILURE);
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// scroll commands
|
2014-11-22 18:33:36 +03:00
|
|
|
for (size_t i = 0; i < mozilla::ArrayLength(scrollCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const ScrollCommand &cmd = scrollCommands[i];
|
2014-11-22 17:39:04 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, cmd.reverseScroll)) {
|
|
|
|
return (selCont->*(cmd.scroll))(false);
|
|
|
|
} else if (!nsCRT::strcmp(aCommandName, cmd.forwardScroll)) {
|
|
|
|
return (selCont->*(cmd.scroll))(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// caret movement/selection commands
|
2014-11-22 18:33:36 +03:00
|
|
|
for (size_t i = 0; i < mozilla::ArrayLength(moveCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const MoveCommand &cmd = moveCommands[i];
|
2014-11-22 17:39:04 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, cmd.reverseMove)) {
|
|
|
|
return (selCont->*(cmd.move))(false, false);
|
|
|
|
} else if (!nsCRT::strcmp(aCommandName, cmd.forwardMove)) {
|
|
|
|
return (selCont->*(cmd.move))(true, false);
|
|
|
|
} else if (!nsCRT::strcmp(aCommandName, cmd.reverseSelect)) {
|
|
|
|
return (selCont->*(cmd.move))(false, true);
|
|
|
|
} else if (!nsCRT::strcmp(aCommandName, cmd.forwardSelect)) {
|
|
|
|
return (selCont->*(cmd.move))(true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:39:04 +03:00
|
|
|
// physical-direction movement/selection
|
2014-11-22 18:33:36 +03:00
|
|
|
for (size_t i = 0; i < mozilla::ArrayLength(physicalCommands); i++) {
|
2014-11-25 00:08:00 +03:00
|
|
|
const PhysicalCommand &cmd = physicalCommands[i];
|
2014-11-22 17:39:04 +03:00
|
|
|
if (!nsCRT::strcmp(aCommandName, cmd.move)) {
|
|
|
|
return selCont->PhysicalMove(cmd.direction, cmd.amount, false);
|
|
|
|
} else if (!nsCRT::strcmp(aCommandName, cmd.select)) {
|
|
|
|
return selCont->PhysicalMove(cmd.direction, cmd.amount, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-16 04:33:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-02-02 08:13:56 +03:00
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectionMoveCommands::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2002-07-16 02:04:13 +04:00
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
2002-02-02 08:13:56 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 00:08:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
SelectionMoveCommands::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-02-02 08:13:56 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUndo;
|
2002-07-16 02:04:13 +04:00
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
|
2014-11-25 00:08:00 +03:00
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
|
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
|
|
|
|
******************************************************************************/
|
|
|
|
|
2002-11-13 02:30:29 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
InsertPlaintextCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2003-04-22 22:11:12 +04:00
|
|
|
if (editor)
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2003-06-30 18:56:22 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
InsertPlaintextCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
InsertPlaintextCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParams);
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
|
2002-11-13 02:30:29 +03:00
|
|
|
|
|
|
|
// Get text to insert from command params
|
|
|
|
nsAutoString text;
|
|
|
|
nsresult rv = aParams->GetStringValue(STATE_DATA, text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!text.IsEmpty())
|
|
|
|
return editor->InsertText(text);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
InsertPlaintextCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-08-21 16:33:07 +03:00
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool aIsEnabled = false;
|
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InsertParagraphCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertParagraphCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aIsEnabled)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
*aIsEnabled = false;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertParagraphCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEditor* textEditor = static_cast<TextEditor*>(editor.get());
|
|
|
|
|
|
|
|
return textEditor->TypedText(EmptyString(), TextEditor::eTypedBreak);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertParagraphCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertParagraphCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool aIsEnabled = false;
|
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InsertLineBreakCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertLineBreakCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aIsEnabled)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
*aIsEnabled = false;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return editor->GetIsSelectionEditable(aIsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertLineBreakCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
if (NS_WARN_IF(!editor)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEditor* textEditor = static_cast<TextEditor*>(editor.get());
|
|
|
|
|
|
|
|
return textEditor->TypedText(EmptyString(), TextEditor::eTypedBR);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertLineBreakCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
return DoCommand(aCommandName, aCommandRefCon);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InsertLineBreakCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aParams)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
bool aIsEnabled = false;
|
|
|
|
IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
|
|
|
|
return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::PasteQuotationCommand
|
|
|
|
******************************************************************************/
|
|
|
|
|
2002-11-13 02:30:29 +03:00
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteQuotationCommand::IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsEnabled);
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
|
2003-10-10 23:02:28 +04:00
|
|
|
if (editor && mailEditor) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2003-10-10 23:02:28 +04:00
|
|
|
editor->GetFlags(&flags);
|
|
|
|
if (!(flags & nsIPlaintextEditor::eEditorSingleLineMask))
|
2016-06-24 05:45:22 +03:00
|
|
|
return editor->CanPaste(nsIClipboard::kGlobalClipboard, aIsEnabled);
|
2003-10-10 23:02:28 +04:00
|
|
|
}
|
2003-06-30 18:56:22 +04:00
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
*aIsEnabled = false;
|
2003-10-10 23:02:28 +04:00
|
|
|
return NS_OK;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteQuotationCommand::DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
|
2003-06-30 18:56:22 +04:00
|
|
|
if (mailEditor)
|
|
|
|
return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2003-06-30 18:56:22 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteQuotationCommand::DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
|
2003-06-30 18:56:22 +04:00
|
|
|
if (mailEditor)
|
|
|
|
return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
2002-11-13 02:30:29 +03:00
|
|
|
|
2003-06-30 18:56:22 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2002-11-13 02:30:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-24 05:45:22 +03:00
|
|
|
PasteQuotationCommand::GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon)
|
2002-11-13 02:30:29 +03:00
|
|
|
{
|
2016-06-24 05:45:22 +03:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
|
2014-11-25 00:08:00 +03:00
|
|
|
if (editor) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enabled = false;
|
2002-11-13 02:30:29 +03:00
|
|
|
editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled);
|
|
|
|
aParams->SetBooleanValue(STATE_ENABLED, enabled);
|
|
|
|
}
|
2014-11-25 00:08:00 +03:00
|
|
|
|
2002-11-13 02:30:29 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-06-24 05:45:22 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|