editor/composer/src/nsComposerCommands.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 nsComposerCommands_h_
     7 #define nsComposerCommands_h_
     9 #include "nsIControllerCommand.h"
    10 #include "nsISupportsImpl.h"            // for NS_DECL_ISUPPORTS_INHERITED, etc
    11 #include "nscore.h"                     // for nsresult, NS_IMETHOD
    13 class nsIAtom;
    14 class nsICommandParams;
    15 class nsIEditor;
    16 class nsISupports;
    17 class nsString;
    19 // This is a virtual base class for commands registered with the composer controller.
    20 // Note that such commands are instantiated once per composer, so can store state.
    21 // Also note that IsCommandEnabled can be called with an editor that may not
    22 // have an editor yet (because the document is loading). Most commands will want
    23 // to return false in this case.
    24 // Don't hold on to any references to the editor or document from
    25 // your command. This will cause leaks. Also, be aware that the document the
    26 // editor is editing can change under you (if the user Reverts the file, for
    27 // instance).
    28 class nsBaseComposerCommand : public nsIControllerCommand
    29 {
    30 public:
    32               nsBaseComposerCommand();
    33   virtual     ~nsBaseComposerCommand() {}
    35   // nsISupports
    36   NS_DECL_ISUPPORTS
    38   // nsIControllerCommand. Declared longhand so we can make them pure virtual
    39   NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) = 0;
    40   NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0;
    42 };
    45 #define NS_DECL_COMPOSER_COMMAND(_cmd)                  \
    46 class _cmd : public nsBaseComposerCommand               \
    47 {                                                       \
    48 public:                                                 \
    49   NS_DECL_NSICONTROLLERCOMMAND                          \
    50 };
    52 // virtual base class for commands that need to save and update Boolean state (like styles etc)
    53 class nsBaseStateUpdatingCommand : public nsBaseComposerCommand
    54 {
    55 public:
    56   nsBaseStateUpdatingCommand(nsIAtom* aTagName);
    57   virtual ~nsBaseStateUpdatingCommand();
    59   NS_DECL_ISUPPORTS_INHERITED
    61   NS_DECL_NSICONTROLLERCOMMAND
    63 protected:
    65   // get the current state (on or off) for this style or block format
    66   virtual nsresult  GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0;
    68   // add/remove the style
    69   virtual nsresult  ToggleState(nsIEditor* aEditor) = 0;
    71 protected:
    72   nsIAtom* mTagName;
    73 };
    76 // Shared class for the various style updating commands like bold, italics etc.
    77 // Suitable for commands whose state is either 'on' or 'off'.
    78 class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand
    79 {
    80 public:
    81   nsStyleUpdatingCommand(nsIAtom* aTagName);
    83 protected:
    85   // get the current state (on or off) for this style or block format
    86   virtual nsresult  GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
    88   // add/remove the style
    89   virtual nsresult  ToggleState(nsIEditor* aEditor);
    90 };
    93 class nsInsertTagCommand : public nsBaseComposerCommand
    94 {
    95 public:
    96   explicit nsInsertTagCommand(nsIAtom* aTagName);
    97   virtual     ~nsInsertTagCommand();
    99   NS_DECL_ISUPPORTS_INHERITED
   101   NS_DECL_NSICONTROLLERCOMMAND
   103 protected:
   105   nsIAtom* mTagName;
   106 };
   109 class nsListCommand : public nsBaseStateUpdatingCommand
   110 {
   111 public:
   112   nsListCommand(nsIAtom* aTagName);
   114 protected:
   116   // get the current state (on or off) for this style or block format
   117   virtual nsresult  GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
   119   // add/remove the style
   120   virtual nsresult  ToggleState(nsIEditor* aEditor);
   121 };
   123 class nsListItemCommand : public nsBaseStateUpdatingCommand
   124 {
   125 public:
   126   nsListItemCommand(nsIAtom* aTagName);
   128 protected:
   130   // get the current state (on or off) for this style or block format
   131   virtual nsresult  GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
   133   // add/remove the style
   134   virtual nsresult  ToggleState(nsIEditor* aEditor);
   135 };
   137 // Base class for commands whose state consists of a string (e.g. para format)
   138 class nsMultiStateCommand : public nsBaseComposerCommand
   139 {
   140 public:
   142                    nsMultiStateCommand();
   143   virtual          ~nsMultiStateCommand();
   145   NS_DECL_ISUPPORTS_INHERITED
   146   NS_DECL_NSICONTROLLERCOMMAND
   148 protected:
   150   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0;
   151   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0;
   153 };
   156 class nsParagraphStateCommand : public nsMultiStateCommand
   157 {
   158 public:
   159                    nsParagraphStateCommand();
   161 protected:
   163   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   164   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   165 };
   167 class nsFontFaceStateCommand : public nsMultiStateCommand
   168 {
   169 public:
   170                    nsFontFaceStateCommand();
   172 protected:
   174   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   175   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   176 };
   178 class nsFontSizeStateCommand : public nsMultiStateCommand
   179 {
   180 public:
   181                    nsFontSizeStateCommand();
   183 protected:
   185   virtual nsresult GetCurrentState(nsIEditor *aEditor,
   186                                    nsICommandParams* aParams);
   187   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   188 };
   190 class nsHighlightColorStateCommand : public nsMultiStateCommand
   191 {
   192 public:
   193                    nsHighlightColorStateCommand();
   195 protected:
   197   NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
   198   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   199   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   201 };
   203 class nsFontColorStateCommand : public nsMultiStateCommand
   204 {
   205 public:
   206                    nsFontColorStateCommand();
   208 protected:
   210   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   211   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   212 };
   214 class nsAlignCommand : public nsMultiStateCommand
   215 {
   216 public:
   217                    nsAlignCommand();
   219 protected:
   221   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   222   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   223 };
   225 class nsBackgroundColorStateCommand : public nsMultiStateCommand
   226 {
   227 public:
   228                    nsBackgroundColorStateCommand();
   230 protected:
   232   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
   233   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
   234 };
   236 class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand
   237 {
   238 public:
   239   nsAbsolutePositioningCommand();
   241 protected:
   243   NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
   244   virtual nsresult  GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
   245   virtual nsresult  ToggleState(nsIEditor* aEditor);
   246 };
   248 // composer commands
   250 NS_DECL_COMPOSER_COMMAND(nsCloseCommand)
   251 NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand)
   252 NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand)
   253 NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand)
   254 //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands)
   256 NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand)
   257 NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand)
   259 // Generic commands
   261 // File menu
   262 NS_DECL_COMPOSER_COMMAND(nsNewCommands)   // handles 'new' anything
   264 // Edit menu
   265 NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand)
   267 // Block transformations
   268 NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
   269 NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
   271 NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
   272 NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
   273 NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
   274 NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)
   276 // Insert content commands
   277 NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand)
   279 #endif // nsComposerCommands_h_

mercurial