1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/composer/src/nsComposerCommands.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,279 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsComposerCommands_h_ 1.10 +#define nsComposerCommands_h_ 1.11 + 1.12 +#include "nsIControllerCommand.h" 1.13 +#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc 1.14 +#include "nscore.h" // for nsresult, NS_IMETHOD 1.15 + 1.16 +class nsIAtom; 1.17 +class nsICommandParams; 1.18 +class nsIEditor; 1.19 +class nsISupports; 1.20 +class nsString; 1.21 + 1.22 +// This is a virtual base class for commands registered with the composer controller. 1.23 +// Note that such commands are instantiated once per composer, so can store state. 1.24 +// Also note that IsCommandEnabled can be called with an editor that may not 1.25 +// have an editor yet (because the document is loading). Most commands will want 1.26 +// to return false in this case. 1.27 +// Don't hold on to any references to the editor or document from 1.28 +// your command. This will cause leaks. Also, be aware that the document the 1.29 +// editor is editing can change under you (if the user Reverts the file, for 1.30 +// instance). 1.31 +class nsBaseComposerCommand : public nsIControllerCommand 1.32 +{ 1.33 +public: 1.34 + 1.35 + nsBaseComposerCommand(); 1.36 + virtual ~nsBaseComposerCommand() {} 1.37 + 1.38 + // nsISupports 1.39 + NS_DECL_ISUPPORTS 1.40 + 1.41 + // nsIControllerCommand. Declared longhand so we can make them pure virtual 1.42 + NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) = 0; 1.43 + NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0; 1.44 + 1.45 +}; 1.46 + 1.47 + 1.48 +#define NS_DECL_COMPOSER_COMMAND(_cmd) \ 1.49 +class _cmd : public nsBaseComposerCommand \ 1.50 +{ \ 1.51 +public: \ 1.52 + NS_DECL_NSICONTROLLERCOMMAND \ 1.53 +}; 1.54 + 1.55 +// virtual base class for commands that need to save and update Boolean state (like styles etc) 1.56 +class nsBaseStateUpdatingCommand : public nsBaseComposerCommand 1.57 +{ 1.58 +public: 1.59 + nsBaseStateUpdatingCommand(nsIAtom* aTagName); 1.60 + virtual ~nsBaseStateUpdatingCommand(); 1.61 + 1.62 + NS_DECL_ISUPPORTS_INHERITED 1.63 + 1.64 + NS_DECL_NSICONTROLLERCOMMAND 1.65 + 1.66 +protected: 1.67 + 1.68 + // get the current state (on or off) for this style or block format 1.69 + virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0; 1.70 + 1.71 + // add/remove the style 1.72 + virtual nsresult ToggleState(nsIEditor* aEditor) = 0; 1.73 + 1.74 +protected: 1.75 + nsIAtom* mTagName; 1.76 +}; 1.77 + 1.78 + 1.79 +// Shared class for the various style updating commands like bold, italics etc. 1.80 +// Suitable for commands whose state is either 'on' or 'off'. 1.81 +class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand 1.82 +{ 1.83 +public: 1.84 + nsStyleUpdatingCommand(nsIAtom* aTagName); 1.85 + 1.86 +protected: 1.87 + 1.88 + // get the current state (on or off) for this style or block format 1.89 + virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); 1.90 + 1.91 + // add/remove the style 1.92 + virtual nsresult ToggleState(nsIEditor* aEditor); 1.93 +}; 1.94 + 1.95 + 1.96 +class nsInsertTagCommand : public nsBaseComposerCommand 1.97 +{ 1.98 +public: 1.99 + explicit nsInsertTagCommand(nsIAtom* aTagName); 1.100 + virtual ~nsInsertTagCommand(); 1.101 + 1.102 + NS_DECL_ISUPPORTS_INHERITED 1.103 + 1.104 + NS_DECL_NSICONTROLLERCOMMAND 1.105 + 1.106 +protected: 1.107 + 1.108 + nsIAtom* mTagName; 1.109 +}; 1.110 + 1.111 + 1.112 +class nsListCommand : public nsBaseStateUpdatingCommand 1.113 +{ 1.114 +public: 1.115 + nsListCommand(nsIAtom* aTagName); 1.116 + 1.117 +protected: 1.118 + 1.119 + // get the current state (on or off) for this style or block format 1.120 + virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); 1.121 + 1.122 + // add/remove the style 1.123 + virtual nsresult ToggleState(nsIEditor* aEditor); 1.124 +}; 1.125 + 1.126 +class nsListItemCommand : public nsBaseStateUpdatingCommand 1.127 +{ 1.128 +public: 1.129 + nsListItemCommand(nsIAtom* aTagName); 1.130 + 1.131 +protected: 1.132 + 1.133 + // get the current state (on or off) for this style or block format 1.134 + virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); 1.135 + 1.136 + // add/remove the style 1.137 + virtual nsresult ToggleState(nsIEditor* aEditor); 1.138 +}; 1.139 + 1.140 +// Base class for commands whose state consists of a string (e.g. para format) 1.141 +class nsMultiStateCommand : public nsBaseComposerCommand 1.142 +{ 1.143 +public: 1.144 + 1.145 + nsMultiStateCommand(); 1.146 + virtual ~nsMultiStateCommand(); 1.147 + 1.148 + NS_DECL_ISUPPORTS_INHERITED 1.149 + NS_DECL_NSICONTROLLERCOMMAND 1.150 + 1.151 +protected: 1.152 + 1.153 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0; 1.154 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0; 1.155 + 1.156 +}; 1.157 + 1.158 + 1.159 +class nsParagraphStateCommand : public nsMultiStateCommand 1.160 +{ 1.161 +public: 1.162 + nsParagraphStateCommand(); 1.163 + 1.164 +protected: 1.165 + 1.166 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.167 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.168 +}; 1.169 + 1.170 +class nsFontFaceStateCommand : public nsMultiStateCommand 1.171 +{ 1.172 +public: 1.173 + nsFontFaceStateCommand(); 1.174 + 1.175 +protected: 1.176 + 1.177 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.178 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.179 +}; 1.180 + 1.181 +class nsFontSizeStateCommand : public nsMultiStateCommand 1.182 +{ 1.183 +public: 1.184 + nsFontSizeStateCommand(); 1.185 + 1.186 +protected: 1.187 + 1.188 + virtual nsresult GetCurrentState(nsIEditor *aEditor, 1.189 + nsICommandParams* aParams); 1.190 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.191 +}; 1.192 + 1.193 +class nsHighlightColorStateCommand : public nsMultiStateCommand 1.194 +{ 1.195 +public: 1.196 + nsHighlightColorStateCommand(); 1.197 + 1.198 +protected: 1.199 + 1.200 + NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); 1.201 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.202 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.203 + 1.204 +}; 1.205 + 1.206 +class nsFontColorStateCommand : public nsMultiStateCommand 1.207 +{ 1.208 +public: 1.209 + nsFontColorStateCommand(); 1.210 + 1.211 +protected: 1.212 + 1.213 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.214 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.215 +}; 1.216 + 1.217 +class nsAlignCommand : public nsMultiStateCommand 1.218 +{ 1.219 +public: 1.220 + nsAlignCommand(); 1.221 + 1.222 +protected: 1.223 + 1.224 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.225 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.226 +}; 1.227 + 1.228 +class nsBackgroundColorStateCommand : public nsMultiStateCommand 1.229 +{ 1.230 +public: 1.231 + nsBackgroundColorStateCommand(); 1.232 + 1.233 +protected: 1.234 + 1.235 + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); 1.236 + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); 1.237 +}; 1.238 + 1.239 +class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand 1.240 +{ 1.241 +public: 1.242 + nsAbsolutePositioningCommand(); 1.243 + 1.244 +protected: 1.245 + 1.246 + NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); 1.247 + virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); 1.248 + virtual nsresult ToggleState(nsIEditor* aEditor); 1.249 +}; 1.250 + 1.251 +// composer commands 1.252 + 1.253 +NS_DECL_COMPOSER_COMMAND(nsCloseCommand) 1.254 +NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand) 1.255 +NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand) 1.256 +NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand) 1.257 +//NS_DECL_COMPOSER_COMMAND(nsPrintingCommands) 1.258 + 1.259 +NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand) 1.260 +NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand) 1.261 + 1.262 +// Generic commands 1.263 + 1.264 +// File menu 1.265 +NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything 1.266 + 1.267 +// Edit menu 1.268 +NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand) 1.269 + 1.270 +// Block transformations 1.271 +NS_DECL_COMPOSER_COMMAND(nsIndentCommand) 1.272 +NS_DECL_COMPOSER_COMMAND(nsOutdentCommand) 1.273 + 1.274 +NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand) 1.275 +NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand) 1.276 +NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand) 1.277 +NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand) 1.278 + 1.279 +// Insert content commands 1.280 +NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand) 1.281 + 1.282 +#endif // nsComposerCommands_h_