Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / editor / libeditor / EditorCommands.h
blob031f9057e6de3a62b42712e894b15451e557a62c
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_EditorCommands_h
7 #define mozilla_EditorCommands_h
9 #include "mozilla/EditorForwards.h"
10 #include "mozilla/EventForwards.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/StaticPtr.h"
13 #include "mozilla/TypedEnumBits.h"
14 #include "nsGkAtoms.h"
15 #include "nsIControllerCommand.h"
16 #include "nsIPrincipal.h"
17 #include "nsISupportsImpl.h"
18 #include "nsRefPtrHashtable.h"
19 #include "nsStringFwd.h"
21 class nsAtom;
22 class nsCommandParams;
23 class nsICommandParams;
24 class nsIEditingSession;
25 class nsITransferable;
26 class nsStaticAtom;
28 namespace mozilla {
30 /**
31 * EditorCommandParamType tells you that EditorCommand subclasses refer
32 * which type in nsCommandParams (e.g., bool or nsString) or do not refer.
33 * If they refer some types, also set where is in nsCommandParams, e.g.,
34 * whether "state_attribute" or "state_data".
36 enum class EditorCommandParamType : uint16_t {
37 // The command does not take params (even if specified, always ignored).
38 None = 0,
39 // The command refers nsCommandParams::GetBool() result.
40 Bool = 1 << 0,
41 // The command refers nsCommandParams::GetString() result.
42 // This may be specified with CString. In such case,
43 // nsCommandParams::GetCString() is preferred.
44 String = 1 << 1,
45 // The command refers nsCommandParams::GetCString() result.
46 CString = 1 << 2,
47 // The command refers nsCommandParams::GetISupports("transferable") result.
48 Transferable = 1 << 3,
50 // The command refres "state_attribute" of nsCommandParams when calling
51 // GetBool()/GetString()/GetCString(). This must not be set when the
52 // type is None or Transferable.
53 StateAttribute = 1 << 14,
54 // The command refers "state_data" of nsCommandParams when calling
55 // GetBool()/GetString()/GetCString(). This must not be set when the
56 // type is None or Transferable.
57 StateData = 1 << 15,
60 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(EditorCommandParamType)
62 /**
63 * This is a base class for commands registered with the editor controller.
64 * Note that such commands are designed as singleton classes. So, MUST be
65 * stateless. Any state must be stored via the refCon (an nsIEditor).
68 class EditorCommand : public nsIControllerCommand {
69 public:
70 NS_DECL_ISUPPORTS
72 static EditorCommandParamType GetParamType(Command aCommand) {
73 // Keep same order of registration in EditorController.cpp and
74 // HTMLEditorController.cpp.
75 switch (aCommand) {
76 // UndoCommand
77 case Command::HistoryUndo:
78 return EditorCommandParamType::None;
79 // RedoCommand
80 case Command::HistoryRedo:
81 return EditorCommandParamType::None;
82 // CutCommand
83 case Command::Cut:
84 return EditorCommandParamType::None;
85 // CutOrDeleteCommand
86 case Command::CutOrDelete:
87 return EditorCommandParamType::None;
88 // CopyCommand
89 case Command::Copy:
90 return EditorCommandParamType::None;
91 // CopyOrDeleteCommand
92 case Command::CopyOrDelete:
93 return EditorCommandParamType::None;
94 // SelectAllCommand
95 case Command::SelectAll:
96 return EditorCommandParamType::None;
97 // PasteCommand
98 case Command::Paste:
99 return EditorCommandParamType::None;
100 case Command::PasteTransferable:
101 return EditorCommandParamType::Transferable;
102 // SwitchTextDirectionCommand
103 case Command::FormatSetBlockTextDirection:
104 return EditorCommandParamType::None;
105 // DeleteCommand
106 case Command::Delete:
107 case Command::DeleteCharBackward:
108 case Command::DeleteCharForward:
109 case Command::DeleteWordBackward:
110 case Command::DeleteWordForward:
111 case Command::DeleteToBeginningOfLine:
112 case Command::DeleteToEndOfLine:
113 return EditorCommandParamType::None;
114 // InsertPlaintextCommand
115 case Command::InsertText:
116 return EditorCommandParamType::String |
117 EditorCommandParamType::StateData;
118 // InsertParagraphCommand
119 case Command::InsertParagraph:
120 return EditorCommandParamType::None;
121 // InsertLineBreakCommand
122 case Command::InsertLineBreak:
123 return EditorCommandParamType::None;
124 // PasteQuotationCommand
125 case Command::PasteAsQuotation:
126 return EditorCommandParamType::None;
128 // SelectionMoveCommand
129 case Command::ScrollTop:
130 case Command::ScrollBottom:
131 case Command::MoveTop:
132 case Command::MoveBottom:
133 case Command::SelectTop:
134 case Command::SelectBottom:
135 case Command::LineNext:
136 case Command::LinePrevious:
137 case Command::SelectLineNext:
138 case Command::SelectLinePrevious:
139 case Command::CharPrevious:
140 case Command::CharNext:
141 case Command::SelectCharPrevious:
142 case Command::SelectCharNext:
143 case Command::BeginLine:
144 case Command::EndLine:
145 case Command::SelectBeginLine:
146 case Command::SelectEndLine:
147 case Command::WordPrevious:
148 case Command::WordNext:
149 case Command::SelectWordPrevious:
150 case Command::SelectWordNext:
151 case Command::ScrollPageUp:
152 case Command::ScrollPageDown:
153 case Command::ScrollLineUp:
154 case Command::ScrollLineDown:
155 case Command::MovePageUp:
156 case Command::MovePageDown:
157 case Command::SelectPageUp:
158 case Command::SelectPageDown:
159 case Command::MoveLeft:
160 case Command::MoveRight:
161 case Command::MoveUp:
162 case Command::MoveDown:
163 case Command::MoveLeft2:
164 case Command::MoveRight2:
165 case Command::MoveUp2:
166 case Command::MoveDown2:
167 case Command::SelectLeft:
168 case Command::SelectRight:
169 case Command::SelectUp:
170 case Command::SelectDown:
171 case Command::SelectLeft2:
172 case Command::SelectRight2:
173 case Command::SelectUp2:
174 case Command::SelectDown2:
175 return EditorCommandParamType::None;
176 // PasteNoFormattingCommand
177 case Command::PasteWithoutFormat:
178 return EditorCommandParamType::None;
180 // DocumentStateCommand
181 case Command::EditorObserverDocumentCreated:
182 case Command::EditorObserverDocumentLocationChanged:
183 case Command::EditorObserverDocumentWillBeDestroyed:
184 return EditorCommandParamType::None;
185 // SetDocumentStateCommand
186 case Command::SetDocumentModified:
187 case Command::SetDocumentUseCSS:
188 case Command::SetDocumentReadOnly:
189 case Command::SetDocumentInsertBROnEnterKeyPress:
190 return EditorCommandParamType::Bool |
191 EditorCommandParamType::StateAttribute;
192 case Command::SetDocumentDefaultParagraphSeparator:
193 return EditorCommandParamType::CString |
194 EditorCommandParamType::StateAttribute;
195 case Command::ToggleObjectResizers:
196 case Command::ToggleInlineTableEditor:
197 case Command::ToggleAbsolutePositionEditor:
198 case Command::EnableCompatibleJoinSplitNodeDirection:
199 return EditorCommandParamType::Bool |
200 EditorCommandParamType::StateAttribute;
202 // IndentCommand
203 case Command::FormatIndent:
204 return EditorCommandParamType::None;
205 // OutdentCommand
206 case Command::FormatOutdent:
207 return EditorCommandParamType::None;
208 // StyleUpdatingCommand
209 case Command::FormatBold:
210 case Command::FormatItalic:
211 case Command::FormatUnderline:
212 case Command::FormatTeletypeText:
213 case Command::FormatStrikeThrough:
214 case Command::FormatSuperscript:
215 case Command::FormatSubscript:
216 case Command::FormatNoBreak:
217 case Command::FormatEmphasis:
218 case Command::FormatStrong:
219 case Command::FormatCitation:
220 case Command::FormatAbbreviation:
221 case Command::FormatAcronym:
222 case Command::FormatCode:
223 case Command::FormatSample:
224 case Command::FormatVariable:
225 case Command::FormatRemoveLink:
226 return EditorCommandParamType::None;
227 // ListCommand
228 case Command::InsertOrderedList:
229 case Command::InsertUnorderedList:
230 return EditorCommandParamType::None;
231 // ListItemCommand
232 case Command::InsertDefinitionTerm:
233 case Command::InsertDefinitionDetails:
234 return EditorCommandParamType::None;
235 // RemoveListCommand
236 case Command::FormatRemoveList:
237 return EditorCommandParamType::None;
238 // ParagraphStateCommand
239 case Command::FormatBlock:
240 case Command::ParagraphState:
241 return EditorCommandParamType::CString |
242 EditorCommandParamType::String |
243 EditorCommandParamType::StateAttribute;
244 // FontFaceStateCommand
245 case Command::FormatFontName:
246 return EditorCommandParamType::CString |
247 EditorCommandParamType::String |
248 EditorCommandParamType::StateAttribute;
249 // FontSizeStateCommand
250 case Command::FormatFontSize:
251 return EditorCommandParamType::CString |
252 EditorCommandParamType::String |
253 EditorCommandParamType::StateAttribute;
254 // FontColorStateCommand
255 case Command::FormatFontColor:
256 return EditorCommandParamType::CString |
257 EditorCommandParamType::String |
258 EditorCommandParamType::StateAttribute;
259 // BackgroundColorStateCommand
260 case Command::FormatDocumentBackgroundColor:
261 return EditorCommandParamType::CString |
262 EditorCommandParamType::String |
263 EditorCommandParamType::StateAttribute;
264 // HighlightColorStateCommand
265 case Command::FormatBackColor:
266 return EditorCommandParamType::CString |
267 EditorCommandParamType::String |
268 EditorCommandParamType::StateAttribute;
269 // AlignCommand:
270 case Command::FormatJustifyLeft:
271 case Command::FormatJustifyRight:
272 case Command::FormatJustifyCenter:
273 case Command::FormatJustifyFull:
274 case Command::FormatJustifyNone:
275 return EditorCommandParamType::CString |
276 EditorCommandParamType::String |
277 EditorCommandParamType::StateAttribute;
278 // RemoveStylesCommand
279 case Command::FormatRemove:
280 return EditorCommandParamType::None;
281 // IncreaseFontSizeCommand
282 case Command::FormatIncreaseFontSize:
283 return EditorCommandParamType::None;
284 // DecreaseFontSizeCommand
285 case Command::FormatDecreaseFontSize:
286 return EditorCommandParamType::None;
287 // InsertHTMLCommand
288 case Command::InsertHTML:
289 return EditorCommandParamType::String |
290 EditorCommandParamType::StateData;
291 // InsertTagCommand
292 case Command::InsertLink:
293 case Command::InsertImage:
294 return EditorCommandParamType::String |
295 EditorCommandParamType::StateAttribute;
296 case Command::InsertHorizontalRule:
297 return EditorCommandParamType::None;
298 // AbsolutePositioningCommand
299 case Command::FormatAbsolutePosition:
300 return EditorCommandParamType::None;
301 // DecreaseZIndexCommand
302 case Command::FormatDecreaseZIndex:
303 return EditorCommandParamType::None;
304 // IncreaseZIndexCommand
305 case Command::FormatIncreaseZIndex:
306 return EditorCommandParamType::None;
308 default:
309 MOZ_ASSERT_UNREACHABLE("Unknown Command");
310 return EditorCommandParamType::None;
314 // nsIControllerCommand methods. Use EditorCommand specific methods instead
315 // for internal use.
316 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
317 IsCommandEnabled(const char* aCommandName, nsISupports* aCommandRefCon,
318 bool* aIsEnabled) final;
319 MOZ_CAN_RUN_SCRIPT NS_IMETHOD DoCommand(const char* aCommandName,
320 nsISupports* aCommandRefCon) final;
321 MOZ_CAN_RUN_SCRIPT NS_IMETHOD
322 DoCommandParams(const char* aCommandName, nsICommandParams* aParams,
323 nsISupports* aCommandRefCon) final;
324 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
325 GetCommandStateParams(const char* aCommandName, nsICommandParams* aParams,
326 nsISupports* aCommandRefCon) final;
328 MOZ_CAN_RUN_SCRIPT virtual bool IsCommandEnabled(
329 Command aCommand, EditorBase* aEditorBase) const = 0;
330 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommand(
331 Command aCommand, EditorBase& aEditorBase,
332 nsIPrincipal* aPrincipal) const = 0;
335 * @param aEditorBase If the context is an editor, should be set to
336 * it. Otherwise, nullptr.
337 * @param aEditingSession If the context is an editing session, should be
338 * set to it. This usually occurs if editor has
339 * not been created yet during initialization.
340 * Otherwise, nullptr.
342 MOZ_CAN_RUN_SCRIPT virtual nsresult GetCommandStateParams(
343 Command aCommand, nsCommandParams& aParams, EditorBase* aEditorBase,
344 nsIEditingSession* aEditingSession) const = 0;
347 * Called only when the result of EditorCommand::GetParamType(aCommand) is
348 * EditorCommandParamType::None.
350 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam(
351 Command aCommand, EditorBase& aEditorBase,
352 nsIPrincipal* aPrincipal) const {
353 MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
354 return NS_ERROR_NOT_IMPLEMENTED;
358 * Called only when the result of EditorCommand::GetParamType(aCommand)
359 * includes EditorCommandParamType::Bool. If aBoolParam is Nothing, it
360 * means that given param was nullptr.
362 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam(
363 Command aCommand, const Maybe<bool>& aBoolParam, EditorBase& aEditorBase,
364 nsIPrincipal* aPrincipal) const {
365 MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
366 return NS_ERROR_NOT_IMPLEMENTED;
370 * Called only when the result of EditorCommand::GetParamType(aCommand)
371 * includes EditorCommandParamType::CString. If aCStringParam is void, it
372 * means that given param was nullptr.
374 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam(
375 Command aCommand, const nsACString& aCStringParam,
376 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const {
377 MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
378 return NS_ERROR_NOT_IMPLEMENTED;
382 * Called only when the result of EditorCommand::GetParamType(aCommand)
383 * includes EditorCommandParamType::String. If aStringParam is void, it
384 * means that given param was nullptr.
386 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam(
387 Command aCommand, const nsAString& aStringParam, EditorBase& aEditorBase,
388 nsIPrincipal* aPrincipal) const {
389 MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
390 return NS_ERROR_NOT_IMPLEMENTED;
394 * Called only when the result of EditorCommand::GetParamType(aCommand) is
395 * EditorCommandParamType::Transferable. If aTransferableParam may be
396 * nullptr.
398 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam(
399 Command aCommand, nsITransferable* aTransferableParam,
400 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const {
401 MOZ_ASSERT_UNREACHABLE("Wrong overload is called");
402 return NS_ERROR_NOT_IMPLEMENTED;
405 protected:
406 EditorCommand() = default;
407 virtual ~EditorCommand() = default;
410 #define NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
411 public: \
412 MOZ_CAN_RUN_SCRIPT virtual bool IsCommandEnabled( \
413 Command aCommand, EditorBase* aEditorBase) const final; \
414 using EditorCommand::IsCommandEnabled; \
415 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommand( \
416 Command aCommand, EditorBase& aEditorBase, nsIPrincipal* aPrincipal) \
417 const final; \
418 using EditorCommand::DoCommand; \
419 MOZ_CAN_RUN_SCRIPT virtual nsresult GetCommandStateParams( \
420 Command aCommand, nsCommandParams& aParams, EditorBase* aEditorBase, \
421 nsIEditingSession* aEditingSession) const final; \
422 using EditorCommand::GetCommandStateParams; \
423 using EditorCommand::DoCommandParam;
425 #define NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND \
426 public: \
427 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam( \
428 Command aCommand, EditorBase& aEditorBase, nsIPrincipal* aPrincipal) \
429 const final { \
430 return DoCommand(aCommand, aEditorBase, aPrincipal); \
433 #define NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM \
434 public: \
435 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam( \
436 Command aCommand, const Maybe<bool>& aBoolParam, \
437 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const final;
439 #define NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM \
440 public: \
441 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam( \
442 Command aCommand, const nsACString& aCStringParam, \
443 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const final;
445 #define NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM \
446 public: \
447 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam( \
448 Command aCommand, const nsAString& aStringParam, \
449 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const final;
451 #define NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM \
452 public: \
453 MOZ_CAN_RUN_SCRIPT virtual nsresult DoCommandParam( \
454 Command aCommand, nsITransferable* aTransferableParam, \
455 EditorBase& aEditorBase, nsIPrincipal* aPrincipal) const final;
457 #define NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
458 public: \
459 static EditorCommand* GetInstance() { \
460 if (!sInstance) { \
461 sInstance = new _cmd(); \
463 return sInstance; \
466 static void Shutdown() { sInstance = nullptr; } \
468 private: \
469 static StaticRefPtr<_cmd> sInstance;
471 #define NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(_cmd) \
472 class _cmd final : public EditorCommand { \
473 NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
474 NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND \
475 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
477 protected: \
478 _cmd() = default; \
479 virtual ~_cmd() = default; \
482 #define NS_DECL_EDITOR_COMMAND_FOR_BOOL_PARAM(_cmd) \
483 class _cmd final : public EditorCommand { \
484 NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
485 NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM \
486 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
488 protected: \
489 _cmd() = default; \
490 virtual ~_cmd() = default; \
493 #define NS_DECL_EDITOR_COMMAND_FOR_CSTRING_PARAM(_cmd) \
494 class _cmd final : public EditorCommand { \
495 NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
496 NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM \
497 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
499 protected: \
500 _cmd() = default; \
501 virtual ~_cmd() = default; \
504 #define NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(_cmd) \
505 class _cmd final : public EditorCommand { \
506 NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
507 NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM \
508 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
510 protected: \
511 _cmd() = default; \
512 virtual ~_cmd() = default; \
515 #define NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM(_cmd) \
516 class _cmd final : public EditorCommand { \
517 NS_DECL_EDITOR_COMMAND_COMMON_METHODS \
518 NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM \
519 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
521 protected: \
522 _cmd() = default; \
523 virtual ~_cmd() = default; \
526 // basic editor commands
527 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(UndoCommand)
528 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RedoCommand)
530 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CutCommand)
531 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CutOrDeleteCommand)
532 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CopyCommand)
533 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(CopyOrDeleteCommand)
534 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteCommand)
535 NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM(PasteTransferableCommand)
536 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SwitchTextDirectionCommand)
537 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DeleteCommand)
538 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SelectAllCommand)
540 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(SelectionMoveCommands)
542 // Insert content commands
543 NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(InsertPlaintextCommand)
544 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(InsertParagraphCommand)
545 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(InsertLineBreakCommand)
546 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteQuotationCommand)
548 /******************************************************************************
549 * Commands for HTML editor
550 ******************************************************************************/
552 // virtual base class for commands that need to save and update Boolean state
553 // (like styles etc)
554 class StateUpdatingCommandBase : public EditorCommand {
555 public:
556 NS_INLINE_DECL_REFCOUNTING_INHERITED(StateUpdatingCommandBase, EditorCommand)
558 NS_DECL_EDITOR_COMMAND_COMMON_METHODS
559 NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
561 protected:
562 StateUpdatingCommandBase() = default;
563 virtual ~StateUpdatingCommandBase() = default;
565 // get the current state (on or off) for this style or block format
566 MOZ_CAN_RUN_SCRIPT virtual nsresult GetCurrentState(
567 nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
568 nsCommandParams& aParams) const = 0;
570 // add/remove the style
571 MOZ_CAN_RUN_SCRIPT virtual nsresult ToggleState(
572 nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
573 nsIPrincipal* aPrincipal) const = 0;
575 static nsStaticAtom* GetTagName(Command aCommand) {
576 switch (aCommand) {
577 case Command::FormatBold:
578 return nsGkAtoms::b;
579 case Command::FormatItalic:
580 return nsGkAtoms::i;
581 case Command::FormatUnderline:
582 return nsGkAtoms::u;
583 case Command::FormatTeletypeText:
584 return nsGkAtoms::tt;
585 case Command::FormatStrikeThrough:
586 return nsGkAtoms::strike;
587 case Command::FormatSuperscript:
588 return nsGkAtoms::sup;
589 case Command::FormatSubscript:
590 return nsGkAtoms::sub;
591 case Command::FormatNoBreak:
592 return nsGkAtoms::nobr;
593 case Command::FormatEmphasis:
594 return nsGkAtoms::em;
595 case Command::FormatStrong:
596 return nsGkAtoms::strong;
597 case Command::FormatCitation:
598 return nsGkAtoms::cite;
599 case Command::FormatAbbreviation:
600 return nsGkAtoms::abbr;
601 case Command::FormatAcronym:
602 return nsGkAtoms::acronym;
603 case Command::FormatCode:
604 return nsGkAtoms::code;
605 case Command::FormatSample:
606 return nsGkAtoms::samp;
607 case Command::FormatVariable:
608 return nsGkAtoms::var;
609 case Command::FormatRemoveLink:
610 return nsGkAtoms::href;
611 case Command::InsertOrderedList:
612 return nsGkAtoms::ol;
613 case Command::InsertUnorderedList:
614 return nsGkAtoms::ul;
615 case Command::InsertDefinitionTerm:
616 return nsGkAtoms::dt;
617 case Command::InsertDefinitionDetails:
618 return nsGkAtoms::dd;
619 case Command::FormatAbsolutePosition:
620 return nsGkAtoms::_empty;
621 default:
622 return nullptr;
625 friend class InsertTagCommand; // for allowing it to access GetTagName()
628 // Shared class for the various style updating commands like bold, italics etc.
629 // Suitable for commands whose state is either 'on' or 'off'.
630 class StyleUpdatingCommand final : public StateUpdatingCommandBase {
631 public:
632 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(StyleUpdatingCommand)
634 protected:
635 StyleUpdatingCommand() = default;
636 virtual ~StyleUpdatingCommand() = default;
638 // get the current state (on or off) for this style or block format
639 MOZ_CAN_RUN_SCRIPT nsresult
640 GetCurrentState(nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
641 nsCommandParams& aParams) const final;
643 // add/remove the style
644 MOZ_CAN_RUN_SCRIPT nsresult ToggleState(nsStaticAtom& aTagName,
645 HTMLEditor& aHTMLEditor,
646 nsIPrincipal* aPrincipal) const final;
649 class InsertTagCommand final : public EditorCommand {
650 public:
651 NS_INLINE_DECL_REFCOUNTING_INHERITED(InsertTagCommand, EditorCommand)
653 NS_DECL_EDITOR_COMMAND_COMMON_METHODS
654 NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
655 NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
656 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(InsertTagCommand)
658 protected:
659 InsertTagCommand() = default;
660 virtual ~InsertTagCommand() = default;
662 static nsAtom* GetTagName(Command aCommand) {
663 switch (aCommand) {
664 case Command::InsertLink:
665 return nsGkAtoms::a;
666 case Command::InsertImage:
667 return nsGkAtoms::img;
668 case Command::InsertHorizontalRule:
669 return nsGkAtoms::hr;
670 default:
671 return StateUpdatingCommandBase::GetTagName(aCommand);
676 class ListCommand final : public StateUpdatingCommandBase {
677 public:
678 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListCommand)
680 protected:
681 ListCommand() = default;
682 virtual ~ListCommand() = default;
684 // get the current state (on or off) for this style or block format
685 MOZ_CAN_RUN_SCRIPT nsresult
686 GetCurrentState(nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
687 nsCommandParams& aParams) const final;
689 // add/remove the style
690 MOZ_CAN_RUN_SCRIPT nsresult ToggleState(nsStaticAtom& aTagName,
691 HTMLEditor& aHTMLEditor,
692 nsIPrincipal* aPrincipal) const final;
695 class ListItemCommand final : public StateUpdatingCommandBase {
696 public:
697 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListItemCommand)
699 protected:
700 ListItemCommand() = default;
701 virtual ~ListItemCommand() = default;
703 // get the current state (on or off) for this style or block format
704 MOZ_CAN_RUN_SCRIPT nsresult
705 GetCurrentState(nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
706 nsCommandParams& aParams) const final;
708 // add/remove the style
709 MOZ_CAN_RUN_SCRIPT nsresult ToggleState(nsStaticAtom& aTagName,
710 HTMLEditor& aHTMLEditor,
711 nsIPrincipal* aPrincipal) const final;
714 // Base class for commands whose state consists of a string (e.g. para format)
715 class MultiStateCommandBase : public EditorCommand {
716 public:
717 NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase, EditorCommand)
719 NS_DECL_EDITOR_COMMAND_COMMON_METHODS
720 NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
722 protected:
723 MultiStateCommandBase() = default;
724 virtual ~MultiStateCommandBase() = default;
726 MOZ_CAN_RUN_SCRIPT virtual nsresult GetCurrentState(
727 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const = 0;
728 MOZ_CAN_RUN_SCRIPT virtual nsresult SetState(
729 HTMLEditor* aHTMLEditor, const nsAString& aNewState,
730 nsIPrincipal* aPrincipal) const = 0;
734 * The command class for Document.execCommand("formatBlock"),
735 * Document.queryCommandValue("formatBlock") etc.
737 class FormatBlockStateCommand final : public MultiStateCommandBase {
738 public:
739 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FormatBlockStateCommand)
741 protected:
742 FormatBlockStateCommand() = default;
743 virtual ~FormatBlockStateCommand() = default;
745 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
746 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
747 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
748 const nsAString& aNewState,
749 nsIPrincipal* aPrincipal) const final;
753 * The command class for the legacy XUL edit command, cmd_paragraphState.
754 * This command treats only <p>, <pre>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>,
755 * <address> as a format node.
757 class ParagraphStateCommand final : public MultiStateCommandBase {
758 public:
759 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ParagraphStateCommand)
761 protected:
762 ParagraphStateCommand() = default;
763 virtual ~ParagraphStateCommand() = default;
765 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
766 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
767 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
768 const nsAString& aNewState,
769 nsIPrincipal* aPrincipal) const final;
772 class FontFaceStateCommand final : public MultiStateCommandBase {
773 public:
774 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontFaceStateCommand)
776 protected:
777 FontFaceStateCommand() = default;
778 virtual ~FontFaceStateCommand() = default;
780 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
781 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
782 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
783 const nsAString& aNewState,
784 nsIPrincipal* aPrincipal) const final;
787 class FontSizeStateCommand final : public MultiStateCommandBase {
788 public:
789 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontSizeStateCommand)
791 protected:
792 FontSizeStateCommand() = default;
793 virtual ~FontSizeStateCommand() = default;
795 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
796 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
797 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
798 const nsAString& aNewState,
799 nsIPrincipal* aPrincipal) const final;
802 class HighlightColorStateCommand final : public MultiStateCommandBase {
803 public:
804 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(HighlightColorStateCommand)
806 protected:
807 HighlightColorStateCommand() = default;
808 virtual ~HighlightColorStateCommand() = default;
810 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
811 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
812 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
813 const nsAString& aNewState,
814 nsIPrincipal* aPrincipal) const final;
817 class FontColorStateCommand final : public MultiStateCommandBase {
818 public:
819 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontColorStateCommand)
821 protected:
822 FontColorStateCommand() = default;
823 virtual ~FontColorStateCommand() = default;
825 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
826 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
827 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
828 const nsAString& aNewState,
829 nsIPrincipal* aPrincipal) const final;
832 class AlignCommand final : public MultiStateCommandBase {
833 public:
834 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AlignCommand)
836 protected:
837 AlignCommand() = default;
838 virtual ~AlignCommand() = default;
840 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
841 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
842 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
843 const nsAString& aNewState,
844 nsIPrincipal* aPrincipal) const final;
847 class BackgroundColorStateCommand final : public MultiStateCommandBase {
848 public:
849 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(BackgroundColorStateCommand)
851 protected:
852 BackgroundColorStateCommand() = default;
853 virtual ~BackgroundColorStateCommand() = default;
855 MOZ_CAN_RUN_SCRIPT nsresult GetCurrentState(
856 HTMLEditor* aHTMLEditor, nsCommandParams& aParams) const final;
857 MOZ_CAN_RUN_SCRIPT nsresult SetState(HTMLEditor* aHTMLEditor,
858 const nsAString& aNewState,
859 nsIPrincipal* aPrincipal) const final;
862 class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
863 public:
864 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AbsolutePositioningCommand)
866 protected:
867 AbsolutePositioningCommand() = default;
868 virtual ~AbsolutePositioningCommand() = default;
870 MOZ_CAN_RUN_SCRIPT nsresult
871 GetCurrentState(nsStaticAtom& aTagName, HTMLEditor& aHTMLEditor,
872 nsCommandParams& aParams) const final;
873 MOZ_CAN_RUN_SCRIPT nsresult ToggleState(nsStaticAtom& aTagName,
874 HTMLEditor& aHTMLEditor,
875 nsIPrincipal* aPrincipal) const final;
878 // composer commands
880 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DocumentStateCommand)
882 class SetDocumentStateCommand final : public EditorCommand {
883 public:
884 NS_INLINE_DECL_REFCOUNTING_INHERITED(SetDocumentStateCommand, EditorCommand)
886 NS_DECL_EDITOR_COMMAND_COMMON_METHODS
887 NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM
888 NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM
889 NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(SetDocumentStateCommand)
891 private:
892 SetDocumentStateCommand() = default;
893 virtual ~SetDocumentStateCommand() = default;
896 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DecreaseZIndexCommand)
897 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IncreaseZIndexCommand)
899 // Generic commands
901 // Edit menu
902 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(PasteNoFormattingCommand)
904 // Block transformations
905 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IndentCommand)
906 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(OutdentCommand)
908 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RemoveListCommand)
909 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(RemoveStylesCommand)
910 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(IncreaseFontSizeCommand)
911 NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE(DecreaseFontSizeCommand)
913 // Insert content commands
914 NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM(InsertHTMLCommand)
916 #undef NS_DECL_EDITOR_COMMAND_FOR_NO_PARAM_WITH_DELEGATE
917 #undef NS_DECL_EDITOR_COMMAND_FOR_BOOL_PARAM
918 #undef NS_DECL_EDITOR_COMMAND_FOR_CSTRING_PARAM
919 #undef NS_DECL_EDITOR_COMMAND_FOR_STRING_PARAM
920 #undef NS_DECL_EDITOR_COMMAND_FOR_TRANSFERABLE_PARAM
921 #undef NS_DECL_EDITOR_COMMAND_COMMON_METHODS
922 #undef NS_DECL_DO_COMMAND_PARAM_DELEGATE_TO_DO_COMMAND
923 #undef NS_DECL_DO_COMMAND_PARAM_FOR_BOOL_PARAM
924 #undef NS_DECL_DO_COMMAND_PARAM_FOR_CSTRING_PARAM
925 #undef NS_DECL_DO_COMMAND_PARAM_FOR_STRING_PARAM
926 #undef NS_DECL_DO_COMMAND_PARAM_FOR_TRANSFERABLE_PARAM
927 #undef NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON
929 } // namespace mozilla
931 #endif // #ifndef mozilla_EditorCommands_h