/work/obj-fuzz/dist/include/mozilla/HTMLEditorCommands.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #ifndef mozilla_HTMLEditorCommands_h_ |
7 | | #define mozilla_HTMLEditorCommands_h_ |
8 | | |
9 | | #include "nsIControllerCommand.h" |
10 | | #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc |
11 | | #include "nsStringFwd.h" |
12 | | #include "nscore.h" // for nsresult, NS_IMETHOD |
13 | | |
14 | | class nsAtom; |
15 | | class nsICommandParams; |
16 | | class nsISupports; |
17 | | |
18 | | namespace mozilla { |
19 | | class HTMLEditor; |
20 | | |
21 | | // This is a virtual base class for commands registered with the composer controller. |
22 | | // Note that such commands are instantiated once per composer, so can store state. |
23 | | // Also note that IsCommandEnabled can be called with an editor that may not |
24 | | // have an editor yet (because the document is loading). Most commands will want |
25 | | // to return false in this case. |
26 | | // Don't hold on to any references to the editor or document from |
27 | | // your command. This will cause leaks. Also, be aware that the document the |
28 | | // editor is editing can change under you (if the user Reverts the file, for |
29 | | // instance). |
30 | | class HTMLEditorCommandBase : public nsIControllerCommand |
31 | | { |
32 | | protected: |
33 | 0 | virtual ~HTMLEditorCommandBase() {} |
34 | | |
35 | | public: |
36 | | HTMLEditorCommandBase(); |
37 | | |
38 | | // nsISupports |
39 | | NS_DECL_ISUPPORTS |
40 | | }; |
41 | | |
42 | | |
43 | | #define NS_DECL_COMPOSER_COMMAND(_cmd) \ |
44 | | class _cmd final : public HTMLEditorCommandBase \ |
45 | | { \ |
46 | | public: \ |
47 | | NS_DECL_NSICONTROLLERCOMMAND \ |
48 | | }; |
49 | | |
50 | | // virtual base class for commands that need to save and update Boolean state (like styles etc) |
51 | | class StateUpdatingCommandBase : public HTMLEditorCommandBase |
52 | | { |
53 | | public: |
54 | | explicit StateUpdatingCommandBase(nsAtom* aTagName); |
55 | | |
56 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(StateUpdatingCommandBase, |
57 | | HTMLEditorCommandBase) |
58 | | |
59 | | NS_DECL_NSICONTROLLERCOMMAND |
60 | | |
61 | | protected: |
62 | | virtual ~StateUpdatingCommandBase(); |
63 | | |
64 | | // get the current state (on or off) for this style or block format |
65 | | virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
66 | | nsICommandParams* aParams) = 0; |
67 | | |
68 | | // add/remove the style |
69 | | virtual nsresult ToggleState(HTMLEditor* aHTMLEditor) = 0; |
70 | | |
71 | | protected: |
72 | | nsAtom* mTagName; |
73 | | }; |
74 | | |
75 | | |
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 StyleUpdatingCommand final : public StateUpdatingCommandBase |
79 | | { |
80 | | public: |
81 | | explicit StyleUpdatingCommand(nsAtom* aTagName); |
82 | | |
83 | | protected: |
84 | | // get the current state (on or off) for this style or block format |
85 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
86 | | nsICommandParams* aParams) final; |
87 | | |
88 | | // add/remove the style |
89 | | nsresult ToggleState(HTMLEditor* aHTMLEditor) final; |
90 | | }; |
91 | | |
92 | | |
93 | | class InsertTagCommand final : public HTMLEditorCommandBase |
94 | | { |
95 | | public: |
96 | | explicit InsertTagCommand(nsAtom* aTagName); |
97 | | |
98 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(InsertTagCommand, HTMLEditorCommandBase) |
99 | | |
100 | | NS_DECL_NSICONTROLLERCOMMAND |
101 | | |
102 | | protected: |
103 | | virtual ~InsertTagCommand(); |
104 | | |
105 | | nsAtom* mTagName; |
106 | | }; |
107 | | |
108 | | |
109 | | class ListCommand final : public StateUpdatingCommandBase |
110 | | { |
111 | | public: |
112 | | explicit ListCommand(nsAtom* aTagName); |
113 | | |
114 | | protected: |
115 | | // get the current state (on or off) for this style or block format |
116 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
117 | | nsICommandParams* aParams) final; |
118 | | |
119 | | // add/remove the style |
120 | | nsresult ToggleState(HTMLEditor* aHTMLEditor) final; |
121 | | }; |
122 | | |
123 | | class ListItemCommand final : public StateUpdatingCommandBase |
124 | | { |
125 | | public: |
126 | | explicit ListItemCommand(nsAtom* aTagName); |
127 | | |
128 | | protected: |
129 | | // get the current state (on or off) for this style or block format |
130 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
131 | | nsICommandParams* aParams) final; |
132 | | |
133 | | // add/remove the style |
134 | | nsresult ToggleState(HTMLEditor* aHTMLEditor) final; |
135 | | }; |
136 | | |
137 | | // Base class for commands whose state consists of a string (e.g. para format) |
138 | | class MultiStateCommandBase : public HTMLEditorCommandBase |
139 | | { |
140 | | public: |
141 | | MultiStateCommandBase(); |
142 | | |
143 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase, |
144 | | HTMLEditorCommandBase) |
145 | | NS_DECL_NSICONTROLLERCOMMAND |
146 | | |
147 | | protected: |
148 | | virtual ~MultiStateCommandBase(); |
149 | | |
150 | | virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
151 | | nsICommandParams* aParams) = 0; |
152 | | virtual nsresult SetState(HTMLEditor* aHTMLEditor, |
153 | | const nsString& newState) = 0; |
154 | | |
155 | | }; |
156 | | |
157 | | |
158 | | class ParagraphStateCommand final : public MultiStateCommandBase |
159 | | { |
160 | | public: |
161 | | ParagraphStateCommand(); |
162 | | |
163 | | protected: |
164 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
165 | | nsICommandParams* aParams) final; |
166 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
167 | | const nsString& newState) final; |
168 | | }; |
169 | | |
170 | | class FontFaceStateCommand final : public MultiStateCommandBase |
171 | | { |
172 | | public: |
173 | | FontFaceStateCommand(); |
174 | | |
175 | | protected: |
176 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
177 | | nsICommandParams* aParams) final; |
178 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
179 | | const nsString& newState) final; |
180 | | }; |
181 | | |
182 | | class FontSizeStateCommand final : public MultiStateCommandBase |
183 | | { |
184 | | public: |
185 | | FontSizeStateCommand(); |
186 | | |
187 | | protected: |
188 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
189 | | nsICommandParams* aParams) final; |
190 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
191 | | const nsString& newState) final; |
192 | | }; |
193 | | |
194 | | class HighlightColorStateCommand final : public MultiStateCommandBase |
195 | | { |
196 | | public: |
197 | | HighlightColorStateCommand(); |
198 | | |
199 | | protected: |
200 | | NS_IMETHOD IsCommandEnabled(const char* aCommandName, |
201 | | nsISupports* aCommandRefCon, |
202 | | bool* _retval) final; |
203 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
204 | | nsICommandParams* aParams) final; |
205 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
206 | | const nsString& newState) final; |
207 | | }; |
208 | | |
209 | | class FontColorStateCommand final : public MultiStateCommandBase |
210 | | { |
211 | | public: |
212 | | FontColorStateCommand(); |
213 | | |
214 | | protected: |
215 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
216 | | nsICommandParams* aParams) final; |
217 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
218 | | const nsString& newState) final; |
219 | | }; |
220 | | |
221 | | class AlignCommand final : public MultiStateCommandBase |
222 | | { |
223 | | public: |
224 | | AlignCommand(); |
225 | | |
226 | | protected: |
227 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
228 | | nsICommandParams* aParams) final; |
229 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
230 | | const nsString& newState) final; |
231 | | }; |
232 | | |
233 | | class BackgroundColorStateCommand final : public MultiStateCommandBase |
234 | | { |
235 | | public: |
236 | | BackgroundColorStateCommand(); |
237 | | |
238 | | protected: |
239 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
240 | | nsICommandParams* aParams) final; |
241 | | nsresult SetState(HTMLEditor* aHTMLEditor, |
242 | | const nsString& newState) final; |
243 | | }; |
244 | | |
245 | | class AbsolutePositioningCommand final : public StateUpdatingCommandBase |
246 | | { |
247 | | public: |
248 | | AbsolutePositioningCommand(); |
249 | | |
250 | | protected: |
251 | | NS_IMETHOD IsCommandEnabled(const char* aCommandName, |
252 | | nsISupports* aCommandRefCon, |
253 | | bool* _retval) final; |
254 | | nsresult GetCurrentState(HTMLEditor* aHTMLEditor, |
255 | | nsICommandParams* aParams) final; |
256 | | nsresult ToggleState(HTMLEditor* aHTMLEditor) final; |
257 | | }; |
258 | | |
259 | | // composer commands |
260 | | |
261 | | NS_DECL_COMPOSER_COMMAND(DocumentStateCommand) |
262 | | NS_DECL_COMPOSER_COMMAND(SetDocumentStateCommand) |
263 | | NS_DECL_COMPOSER_COMMAND(SetDocumentOptionsCommand) |
264 | | |
265 | | NS_DECL_COMPOSER_COMMAND(DecreaseZIndexCommand) |
266 | | NS_DECL_COMPOSER_COMMAND(IncreaseZIndexCommand) |
267 | | |
268 | | // Generic commands |
269 | | |
270 | | // Edit menu |
271 | | NS_DECL_COMPOSER_COMMAND(PasteNoFormattingCommand) |
272 | | |
273 | | // Block transformations |
274 | | NS_DECL_COMPOSER_COMMAND(IndentCommand) |
275 | | NS_DECL_COMPOSER_COMMAND(OutdentCommand) |
276 | | |
277 | | NS_DECL_COMPOSER_COMMAND(RemoveListCommand) |
278 | | NS_DECL_COMPOSER_COMMAND(RemoveStylesCommand) |
279 | | NS_DECL_COMPOSER_COMMAND(IncreaseFontSizeCommand) |
280 | | NS_DECL_COMPOSER_COMMAND(DecreaseFontSizeCommand) |
281 | | |
282 | | // Insert content commands |
283 | | NS_DECL_COMPOSER_COMMAND(InsertHTMLCommand) |
284 | | |
285 | | } // namespace mozilla |
286 | | |
287 | | #endif // mozilla_HTMLEditorCommands_h_ |