Line data Source code
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 : #include "EditorCommands.h"
7 :
8 : #include "mozilla/ArrayUtils.h"
9 : #include "mozilla/Assertions.h"
10 : #include "mozilla/FlushType.h"
11 : #include "mozilla/TextEditor.h"
12 : #include "nsCOMPtr.h"
13 : #include "nsCRT.h"
14 : #include "nsDebug.h"
15 : #include "nsError.h"
16 : #include "nsIClipboard.h"
17 : #include "nsICommandParams.h"
18 : #include "nsID.h"
19 : #include "nsIDOMDocument.h"
20 : #include "nsIDocument.h"
21 : #include "nsIEditor.h"
22 : #include "nsIEditorMailSupport.h"
23 : #include "nsIPlaintextEditor.h"
24 : #include "nsISelection.h"
25 : #include "nsISelectionController.h"
26 : #include "nsITransferable.h"
27 : #include "nsString.h"
28 : #include "nsAString.h"
29 :
30 : class nsISupports;
31 :
32 : #define STATE_ENABLED "state_enabled"
33 : #define STATE_DATA "state_data"
34 :
35 : namespace mozilla {
36 :
37 : /******************************************************************************
38 : * mozilla::EditorCommandBase
39 : ******************************************************************************/
40 :
41 18 : EditorCommandBase::EditorCommandBase()
42 : {
43 18 : }
44 :
45 276 : NS_IMPL_ISUPPORTS(EditorCommandBase, nsIControllerCommand)
46 :
47 : /******************************************************************************
48 : * mozilla::UndoCommand
49 : ******************************************************************************/
50 :
51 : NS_IMETHODIMP
52 0 : UndoCommand::IsCommandEnabled(const char* aCommandName,
53 : nsISupports* aCommandRefCon,
54 : bool* aIsEnabled)
55 : {
56 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
57 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
58 0 : if (editor) {
59 0 : bool isEnabled, isEditable = false;
60 0 : nsresult rv = editor->GetIsSelectionEditable(&isEditable);
61 0 : NS_ENSURE_SUCCESS(rv, rv);
62 0 : if (isEditable)
63 0 : return editor->CanUndo(&isEnabled, aIsEnabled);
64 : }
65 :
66 0 : *aIsEnabled = false;
67 0 : return NS_OK;
68 : }
69 :
70 : NS_IMETHODIMP
71 0 : UndoCommand::DoCommand(const char* aCommandName,
72 : nsISupports* aCommandRefCon)
73 : {
74 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
75 0 : if (editor)
76 0 : return editor->Undo(1);
77 :
78 0 : return NS_ERROR_FAILURE;
79 : }
80 :
81 : NS_IMETHODIMP
82 0 : UndoCommand::DoCommandParams(const char* aCommandName,
83 : nsICommandParams* aParams,
84 : nsISupports* aCommandRefCon)
85 : {
86 0 : return DoCommand(aCommandName, aCommandRefCon);
87 : }
88 :
89 : NS_IMETHODIMP
90 0 : UndoCommand::GetCommandStateParams(const char* aCommandName,
91 : nsICommandParams* aParams,
92 : nsISupports* aCommandRefCon)
93 : {
94 : bool canUndo;
95 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
96 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
97 : }
98 :
99 : /******************************************************************************
100 : * mozilla::RedoCommand
101 : ******************************************************************************/
102 :
103 : NS_IMETHODIMP
104 0 : RedoCommand::IsCommandEnabled(const char* aCommandName,
105 : nsISupports* aCommandRefCon,
106 : bool* aIsEnabled)
107 : {
108 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
109 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
110 0 : if (editor) {
111 0 : bool isEnabled, isEditable = false;
112 0 : nsresult rv = editor->GetIsSelectionEditable(&isEditable);
113 0 : NS_ENSURE_SUCCESS(rv, rv);
114 0 : if (isEditable)
115 0 : return editor->CanRedo(&isEnabled, aIsEnabled);
116 : }
117 :
118 0 : *aIsEnabled = false;
119 0 : return NS_OK;
120 : }
121 :
122 : NS_IMETHODIMP
123 0 : RedoCommand::DoCommand(const char* aCommandName,
124 : nsISupports* aCommandRefCon)
125 : {
126 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
127 0 : if (editor)
128 0 : return editor->Redo(1);
129 :
130 0 : return NS_ERROR_FAILURE;
131 : }
132 :
133 : NS_IMETHODIMP
134 0 : RedoCommand::DoCommandParams(const char* aCommandName,
135 : nsICommandParams* aParams,
136 : nsISupports* aCommandRefCon)
137 : {
138 0 : return DoCommand(aCommandName, aCommandRefCon);
139 : }
140 :
141 : NS_IMETHODIMP
142 0 : RedoCommand::GetCommandStateParams(const char* aCommandName,
143 : nsICommandParams* aParams,
144 : nsISupports* aCommandRefCon)
145 : {
146 : bool canUndo;
147 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
148 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
149 : }
150 :
151 : /******************************************************************************
152 : * mozilla::ClearUndoCommand
153 : ******************************************************************************/
154 :
155 : NS_IMETHODIMP
156 0 : ClearUndoCommand::IsCommandEnabled(const char* aCommandName,
157 : nsISupports* aCommandRefCon,
158 : bool* aIsEnabled)
159 : {
160 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
161 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
162 0 : if (editor)
163 0 : return editor->GetIsSelectionEditable(aIsEnabled);
164 :
165 0 : *aIsEnabled = false;
166 0 : return NS_OK;
167 : }
168 :
169 : NS_IMETHODIMP
170 0 : ClearUndoCommand::DoCommand(const char* aCommandName,
171 : nsISupports* aCommandRefCon)
172 : {
173 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
174 0 : NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
175 :
176 0 : editor->EnableUndo(false); // Turning off undo clears undo/redo stacks.
177 0 : editor->EnableUndo(true); // This re-enables undo/redo.
178 :
179 0 : return NS_OK;
180 : }
181 :
182 : NS_IMETHODIMP
183 0 : ClearUndoCommand::DoCommandParams(const char* aCommandName,
184 : nsICommandParams* aParams,
185 : nsISupports* aCommandRefCon)
186 : {
187 0 : return DoCommand(aCommandName, aCommandRefCon);
188 : }
189 :
190 : NS_IMETHODIMP
191 0 : ClearUndoCommand::GetCommandStateParams(const char* aCommandName,
192 : nsICommandParams* aParams,
193 : nsISupports* aCommandRefCon)
194 : {
195 0 : NS_ENSURE_ARG_POINTER(aParams);
196 :
197 : bool enabled;
198 0 : nsresult rv = IsCommandEnabled(aCommandName, aCommandRefCon, &enabled);
199 0 : NS_ENSURE_SUCCESS(rv, rv);
200 :
201 0 : return aParams->SetBooleanValue(STATE_ENABLED, enabled);
202 : }
203 :
204 : /******************************************************************************
205 : * mozilla::CutCommand
206 : ******************************************************************************/
207 :
208 : NS_IMETHODIMP
209 0 : CutCommand::IsCommandEnabled(const char* aCommandName,
210 : nsISupports* aCommandRefCon,
211 : bool* aIsEnabled)
212 : {
213 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
214 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
215 0 : if (editor) {
216 0 : bool isEditable = false;
217 0 : nsresult rv = editor->GetIsSelectionEditable(&isEditable);
218 0 : NS_ENSURE_SUCCESS(rv, rv);
219 0 : if (isEditable)
220 0 : return editor->CanCut(aIsEnabled);
221 : }
222 :
223 0 : *aIsEnabled = false;
224 0 : return NS_OK;
225 : }
226 :
227 : NS_IMETHODIMP
228 0 : CutCommand::DoCommand(const char* aCommandName,
229 : nsISupports* aCommandRefCon)
230 : {
231 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
232 0 : if (editor)
233 0 : return editor->Cut();
234 :
235 0 : return NS_ERROR_FAILURE;
236 : }
237 :
238 : NS_IMETHODIMP
239 0 : CutCommand::DoCommandParams(const char* aCommandName,
240 : nsICommandParams* aParams,
241 : nsISupports* aCommandRefCon)
242 : {
243 0 : return DoCommand(aCommandName, aCommandRefCon);
244 : }
245 :
246 : NS_IMETHODIMP
247 0 : CutCommand::GetCommandStateParams(const char* aCommandName,
248 : nsICommandParams* aParams,
249 : nsISupports* aCommandRefCon)
250 : {
251 : bool canUndo;
252 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
253 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
254 : }
255 :
256 : /******************************************************************************
257 : * mozilla::CutOrDeleteCommand
258 : ******************************************************************************/
259 :
260 : NS_IMETHODIMP
261 0 : CutOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
262 : nsISupports* aCommandRefCon,
263 : bool* aIsEnabled)
264 : {
265 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
266 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
267 0 : if (editor)
268 0 : return editor->GetIsSelectionEditable(aIsEnabled);
269 :
270 0 : *aIsEnabled = false;
271 0 : return NS_OK;
272 : }
273 :
274 : NS_IMETHODIMP
275 0 : CutOrDeleteCommand::DoCommand(const char* aCommandName,
276 : nsISupports* aCommandRefCon)
277 : {
278 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
279 0 : if (editor) {
280 0 : nsCOMPtr<nsISelection> selection;
281 0 : nsresult rv = editor->GetSelection(getter_AddRefs(selection));
282 0 : if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
283 0 : return editor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
284 : }
285 0 : return editor->Cut();
286 : }
287 :
288 0 : return NS_ERROR_FAILURE;
289 : }
290 :
291 : NS_IMETHODIMP
292 0 : CutOrDeleteCommand::DoCommandParams(const char* aCommandName,
293 : nsICommandParams* aParams,
294 : nsISupports* aCommandRefCon)
295 : {
296 0 : return DoCommand(aCommandName, aCommandRefCon);
297 : }
298 :
299 : NS_IMETHODIMP
300 0 : CutOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
301 : nsICommandParams* aParams,
302 : nsISupports* aCommandRefCon)
303 : {
304 : bool canUndo;
305 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
306 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
307 : }
308 :
309 : /******************************************************************************
310 : * mozilla::CopyCommand
311 : ******************************************************************************/
312 :
313 : NS_IMETHODIMP
314 0 : CopyCommand::IsCommandEnabled(const char* aCommandName,
315 : nsISupports* aCommandRefCon,
316 : bool* aIsEnabled)
317 : {
318 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
319 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
320 0 : if (editor)
321 0 : return editor->CanCopy(aIsEnabled);
322 :
323 0 : *aIsEnabled = false;
324 0 : return NS_OK;
325 : }
326 :
327 : NS_IMETHODIMP
328 0 : CopyCommand::DoCommand(const char* aCommandName,
329 : nsISupports* aCommandRefCon)
330 : {
331 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
332 0 : if (editor)
333 0 : return editor->Copy();
334 :
335 0 : return NS_ERROR_FAILURE;
336 : }
337 :
338 : NS_IMETHODIMP
339 0 : CopyCommand::DoCommandParams(const char* aCommandName,
340 : nsICommandParams* aParams,
341 : nsISupports* aCommandRefCon)
342 : {
343 0 : return DoCommand(aCommandName, aCommandRefCon);
344 : }
345 :
346 : NS_IMETHODIMP
347 0 : CopyCommand::GetCommandStateParams(const char* aCommandName,
348 : nsICommandParams* aParams,
349 : nsISupports* aCommandRefCon)
350 : {
351 : bool canUndo;
352 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
353 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
354 : }
355 :
356 : /******************************************************************************
357 : * mozilla::CopyOrDeleteCommand
358 : ******************************************************************************/
359 :
360 : NS_IMETHODIMP
361 0 : CopyOrDeleteCommand::IsCommandEnabled(const char* aCommandName,
362 : nsISupports* aCommandRefCon,
363 : bool* aIsEnabled)
364 : {
365 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
366 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
367 0 : if (editor)
368 0 : return editor->GetIsSelectionEditable(aIsEnabled);
369 :
370 0 : *aIsEnabled = false;
371 0 : return NS_OK;
372 : }
373 :
374 : NS_IMETHODIMP
375 0 : CopyOrDeleteCommand::DoCommand(const char* aCommandName,
376 : nsISupports* aCommandRefCon)
377 : {
378 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
379 0 : if (editor) {
380 0 : nsCOMPtr<nsISelection> selection;
381 0 : nsresult rv = editor->GetSelection(getter_AddRefs(selection));
382 0 : if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
383 0 : return editor->DeleteSelection(nsIEditor::eNextWord, nsIEditor::eStrip);
384 : }
385 0 : return editor->Copy();
386 : }
387 :
388 0 : return NS_ERROR_FAILURE;
389 : }
390 :
391 : NS_IMETHODIMP
392 0 : CopyOrDeleteCommand::DoCommandParams(const char* aCommandName,
393 : nsICommandParams* aParams,
394 : nsISupports* aCommandRefCon)
395 : {
396 0 : return DoCommand(aCommandName, aCommandRefCon);
397 : }
398 :
399 : NS_IMETHODIMP
400 0 : CopyOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
401 : nsICommandParams* aParams,
402 : nsISupports* aCommandRefCon)
403 : {
404 : bool canUndo;
405 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
406 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
407 : }
408 :
409 : /******************************************************************************
410 : * mozilla::CopyAndCollapseToEndCommand
411 : ******************************************************************************/
412 :
413 : NS_IMETHODIMP
414 0 : CopyAndCollapseToEndCommand::IsCommandEnabled(const char* aCommandName,
415 : nsISupports* aCommandRefCon,
416 : bool* aIsEnabled)
417 : {
418 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
419 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
420 0 : if (editor)
421 0 : return editor->CanCopy(aIsEnabled);
422 :
423 0 : *aIsEnabled = false;
424 0 : return NS_OK;
425 : }
426 :
427 : NS_IMETHODIMP
428 0 : CopyAndCollapseToEndCommand::DoCommand(const char* aCommandName,
429 : nsISupports* aCommandRefCon)
430 : {
431 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
432 0 : if (editor) {
433 0 : nsresult rv = editor->Copy();
434 0 : if (NS_FAILED(rv)) {
435 0 : return rv;
436 : }
437 :
438 0 : nsCOMPtr<nsISelection> selection;
439 0 : rv = editor->GetSelection(getter_AddRefs(selection));
440 0 : if (NS_SUCCEEDED(rv) && selection) {
441 0 : selection->CollapseToEnd();
442 : }
443 0 : return rv;
444 : }
445 :
446 0 : return NS_ERROR_FAILURE;
447 : }
448 :
449 : NS_IMETHODIMP
450 0 : CopyAndCollapseToEndCommand::DoCommandParams(const char* aCommandName,
451 : nsICommandParams* aParams,
452 : nsISupports* aCommandRefCon)
453 : {
454 0 : return DoCommand(aCommandName, aCommandRefCon);
455 : }
456 :
457 : NS_IMETHODIMP
458 0 : CopyAndCollapseToEndCommand::GetCommandStateParams(const char* aCommandName,
459 : nsICommandParams* aParams,
460 : nsISupports* aCommandRefCon)
461 : {
462 : bool canUndo;
463 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
464 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
465 : }
466 :
467 : /******************************************************************************
468 : * mozilla::PasteCommand
469 : ******************************************************************************/
470 :
471 : NS_IMETHODIMP
472 0 : PasteCommand::IsCommandEnabled(const char* aCommandName,
473 : nsISupports* aCommandRefCon,
474 : bool* aIsEnabled)
475 : {
476 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
477 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
478 0 : if (editor) {
479 0 : bool isEditable = false;
480 0 : nsresult rv = editor->GetIsSelectionEditable(&isEditable);
481 0 : NS_ENSURE_SUCCESS(rv, rv);
482 0 : if (isEditable)
483 0 : return editor->CanPaste(nsIClipboard::kGlobalClipboard, aIsEnabled);
484 : }
485 :
486 0 : *aIsEnabled = false;
487 0 : return NS_OK;
488 : }
489 :
490 : NS_IMETHODIMP
491 0 : PasteCommand::DoCommand(const char* aCommandName,
492 : nsISupports* aCommandRefCon)
493 : {
494 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
495 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
496 :
497 0 : return editor->Paste(nsIClipboard::kGlobalClipboard);
498 : }
499 :
500 : NS_IMETHODIMP
501 0 : PasteCommand::DoCommandParams(const char* aCommandName,
502 : nsICommandParams* aParams,
503 : nsISupports* aCommandRefCon)
504 : {
505 0 : return DoCommand(aCommandName, aCommandRefCon);
506 : }
507 :
508 : NS_IMETHODIMP
509 0 : PasteCommand::GetCommandStateParams(const char* aCommandName,
510 : nsICommandParams* aParams,
511 : nsISupports* aCommandRefCon)
512 : {
513 : bool canUndo;
514 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
515 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
516 : }
517 :
518 : /******************************************************************************
519 : * mozilla::PasteTransferableCommand
520 : ******************************************************************************/
521 :
522 : NS_IMETHODIMP
523 0 : PasteTransferableCommand::IsCommandEnabled(const char* aCommandName,
524 : nsISupports* aCommandRefCon,
525 : bool* aIsEnabled)
526 : {
527 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
528 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
529 0 : if (editor) {
530 0 : bool isEditable = false;
531 0 : nsresult rv = editor->GetIsSelectionEditable(&isEditable);
532 0 : NS_ENSURE_SUCCESS(rv, rv);
533 0 : if (isEditable)
534 0 : return editor->CanPasteTransferable(nullptr, aIsEnabled);
535 : }
536 :
537 0 : *aIsEnabled = false;
538 0 : return NS_OK;
539 : }
540 :
541 : NS_IMETHODIMP
542 0 : PasteTransferableCommand::DoCommand(const char* aCommandName,
543 : nsISupports* aCommandRefCon)
544 : {
545 0 : return NS_ERROR_FAILURE;
546 : }
547 :
548 : NS_IMETHODIMP
549 0 : PasteTransferableCommand::DoCommandParams(const char* aCommandName,
550 : nsICommandParams* aParams,
551 : nsISupports* aCommandRefCon)
552 : {
553 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
554 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
555 :
556 0 : nsCOMPtr<nsISupports> supports;
557 0 : aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
558 0 : NS_ENSURE_TRUE(supports, NS_ERROR_FAILURE);
559 :
560 0 : nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
561 0 : NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
562 :
563 0 : return editor->PasteTransferable(trans);
564 : }
565 :
566 : NS_IMETHODIMP
567 0 : PasteTransferableCommand::GetCommandStateParams(const char* aCommandName,
568 : nsICommandParams* aParams,
569 : nsISupports* aCommandRefCon)
570 : {
571 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
572 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
573 :
574 0 : nsCOMPtr<nsITransferable> trans;
575 :
576 0 : nsCOMPtr<nsISupports> supports;
577 0 : aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
578 0 : if (supports) {
579 0 : trans = do_QueryInterface(supports);
580 0 : NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
581 : }
582 :
583 : bool canPaste;
584 0 : nsresult rv = editor->CanPasteTransferable(trans, &canPaste);
585 0 : NS_ENSURE_SUCCESS(rv, rv);
586 :
587 0 : return aParams->SetBooleanValue(STATE_ENABLED, canPaste);
588 : }
589 :
590 : /******************************************************************************
591 : * mozilla::SwitchTextDirectionCommand
592 : ******************************************************************************/
593 :
594 : NS_IMETHODIMP
595 0 : SwitchTextDirectionCommand::IsCommandEnabled(const char* aCommandName,
596 : nsISupports* aCommandRefCon,
597 : bool* aIsEnabled)
598 : {
599 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
600 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
601 0 : if (editor)
602 0 : return editor->GetIsSelectionEditable(aIsEnabled);
603 :
604 0 : *aIsEnabled = false;
605 0 : return NS_OK;
606 : }
607 :
608 : NS_IMETHODIMP
609 0 : SwitchTextDirectionCommand::DoCommand(const char* aCommandName,
610 : nsISupports* aCommandRefCon)
611 : {
612 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
613 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
614 :
615 0 : return editor->SwitchTextDirection();
616 : }
617 :
618 : NS_IMETHODIMP
619 0 : SwitchTextDirectionCommand::DoCommandParams(const char* aCommandName,
620 : nsICommandParams* aParams,
621 : nsISupports* aCommandRefCon)
622 : {
623 0 : return DoCommand(aCommandName, aCommandRefCon);
624 : }
625 :
626 : NS_IMETHODIMP
627 0 : SwitchTextDirectionCommand::GetCommandStateParams(const char* aCommandName,
628 : nsICommandParams* aParams,
629 : nsISupports* aCommandRefCon)
630 : {
631 0 : bool canSwitchTextDirection = true;
632 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canSwitchTextDirection);
633 0 : return aParams->SetBooleanValue(STATE_ENABLED, canSwitchTextDirection);
634 : }
635 :
636 : /******************************************************************************
637 : * mozilla::DeleteCommand
638 : ******************************************************************************/
639 :
640 : NS_IMETHODIMP
641 0 : DeleteCommand::IsCommandEnabled(const char* aCommandName,
642 : nsISupports* aCommandRefCon,
643 : bool* aIsEnabled)
644 : {
645 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
646 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
647 0 : *aIsEnabled = false;
648 :
649 0 : if (!editor) {
650 0 : return NS_OK;
651 : }
652 :
653 : // We can generally delete whenever the selection is editable. However,
654 : // cmd_delete doesn't make sense if the selection is collapsed because it's
655 : // directionless, which is the same condition under which we can't cut.
656 0 : nsresult rv = editor->GetIsSelectionEditable(aIsEnabled);
657 0 : NS_ENSURE_SUCCESS(rv, rv);
658 :
659 0 : if (!nsCRT::strcmp("cmd_delete", aCommandName) && *aIsEnabled) {
660 0 : rv = editor->CanDelete(aIsEnabled);
661 0 : NS_ENSURE_SUCCESS(rv, rv);
662 : }
663 :
664 0 : return NS_OK;
665 : }
666 :
667 : NS_IMETHODIMP
668 0 : DeleteCommand::DoCommand(const char* aCommandName,
669 : nsISupports* aCommandRefCon)
670 : {
671 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
672 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
673 :
674 0 : nsIEditor::EDirection deleteDir = nsIEditor::eNone;
675 :
676 0 : if (!nsCRT::strcmp("cmd_delete", aCommandName)) {
677 : // Really this should probably be eNone, but it only makes a difference if
678 : // the selection is collapsed, and then this command is disabled. So let's
679 : // keep it as it always was to avoid breaking things.
680 0 : deleteDir = nsIEditor::ePrevious;
681 0 : } else if (!nsCRT::strcmp("cmd_deleteCharForward", aCommandName)) {
682 0 : deleteDir = nsIEditor::eNext;
683 0 : } else if (!nsCRT::strcmp("cmd_deleteCharBackward", aCommandName)) {
684 0 : deleteDir = nsIEditor::ePrevious;
685 0 : } else if (!nsCRT::strcmp("cmd_deleteWordBackward", aCommandName)) {
686 0 : deleteDir = nsIEditor::ePreviousWord;
687 0 : } else if (!nsCRT::strcmp("cmd_deleteWordForward", aCommandName)) {
688 0 : deleteDir = nsIEditor::eNextWord;
689 0 : } else if (!nsCRT::strcmp("cmd_deleteToBeginningOfLine", aCommandName)) {
690 0 : deleteDir = nsIEditor::eToBeginningOfLine;
691 0 : } else if (!nsCRT::strcmp("cmd_deleteToEndOfLine", aCommandName)) {
692 0 : deleteDir = nsIEditor::eToEndOfLine;
693 : } else {
694 0 : MOZ_CRASH("Unrecognized nsDeleteCommand");
695 : }
696 :
697 0 : return editor->DeleteSelection(deleteDir, nsIEditor::eStrip);
698 : }
699 :
700 : NS_IMETHODIMP
701 0 : DeleteCommand::DoCommandParams(const char* aCommandName,
702 : nsICommandParams* aParams,
703 : nsISupports* aCommandRefCon)
704 : {
705 0 : return DoCommand(aCommandName, aCommandRefCon);
706 : }
707 :
708 : NS_IMETHODIMP
709 0 : DeleteCommand::GetCommandStateParams(const char* aCommandName,
710 : nsICommandParams* aParams,
711 : nsISupports* aCommandRefCon)
712 : {
713 : bool canUndo;
714 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
715 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
716 : }
717 :
718 : /******************************************************************************
719 : * mozilla::SelectAllCommand
720 : ******************************************************************************/
721 :
722 : NS_IMETHODIMP
723 0 : SelectAllCommand::IsCommandEnabled(const char* aCommandName,
724 : nsISupports* aCommandRefCon,
725 : bool* aIsEnabled)
726 : {
727 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
728 :
729 0 : nsresult rv = NS_OK;
730 : // You can always select all, unless the selection is editable,
731 : // and the editable region is empty!
732 0 : *aIsEnabled = true;
733 : bool docIsEmpty;
734 :
735 : // you can select all if there is an editor which is non-empty
736 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
737 0 : if (editor) {
738 0 : rv = editor->GetDocumentIsEmpty(&docIsEmpty);
739 0 : NS_ENSURE_SUCCESS(rv, rv);
740 0 : *aIsEnabled = !docIsEmpty;
741 : }
742 :
743 0 : return rv;
744 : }
745 :
746 : NS_IMETHODIMP
747 0 : SelectAllCommand::DoCommand(const char* aCommandName,
748 : nsISupports* aCommandRefCon)
749 : {
750 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
751 0 : if (editor)
752 0 : return editor->SelectAll();
753 :
754 0 : return NS_ERROR_FAILURE;
755 : }
756 :
757 : NS_IMETHODIMP
758 0 : SelectAllCommand::DoCommandParams(const char* aCommandName,
759 : nsICommandParams* aParams,
760 : nsISupports* aCommandRefCon)
761 : {
762 0 : return DoCommand(aCommandName, aCommandRefCon);
763 : }
764 :
765 : NS_IMETHODIMP
766 0 : SelectAllCommand::GetCommandStateParams(const char* aCommandName,
767 : nsICommandParams* aParams,
768 : nsISupports* aCommandRefCon)
769 : {
770 : bool canUndo;
771 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
772 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
773 : }
774 :
775 : /******************************************************************************
776 : * mozilla::SelectionMoveCommands
777 : ******************************************************************************/
778 :
779 : NS_IMETHODIMP
780 0 : SelectionMoveCommands::IsCommandEnabled(const char* aCommandName,
781 : nsISupports* aCommandRefCon,
782 : bool* aIsEnabled)
783 : {
784 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
785 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
786 0 : if (editor)
787 0 : return editor->GetIsSelectionEditable(aIsEnabled);
788 :
789 0 : *aIsEnabled = false;
790 0 : return NS_OK;
791 : }
792 :
793 : static const struct ScrollCommand {
794 : const char *reverseScroll;
795 : const char *forwardScroll;
796 : nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
797 : } scrollCommands[] = {
798 : { "cmd_scrollTop", "cmd_scrollBottom",
799 : &nsISelectionController::CompleteScroll },
800 : { "cmd_scrollPageUp", "cmd_scrollPageDown",
801 : &nsISelectionController::ScrollPage },
802 : { "cmd_scrollLineUp", "cmd_scrollLineDown",
803 : &nsISelectionController::ScrollLine }
804 : };
805 :
806 : static const struct MoveCommand {
807 : const char *reverseMove;
808 : const char *forwardMove;
809 : const char *reverseSelect;
810 : const char *forwardSelect;
811 : nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool);
812 : } moveCommands[] = {
813 : { "cmd_charPrevious", "cmd_charNext",
814 : "cmd_selectCharPrevious", "cmd_selectCharNext",
815 : &nsISelectionController::CharacterMove },
816 : { "cmd_linePrevious", "cmd_lineNext",
817 : "cmd_selectLinePrevious", "cmd_selectLineNext",
818 : &nsISelectionController::LineMove },
819 : { "cmd_wordPrevious", "cmd_wordNext",
820 : "cmd_selectWordPrevious", "cmd_selectWordNext",
821 : &nsISelectionController::WordMove },
822 : { "cmd_beginLine", "cmd_endLine",
823 : "cmd_selectBeginLine", "cmd_selectEndLine",
824 : &nsISelectionController::IntraLineMove },
825 : { "cmd_movePageUp", "cmd_movePageDown",
826 : "cmd_selectPageUp", "cmd_selectPageDown",
827 : &nsISelectionController::PageMove },
828 : { "cmd_moveTop", "cmd_moveBottom",
829 : "cmd_selectTop", "cmd_selectBottom",
830 : &nsISelectionController::CompleteMove }
831 : };
832 :
833 : static const struct PhysicalCommand {
834 : const char *move;
835 : const char *select;
836 : int16_t direction;
837 : int16_t amount;
838 : } physicalCommands[] = {
839 : { "cmd_moveLeft", "cmd_selectLeft",
840 : nsISelectionController::MOVE_LEFT, 0 },
841 : { "cmd_moveRight", "cmd_selectRight",
842 : nsISelectionController::MOVE_RIGHT, 0 },
843 : { "cmd_moveUp", "cmd_selectUp",
844 : nsISelectionController::MOVE_UP, 0 },
845 : { "cmd_moveDown", "cmd_selectDown",
846 : nsISelectionController::MOVE_DOWN, 0 },
847 : { "cmd_moveLeft2", "cmd_selectLeft2",
848 : nsISelectionController::MOVE_LEFT, 1 },
849 : { "cmd_moveRight2", "cmd_selectRight2",
850 : nsISelectionController::MOVE_RIGHT, 1 },
851 : { "cmd_moveUp2", "cmd_selectUp2",
852 : nsISelectionController::MOVE_UP, 1 },
853 : { "cmd_moveDown2", "cmd_selectDown2",
854 : nsISelectionController::MOVE_DOWN, 1 }
855 : };
856 :
857 : NS_IMETHODIMP
858 0 : SelectionMoveCommands::DoCommand(const char* aCommandName,
859 : nsISupports* aCommandRefCon)
860 : {
861 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
862 0 : NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
863 :
864 0 : nsCOMPtr<nsIDOMDocument> domDoc;
865 0 : editor->GetDocument(getter_AddRefs(domDoc));
866 0 : nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
867 0 : if (doc) {
868 : // Most of the commands below (possibly all of them) need layout to
869 : // be up to date.
870 0 : doc->FlushPendingNotifications(FlushType::Layout);
871 : }
872 :
873 0 : nsCOMPtr<nsISelectionController> selCont;
874 0 : nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont));
875 0 : NS_ENSURE_SUCCESS(rv, rv);
876 0 : NS_ENSURE_TRUE(selCont, NS_ERROR_FAILURE);
877 :
878 : // scroll commands
879 0 : for (size_t i = 0; i < mozilla::ArrayLength(scrollCommands); i++) {
880 0 : const ScrollCommand &cmd = scrollCommands[i];
881 0 : if (!nsCRT::strcmp(aCommandName, cmd.reverseScroll)) {
882 0 : return (selCont->*(cmd.scroll))(false);
883 0 : } else if (!nsCRT::strcmp(aCommandName, cmd.forwardScroll)) {
884 0 : return (selCont->*(cmd.scroll))(true);
885 : }
886 : }
887 :
888 : // caret movement/selection commands
889 0 : for (size_t i = 0; i < mozilla::ArrayLength(moveCommands); i++) {
890 0 : const MoveCommand &cmd = moveCommands[i];
891 0 : if (!nsCRT::strcmp(aCommandName, cmd.reverseMove)) {
892 0 : return (selCont->*(cmd.move))(false, false);
893 0 : } else if (!nsCRT::strcmp(aCommandName, cmd.forwardMove)) {
894 0 : return (selCont->*(cmd.move))(true, false);
895 0 : } else if (!nsCRT::strcmp(aCommandName, cmd.reverseSelect)) {
896 0 : return (selCont->*(cmd.move))(false, true);
897 0 : } else if (!nsCRT::strcmp(aCommandName, cmd.forwardSelect)) {
898 0 : return (selCont->*(cmd.move))(true, true);
899 : }
900 : }
901 :
902 : // physical-direction movement/selection
903 0 : for (size_t i = 0; i < mozilla::ArrayLength(physicalCommands); i++) {
904 0 : const PhysicalCommand &cmd = physicalCommands[i];
905 0 : if (!nsCRT::strcmp(aCommandName, cmd.move)) {
906 0 : return selCont->PhysicalMove(cmd.direction, cmd.amount, false);
907 0 : } else if (!nsCRT::strcmp(aCommandName, cmd.select)) {
908 0 : return selCont->PhysicalMove(cmd.direction, cmd.amount, true);
909 : }
910 : }
911 :
912 0 : return NS_ERROR_FAILURE;
913 : }
914 :
915 : NS_IMETHODIMP
916 0 : SelectionMoveCommands::DoCommandParams(const char* aCommandName,
917 : nsICommandParams* aParams,
918 : nsISupports* aCommandRefCon)
919 : {
920 0 : return DoCommand(aCommandName, aCommandRefCon);
921 : }
922 :
923 : NS_IMETHODIMP
924 0 : SelectionMoveCommands::GetCommandStateParams(const char* aCommandName,
925 : nsICommandParams* aParams,
926 : nsISupports* aCommandRefCon)
927 : {
928 : bool canUndo;
929 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
930 0 : return aParams->SetBooleanValue(STATE_ENABLED, canUndo);
931 : }
932 :
933 : /******************************************************************************
934 : * mozilla::InsertPlaintextCommand
935 : ******************************************************************************/
936 :
937 : NS_IMETHODIMP
938 0 : InsertPlaintextCommand::IsCommandEnabled(const char* aCommandName,
939 : nsISupports* aCommandRefCon,
940 : bool* aIsEnabled)
941 : {
942 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
943 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
944 0 : if (editor)
945 0 : return editor->GetIsSelectionEditable(aIsEnabled);
946 :
947 0 : *aIsEnabled = false;
948 0 : return NS_ERROR_NOT_IMPLEMENTED;
949 : }
950 :
951 : NS_IMETHODIMP
952 0 : InsertPlaintextCommand::DoCommand(const char* aCommandName,
953 : nsISupports* aCommandRefCon)
954 : {
955 : // No value is equivalent to empty string
956 0 : nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
957 0 : if (NS_WARN_IF(!editor)) {
958 0 : return NS_ERROR_NOT_IMPLEMENTED;
959 : }
960 :
961 0 : return editor->InsertText(EmptyString());
962 : }
963 :
964 : NS_IMETHODIMP
965 0 : InsertPlaintextCommand::DoCommandParams(const char* aCommandName,
966 : nsICommandParams* aParams,
967 : nsISupports* aCommandRefCon)
968 : {
969 0 : NS_ENSURE_ARG_POINTER(aParams);
970 :
971 0 : nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
972 0 : NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
973 :
974 : // Get text to insert from command params
975 0 : nsAutoString text;
976 0 : nsresult rv = aParams->GetStringValue(STATE_DATA, text);
977 0 : NS_ENSURE_SUCCESS(rv, rv);
978 :
979 0 : return editor->InsertText(text);
980 : }
981 :
982 : NS_IMETHODIMP
983 0 : InsertPlaintextCommand::GetCommandStateParams(const char* aCommandName,
984 : nsICommandParams* aParams,
985 : nsISupports* aCommandRefCon)
986 : {
987 0 : if (NS_WARN_IF(!aParams)) {
988 0 : return NS_ERROR_INVALID_ARG;
989 : }
990 :
991 0 : bool aIsEnabled = false;
992 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
993 0 : return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
994 : }
995 :
996 : /******************************************************************************
997 : * mozilla::InsertParagraphCommand
998 : ******************************************************************************/
999 :
1000 : NS_IMETHODIMP
1001 0 : InsertParagraphCommand::IsCommandEnabled(const char* aCommandName,
1002 : nsISupports* aCommandRefCon,
1003 : bool* aIsEnabled)
1004 : {
1005 0 : if (NS_WARN_IF(!aIsEnabled)) {
1006 0 : return NS_ERROR_INVALID_ARG;
1007 : }
1008 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
1009 0 : if (NS_WARN_IF(!editor)) {
1010 0 : *aIsEnabled = false;
1011 0 : return NS_ERROR_NOT_IMPLEMENTED;
1012 : }
1013 :
1014 0 : return editor->GetIsSelectionEditable(aIsEnabled);
1015 : }
1016 :
1017 : NS_IMETHODIMP
1018 0 : InsertParagraphCommand::DoCommand(const char* aCommandName,
1019 : nsISupports* aCommandRefCon)
1020 : {
1021 0 : nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
1022 0 : if (NS_WARN_IF(!editor)) {
1023 0 : return NS_ERROR_NOT_IMPLEMENTED;
1024 : }
1025 :
1026 0 : TextEditor* textEditor = static_cast<TextEditor*>(editor.get());
1027 :
1028 0 : return textEditor->TypedText(EmptyString(), TextEditor::eTypedBreak);
1029 : }
1030 :
1031 : NS_IMETHODIMP
1032 0 : InsertParagraphCommand::DoCommandParams(const char* aCommandName,
1033 : nsICommandParams* aParams,
1034 : nsISupports* aCommandRefCon)
1035 : {
1036 0 : return DoCommand(aCommandName, aCommandRefCon);
1037 : }
1038 :
1039 : NS_IMETHODIMP
1040 0 : InsertParagraphCommand::GetCommandStateParams(const char* aCommandName,
1041 : nsICommandParams* aParams,
1042 : nsISupports* aCommandRefCon)
1043 : {
1044 0 : if (NS_WARN_IF(!aParams)) {
1045 0 : return NS_ERROR_INVALID_ARG;
1046 : }
1047 :
1048 0 : bool aIsEnabled = false;
1049 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
1050 0 : return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
1051 : }
1052 :
1053 : /******************************************************************************
1054 : * mozilla::InsertLineBreakCommand
1055 : ******************************************************************************/
1056 :
1057 : NS_IMETHODIMP
1058 0 : InsertLineBreakCommand::IsCommandEnabled(const char* aCommandName,
1059 : nsISupports* aCommandRefCon,
1060 : bool* aIsEnabled)
1061 : {
1062 0 : if (NS_WARN_IF(!aIsEnabled)) {
1063 0 : return NS_ERROR_INVALID_ARG;
1064 : }
1065 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
1066 0 : if (NS_WARN_IF(!editor)) {
1067 0 : *aIsEnabled = false;
1068 0 : return NS_ERROR_NOT_IMPLEMENTED;
1069 : }
1070 :
1071 0 : return editor->GetIsSelectionEditable(aIsEnabled);
1072 : }
1073 :
1074 : NS_IMETHODIMP
1075 0 : InsertLineBreakCommand::DoCommand(const char* aCommandName,
1076 : nsISupports* aCommandRefCon)
1077 : {
1078 0 : nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(aCommandRefCon);
1079 0 : if (NS_WARN_IF(!editor)) {
1080 0 : return NS_ERROR_NOT_IMPLEMENTED;
1081 : }
1082 :
1083 0 : TextEditor* textEditor = static_cast<TextEditor*>(editor.get());
1084 :
1085 0 : return textEditor->TypedText(EmptyString(), TextEditor::eTypedBR);
1086 : }
1087 :
1088 : NS_IMETHODIMP
1089 0 : InsertLineBreakCommand::DoCommandParams(const char* aCommandName,
1090 : nsICommandParams* aParams,
1091 : nsISupports* aCommandRefCon)
1092 : {
1093 0 : return DoCommand(aCommandName, aCommandRefCon);
1094 : }
1095 :
1096 : NS_IMETHODIMP
1097 0 : InsertLineBreakCommand::GetCommandStateParams(const char* aCommandName,
1098 : nsICommandParams* aParams,
1099 : nsISupports* aCommandRefCon)
1100 : {
1101 0 : if (NS_WARN_IF(!aParams)) {
1102 0 : return NS_ERROR_INVALID_ARG;
1103 : }
1104 :
1105 0 : bool aIsEnabled = false;
1106 0 : IsCommandEnabled(aCommandName, aCommandRefCon, &aIsEnabled);
1107 0 : return aParams->SetBooleanValue(STATE_ENABLED, aIsEnabled);
1108 : }
1109 :
1110 : /******************************************************************************
1111 : * mozilla::PasteQuotationCommand
1112 : ******************************************************************************/
1113 :
1114 : NS_IMETHODIMP
1115 0 : PasteQuotationCommand::IsCommandEnabled(const char* aCommandName,
1116 : nsISupports* aCommandRefCon,
1117 : bool* aIsEnabled)
1118 : {
1119 0 : NS_ENSURE_ARG_POINTER(aIsEnabled);
1120 :
1121 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
1122 0 : nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
1123 0 : if (editor && mailEditor) {
1124 : uint32_t flags;
1125 0 : editor->GetFlags(&flags);
1126 0 : if (!(flags & nsIPlaintextEditor::eEditorSingleLineMask))
1127 0 : return editor->CanPaste(nsIClipboard::kGlobalClipboard, aIsEnabled);
1128 : }
1129 :
1130 0 : *aIsEnabled = false;
1131 0 : return NS_OK;
1132 : }
1133 :
1134 : NS_IMETHODIMP
1135 0 : PasteQuotationCommand::DoCommand(const char* aCommandName,
1136 : nsISupports* aCommandRefCon)
1137 : {
1138 0 : nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
1139 0 : if (mailEditor)
1140 0 : return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
1141 :
1142 0 : return NS_ERROR_NOT_IMPLEMENTED;
1143 : }
1144 :
1145 : NS_IMETHODIMP
1146 0 : PasteQuotationCommand::DoCommandParams(const char* aCommandName,
1147 : nsICommandParams* aParams,
1148 : nsISupports* aCommandRefCon)
1149 : {
1150 0 : nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(aCommandRefCon);
1151 0 : if (mailEditor)
1152 0 : return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
1153 :
1154 0 : return NS_ERROR_NOT_IMPLEMENTED;
1155 : }
1156 :
1157 : NS_IMETHODIMP
1158 0 : PasteQuotationCommand::GetCommandStateParams(const char* aCommandName,
1159 : nsICommandParams* aParams,
1160 : nsISupports* aCommandRefCon)
1161 : {
1162 0 : nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
1163 0 : if (editor) {
1164 0 : bool enabled = false;
1165 0 : editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled);
1166 0 : aParams->SetBooleanValue(STATE_ENABLED, enabled);
1167 : }
1168 :
1169 0 : return NS_OK;
1170 : }
1171 :
1172 : } // namespace mozilla
|