2016-06-24 05:45:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
#ifndef mozilla_EditorCommands_h
|
|
|
|
#define mozilla_EditorCommands_h
|
2016-06-24 05:45:22 +03:00
|
|
|
|
2019-05-21 10:44:39 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-04-15 10:49:46 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2019-05-21 10:44:11 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2016-06-24 05:45:22 +03:00
|
|
|
#include "nsIControllerCommand.h"
|
2019-06-10 13:27:07 +03:00
|
|
|
#include "nsIPrincipal.h"
|
2016-06-24 05:45:22 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
2019-04-26 05:20:22 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsStringFwd.h"
|
2016-06-24 05:45:22 +03:00
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
class nsAtom;
|
2019-04-26 18:32:06 +03:00
|
|
|
class nsCommandParams;
|
2016-06-24 05:45:22 +03:00
|
|
|
class nsICommandParams;
|
2019-04-27 10:35:56 +03:00
|
|
|
class nsIEditingSession;
|
2019-05-21 10:47:49 +03:00
|
|
|
class nsITransferable;
|
2016-06-24 05:45:22 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
class HTMLEditor;
|
2019-04-26 16:11:24 +03:00
|
|
|
class TextEditor;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
/**
|
|
|
|
* EditorCommandParamType tells you that EditorCommand subclasses refer
|
|
|
|
* which type in nsCommandParams (e.g., bool or nsString) or do not refer.
|
|
|
|
* If they refer some types, also set where is in nsCommandParams, e.g.,
|
|
|
|
* whether "state_attribute" or "state_data".
|
|
|
|
*/
|
|
|
|
enum class EditorCommandParamType : uint16_t {
|
|
|
|
// The command does not take params (even if specified, always ignored).
|
|
|
|
None = 0,
|
|
|
|
// The command refers nsCommandParams::GetBool() result.
|
|
|
|
Bool = 1 << 0,
|
|
|
|
// The command refers nsCommandParams::GetString() result.
|
|
|
|
// This may be specified with CString. In such case,
|
|
|
|
// nsCommandParams::GetCString() is preferred.
|
|
|
|
String = 1 << 1,
|
|
|
|
// The command refers nsCommandParams::GetCString() result.
|
|
|
|
CString = 1 << 2,
|
|
|
|
// The command refers nsCommandParams::GetISupports("transferable") result.
|
|
|
|
Transferable = 1 << 3,
|
|
|
|
|
|
|
|
// The command refres "state_attribute" of nsCommandParams when calling
|
|
|
|
// GetBool()/GetString()/GetCString(). This must not be set when the
|
|
|
|
// type is None or Transferable.
|
|
|
|
StateAttribute = 1 << 14,
|
|
|
|
// The command refers "state_data" of nsCommandParams when calling
|
|
|
|
// GetBool()/GetString()/GetCString(). This must not be set when the
|
|
|
|
// type is None or Transferable.
|
|
|
|
StateData = 1 << 15,
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(EditorCommandParamType)
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
/**
|
2019-04-15 10:49:46 +03:00
|
|
|
* This is a base class for commands registered with the editor controller.
|
|
|
|
* Note that such commands are designed as singleton classes. So, MUST be
|
|
|
|
* stateless. Any state must be stored via the refCon (an nsIEditor).
|
2016-06-24 05:45:22 +03:00
|
|
|
*/
|
|
|
|
|
2019-04-26 06:20:02 +03:00
|
|
|
class EditorCommand : public nsIControllerCommand {
|
2016-06-24 05:45:22 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
static EditorCommandParamType GetParamType(Command aCommand) {
|
|
|
|
// Keep same order of registration in EditorController.cpp and
|
|
|
|
// HTMLEditorController.cpp.
|
|
|
|
switch (aCommand) {
|
|
|
|
// UndoCommand
|
|
|
|
case Command::HistoryUndo:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// RedoCommand
|
|
|
|
case Command::HistoryRedo:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// CutCommand
|
|
|
|
case Command::Cut:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// CutOrDeleteCommand
|
|
|
|
case Command::CutOrDelete:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// CopyCommand
|
|
|
|
case Command::Copy:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// CopyOrDeleteCommand
|
|
|
|
case Command::CopyOrDelete:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// SelectAllCommand
|
|
|
|
case Command::SelectAll:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// PasteCommand
|
|
|
|
case Command::Paste:
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:47:49 +03:00
|
|
|
case Command::PasteTransferable:
|
|
|
|
return EditorCommandParamType::Transferable;
|
2019-05-21 10:44:11 +03:00
|
|
|
// SwitchTextDirectionCommand
|
|
|
|
case Command::FormatSetBlockTextDirection:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// DeleteCommand
|
|
|
|
case Command::Delete:
|
|
|
|
case Command::DeleteCharBackward:
|
|
|
|
case Command::DeleteCharForward:
|
|
|
|
case Command::DeleteWordBackward:
|
|
|
|
case Command::DeleteWordForward:
|
|
|
|
case Command::DeleteToBeginningOfLine:
|
|
|
|
case Command::DeleteToEndOfLine:
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:45:55 +03:00
|
|
|
// InsertPlaintextCommand
|
|
|
|
case Command::InsertText:
|
|
|
|
return EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateData;
|
2019-05-21 10:44:11 +03:00
|
|
|
// InsertParagraphCommand
|
|
|
|
case Command::InsertParagraph:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// InsertLineBreakCommand
|
|
|
|
case Command::InsertLineBreak:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// PasteQuotationCommand
|
|
|
|
case Command::PasteAsQuotation:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
|
|
|
|
// SelectionMoveCommand
|
|
|
|
case Command::ScrollTop:
|
|
|
|
case Command::ScrollBottom:
|
|
|
|
case Command::MoveTop:
|
|
|
|
case Command::MoveBottom:
|
|
|
|
case Command::SelectTop:
|
|
|
|
case Command::SelectBottom:
|
|
|
|
case Command::LineNext:
|
|
|
|
case Command::LinePrevious:
|
|
|
|
case Command::SelectLineNext:
|
|
|
|
case Command::SelectLinePrevious:
|
|
|
|
case Command::CharPrevious:
|
|
|
|
case Command::CharNext:
|
|
|
|
case Command::SelectCharPrevious:
|
|
|
|
case Command::SelectCharNext:
|
|
|
|
case Command::BeginLine:
|
|
|
|
case Command::EndLine:
|
|
|
|
case Command::SelectBeginLine:
|
|
|
|
case Command::SelectEndLine:
|
|
|
|
case Command::WordPrevious:
|
|
|
|
case Command::WordNext:
|
|
|
|
case Command::SelectWordPrevious:
|
|
|
|
case Command::SelectWordNext:
|
|
|
|
case Command::ScrollPageUp:
|
|
|
|
case Command::ScrollPageDown:
|
|
|
|
case Command::ScrollLineUp:
|
|
|
|
case Command::ScrollLineDown:
|
|
|
|
case Command::MovePageUp:
|
|
|
|
case Command::MovePageDown:
|
|
|
|
case Command::SelectPageUp:
|
|
|
|
case Command::SelectPageDown:
|
|
|
|
case Command::MoveLeft:
|
|
|
|
case Command::MoveRight:
|
|
|
|
case Command::MoveUp:
|
|
|
|
case Command::MoveDown:
|
|
|
|
case Command::MoveLeft2:
|
|
|
|
case Command::MoveRight2:
|
|
|
|
case Command::MoveUp2:
|
|
|
|
case Command::MoveDown2:
|
|
|
|
case Command::SelectLeft:
|
|
|
|
case Command::SelectRight:
|
|
|
|
case Command::SelectUp:
|
|
|
|
case Command::SelectDown:
|
|
|
|
case Command::SelectLeft2:
|
|
|
|
case Command::SelectRight2:
|
|
|
|
case Command::SelectUp2:
|
|
|
|
case Command::SelectDown2:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// PasteNoFormattingCommand
|
|
|
|
case Command::PasteWithoutFormat:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
|
|
|
|
// DocumentStateCommand
|
|
|
|
case Command::EditorObserverDocumentCreated:
|
|
|
|
case Command::EditorObserverDocumentLocationChanged:
|
|
|
|
case Command::EditorObserverDocumentWillBeDestroyed:
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:44:39 +03:00
|
|
|
// SetDocumentStateCommand
|
|
|
|
case Command::SetDocumentModified:
|
|
|
|
case Command::SetDocumentUseCSS:
|
|
|
|
case Command::SetDocumentReadOnly:
|
|
|
|
case Command::SetDocumentInsertBROnEnterKeyPress:
|
|
|
|
return EditorCommandParamType::Bool |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
case Command::SetDocumentDefaultParagraphSeparator:
|
2019-05-21 10:45:22 +03:00
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
2019-05-21 10:44:39 +03:00
|
|
|
case Command::ToggleObjectResizers:
|
|
|
|
case Command::ToggleInlineTableEditor:
|
|
|
|
case Command::ToggleAbsolutePositionEditor:
|
|
|
|
return EditorCommandParamType::Bool |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
2019-05-21 10:44:11 +03:00
|
|
|
|
|
|
|
// IndentCommand
|
|
|
|
case Command::FormatIndent:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// OutdentCommand
|
|
|
|
case Command::FormatOutdent:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// StyleUpdatingCommand
|
|
|
|
case Command::FormatBold:
|
|
|
|
case Command::FormatItalic:
|
|
|
|
case Command::FormatUnderline:
|
|
|
|
case Command::FormatTeletypeText:
|
|
|
|
case Command::FormatStrikeThrough:
|
|
|
|
case Command::FormatSuperscript:
|
|
|
|
case Command::FormatSubscript:
|
|
|
|
case Command::FormatNoBreak:
|
|
|
|
case Command::FormatEmphasis:
|
|
|
|
case Command::FormatStrong:
|
|
|
|
case Command::FormatCitation:
|
|
|
|
case Command::FormatAbbreviation:
|
|
|
|
case Command::FormatAcronym:
|
|
|
|
case Command::FormatCode:
|
|
|
|
case Command::FormatSample:
|
|
|
|
case Command::FormatVariable:
|
|
|
|
case Command::FormatRemoveLink:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// ListCommand
|
|
|
|
case Command::InsertOrderedList:
|
|
|
|
case Command::InsertUnorderedList:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// ListItemCommand
|
|
|
|
case Command::InsertDefinitionTerm:
|
|
|
|
case Command::InsertDefinitionDetails:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// RemoveListCommand
|
|
|
|
case Command::FormatRemoveList:
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:47:47 +03:00
|
|
|
// ParagraphStateCommand
|
|
|
|
case Command::FormatBlock:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// FontFaceStateCommand
|
|
|
|
case Command::FormatFontName:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// FontSizeStateCommand
|
|
|
|
case Command::FormatFontSize:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// FontColorStateCommand
|
|
|
|
case Command::FormatFontColor:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// BackgroundColorStateCommand
|
|
|
|
case Command::FormatDocumentBackgroundColor:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// HighlightColorStateCommand
|
|
|
|
case Command::FormatBackColor:
|
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
|
|
|
// AlignCommand:
|
|
|
|
case Command::FormatJustifyLeft:
|
|
|
|
case Command::FormatJustifyRight:
|
|
|
|
case Command::FormatJustifyCenter:
|
|
|
|
case Command::FormatJustifyFull:
|
2019-06-04 13:01:31 +03:00
|
|
|
case Command::FormatJustifyNone:
|
2019-05-21 10:47:47 +03:00
|
|
|
return EditorCommandParamType::CString |
|
|
|
|
EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
2019-05-21 10:44:11 +03:00
|
|
|
// RemoveStylesCommand
|
|
|
|
case Command::FormatRemove:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// IncreaseFontSizeCommand
|
|
|
|
case Command::FormatIncreaseFontSize:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// DecreaseFontSizeCommand
|
|
|
|
case Command::FormatDecreaseFontSize:
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:45:55 +03:00
|
|
|
// InsertHTMLCommand
|
|
|
|
case Command::InsertHTML:
|
|
|
|
return EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateData;
|
|
|
|
// InsertTagCommand
|
|
|
|
case Command::InsertLink:
|
|
|
|
case Command::InsertImage:
|
|
|
|
return EditorCommandParamType::String |
|
|
|
|
EditorCommandParamType::StateAttribute;
|
2019-05-21 10:44:11 +03:00
|
|
|
case Command::InsertHorizontalRule:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// AbsolutePositioningCommand
|
|
|
|
case Command::FormatAbsolutePosition:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// DecreaseZIndexCommand
|
|
|
|
case Command::FormatDecreaseZIndex:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
// IncreaseZIndexCommand
|
|
|
|
case Command::FormatIncreaseZIndex:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
|
Bug 1529884 - part 1: Make Document use hashtable to map HTML command and internal command data r=smaug
Currently, `Document` converts HTML command (e.g., used by `execCommand()`) to
internal XUL command with array in the global space. However, it requires scan
of the array for every command access.
This patch makes `Document` use hashtable to make the conversion faster.
New mapping info comes from:
- `mXULCommandName` is same as `internalCommandString`
- `mCommand` is mapped in CommandList.h from `mXULCommandName`
- `mGetEditorCommandFunc` is mapped from `mXULCommandName` in:
- https://searchfox.org/mozilla-central/rev/d143f8ce30d1bcfee7a1227c27bf876a85f8cede/editor/libeditor/EditorController.cpp#31-32,34-38,40-41,43,45-51,54-57,67-112
- https://searchfox.org/mozilla-central/rev/75294521381b331f821aad3d6b60636844080ee2/editor/libeditor/HTMLEditorController.cpp#26-28,31-39,48,51-52,55-58,60-63,65-73,76-80,83-88,90-91,93-94,97-100,102-104
- `mExecCommandParam` is converted from `useNewParam` and `convertToBoolean`:
- If corresponding editor command class's `DoCommandParam()` just calls
`DoCommand()`, `ExecCommandParam::Ignore`.
- If `useNewParam` is `true` and `convertToBoolean` is `false`, given value
should be ignored and may set constant instead. In this case,
`ExecCommandParam::Ignore`.
- If `useNewParam` is `false` and `convertToBoolean` is `false`, given value
should be treated as string. In this case, `ExecCommandParam::String`.
- If `useNewParam` is `false` and `convertToBoolean` is `true`, given value
should be treated as bool. In this case, if given command is not a legacy
one, `ExecCommandParam::Boolean`. Otherwise, i.e., if given command
is a legacy one, `ExecCommandParam::InvertedBoolean`.
- Otherwise, `ExecCommandParam::String`.
Differential Revision: https://phabricator.services.mozilla.com/D29628
--HG--
extra : moz-landing-system : lando
2019-06-10 13:23:59 +03:00
|
|
|
// nsClipboardGetContentsCommand
|
|
|
|
// XXX nsClipboardGetContentsCommand is implemented by
|
|
|
|
// nsGlobalWindowCommands.cpp but cmd_getContents command is not
|
|
|
|
// used internally, but it's accessible from JS with
|
|
|
|
// queryCommandValue(), etc. So, this class is out of scope of
|
|
|
|
// editor module for now but we should return None for making
|
|
|
|
// Document code simpler. We should reimplement the command class
|
|
|
|
// in editor later for making Document's related methods possible
|
|
|
|
// to access directly. Anyway, it does not support `DoCommand()`
|
|
|
|
// nor `DoCommandParams()` so that let's return `None` here.
|
|
|
|
case Command::GetHTML:
|
|
|
|
return EditorCommandParamType::None;
|
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
default:
|
2019-05-21 10:47:49 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown Command");
|
|
|
|
return EditorCommandParamType::None;
|
2019-05-21 10:44:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:11:24 +03:00
|
|
|
// nsIControllerCommand methods. Use EditorCommand specific methods instead
|
|
|
|
// for internal use.
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2019-04-26 16:11:24 +03:00
|
|
|
NS_IMETHOD IsCommandEnabled(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon,
|
|
|
|
bool* aIsEnabled) final;
|
2019-04-26 17:00:47 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
NS_IMETHOD DoCommand(const char* aCommandName,
|
|
|
|
nsISupports* aCommandRefCon) final;
|
2019-04-26 18:32:06 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
NS_IMETHOD DoCommandParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon) final;
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2019-04-27 10:35:56 +03:00
|
|
|
NS_IMETHOD GetCommandStateParams(const char* aCommandName,
|
|
|
|
nsICommandParams* aParams,
|
|
|
|
nsISupports* aCommandRefCon) final;
|
2019-04-26 16:11:24 +03:00
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-04-30 07:24:49 +03:00
|
|
|
virtual bool IsCommandEnabled(Command aCommand,
|
2019-04-26 16:11:24 +03:00
|
|
|
TextEditor* aTextEditor) const = 0;
|
2019-04-26 17:00:47 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult DoCommand(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const = 0;
|
2019-05-21 10:44:11 +03:00
|
|
|
|
2019-04-27 10:35:56 +03:00
|
|
|
/**
|
|
|
|
* @param aTextEditor If the context is an editor, should be set to
|
|
|
|
* it. Otherwise, nullptr.
|
|
|
|
* @param aEditingSession If the context is an editing session, should be
|
|
|
|
* set to it. This usually occurs if editor has
|
|
|
|
* not been created yet during initialization.
|
|
|
|
* Otherwise, nullptr.
|
|
|
|
*/
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-04-27 10:35:56 +03:00
|
|
|
virtual nsresult GetCommandStateParams(
|
2019-04-30 07:24:49 +03:00
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor,
|
|
|
|
nsIEditingSession* aEditingSession) const = 0;
|
2019-04-26 16:11:24 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
/**
|
|
|
|
* Called only when the result of EditorCommand::GetParamType(aCommand) is
|
|
|
|
* EditorCommandParamType::None.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult DoCommandParam(Command aCommand, TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:44:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:44:39 +03:00
|
|
|
/**
|
|
|
|
* Called only when the result of EditorCommand::GetParamType(aCommand)
|
|
|
|
* includes EditorCommandParamType::Bool. If aBoolParam is Nothing, it
|
|
|
|
* means that given param was nullptr.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult DoCommandParam(Command aCommand,
|
|
|
|
const Maybe<bool>& aBoolParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:44:39 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:22 +03:00
|
|
|
/**
|
|
|
|
* Called only when the result of EditorCommand::GetParamType(aCommand)
|
|
|
|
* includes EditorCommandParamType::CString. If aCStringParam is void, it
|
|
|
|
* means that given param was nullptr.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult DoCommandParam(Command aCommand,
|
|
|
|
const nsACString& aCStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:45:22 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
/**
|
|
|
|
* Called only when the result of EditorCommand::GetParamType(aCommand)
|
|
|
|
* includes EditorCommandParamType::String. If aStringParam is void, it
|
|
|
|
* means that given param was nullptr.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult DoCommandParam(Command aCommand,
|
|
|
|
const nsAString& aStringParam,
|
2019-06-10 13:27:07 +03:00
|
|
|
TextEditor& aTextEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const {
|
2019-05-21 10:45:55 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-05-21 10:47:49 +03:00
|
|
|
/**
|
|
|
|
* Called only when the result of EditorCommand::GetParamType(aCommand) is
|
|
|
|
* EditorCommandParamType::Transferable. If aTransferableParam may be
|
|
|
|
* nullptr.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult 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
|
|
|
MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
protected:
|
2019-04-26 06:20:02 +03:00
|
|
|
EditorCommand() = default;
|
|
|
|
virtual ~EditorCommand() = default;
|
2016-06-24 05:45:22 +03:00
|
|
|
};
|
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual bool IsCommandEnabled(Command aCommand, TextEditor* aTextEditor) \
|
|
|
|
const final; \
|
|
|
|
using EditorCommand::IsCommandEnabled; \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult DoCommand(Command aCommand, TextEditor& aTextEditor, \
|
|
|
|
nsIPrincipal* aPrincipal) const final; \
|
2019-05-21 10:44:11 +03:00
|
|
|
using EditorCommand::DoCommand; \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual nsresult GetCommandStateParams( \
|
|
|
|
Command aCommand, nsCommandParams& aParams, TextEditor* aTextEditor, \
|
|
|
|
nsIEditingSession* aEditingSession) const final; \
|
|
|
|
using EditorCommand::GetCommandStateParams; \
|
|
|
|
using EditorCommand::DoCommandParam;
|
|
|
|
|
|
|
|
#define NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult DoCommandParam(Command aCommand, TextEditor& aTextEditor, \
|
|
|
|
nsIPrincipal* aPrincipal) const final { \
|
|
|
|
return DoCommand(aCommand, aTextEditor, aPrincipal); \
|
2019-05-21 10:44:11 +03:00
|
|
|
}
|
2019-04-26 06:20:02 +03:00
|
|
|
|
2019-06-10 13:27:07 +03:00
|
|
|
#define NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual nsresult DoCommandParam( \
|
|
|
|
Command aCommand, const Maybe<bool>& aBoolParam, \
|
|
|
|
TextEditor& aTextEditor, nsIPrincipal* aPrincipal) const final;
|
|
|
|
|
|
|
|
#define NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual nsresult DoCommandParam( \
|
|
|
|
Command aCommand, const nsACString& aCStringParam, \
|
|
|
|
TextEditor& aTextEditor, nsIPrincipal* aPrincipal) const final;
|
|
|
|
|
|
|
|
#define NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual nsresult DoCommandParam( \
|
|
|
|
Command aCommand, const nsAString& aStringParam, \
|
|
|
|
TextEditor& aTextEditor, nsIPrincipal* aPrincipal) const final;
|
|
|
|
|
|
|
|
#define NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM \
|
|
|
|
public: \
|
|
|
|
MOZ_CAN_RUN_SCRIPT \
|
|
|
|
virtual nsresult DoCommandParam( \
|
|
|
|
Command aCommand, nsITransferable* aTransferableParam, \
|
|
|
|
TextEditor& aTextEditor, nsIPrincipal* aPrincipal) const final;
|
2019-05-21 10:47:49 +03:00
|
|
|
|
2019-04-26 06:20:02 +03:00
|
|
|
#define NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
public: \
|
Bug 1529884 - part 1: Make Document use hashtable to map HTML command and internal command data r=smaug
Currently, `Document` converts HTML command (e.g., used by `execCommand()`) to
internal XUL command with array in the global space. However, it requires scan
of the array for every command access.
This patch makes `Document` use hashtable to make the conversion faster.
New mapping info comes from:
- `mXULCommandName` is same as `internalCommandString`
- `mCommand` is mapped in CommandList.h from `mXULCommandName`
- `mGetEditorCommandFunc` is mapped from `mXULCommandName` in:
- https://searchfox.org/mozilla-central/rev/d143f8ce30d1bcfee7a1227c27bf876a85f8cede/editor/libeditor/EditorController.cpp#31-32,34-38,40-41,43,45-51,54-57,67-112
- https://searchfox.org/mozilla-central/rev/75294521381b331f821aad3d6b60636844080ee2/editor/libeditor/HTMLEditorController.cpp#26-28,31-39,48,51-52,55-58,60-63,65-73,76-80,83-88,90-91,93-94,97-100,102-104
- `mExecCommandParam` is converted from `useNewParam` and `convertToBoolean`:
- If corresponding editor command class's `DoCommandParam()` just calls
`DoCommand()`, `ExecCommandParam::Ignore`.
- If `useNewParam` is `true` and `convertToBoolean` is `false`, given value
should be ignored and may set constant instead. In this case,
`ExecCommandParam::Ignore`.
- If `useNewParam` is `false` and `convertToBoolean` is `false`, given value
should be treated as string. In this case, `ExecCommandParam::String`.
- If `useNewParam` is `false` and `convertToBoolean` is `true`, given value
should be treated as bool. In this case, if given command is not a legacy
one, `ExecCommandParam::Boolean`. Otherwise, i.e., if given command
is a legacy one, `ExecCommandParam::InvertedBoolean`.
- Otherwise, `ExecCommandParam::String`.
Differential Revision: https://phabricator.services.mozilla.com/D29628
--HG--
extra : moz-landing-system : lando
2019-06-10 13:23:59 +03:00
|
|
|
static EditorCommand* GetInstance() { \
|
2019-04-26 06:20:02 +03:00
|
|
|
if (!sInstance) { \
|
|
|
|
sInstance = new _cmd(); \
|
|
|
|
} \
|
|
|
|
return sInstance; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void Shutdown() { sInstance = nullptr; } \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
static StaticRefPtr<_cmd> sInstance;
|
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(_cmd) \
|
|
|
|
class _cmd final : public EditorCommand { \
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND \
|
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
_cmd() = default; \
|
|
|
|
virtual ~_cmd() = default; \
|
|
|
|
};
|
|
|
|
|
2019-05-21 10:44:39 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_FOR_BOOL_PARAM(_cmd) \
|
|
|
|
class _cmd final : public EditorCommand { \
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM \
|
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
_cmd() = default; \
|
|
|
|
virtual ~_cmd() = default; \
|
|
|
|
};
|
|
|
|
|
2019-05-21 10:45:22 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_FOR_CSTRING_PARAM(_cmd) \
|
|
|
|
class _cmd final : public EditorCommand { \
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM \
|
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
_cmd() = default; \
|
|
|
|
virtual ~_cmd() = default; \
|
|
|
|
};
|
|
|
|
|
2019-05-21 10:45:55 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(_cmd) \
|
|
|
|
class _cmd final : public EditorCommand { \
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM \
|
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
_cmd() = default; \
|
|
|
|
virtual ~_cmd() = default; \
|
|
|
|
};
|
|
|
|
|
2019-05-21 10:47:49 +03:00
|
|
|
#define NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM(_cmd) \
|
|
|
|
class _cmd final : public EditorCommand { \
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM \
|
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
_cmd() = default; \
|
|
|
|
virtual ~_cmd() = default; \
|
|
|
|
};
|
|
|
|
|
2016-06-24 05:45:22 +03:00
|
|
|
// basic editor commands
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(UndoCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RedoCommand)
|
|
|
|
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CutCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CutOrDeleteCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CopyCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CopyOrDeleteCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteCommand)
|
2019-05-21 10:47:49 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM(PasteTransferableCommand)
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SwitchTextDirectionCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DeleteCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SelectAllCommand)
|
2016-06-24 05:45:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SelectionMoveCommands)
|
2016-06-24 05:45:22 +03:00
|
|
|
|
|
|
|
// Insert content commands
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(InsertPlaintextCommand)
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(InsertParagraphCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(InsertLineBreakCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteQuotationCommand)
|
2016-06-24 05:45:22 +03:00
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* Commands for HTML editor
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
// virtual base class for commands that need to save and update Boolean state
|
|
|
|
// (like styles etc)
|
2019-04-26 06:20:02 +03:00
|
|
|
class StateUpdatingCommandBase : public EditorCommand {
|
2019-04-26 05:20:22 +03:00
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(StateUpdatingCommandBase, EditorCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
StateUpdatingCommandBase() = default;
|
2019-04-30 07:24:49 +03:00
|
|
|
virtual ~StateUpdatingCommandBase() = default;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// get the current state (on or off) for this style or block format
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const = 0;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// add/remove the style
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const = 0;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-04-30 07:24:49 +03:00
|
|
|
static nsAtom* GetTagName(Command aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case Command::FormatBold:
|
|
|
|
return nsGkAtoms::b;
|
|
|
|
case Command::FormatItalic:
|
|
|
|
return nsGkAtoms::i;
|
|
|
|
case Command::FormatUnderline:
|
|
|
|
return nsGkAtoms::u;
|
|
|
|
case Command::FormatTeletypeText:
|
|
|
|
return nsGkAtoms::tt;
|
|
|
|
case Command::FormatStrikeThrough:
|
|
|
|
return nsGkAtoms::strike;
|
|
|
|
case Command::FormatSuperscript:
|
|
|
|
return nsGkAtoms::sup;
|
|
|
|
case Command::FormatSubscript:
|
|
|
|
return nsGkAtoms::sub;
|
|
|
|
case Command::FormatNoBreak:
|
|
|
|
return nsGkAtoms::nobr;
|
|
|
|
case Command::FormatEmphasis:
|
|
|
|
return nsGkAtoms::em;
|
|
|
|
case Command::FormatStrong:
|
|
|
|
return nsGkAtoms::strong;
|
|
|
|
case Command::FormatCitation:
|
|
|
|
return nsGkAtoms::cite;
|
|
|
|
case Command::FormatAbbreviation:
|
|
|
|
return nsGkAtoms::abbr;
|
|
|
|
case Command::FormatAcronym:
|
|
|
|
return nsGkAtoms::acronym;
|
|
|
|
case Command::FormatCode:
|
|
|
|
return nsGkAtoms::code;
|
|
|
|
case Command::FormatSample:
|
|
|
|
return nsGkAtoms::samp;
|
|
|
|
case Command::FormatVariable:
|
|
|
|
return nsGkAtoms::var;
|
|
|
|
case Command::FormatRemoveLink:
|
|
|
|
return nsGkAtoms::href;
|
|
|
|
case Command::InsertOrderedList:
|
|
|
|
return nsGkAtoms::ol;
|
|
|
|
case Command::InsertUnorderedList:
|
|
|
|
return nsGkAtoms::ul;
|
|
|
|
case Command::InsertDefinitionTerm:
|
|
|
|
return nsGkAtoms::dt;
|
|
|
|
case Command::InsertDefinitionDetails:
|
|
|
|
return nsGkAtoms::dd;
|
|
|
|
case Command::FormatAbsolutePosition:
|
|
|
|
return nsGkAtoms::_empty;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
2019-04-26 05:20:22 +03:00
|
|
|
}
|
|
|
|
}
|
2019-04-30 07:24:49 +03:00
|
|
|
friend class InsertTagCommand; // for allowing it to access GetTagName()
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Shared class for the various style updating commands like bold, italics etc.
|
|
|
|
// Suitable for commands whose state is either 'on' or 'off'.
|
|
|
|
class StyleUpdatingCommand final : public StateUpdatingCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(StyleUpdatingCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
StyleUpdatingCommand() = default;
|
|
|
|
virtual ~StyleUpdatingCommand() = default;
|
|
|
|
|
|
|
|
// get the current state (on or off) for this style or block format
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// add/remove the style
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
2019-04-26 06:20:02 +03:00
|
|
|
class InsertTagCommand final : public EditorCommand {
|
2019-04-26 05:20:22 +03:00
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(InsertTagCommand, EditorCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(InsertTagCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
InsertTagCommand() = default;
|
2019-04-30 07:24:49 +03:00
|
|
|
virtual ~InsertTagCommand() = default;
|
|
|
|
|
|
|
|
static nsAtom* GetTagName(Command aCommand) {
|
|
|
|
switch (aCommand) {
|
|
|
|
case Command::InsertLink:
|
|
|
|
return nsGkAtoms::a;
|
|
|
|
case Command::InsertImage:
|
|
|
|
return nsGkAtoms::img;
|
|
|
|
case Command::InsertHorizontalRule:
|
|
|
|
return nsGkAtoms::hr;
|
|
|
|
default:
|
|
|
|
return StateUpdatingCommandBase::GetTagName(aCommand);
|
2019-04-26 05:20:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ListCommand final : public StateUpdatingCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ListCommand() = default;
|
|
|
|
virtual ~ListCommand() = default;
|
|
|
|
|
|
|
|
// get the current state (on or off) for this style or block format
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// add/remove the style
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ListItemCommand final : public StateUpdatingCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListItemCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ListItemCommand() = default;
|
|
|
|
virtual ~ListItemCommand() = default;
|
|
|
|
|
|
|
|
// get the current state (on or off) for this style or block format
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// add/remove the style
|
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Base class for commands whose state consists of a string (e.g. para format)
|
2019-04-26 06:20:02 +03:00
|
|
|
class MultiStateCommandBase : public EditorCommand {
|
2019-04-26 05:20:22 +03:00
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase, EditorCommand)
|
2019-05-21 10:44:11 +03:00
|
|
|
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS
|
2019-05-21 10:47:47 +03:00
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MultiStateCommandBase() = default;
|
|
|
|
virtual ~MultiStateCommandBase() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const = 0;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
virtual nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const = 0;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParagraphStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ParagraphStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ParagraphStateCommand() = default;
|
|
|
|
virtual ~ParagraphStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class FontFaceStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontFaceStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FontFaceStateCommand() = default;
|
|
|
|
virtual ~FontFaceStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class FontSizeStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontSizeStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FontSizeStateCommand() = default;
|
|
|
|
virtual ~FontSizeStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class HighlightColorStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(HighlightColorStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
HighlightColorStateCommand() = default;
|
|
|
|
virtual ~HighlightColorStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class FontColorStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontColorStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FontColorStateCommand() = default;
|
|
|
|
virtual ~FontColorStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class AlignCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AlignCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AlignCommand() = default;
|
|
|
|
virtual ~AlignCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class BackgroundColorStateCommand final : public MultiStateCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(BackgroundColorStateCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
BackgroundColorStateCommand() = default;
|
|
|
|
virtual ~BackgroundColorStateCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult SetState(HTMLEditor* aHTMLEditor, const nsAString& aNewState,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
|
|
|
|
public:
|
2019-04-26 06:20:02 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AbsolutePositioningCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AbsolutePositioningCommand() = default;
|
|
|
|
virtual ~AbsolutePositioningCommand() = default;
|
|
|
|
|
2019-04-27 10:37:19 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
|
|
|
nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsCommandParams& aParams) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2019-06-10 13:27:07 +03:00
|
|
|
nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
|
|
|
|
nsIPrincipal* aPrincipal) const final;
|
2019-04-26 05:20:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// composer commands
|
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DocumentStateCommand)
|
2019-05-21 10:44:39 +03:00
|
|
|
|
|
|
|
class SetDocumentStateCommand final : public EditorCommand {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(SetDocumentStateCommand, EditorCommand)
|
|
|
|
|
|
|
|
NS_DECL_EDITOR_COMMAND_COMMON_METHODS
|
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM
|
2019-05-21 10:45:22 +03:00
|
|
|
NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM
|
2019-05-21 10:44:39 +03:00
|
|
|
NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(SetDocumentStateCommand)
|
|
|
|
|
|
|
|
private:
|
|
|
|
SetDocumentStateCommand() = default;
|
|
|
|
virtual ~SetDocumentStateCommand() = default;
|
|
|
|
};
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DecreaseZIndexCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IncreaseZIndexCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// Generic commands
|
|
|
|
|
|
|
|
// Edit menu
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteNoFormattingCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// Block transformations
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IndentCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(OutdentCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RemoveListCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RemoveStylesCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IncreaseFontSizeCommand)
|
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DecreaseFontSizeCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
|
|
|
// Insert content commands
|
2019-05-21 10:45:55 +03:00
|
|
|
NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(InsertHTMLCommand)
|
2019-04-26 05:20:22 +03:00
|
|
|
|
2019-05-21 10:44:11 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE
|
2019-05-21 10:44:39 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_FOR_BOOL_PARAM
|
2019-05-21 10:45:22 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_FOR_CSTRING_PARAM
|
2019-05-21 10:45:55 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM
|
2019-05-21 10:47:49 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM
|
2019-05-21 10:44:11 +03:00
|
|
|
#undef NS_DECL_EDITOR_COMMAND_COMMON_METHODS
|
|
|
|
#undef NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
|
2019-05-21 10:44:39 +03:00
|
|
|
#undef NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM
|
2019-05-21 10:45:22 +03:00
|
|
|
#undef NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM
|
2019-05-21 10:45:55 +03:00
|
|
|
#undef NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
|
2019-05-21 10:47:49 +03:00
|
|
|
#undef NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM
|
2019-04-26 06:20:02 +03:00
|
|
|
#undef NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON
|
2016-06-24 05:45:22 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-04-26 05:20:22 +03:00
|
|
|
#endif // #ifndef mozilla_EditorCommands_h
|