editor/composer/src/nsComposerCommands.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsComposerCommands_h_
michael@0 7 #define nsComposerCommands_h_
michael@0 8
michael@0 9 #include "nsIControllerCommand.h"
michael@0 10 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc
michael@0 11 #include "nscore.h" // for nsresult, NS_IMETHOD
michael@0 12
michael@0 13 class nsIAtom;
michael@0 14 class nsICommandParams;
michael@0 15 class nsIEditor;
michael@0 16 class nsISupports;
michael@0 17 class nsString;
michael@0 18
michael@0 19 // This is a virtual base class for commands registered with the composer controller.
michael@0 20 // Note that such commands are instantiated once per composer, so can store state.
michael@0 21 // Also note that IsCommandEnabled can be called with an editor that may not
michael@0 22 // have an editor yet (because the document is loading). Most commands will want
michael@0 23 // to return false in this case.
michael@0 24 // Don't hold on to any references to the editor or document from
michael@0 25 // your command. This will cause leaks. Also, be aware that the document the
michael@0 26 // editor is editing can change under you (if the user Reverts the file, for
michael@0 27 // instance).
michael@0 28 class nsBaseComposerCommand : public nsIControllerCommand
michael@0 29 {
michael@0 30 public:
michael@0 31
michael@0 32 nsBaseComposerCommand();
michael@0 33 virtual ~nsBaseComposerCommand() {}
michael@0 34
michael@0 35 // nsISupports
michael@0 36 NS_DECL_ISUPPORTS
michael@0 37
michael@0 38 // nsIControllerCommand. Declared longhand so we can make them pure virtual
michael@0 39 NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) = 0;
michael@0 40 NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0;
michael@0 41
michael@0 42 };
michael@0 43
michael@0 44
michael@0 45 #define NS_DECL_COMPOSER_COMMAND(_cmd) \
michael@0 46 class _cmd : public nsBaseComposerCommand \
michael@0 47 { \
michael@0 48 public: \
michael@0 49 NS_DECL_NSICONTROLLERCOMMAND \
michael@0 50 };
michael@0 51
michael@0 52 // virtual base class for commands that need to save and update Boolean state (like styles etc)
michael@0 53 class nsBaseStateUpdatingCommand : public nsBaseComposerCommand
michael@0 54 {
michael@0 55 public:
michael@0 56 nsBaseStateUpdatingCommand(nsIAtom* aTagName);
michael@0 57 virtual ~nsBaseStateUpdatingCommand();
michael@0 58
michael@0 59 NS_DECL_ISUPPORTS_INHERITED
michael@0 60
michael@0 61 NS_DECL_NSICONTROLLERCOMMAND
michael@0 62
michael@0 63 protected:
michael@0 64
michael@0 65 // get the current state (on or off) for this style or block format
michael@0 66 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0;
michael@0 67
michael@0 68 // add/remove the style
michael@0 69 virtual nsresult ToggleState(nsIEditor* aEditor) = 0;
michael@0 70
michael@0 71 protected:
michael@0 72 nsIAtom* mTagName;
michael@0 73 };
michael@0 74
michael@0 75
michael@0 76 // Shared class for the various style updating commands like bold, italics etc.
michael@0 77 // Suitable for commands whose state is either 'on' or 'off'.
michael@0 78 class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand
michael@0 79 {
michael@0 80 public:
michael@0 81 nsStyleUpdatingCommand(nsIAtom* aTagName);
michael@0 82
michael@0 83 protected:
michael@0 84
michael@0 85 // get the current state (on or off) for this style or block format
michael@0 86 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
michael@0 87
michael@0 88 // add/remove the style
michael@0 89 virtual nsresult ToggleState(nsIEditor* aEditor);
michael@0 90 };
michael@0 91
michael@0 92
michael@0 93 class nsInsertTagCommand : public nsBaseComposerCommand
michael@0 94 {
michael@0 95 public:
michael@0 96 explicit nsInsertTagCommand(nsIAtom* aTagName);
michael@0 97 virtual ~nsInsertTagCommand();
michael@0 98
michael@0 99 NS_DECL_ISUPPORTS_INHERITED
michael@0 100
michael@0 101 NS_DECL_NSICONTROLLERCOMMAND
michael@0 102
michael@0 103 protected:
michael@0 104
michael@0 105 nsIAtom* mTagName;
michael@0 106 };
michael@0 107
michael@0 108
michael@0 109 class nsListCommand : public nsBaseStateUpdatingCommand
michael@0 110 {
michael@0 111 public:
michael@0 112 nsListCommand(nsIAtom* aTagName);
michael@0 113
michael@0 114 protected:
michael@0 115
michael@0 116 // get the current state (on or off) for this style or block format
michael@0 117 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
michael@0 118
michael@0 119 // add/remove the style
michael@0 120 virtual nsresult ToggleState(nsIEditor* aEditor);
michael@0 121 };
michael@0 122
michael@0 123 class nsListItemCommand : public nsBaseStateUpdatingCommand
michael@0 124 {
michael@0 125 public:
michael@0 126 nsListItemCommand(nsIAtom* aTagName);
michael@0 127
michael@0 128 protected:
michael@0 129
michael@0 130 // get the current state (on or off) for this style or block format
michael@0 131 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
michael@0 132
michael@0 133 // add/remove the style
michael@0 134 virtual nsresult ToggleState(nsIEditor* aEditor);
michael@0 135 };
michael@0 136
michael@0 137 // Base class for commands whose state consists of a string (e.g. para format)
michael@0 138 class nsMultiStateCommand : public nsBaseComposerCommand
michael@0 139 {
michael@0 140 public:
michael@0 141
michael@0 142 nsMultiStateCommand();
michael@0 143 virtual ~nsMultiStateCommand();
michael@0 144
michael@0 145 NS_DECL_ISUPPORTS_INHERITED
michael@0 146 NS_DECL_NSICONTROLLERCOMMAND
michael@0 147
michael@0 148 protected:
michael@0 149
michael@0 150 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0;
michael@0 151 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0;
michael@0 152
michael@0 153 };
michael@0 154
michael@0 155
michael@0 156 class nsParagraphStateCommand : public nsMultiStateCommand
michael@0 157 {
michael@0 158 public:
michael@0 159 nsParagraphStateCommand();
michael@0 160
michael@0 161 protected:
michael@0 162
michael@0 163 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 164 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 165 };
michael@0 166
michael@0 167 class nsFontFaceStateCommand : public nsMultiStateCommand
michael@0 168 {
michael@0 169 public:
michael@0 170 nsFontFaceStateCommand();
michael@0 171
michael@0 172 protected:
michael@0 173
michael@0 174 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 175 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 176 };
michael@0 177
michael@0 178 class nsFontSizeStateCommand : public nsMultiStateCommand
michael@0 179 {
michael@0 180 public:
michael@0 181 nsFontSizeStateCommand();
michael@0 182
michael@0 183 protected:
michael@0 184
michael@0 185 virtual nsresult GetCurrentState(nsIEditor *aEditor,
michael@0 186 nsICommandParams* aParams);
michael@0 187 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 188 };
michael@0 189
michael@0 190 class nsHighlightColorStateCommand : public nsMultiStateCommand
michael@0 191 {
michael@0 192 public:
michael@0 193 nsHighlightColorStateCommand();
michael@0 194
michael@0 195 protected:
michael@0 196
michael@0 197 NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
michael@0 198 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 199 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 200
michael@0 201 };
michael@0 202
michael@0 203 class nsFontColorStateCommand : public nsMultiStateCommand
michael@0 204 {
michael@0 205 public:
michael@0 206 nsFontColorStateCommand();
michael@0 207
michael@0 208 protected:
michael@0 209
michael@0 210 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 211 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 212 };
michael@0 213
michael@0 214 class nsAlignCommand : public nsMultiStateCommand
michael@0 215 {
michael@0 216 public:
michael@0 217 nsAlignCommand();
michael@0 218
michael@0 219 protected:
michael@0 220
michael@0 221 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 222 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 223 };
michael@0 224
michael@0 225 class nsBackgroundColorStateCommand : public nsMultiStateCommand
michael@0 226 {
michael@0 227 public:
michael@0 228 nsBackgroundColorStateCommand();
michael@0 229
michael@0 230 protected:
michael@0 231
michael@0 232 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
michael@0 233 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
michael@0 234 };
michael@0 235
michael@0 236 class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand
michael@0 237 {
michael@0 238 public:
michael@0 239 nsAbsolutePositioningCommand();
michael@0 240
michael@0 241 protected:
michael@0 242
michael@0 243 NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
michael@0 244 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
michael@0 245 virtual nsresult ToggleState(nsIEditor* aEditor);
michael@0 246 };
michael@0 247
michael@0 248 // composer commands
michael@0 249
michael@0 250 NS_DECL_COMPOSER_COMMAND(nsCloseCommand)
michael@0 251 NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand)
michael@0 252 NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand)
michael@0 253 NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand)
michael@0 254 //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands)
michael@0 255
michael@0 256 NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand)
michael@0 257 NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand)
michael@0 258
michael@0 259 // Generic commands
michael@0 260
michael@0 261 // File menu
michael@0 262 NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything
michael@0 263
michael@0 264 // Edit menu
michael@0 265 NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand)
michael@0 266
michael@0 267 // Block transformations
michael@0 268 NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
michael@0 269 NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
michael@0 270
michael@0 271 NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
michael@0 272 NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
michael@0 273 NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
michael@0 274 NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)
michael@0 275
michael@0 276 // Insert content commands
michael@0 277 NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand)
michael@0 278
michael@0 279 #endif // nsComposerCommands_h_

mercurial