Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / nsGlobalWindowCommands.cpp
blob4fa14da6231cc24b919574609718e10ae74deb18
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsGlobalWindowCommands.h"
9 #include "nsIComponentManager.h"
10 #include "nsIInterfaceRequestor.h"
11 #include "nsIInterfaceRequestorUtils.h"
12 #include "nsCommandParams.h"
13 #include "nsCRT.h"
14 #include "nsString.h"
15 #include "mozilla/ArrayUtils.h"
16 #include "mozilla/Preferences.h"
17 #include "mozilla/PresShell.h"
19 #include "nsControllerCommandTable.h"
20 #include "nsCommandParams.h"
22 #include "nsPIDOMWindow.h"
23 #include "nsIDocShell.h"
24 #include "nsISelectionController.h"
25 #include "nsIWebNavigation.h"
26 #include "nsIContentViewerEdit.h"
27 #include "nsIContentViewer.h"
28 #include "nsFocusManager.h"
29 #include "nsCopySupport.h"
30 #include "nsIClipboard.h"
31 #include "ContentEventHandler.h"
32 #include "nsContentUtils.h"
33 #include "mozilla/Attributes.h"
34 #include "mozilla/BasicEvents.h"
35 #include "mozilla/TextEvents.h"
36 #include "mozilla/dom/Document.h"
37 #include "mozilla/dom/Selection.h"
38 #include "mozilla/layers/KeyboardMap.h"
40 using namespace mozilla;
41 using namespace mozilla::layers;
43 constexpr const char* sSelectAllString = "cmd_selectAll";
44 constexpr const char* sSelectNoneString = "cmd_selectNone";
45 constexpr const char* sCopyImageLocationString = "cmd_copyImageLocation";
46 constexpr const char* sCopyImageContentsString = "cmd_copyImageContents";
47 constexpr const char* sCopyImageString = "cmd_copyImage";
49 constexpr const char* sScrollTopString = "cmd_scrollTop";
50 constexpr const char* sScrollBottomString = "cmd_scrollBottom";
51 constexpr const char* sScrollPageUpString = "cmd_scrollPageUp";
52 constexpr const char* sScrollPageDownString = "cmd_scrollPageDown";
53 constexpr const char* sScrollLineUpString = "cmd_scrollLineUp";
54 constexpr const char* sScrollLineDownString = "cmd_scrollLineDown";
55 constexpr const char* sScrollLeftString = "cmd_scrollLeft";
56 constexpr const char* sScrollRightString = "cmd_scrollRight";
57 constexpr const char* sMoveTopString = "cmd_moveTop";
58 constexpr const char* sMoveBottomString = "cmd_moveBottom";
59 constexpr const char* sMovePageUpString = "cmd_movePageUp";
60 constexpr const char* sMovePageDownString = "cmd_movePageDown";
61 constexpr const char* sLinePreviousString = "cmd_linePrevious";
62 constexpr const char* sLineNextString = "cmd_lineNext";
63 constexpr const char* sCharPreviousString = "cmd_charPrevious";
64 constexpr const char* sCharNextString = "cmd_charNext";
66 // These are so the browser can use editor navigation key bindings
67 // helps with accessibility (boolean pref accessibility.browsewithcaret)
69 constexpr const char* sSelectCharPreviousString = "cmd_selectCharPrevious";
70 constexpr const char* sSelectCharNextString = "cmd_selectCharNext";
72 constexpr const char* sWordPreviousString = "cmd_wordPrevious";
73 constexpr const char* sWordNextString = "cmd_wordNext";
74 constexpr const char* sSelectWordPreviousString = "cmd_selectWordPrevious";
75 constexpr const char* sSelectWordNextString = "cmd_selectWordNext";
77 constexpr const char* sBeginLineString = "cmd_beginLine";
78 constexpr const char* sEndLineString = "cmd_endLine";
79 constexpr const char* sSelectBeginLineString = "cmd_selectBeginLine";
80 constexpr const char* sSelectEndLineString = "cmd_selectEndLine";
82 constexpr const char* sSelectLinePreviousString = "cmd_selectLinePrevious";
83 constexpr const char* sSelectLineNextString = "cmd_selectLineNext";
85 constexpr const char* sSelectPageUpString = "cmd_selectPageUp";
86 constexpr const char* sSelectPageDownString = "cmd_selectPageDown";
88 constexpr const char* sSelectTopString = "cmd_selectTop";
89 constexpr const char* sSelectBottomString = "cmd_selectBottom";
91 // Physical-direction movement and selection commands
92 constexpr const char* sMoveLeftString = "cmd_moveLeft";
93 constexpr const char* sMoveRightString = "cmd_moveRight";
94 constexpr const char* sMoveUpString = "cmd_moveUp";
95 constexpr const char* sMoveDownString = "cmd_moveDown";
96 constexpr const char* sMoveLeft2String = "cmd_moveLeft2";
97 constexpr const char* sMoveRight2String = "cmd_moveRight2";
98 constexpr const char* sMoveUp2String = "cmd_moveUp2";
99 constexpr const char* sMoveDown2String = "cmd_moveDown2";
101 constexpr const char* sSelectLeftString = "cmd_selectLeft";
102 constexpr const char* sSelectRightString = "cmd_selectRight";
103 constexpr const char* sSelectUpString = "cmd_selectUp";
104 constexpr const char* sSelectDownString = "cmd_selectDown";
105 constexpr const char* sSelectLeft2String = "cmd_selectLeft2";
106 constexpr const char* sSelectRight2String = "cmd_selectRight2";
107 constexpr const char* sSelectUp2String = "cmd_selectUp2";
108 constexpr const char* sSelectDown2String = "cmd_selectDown2";
110 #if 0
111 # pragma mark -
112 #endif
114 // a base class for selection-related commands, for code sharing
115 class nsSelectionCommandsBase : public nsIControllerCommand {
116 public:
117 NS_DECL_ISUPPORTS
118 NS_IMETHOD IsCommandEnabled(const char* aCommandName,
119 nsISupports* aCommandContext,
120 bool* _retval) override;
121 NS_IMETHOD GetCommandStateParams(const char* aCommandName,
122 nsICommandParams* aParams,
123 nsISupports* aCommandContext) override;
124 MOZ_CAN_RUN_SCRIPT
125 NS_IMETHOD DoCommandParams(const char* aCommandName,
126 nsICommandParams* aParams,
127 nsISupports* aCommandContext) override;
129 protected:
130 virtual ~nsSelectionCommandsBase() {}
132 static nsresult GetPresShellFromWindow(nsPIDOMWindowOuter* aWindow,
133 PresShell** aPresShell);
134 static nsresult GetSelectionControllerFromWindow(
135 nsPIDOMWindowOuter* aWindow, nsISelectionController** aSelCon);
137 // no member variables, please, we're stateless!
140 // this class implements commands whose behavior depends on the 'browse with
141 // caret' setting
142 class nsSelectMoveScrollCommand : public nsSelectionCommandsBase {
143 public:
144 NS_IMETHOD DoCommand(const char* aCommandName,
145 nsISupports* aCommandContext) override;
147 // no member variables, please, we're stateless!
150 // this class implements physical-movement versions of the above
151 class nsPhysicalSelectMoveScrollCommand : public nsSelectionCommandsBase {
152 public:
153 NS_IMETHOD DoCommand(const char* aCommandName,
154 nsISupports* aCommandContext) override;
156 // no member variables, please, we're stateless!
159 // this class implements other selection commands
160 class nsSelectCommand : public nsSelectionCommandsBase {
161 public:
162 NS_IMETHOD DoCommand(const char* aCommandName,
163 nsISupports* aCommandContext) override;
165 // no member variables, please, we're stateless!
168 // this class implements physical-movement versions of selection commands
169 class nsPhysicalSelectCommand : public nsSelectionCommandsBase {
170 public:
171 NS_IMETHOD DoCommand(const char* aCommandName,
172 nsISupports* aCommandContext) override;
174 // no member variables, please, we're stateless!
177 #if 0
178 # pragma mark -
179 #endif
181 NS_IMPL_ISUPPORTS(nsSelectionCommandsBase, nsIControllerCommand)
183 NS_IMETHODIMP
184 nsSelectionCommandsBase::IsCommandEnabled(const char* aCommandName,
185 nsISupports* aCommandContext,
186 bool* outCmdEnabled) {
187 // XXX this needs fixing. e.g. you can't scroll up if you're already at the
188 // top of the document.
189 *outCmdEnabled = true;
190 return NS_OK;
193 NS_IMETHODIMP
194 nsSelectionCommandsBase::GetCommandStateParams(const char* aCommandName,
195 nsICommandParams* aParams,
196 nsISupports* aCommandContext) {
197 // XXX we should probably return the enabled state
198 return NS_ERROR_NOT_IMPLEMENTED;
201 NS_IMETHODIMP
202 nsSelectionCommandsBase::DoCommandParams(const char* aCommandName,
203 nsICommandParams* aParams,
204 nsISupports* aCommandContext) {
205 return DoCommand(aCommandName, aCommandContext);
208 // protected methods
210 nsresult nsSelectionCommandsBase::GetPresShellFromWindow(
211 nsPIDOMWindowOuter* aWindow, PresShell** aPresShell) {
212 *aPresShell = nullptr;
213 NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
215 nsIDocShell* docShell = aWindow->GetDocShell();
216 NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
218 NS_IF_ADDREF(*aPresShell = docShell->GetPresShell());
219 return NS_OK;
222 nsresult nsSelectionCommandsBase::GetSelectionControllerFromWindow(
223 nsPIDOMWindowOuter* aWindow, nsISelectionController** aSelCon) {
224 RefPtr<PresShell> presShell;
225 GetPresShellFromWindow(aWindow, getter_AddRefs(presShell));
226 if (!presShell) {
227 *aSelCon = nullptr;
228 return NS_ERROR_FAILURE;
230 *aSelCon = presShell.forget().take();
231 return NS_OK;
234 #if 0
235 # pragma mark -
236 #endif
238 // Helpers for nsSelectMoveScrollCommand and nsPhysicalSelectMoveScrollCommand
239 static void AdjustFocusAfterCaretMove(nsPIDOMWindowOuter* aWindow) {
240 // adjust the focus to the new caret position
241 nsIFocusManager* fm = nsFocusManager::GetFocusManager();
242 if (fm) {
243 RefPtr<dom::Element> result;
244 fm->MoveFocus(aWindow, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
245 nsIFocusManager::FLAG_NOSCROLL, getter_AddRefs(result));
249 static bool IsCaretOnInWindow(nsPIDOMWindowOuter* aWindow,
250 nsISelectionController* aSelCont) {
251 // We allow the caret to be moved with arrow keys on any window for which
252 // the caret is enabled. In particular, this includes caret-browsing mode
253 // in non-chrome documents.
254 bool caretOn = false;
255 aSelCont->GetCaretEnabled(&caretOn);
256 if (!caretOn) {
257 caretOn = Preferences::GetBool("accessibility.browsewithcaret");
258 if (caretOn) {
259 nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
260 if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
261 caretOn = false;
265 return caretOn;
268 static constexpr struct BrowseCommand {
269 const char *reverse, *forward;
270 KeyboardScrollAction::KeyboardScrollActionType scrollAction;
271 nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
272 nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool);
273 } browseCommands[] = {
274 {sScrollTopString, sScrollBottomString,
275 KeyboardScrollAction::eScrollComplete,
276 &nsISelectionController::CompleteScroll},
277 {sScrollPageUpString, sScrollPageDownString,
278 KeyboardScrollAction::eScrollPage, &nsISelectionController::ScrollPage},
279 {sScrollLineUpString, sScrollLineDownString,
280 KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
281 {sScrollLeftString, sScrollRightString,
282 KeyboardScrollAction::eScrollCharacter,
283 &nsISelectionController::ScrollCharacter},
284 {sMoveTopString, sMoveBottomString, KeyboardScrollAction::eScrollComplete,
285 &nsISelectionController::CompleteScroll,
286 &nsISelectionController::CompleteMove},
287 {sMovePageUpString, sMovePageDownString, KeyboardScrollAction::eScrollPage,
288 &nsISelectionController::ScrollPage, &nsISelectionController::PageMove},
289 {sLinePreviousString, sLineNextString, KeyboardScrollAction::eScrollLine,
290 &nsISelectionController::ScrollLine, &nsISelectionController::LineMove},
291 {sWordPreviousString, sWordNextString,
292 KeyboardScrollAction::eScrollCharacter,
293 &nsISelectionController::ScrollCharacter,
294 &nsISelectionController::WordMove},
295 {sCharPreviousString, sCharNextString,
296 KeyboardScrollAction::eScrollCharacter,
297 &nsISelectionController::ScrollCharacter,
298 &nsISelectionController::CharacterMove},
299 {sBeginLineString, sEndLineString, KeyboardScrollAction::eScrollComplete,
300 &nsISelectionController::CompleteScroll,
301 &nsISelectionController::IntraLineMove}};
303 nsresult nsSelectMoveScrollCommand::DoCommand(const char* aCommandName,
304 nsISupports* aCommandContext) {
305 nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
306 nsCOMPtr<nsISelectionController> selCont;
307 GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
308 NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
310 bool caretOn = IsCaretOnInWindow(piWindow, selCont);
312 for (size_t i = 0; i < ArrayLength(browseCommands); i++) {
313 bool forward = !strcmp(aCommandName, browseCommands[i].forward);
314 if (forward || !strcmp(aCommandName, browseCommands[i].reverse)) {
315 if (caretOn && browseCommands[i].move &&
316 NS_SUCCEEDED((selCont->*(browseCommands[i].move))(forward, false))) {
317 AdjustFocusAfterCaretMove(piWindow);
318 return NS_OK;
320 return (selCont->*(browseCommands[i].scroll))(forward);
324 return NS_ERROR_NOT_IMPLEMENTED;
327 // XXX It's not clear to me yet how we should handle the "scroll" option
328 // for these commands; for now, I'm mapping them back to ScrollCharacter,
329 // ScrollLine, etc., as if for horizontal-mode content, but this may need
330 // to be reconsidered once we have more experience with vertical content.
331 static const struct PhysicalBrowseCommand {
332 const char* command;
333 int16_t direction, amount;
334 KeyboardScrollAction::KeyboardScrollActionType scrollAction;
335 nsresult (NS_STDCALL nsISelectionController::*scroll)(bool);
336 } physicalBrowseCommands[] = {
337 {sMoveLeftString, nsISelectionController::MOVE_LEFT, 0,
338 KeyboardScrollAction::eScrollCharacter,
339 &nsISelectionController::ScrollCharacter},
340 {sMoveRightString, nsISelectionController::MOVE_RIGHT, 0,
341 KeyboardScrollAction::eScrollCharacter,
342 &nsISelectionController::ScrollCharacter},
343 {sMoveUpString, nsISelectionController::MOVE_UP, 0,
344 KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
345 {sMoveDownString, nsISelectionController::MOVE_DOWN, 0,
346 KeyboardScrollAction::eScrollLine, &nsISelectionController::ScrollLine},
347 {sMoveLeft2String, nsISelectionController::MOVE_LEFT, 1,
348 KeyboardScrollAction::eScrollCharacter,
349 &nsISelectionController::ScrollCharacter},
350 {sMoveRight2String, nsISelectionController::MOVE_RIGHT, 1,
351 KeyboardScrollAction::eScrollCharacter,
352 &nsISelectionController::ScrollCharacter},
353 {sMoveUp2String, nsISelectionController::MOVE_UP, 1,
354 KeyboardScrollAction::eScrollComplete,
355 &nsISelectionController::CompleteScroll},
356 {sMoveDown2String, nsISelectionController::MOVE_DOWN, 1,
357 KeyboardScrollAction::eScrollComplete,
358 &nsISelectionController::CompleteScroll},
361 nsresult nsPhysicalSelectMoveScrollCommand::DoCommand(
362 const char* aCommandName, nsISupports* aCommandContext) {
363 nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
364 nsCOMPtr<nsISelectionController> selCont;
365 GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
366 NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
368 bool caretOn = IsCaretOnInWindow(piWindow, selCont);
370 for (size_t i = 0; i < ArrayLength(physicalBrowseCommands); i++) {
371 const PhysicalBrowseCommand& cmd = physicalBrowseCommands[i];
372 if (!strcmp(aCommandName, cmd.command)) {
373 int16_t dir = cmd.direction;
374 if (caretOn &&
375 NS_SUCCEEDED(selCont->PhysicalMove(dir, cmd.amount, false))) {
376 AdjustFocusAfterCaretMove(piWindow);
377 return NS_OK;
380 bool forward = (dir == nsISelectionController::MOVE_RIGHT ||
381 dir == nsISelectionController::MOVE_DOWN);
382 return (selCont->*(cmd.scroll))(forward);
386 return NS_ERROR_NOT_IMPLEMENTED;
389 #if 0
390 # pragma mark -
391 #endif
393 static const struct SelectCommand {
394 const char *reverse, *forward;
395 nsresult (NS_STDCALL nsISelectionController::*select)(bool, bool);
396 } selectCommands[] = {{sSelectCharPreviousString, sSelectCharNextString,
397 &nsISelectionController::CharacterMove},
398 {sSelectWordPreviousString, sSelectWordNextString,
399 &nsISelectionController::WordMove},
400 {sSelectBeginLineString, sSelectEndLineString,
401 &nsISelectionController::IntraLineMove},
402 {sSelectLinePreviousString, sSelectLineNextString,
403 &nsISelectionController::LineMove},
404 {sSelectPageUpString, sSelectPageDownString,
405 &nsISelectionController::PageMove},
406 {sSelectTopString, sSelectBottomString,
407 &nsISelectionController::CompleteMove}};
409 nsresult nsSelectCommand::DoCommand(const char* aCommandName,
410 nsISupports* aCommandContext) {
411 nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
412 nsCOMPtr<nsISelectionController> selCont;
413 GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
414 NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
416 // These commands are so the browser can use caret navigation key bindings -
417 // Helps with accessibility - aaronl@netscape.com
418 for (size_t i = 0; i < ArrayLength(selectCommands); i++) {
419 bool forward = !strcmp(aCommandName, selectCommands[i].forward);
420 if (forward || !strcmp(aCommandName, selectCommands[i].reverse)) {
421 return (selCont->*(selectCommands[i].select))(forward, true);
424 return NS_ERROR_NOT_IMPLEMENTED;
427 #if 0
428 # pragma mark -
429 #endif
431 static const struct PhysicalSelectCommand {
432 const char* command;
433 int16_t direction, amount;
434 } physicalSelectCommands[] = {
435 {sSelectLeftString, nsISelectionController::MOVE_LEFT, 0},
436 {sSelectRightString, nsISelectionController::MOVE_RIGHT, 0},
437 {sSelectUpString, nsISelectionController::MOVE_UP, 0},
438 {sSelectDownString, nsISelectionController::MOVE_DOWN, 0},
439 {sSelectLeft2String, nsISelectionController::MOVE_LEFT, 1},
440 {sSelectRight2String, nsISelectionController::MOVE_RIGHT, 1},
441 {sSelectUp2String, nsISelectionController::MOVE_UP, 1},
442 {sSelectDown2String, nsISelectionController::MOVE_DOWN, 1}};
444 nsresult nsPhysicalSelectCommand::DoCommand(const char* aCommandName,
445 nsISupports* aCommandContext) {
446 nsCOMPtr<nsPIDOMWindowOuter> piWindow(do_QueryInterface(aCommandContext));
447 nsCOMPtr<nsISelectionController> selCont;
448 GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont));
449 NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED);
451 for (size_t i = 0; i < ArrayLength(physicalSelectCommands); i++) {
452 if (!strcmp(aCommandName, physicalSelectCommands[i].command)) {
453 return selCont->PhysicalMove(physicalSelectCommands[i].direction,
454 physicalSelectCommands[i].amount, true);
458 return NS_ERROR_NOT_IMPLEMENTED;
461 #if 0
462 # pragma mark -
463 #endif
465 class nsClipboardCommand final : public nsIControllerCommand {
466 ~nsClipboardCommand() {}
468 public:
469 NS_DECL_ISUPPORTS
470 NS_DECL_NSICONTROLLERCOMMAND
473 NS_IMPL_ISUPPORTS(nsClipboardCommand, nsIControllerCommand)
475 nsresult nsClipboardCommand::IsCommandEnabled(const char* aCommandName,
476 nsISupports* aContext,
477 bool* outCmdEnabled) {
478 NS_ENSURE_ARG_POINTER(outCmdEnabled);
479 *outCmdEnabled = false;
481 if (strcmp(aCommandName, "cmd_copy") && strcmp(aCommandName, "cmd_cut") &&
482 strcmp(aCommandName, "cmd_paste")) {
483 return NS_OK;
486 nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
487 NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
488 RefPtr<dom::Document> doc = window->GetExtantDoc();
489 NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
491 if (doc->IsHTMLOrXHTML()) {
492 // In HTML and XHTML documents, we always want the cut, copy and paste
493 // commands to be enabled.
494 *outCmdEnabled = true;
495 } else {
496 // Cut isn't enabled in xul documents which use nsClipboardCommand
497 if (strcmp(aCommandName, "cmd_copy") == 0) {
498 *outCmdEnabled = nsCopySupport::CanCopy(doc);
501 return NS_OK;
504 nsresult nsClipboardCommand::DoCommand(const char* aCommandName,
505 nsISupports* aContext) {
506 if (strcmp(aCommandName, "cmd_cut") && strcmp(aCommandName, "cmd_copy") &&
507 strcmp(aCommandName, "cmd_paste"))
508 return NS_OK;
510 nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
511 NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
513 nsIDocShell* docShell = window->GetDocShell();
514 NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
516 RefPtr<PresShell> presShell = docShell->GetPresShell();
517 NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
519 EventMessage eventMessage = eCopy;
520 if (strcmp(aCommandName, "cmd_cut") == 0) {
521 eventMessage = eCut;
522 } else if (strcmp(aCommandName, "cmd_paste") == 0) {
523 eventMessage = ePaste;
526 bool actionTaken = false;
527 nsCopySupport::FireClipboardEvent(eventMessage,
528 nsIClipboard::kGlobalClipboard, presShell,
529 nullptr, &actionTaken);
531 return actionTaken ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION;
534 NS_IMETHODIMP
535 nsClipboardCommand::GetCommandStateParams(const char* aCommandName,
536 nsICommandParams* aParams,
537 nsISupports* aCommandContext) {
538 return NS_ERROR_NOT_IMPLEMENTED;
541 nsresult nsClipboardCommand::DoCommandParams(const char* aCommandName,
542 nsICommandParams* aParams,
543 nsISupports* aContext) {
544 return DoCommand(aCommandName, aContext);
547 #if 0
548 # pragma mark -
549 #endif
551 class nsSelectionCommand : public nsIControllerCommand {
552 public:
553 NS_DECL_ISUPPORTS
554 NS_DECL_NSICONTROLLERCOMMAND
556 protected:
557 virtual ~nsSelectionCommand() {}
559 virtual nsresult IsClipboardCommandEnabled(const char* aCommandName,
560 nsIContentViewerEdit* aEdit,
561 bool* outCmdEnabled) = 0;
562 virtual nsresult DoClipboardCommand(const char* aCommandName,
563 nsIContentViewerEdit* aEdit,
564 nsICommandParams* aParams) = 0;
566 static nsresult GetContentViewerEditFromContext(
567 nsISupports* aContext, nsIContentViewerEdit** aEditInterface);
569 // no member variables, please, we're stateless!
572 NS_IMPL_ISUPPORTS(nsSelectionCommand, nsIControllerCommand)
574 /*---------------------------------------------------------------------------
576 nsSelectionCommand
578 ----------------------------------------------------------------------------*/
580 NS_IMETHODIMP
581 nsSelectionCommand::IsCommandEnabled(const char* aCommandName,
582 nsISupports* aCommandContext,
583 bool* outCmdEnabled) {
584 NS_ENSURE_ARG_POINTER(outCmdEnabled);
585 *outCmdEnabled = false;
587 nsCOMPtr<nsIContentViewerEdit> contentEdit;
588 GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
589 NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
591 return IsClipboardCommandEnabled(aCommandName, contentEdit, outCmdEnabled);
594 NS_IMETHODIMP
595 nsSelectionCommand::DoCommand(const char* aCommandName,
596 nsISupports* aCommandContext) {
597 nsCOMPtr<nsIContentViewerEdit> contentEdit;
598 GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
599 NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
601 return DoClipboardCommand(aCommandName, contentEdit, nullptr);
604 NS_IMETHODIMP
605 nsSelectionCommand::GetCommandStateParams(const char* aCommandName,
606 nsICommandParams* aParams,
607 nsISupports* aCommandContext) {
608 return NS_ERROR_NOT_IMPLEMENTED;
611 NS_IMETHODIMP
612 nsSelectionCommand::DoCommandParams(const char* aCommandName,
613 nsICommandParams* aParams,
614 nsISupports* aCommandContext) {
615 nsCOMPtr<nsIContentViewerEdit> contentEdit;
616 GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit));
617 NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED);
619 return DoClipboardCommand(aCommandName, contentEdit, aParams);
622 nsresult nsSelectionCommand::GetContentViewerEditFromContext(
623 nsISupports* aContext, nsIContentViewerEdit** aEditInterface) {
624 NS_ENSURE_ARG(aEditInterface);
625 *aEditInterface = nullptr;
627 nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
628 NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG);
630 nsIDocShell* docShell = window->GetDocShell();
631 NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
633 nsCOMPtr<nsIContentViewer> viewer;
634 docShell->GetContentViewer(getter_AddRefs(viewer));
635 nsCOMPtr<nsIContentViewerEdit> edit(do_QueryInterface(viewer));
636 NS_ENSURE_TRUE(edit, NS_ERROR_FAILURE);
638 edit.forget(aEditInterface);
639 return NS_OK;
642 #if 0
643 # pragma mark -
644 #endif
646 #define NS_DECL_CLIPBOARD_COMMAND(_cmd) \
647 class _cmd : public nsSelectionCommand { \
648 protected: \
649 virtual nsresult IsClipboardCommandEnabled(const char* aCommandName, \
650 nsIContentViewerEdit* aEdit, \
651 bool* outCmdEnabled) override; \
652 virtual nsresult DoClipboardCommand(const char* aCommandName, \
653 nsIContentViewerEdit* aEdit, \
654 nsICommandParams* aParams) override; \
655 /* no member variables, please, we're stateless! */ \
658 NS_DECL_CLIPBOARD_COMMAND(nsClipboardCopyLinkCommand)
659 NS_DECL_CLIPBOARD_COMMAND(nsClipboardImageCommands)
660 NS_DECL_CLIPBOARD_COMMAND(nsClipboardSelectAllNoneCommands)
661 NS_DECL_CLIPBOARD_COMMAND(nsClipboardGetContentsCommand)
663 nsresult nsClipboardCopyLinkCommand::IsClipboardCommandEnabled(
664 const char* aCommandName, nsIContentViewerEdit* aEdit,
665 bool* outCmdEnabled) {
666 return aEdit->GetInLink(outCmdEnabled);
669 nsresult nsClipboardCopyLinkCommand::DoClipboardCommand(
670 const char* aCommandName, nsIContentViewerEdit* aEdit,
671 nsICommandParams* aParams) {
672 return aEdit->CopyLinkLocation();
675 #if 0
676 # pragma mark -
677 #endif
679 nsresult nsClipboardImageCommands::IsClipboardCommandEnabled(
680 const char* aCommandName, nsIContentViewerEdit* aEdit,
681 bool* outCmdEnabled) {
682 return aEdit->GetInImage(outCmdEnabled);
685 nsresult nsClipboardImageCommands::DoClipboardCommand(
686 const char* aCommandName, nsIContentViewerEdit* aEdit,
687 nsICommandParams* aParams) {
688 if (!nsCRT::strcmp(sCopyImageLocationString, aCommandName))
689 return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_TEXT);
690 if (!nsCRT::strcmp(sCopyImageContentsString, aCommandName))
691 return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_DATA);
692 int32_t copyFlags = nsIContentViewerEdit::COPY_IMAGE_DATA |
693 nsIContentViewerEdit::COPY_IMAGE_HTML;
694 if (aParams) {
695 copyFlags = aParams->AsCommandParams()->GetInt("imageCopy");
697 return aEdit->CopyImage(copyFlags);
700 #if 0
701 # pragma mark -
702 #endif
704 nsresult nsClipboardSelectAllNoneCommands::IsClipboardCommandEnabled(
705 const char* aCommandName, nsIContentViewerEdit* aEdit,
706 bool* outCmdEnabled) {
707 *outCmdEnabled = true;
708 return NS_OK;
711 nsresult nsClipboardSelectAllNoneCommands::DoClipboardCommand(
712 const char* aCommandName, nsIContentViewerEdit* aEdit,
713 nsICommandParams* aParams) {
714 if (!nsCRT::strcmp(sSelectAllString, aCommandName)) return aEdit->SelectAll();
716 return aEdit->ClearSelection();
719 #if 0
720 # pragma mark -
721 #endif
723 nsresult nsClipboardGetContentsCommand::IsClipboardCommandEnabled(
724 const char* aCommandName, nsIContentViewerEdit* aEdit,
725 bool* outCmdEnabled) {
726 return aEdit->GetCanGetContents(outCmdEnabled);
729 nsresult nsClipboardGetContentsCommand::DoClipboardCommand(
730 const char* aCommandName, nsIContentViewerEdit* aEdit,
731 nsICommandParams* aParams) {
732 NS_ENSURE_ARG(aParams);
734 nsCommandParams* params = aParams->AsCommandParams();
736 nsAutoCString mimeType("text/plain");
738 nsAutoCString format;
739 if (NS_SUCCEEDED(params->GetCString("format", format))) {
740 mimeType.Assign(format);
743 nsAutoString contents;
744 nsresult rv = aEdit->GetContents(mimeType.get(),
745 params->GetBool("selection_only"), contents);
746 if (NS_FAILED(rv)) {
747 return rv;
749 return params->SetString("result", contents);
752 #if 0 // Remove unless needed again, bug 204777
753 class nsWebNavigationBaseCommand : public nsIControllerCommand
755 public:
756 virtual ~nsWebNavigationBaseCommand() {}
758 NS_DECL_ISUPPORTS
759 NS_DECL_NSICONTROLLERCOMMAND
761 protected:
763 virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled) = 0;
764 virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation) = 0;
766 static nsresult GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation);
768 // no member variables, please, we're stateless!
771 class nsGoForwardCommand : public nsWebNavigationBaseCommand
773 protected:
775 virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled);
776 virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation);
777 // no member variables, please, we're stateless!
780 class nsGoBackCommand : public nsWebNavigationBaseCommand
782 protected:
784 virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled);
785 virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation);
786 // no member variables, please, we're stateless!
789 /*---------------------------------------------------------------------------
791 nsWebNavigationCommands
792 no params
793 ----------------------------------------------------------------------------*/
795 NS_IMPL_ISUPPORTS(nsWebNavigationBaseCommand, nsIControllerCommand)
797 NS_IMETHODIMP
798 nsWebNavigationBaseCommand::IsCommandEnabled(const char * aCommandName,
799 nsISupports *aCommandContext,
800 bool *outCmdEnabled)
802 NS_ENSURE_ARG_POINTER(outCmdEnabled);
803 *outCmdEnabled = false;
805 nsCOMPtr<nsIWebNavigation> webNav;
806 GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav));
807 NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG);
809 return IsCommandEnabled(aCommandName, webNav, outCmdEnabled);
812 NS_IMETHODIMP
813 nsWebNavigationBaseCommand::GetCommandStateParams(const char *aCommandName,
814 nsICommandParams *aParams, nsISupports *aCommandContext)
816 // XXX we should probably return the enabled state
817 return NS_ERROR_NOT_IMPLEMENTED;
820 NS_IMETHODIMP
821 nsWebNavigationBaseCommand::DoCommand(const char *aCommandName,
822 nsISupports *aCommandContext)
824 nsCOMPtr<nsIWebNavigation> webNav;
825 GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav));
826 NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG);
828 return DoWebNavCommand(aCommandName, webNav);
831 NS_IMETHODIMP
832 nsWebNavigationBaseCommand::DoCommandParams(const char *aCommandName,
833 nsICommandParams *aParams, nsISupports *aCommandContext)
835 return DoCommand(aCommandName, aCommandContext);
838 nsresult
839 nsWebNavigationBaseCommand::GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation)
841 nsCOMPtr<nsIInterfaceRequestor> windowReq = do_QueryInterface(aContext);
842 CallGetInterface(windowReq.get(), aWebNavigation);
843 return (*aWebNavigation) ? NS_OK : NS_ERROR_FAILURE;
846 nsresult
847 nsGoForwardCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled)
849 return aWebNavigation->GetCanGoForward(outCmdEnabled);
852 nsresult
853 nsGoForwardCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation)
855 return aWebNavigation->GoForward();
858 nsresult
859 nsGoBackCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled)
861 return aWebNavigation->GetCanGoBack(outCmdEnabled);
864 nsresult
865 nsGoBackCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation)
867 return aWebNavigation->GoBack();
869 #endif
871 class nsLookUpDictionaryCommand final : public nsIControllerCommand {
872 public:
873 NS_DECL_ISUPPORTS
874 NS_DECL_NSICONTROLLERCOMMAND
876 private:
877 virtual ~nsLookUpDictionaryCommand() {}
880 NS_IMPL_ISUPPORTS(nsLookUpDictionaryCommand, nsIControllerCommand)
882 NS_IMETHODIMP
883 nsLookUpDictionaryCommand::IsCommandEnabled(const char* aCommandName,
884 nsISupports* aCommandContext,
885 bool* aRetval) {
886 *aRetval = true;
887 return NS_OK;
890 NS_IMETHODIMP
891 nsLookUpDictionaryCommand::GetCommandStateParams(const char* aCommandName,
892 nsICommandParams* aParams,
893 nsISupports* aCommandContext) {
894 return NS_ERROR_NOT_IMPLEMENTED;
897 NS_IMETHODIMP
898 nsLookUpDictionaryCommand::DoCommand(const char* aCommandName,
899 nsISupports* aCommandContext) {
900 return NS_ERROR_NOT_IMPLEMENTED;
903 NS_IMETHODIMP
904 nsLookUpDictionaryCommand::DoCommandParams(const char* aCommandName,
905 nsICommandParams* aParams,
906 nsISupports* aCommandContext) {
907 if (NS_WARN_IF(!nsContentUtils::IsSafeToRunScript())) {
908 return NS_ERROR_NOT_AVAILABLE;
911 nsCommandParams* params = aParams->AsCommandParams();
913 ErrorResult error;
914 int32_t x = params->GetInt("x", error);
915 if (NS_WARN_IF(error.Failed())) {
916 return error.StealNSResult();
918 int32_t y = params->GetInt("y", error);
919 if (NS_WARN_IF(error.Failed())) {
920 return error.StealNSResult();
923 LayoutDeviceIntPoint point(x, y);
925 nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aCommandContext);
926 if (NS_WARN_IF(!window)) {
927 return NS_ERROR_FAILURE;
930 nsIDocShell* docShell = window->GetDocShell();
931 if (NS_WARN_IF(!docShell)) {
932 return NS_ERROR_FAILURE;
935 PresShell* presShell = docShell->GetPresShell();
936 if (NS_WARN_IF(!presShell)) {
937 return NS_ERROR_FAILURE;
940 nsPresContext* presContext = presShell->GetPresContext();
941 if (NS_WARN_IF(!presContext)) {
942 return NS_ERROR_FAILURE;
945 nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget();
946 if (NS_WARN_IF(!widget)) {
947 return NS_ERROR_FAILURE;
950 WidgetQueryContentEvent charAt(true, eQueryCharacterAtPoint, widget);
951 charAt.mRefPoint.x = x;
952 charAt.mRefPoint.y = y;
953 ContentEventHandler handler(presContext);
954 handler.OnQueryCharacterAtPoint(&charAt);
956 if (NS_WARN_IF(!charAt.mSucceeded) ||
957 charAt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND) {
958 return NS_ERROR_FAILURE;
961 WidgetQueryContentEvent textContent(true, eQueryTextContent, widget);
962 // OSX 10.7 queries 50 characters before/after current point. So we fetch
963 // same length.
964 uint32_t offset = charAt.mReply.mOffset;
965 if (offset > 50) {
966 offset -= 50;
967 } else {
968 offset = 0;
970 textContent.InitForQueryTextContent(offset, 100);
971 handler.OnQueryTextContent(&textContent);
972 if (NS_WARN_IF(!textContent.mSucceeded ||
973 textContent.mReply.mString.IsEmpty())) {
974 return NS_ERROR_FAILURE;
977 // XXX nsIWordBreaker doesn't use contextual breaker.
978 // If OS provides it, widget should use it if contextual breaker is needed.
979 RefPtr<mozilla::intl::WordBreaker> wordBreaker =
980 nsContentUtils::WordBreaker();
981 if (NS_WARN_IF(!wordBreaker)) {
982 return NS_ERROR_FAILURE;
985 mozilla::intl::WordRange range = wordBreaker->FindWord(
986 textContent.mReply.mString.get(), textContent.mReply.mString.Length(),
987 charAt.mReply.mOffset - offset);
988 if (range.mEnd == range.mBegin) {
989 return NS_ERROR_FAILURE;
991 range.mBegin += offset;
992 range.mEnd += offset;
994 WidgetQueryContentEvent lookUpContent(true, eQueryTextContent, widget);
995 lookUpContent.InitForQueryTextContent(range.mBegin,
996 range.mEnd - range.mBegin);
997 lookUpContent.RequestFontRanges();
998 handler.OnQueryTextContent(&lookUpContent);
999 if (NS_WARN_IF(!lookUpContent.mSucceeded ||
1000 lookUpContent.mReply.mString.IsEmpty())) {
1001 return NS_ERROR_FAILURE;
1004 WidgetQueryContentEvent charRect(true, eQueryTextRect, widget);
1005 charRect.InitForQueryTextRect(range.mBegin, range.mEnd - range.mBegin);
1006 handler.OnQueryTextRect(&charRect);
1007 if (NS_WARN_IF(!charRect.mSucceeded)) {
1008 return NS_ERROR_FAILURE;
1011 widget->LookUpDictionary(lookUpContent.mReply.mString,
1012 lookUpContent.mReply.mFontRanges,
1013 charRect.mReply.mWritingMode.IsVertical(),
1014 charRect.mReply.mRect.TopLeft());
1016 return NS_OK;
1019 /*---------------------------------------------------------------------------
1021 RegisterWindowCommands
1023 ----------------------------------------------------------------------------*/
1025 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
1027 _cmdClass* theCmd = new _cmdClass(); \
1028 rv = aCommandTable->RegisterCommand( \
1029 _cmdName, static_cast<nsIControllerCommand*>(theCmd)); \
1032 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \
1034 _cmdClass* theCmd = new _cmdClass(); \
1035 rv = aCommandTable->RegisterCommand( \
1036 _cmdName, static_cast<nsIControllerCommand*>(theCmd));
1038 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \
1039 rv = aCommandTable->RegisterCommand( \
1040 _cmdName, static_cast<nsIControllerCommand*>(theCmd));
1042 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \
1043 rv = aCommandTable->RegisterCommand( \
1044 _cmdName, static_cast<nsIControllerCommand*>(theCmd)); \
1047 // static
1048 nsresult nsWindowCommandRegistration::RegisterWindowCommands(
1049 nsControllerCommandTable* aCommandTable) {
1050 nsresult rv;
1052 // XXX rework the macros to use a loop is possible, reducing code size
1054 // this set of commands is affected by the 'browse with caret' setting
1055 NS_REGISTER_FIRST_COMMAND(nsSelectMoveScrollCommand, sScrollTopString);
1056 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollBottomString);
1057 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageUpString);
1058 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageDownString);
1059 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineUpString);
1060 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineDownString);
1061 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLeftString);
1062 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollRightString);
1063 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveTopString);
1064 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveBottomString);
1065 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordPreviousString);
1066 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordNextString);
1067 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sBeginLineString);
1068 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sEndLineString);
1069 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageUpString);
1070 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageDownString);
1071 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLinePreviousString);
1072 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLineNextString);
1073 NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sCharPreviousString);
1074 NS_REGISTER_LAST_COMMAND(nsSelectMoveScrollCommand, sCharNextString);
1076 NS_REGISTER_FIRST_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveLeftString);
1077 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveRightString);
1078 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveUpString);
1079 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveDownString);
1080 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveLeft2String);
1081 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand,
1082 sMoveRight2String);
1083 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveUp2String);
1084 NS_REGISTER_LAST_COMMAND(nsPhysicalSelectMoveScrollCommand, sMoveDown2String);
1086 NS_REGISTER_FIRST_COMMAND(nsSelectCommand, sSelectCharPreviousString);
1087 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectCharNextString);
1088 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordPreviousString);
1089 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordNextString);
1090 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectBeginLineString);
1091 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectEndLineString);
1092 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLinePreviousString);
1093 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLineNextString);
1094 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageUpString);
1095 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageDownString);
1096 NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectTopString);
1097 NS_REGISTER_LAST_COMMAND(nsSelectCommand, sSelectBottomString);
1099 NS_REGISTER_FIRST_COMMAND(nsPhysicalSelectCommand, sSelectLeftString);
1100 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectRightString);
1101 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectUpString);
1102 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectDownString);
1103 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectLeft2String);
1104 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectRight2String);
1105 NS_REGISTER_NEXT_COMMAND(nsPhysicalSelectCommand, sSelectUp2String);
1106 NS_REGISTER_LAST_COMMAND(nsPhysicalSelectCommand, sSelectDown2String);
1108 NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_cut");
1109 NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_copy");
1110 NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_paste");
1111 NS_REGISTER_ONE_COMMAND(nsClipboardCopyLinkCommand, "cmd_copyLink");
1112 NS_REGISTER_FIRST_COMMAND(nsClipboardImageCommands, sCopyImageLocationString);
1113 NS_REGISTER_NEXT_COMMAND(nsClipboardImageCommands, sCopyImageContentsString);
1114 NS_REGISTER_LAST_COMMAND(nsClipboardImageCommands, sCopyImageString);
1115 NS_REGISTER_FIRST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectAllString);
1116 NS_REGISTER_LAST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectNoneString);
1118 NS_REGISTER_ONE_COMMAND(nsClipboardGetContentsCommand, "cmd_getContents");
1120 #if 0 // Remove unless needed again, bug 204777
1121 NS_REGISTER_ONE_COMMAND(nsGoBackCommand, "cmd_browserBack");
1122 NS_REGISTER_ONE_COMMAND(nsGoForwardCommand, "cmd_browserForward");
1123 #endif
1125 NS_REGISTER_ONE_COMMAND(nsLookUpDictionaryCommand, "cmd_lookUpDictionary");
1127 return rv;
1130 /* static */
1131 bool nsGlobalWindowCommands::FindScrollCommand(
1132 const char* aCommandName, KeyboardScrollAction* aOutAction) {
1133 // Search for a keyboard scroll action to do for this command in
1134 // browseCommands and physicalBrowseCommands. Each command exists in only one
1135 // of them, so the order we examine browseCommands and physicalBrowseCommands
1136 // doesn't matter.
1138 for (size_t i = 0; i < ArrayLength(browseCommands); i++) {
1139 const BrowseCommand& cmd = browseCommands[i];
1140 bool forward = !strcmp(aCommandName, cmd.forward);
1141 bool reverse = !strcmp(aCommandName, cmd.reverse);
1142 if (forward || reverse) {
1143 *aOutAction = KeyboardScrollAction(cmd.scrollAction, forward);
1144 return true;
1148 for (size_t i = 0; i < ArrayLength(physicalBrowseCommands); i++) {
1149 const PhysicalBrowseCommand& cmd = physicalBrowseCommands[i];
1150 if (!strcmp(aCommandName, cmd.command)) {
1151 int16_t dir = cmd.direction;
1152 bool forward = (dir == nsISelectionController::MOVE_RIGHT ||
1153 dir == nsISelectionController::MOVE_DOWN);
1155 *aOutAction = KeyboardScrollAction(cmd.scrollAction, forward);
1156 return true;
1160 return false;