Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | #include "nsGlobalWindowCommands.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIComponentManager.h" |
michael@0 | 9 | #include "nsIDOMElement.h" |
michael@0 | 10 | #include "nsIInterfaceRequestor.h" |
michael@0 | 11 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 12 | #include "nsCRT.h" |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | #include "mozilla/ArrayUtils.h" |
michael@0 | 15 | #include "mozilla/Preferences.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "nsIControllerCommandTable.h" |
michael@0 | 18 | #include "nsICommandParams.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "nsPIDOMWindow.h" |
michael@0 | 21 | #include "nsIPresShell.h" |
michael@0 | 22 | #include "nsIDocShell.h" |
michael@0 | 23 | #include "nsISelectionController.h" |
michael@0 | 24 | #include "nsIWebNavigation.h" |
michael@0 | 25 | #include "nsIContentViewerEdit.h" |
michael@0 | 26 | #include "nsIContentViewer.h" |
michael@0 | 27 | #include "nsFocusManager.h" |
michael@0 | 28 | #include "nsCopySupport.h" |
michael@0 | 29 | #include "nsIClipboard.h" |
michael@0 | 30 | #include "mozilla/Attributes.h" |
michael@0 | 31 | #include "mozilla/BasicEvents.h" |
michael@0 | 32 | |
michael@0 | 33 | #include "nsIClipboardDragDropHooks.h" |
michael@0 | 34 | #include "nsIClipboardDragDropHookList.h" |
michael@0 | 35 | |
michael@0 | 36 | using namespace mozilla; |
michael@0 | 37 | |
michael@0 | 38 | const char * const sSelectAllString = "cmd_selectAll"; |
michael@0 | 39 | const char * const sSelectNoneString = "cmd_selectNone"; |
michael@0 | 40 | const char * const sCopyImageLocationString = "cmd_copyImageLocation"; |
michael@0 | 41 | const char * const sCopyImageContentsString = "cmd_copyImageContents"; |
michael@0 | 42 | const char * const sCopyImageString = "cmd_copyImage"; |
michael@0 | 43 | |
michael@0 | 44 | const char * const sScrollTopString = "cmd_scrollTop"; |
michael@0 | 45 | const char * const sScrollBottomString = "cmd_scrollBottom"; |
michael@0 | 46 | const char * const sScrollPageUpString = "cmd_scrollPageUp"; |
michael@0 | 47 | const char * const sScrollPageDownString = "cmd_scrollPageDown"; |
michael@0 | 48 | const char * const sScrollLineUpString = "cmd_scrollLineUp"; |
michael@0 | 49 | const char * const sScrollLineDownString = "cmd_scrollLineDown"; |
michael@0 | 50 | const char * const sScrollLeftString = "cmd_scrollLeft"; |
michael@0 | 51 | const char * const sScrollRightString = "cmd_scrollRight"; |
michael@0 | 52 | const char * const sMoveTopString = "cmd_moveTop"; |
michael@0 | 53 | const char * const sMoveBottomString = "cmd_moveBottom"; |
michael@0 | 54 | const char * const sMovePageUpString = "cmd_movePageUp"; |
michael@0 | 55 | const char * const sMovePageDownString = "cmd_movePageDown"; |
michael@0 | 56 | const char * const sLinePreviousString = "cmd_linePrevious"; |
michael@0 | 57 | const char * const sLineNextString = "cmd_lineNext"; |
michael@0 | 58 | const char * const sCharPreviousString = "cmd_charPrevious"; |
michael@0 | 59 | const char * const sCharNextString = "cmd_charNext"; |
michael@0 | 60 | |
michael@0 | 61 | // These are so the browser can use editor navigation key bindings |
michael@0 | 62 | // helps with accessibility (boolean pref accessibility.browsewithcaret) |
michael@0 | 63 | |
michael@0 | 64 | const char * const sSelectCharPreviousString = "cmd_selectCharPrevious"; |
michael@0 | 65 | const char * const sSelectCharNextString = "cmd_selectCharNext"; |
michael@0 | 66 | |
michael@0 | 67 | const char * const sWordPreviousString = "cmd_wordPrevious"; |
michael@0 | 68 | const char * const sWordNextString = "cmd_wordNext"; |
michael@0 | 69 | const char * const sSelectWordPreviousString = "cmd_selectWordPrevious"; |
michael@0 | 70 | const char * const sSelectWordNextString = "cmd_selectWordNext"; |
michael@0 | 71 | |
michael@0 | 72 | const char * const sBeginLineString = "cmd_beginLine"; |
michael@0 | 73 | const char * const sEndLineString = "cmd_endLine"; |
michael@0 | 74 | const char * const sSelectBeginLineString = "cmd_selectBeginLine"; |
michael@0 | 75 | const char * const sSelectEndLineString = "cmd_selectEndLine"; |
michael@0 | 76 | |
michael@0 | 77 | const char * const sSelectLinePreviousString = "cmd_selectLinePrevious"; |
michael@0 | 78 | const char * const sSelectLineNextString = "cmd_selectLineNext"; |
michael@0 | 79 | |
michael@0 | 80 | const char * const sSelectPageUpString = "cmd_selectPageUp"; |
michael@0 | 81 | const char * const sSelectPageDownString = "cmd_selectPageDown"; |
michael@0 | 82 | |
michael@0 | 83 | const char * const sSelectTopString = "cmd_selectTop"; |
michael@0 | 84 | const char * const sSelectBottomString = "cmd_selectBottom"; |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | #if 0 |
michael@0 | 88 | #pragma mark - |
michael@0 | 89 | #endif |
michael@0 | 90 | |
michael@0 | 91 | // a base class for selection-related commands, for code sharing |
michael@0 | 92 | class nsSelectionCommandsBase : public nsIControllerCommand |
michael@0 | 93 | { |
michael@0 | 94 | public: |
michael@0 | 95 | virtual ~nsSelectionCommandsBase() {} |
michael@0 | 96 | |
michael@0 | 97 | NS_DECL_ISUPPORTS |
michael@0 | 98 | NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandContext, bool *_retval); |
michael@0 | 99 | NS_IMETHOD GetCommandStateParams(const char * aCommandName, nsICommandParams *aParams, nsISupports *aCommandContext); |
michael@0 | 100 | NS_IMETHOD DoCommandParams(const char * aCommandName, nsICommandParams *aParams, nsISupports *aCommandContext); |
michael@0 | 101 | |
michael@0 | 102 | protected: |
michael@0 | 103 | |
michael@0 | 104 | static nsresult GetPresShellFromWindow(nsPIDOMWindow *aWindow, nsIPresShell **aPresShell); |
michael@0 | 105 | static nsresult GetSelectionControllerFromWindow(nsPIDOMWindow *aWindow, nsISelectionController **aSelCon); |
michael@0 | 106 | |
michael@0 | 107 | // no member variables, please, we're stateless! |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | // this class implements commands whose behavior depends on the 'browse with caret' setting |
michael@0 | 111 | class nsSelectMoveScrollCommand : public nsSelectionCommandsBase |
michael@0 | 112 | { |
michael@0 | 113 | public: |
michael@0 | 114 | |
michael@0 | 115 | NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandContext); |
michael@0 | 116 | |
michael@0 | 117 | // no member variables, please, we're stateless! |
michael@0 | 118 | }; |
michael@0 | 119 | |
michael@0 | 120 | // this class implements other selection commands |
michael@0 | 121 | class nsSelectCommand : public nsSelectionCommandsBase |
michael@0 | 122 | { |
michael@0 | 123 | public: |
michael@0 | 124 | |
michael@0 | 125 | NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandContext); |
michael@0 | 126 | |
michael@0 | 127 | // no member variables, please, we're stateless! |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | #if 0 |
michael@0 | 131 | #pragma mark - |
michael@0 | 132 | #endif |
michael@0 | 133 | |
michael@0 | 134 | |
michael@0 | 135 | NS_IMPL_ISUPPORTS(nsSelectionCommandsBase, nsIControllerCommand) |
michael@0 | 136 | |
michael@0 | 137 | /* boolean isCommandEnabled (in string aCommandName, in nsISupports aCommandContext); */ |
michael@0 | 138 | NS_IMETHODIMP |
michael@0 | 139 | nsSelectionCommandsBase::IsCommandEnabled(const char * aCommandName, |
michael@0 | 140 | nsISupports *aCommandContext, |
michael@0 | 141 | bool *outCmdEnabled) |
michael@0 | 142 | { |
michael@0 | 143 | // XXX this needs fixing. e.g. you can't scroll up if you're already at the top of |
michael@0 | 144 | // the document. |
michael@0 | 145 | *outCmdEnabled = true; |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | /* void getCommandStateParams (in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); */ |
michael@0 | 150 | NS_IMETHODIMP |
michael@0 | 151 | nsSelectionCommandsBase::GetCommandStateParams(const char *aCommandName, |
michael@0 | 152 | nsICommandParams *aParams, nsISupports *aCommandContext) |
michael@0 | 153 | { |
michael@0 | 154 | // XXX we should probably return the enabled state |
michael@0 | 155 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | /* void doCommandParams (in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); */ |
michael@0 | 159 | NS_IMETHODIMP |
michael@0 | 160 | nsSelectionCommandsBase::DoCommandParams(const char *aCommandName, |
michael@0 | 161 | nsICommandParams *aParams, nsISupports *aCommandContext) |
michael@0 | 162 | { |
michael@0 | 163 | return DoCommand(aCommandName, aCommandContext); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | // protected methods |
michael@0 | 167 | |
michael@0 | 168 | nsresult |
michael@0 | 169 | nsSelectionCommandsBase::GetPresShellFromWindow(nsPIDOMWindow *aWindow, nsIPresShell **aPresShell) |
michael@0 | 170 | { |
michael@0 | 171 | *aPresShell = nullptr; |
michael@0 | 172 | NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE); |
michael@0 | 173 | |
michael@0 | 174 | nsIDocShell *docShell = aWindow->GetDocShell(); |
michael@0 | 175 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 176 | |
michael@0 | 177 | NS_IF_ADDREF(*aPresShell = docShell->GetPresShell()); |
michael@0 | 178 | return NS_OK; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | nsresult |
michael@0 | 182 | nsSelectionCommandsBase::GetSelectionControllerFromWindow(nsPIDOMWindow *aWindow, nsISelectionController **aSelCon) |
michael@0 | 183 | { |
michael@0 | 184 | *aSelCon = nullptr; |
michael@0 | 185 | |
michael@0 | 186 | nsCOMPtr<nsIPresShell> presShell; |
michael@0 | 187 | GetPresShellFromWindow(aWindow, getter_AddRefs(presShell)); |
michael@0 | 188 | if (presShell) |
michael@0 | 189 | return CallQueryInterface(presShell, aSelCon); |
michael@0 | 190 | |
michael@0 | 191 | return NS_ERROR_FAILURE; |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | #if 0 |
michael@0 | 195 | #pragma mark - |
michael@0 | 196 | #endif |
michael@0 | 197 | |
michael@0 | 198 | static const struct BrowseCommand { |
michael@0 | 199 | const char *reverse, *forward; |
michael@0 | 200 | nsresult (NS_STDCALL nsISelectionController::*scroll)(bool); |
michael@0 | 201 | nsresult (NS_STDCALL nsISelectionController::*move)(bool, bool); |
michael@0 | 202 | } browseCommands[] = { |
michael@0 | 203 | { sScrollTopString, sScrollBottomString, |
michael@0 | 204 | &nsISelectionController::CompleteScroll }, |
michael@0 | 205 | { sScrollPageUpString, sScrollPageDownString, |
michael@0 | 206 | &nsISelectionController::ScrollPage }, |
michael@0 | 207 | { sScrollLineUpString, sScrollLineDownString, |
michael@0 | 208 | &nsISelectionController::ScrollLine }, |
michael@0 | 209 | { sScrollLeftString, sScrollRightString, |
michael@0 | 210 | &nsISelectionController::ScrollCharacter }, |
michael@0 | 211 | { sMoveTopString, sMoveBottomString, |
michael@0 | 212 | &nsISelectionController::CompleteScroll, |
michael@0 | 213 | &nsISelectionController::CompleteMove }, |
michael@0 | 214 | { sMovePageUpString, sMovePageDownString, |
michael@0 | 215 | &nsISelectionController::ScrollPage, |
michael@0 | 216 | &nsISelectionController::PageMove }, |
michael@0 | 217 | { sLinePreviousString, sLineNextString, |
michael@0 | 218 | &nsISelectionController::ScrollLine, |
michael@0 | 219 | &nsISelectionController::LineMove }, |
michael@0 | 220 | { sWordPreviousString, sWordNextString, |
michael@0 | 221 | &nsISelectionController::ScrollCharacter, |
michael@0 | 222 | &nsISelectionController::WordMove }, |
michael@0 | 223 | { sCharPreviousString, sCharNextString, |
michael@0 | 224 | &nsISelectionController::ScrollCharacter, |
michael@0 | 225 | &nsISelectionController::CharacterMove }, |
michael@0 | 226 | { sBeginLineString, sEndLineString, |
michael@0 | 227 | &nsISelectionController::CompleteScroll, |
michael@0 | 228 | &nsISelectionController::IntraLineMove } |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | nsresult |
michael@0 | 232 | nsSelectMoveScrollCommand::DoCommand(const char *aCommandName, nsISupports *aCommandContext) |
michael@0 | 233 | { |
michael@0 | 234 | nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(aCommandContext)); |
michael@0 | 235 | nsCOMPtr<nsISelectionController> selCont; |
michael@0 | 236 | GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont)); |
michael@0 | 237 | NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 238 | |
michael@0 | 239 | // We allow the caret to be moved with arrow keys on any window for which |
michael@0 | 240 | // the caret is enabled. In particular, this includes caret-browsing mode |
michael@0 | 241 | // in non-chrome documents. |
michael@0 | 242 | bool caretOn = false; |
michael@0 | 243 | selCont->GetCaretEnabled(&caretOn); |
michael@0 | 244 | if (!caretOn) { |
michael@0 | 245 | caretOn = Preferences::GetBool("accessibility.browsewithcaret"); |
michael@0 | 246 | if (caretOn) { |
michael@0 | 247 | nsCOMPtr<nsIDocShell> docShell = piWindow->GetDocShell(); |
michael@0 | 248 | if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) { |
michael@0 | 249 | caretOn = false; |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | for (size_t i = 0; i < ArrayLength(browseCommands); i++) { |
michael@0 | 255 | bool forward = !strcmp(aCommandName, browseCommands[i].forward); |
michael@0 | 256 | if (forward || !strcmp(aCommandName, browseCommands[i].reverse)) { |
michael@0 | 257 | if (caretOn && browseCommands[i].move && |
michael@0 | 258 | NS_SUCCEEDED((selCont->*(browseCommands[i].move))(forward, false))) { |
michael@0 | 259 | // adjust the focus to the new caret position |
michael@0 | 260 | nsIFocusManager* fm = nsFocusManager::GetFocusManager(); |
michael@0 | 261 | if (fm) { |
michael@0 | 262 | nsCOMPtr<nsIDOMElement> result; |
michael@0 | 263 | fm->MoveFocus(piWindow, nullptr, nsIFocusManager::MOVEFOCUS_CARET, |
michael@0 | 264 | nsIFocusManager::FLAG_NOSCROLL, |
michael@0 | 265 | getter_AddRefs(result)); |
michael@0 | 266 | } |
michael@0 | 267 | return NS_OK; |
michael@0 | 268 | } |
michael@0 | 269 | return (selCont->*(browseCommands[i].scroll))(forward); |
michael@0 | 270 | } |
michael@0 | 271 | } |
michael@0 | 272 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | |
michael@0 | 276 | #if 0 |
michael@0 | 277 | #pragma mark - |
michael@0 | 278 | #endif |
michael@0 | 279 | |
michael@0 | 280 | nsresult |
michael@0 | 281 | nsSelectCommand::DoCommand(const char *aCommandName, nsISupports *aCommandContext) |
michael@0 | 282 | { |
michael@0 | 283 | nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(aCommandContext)); |
michael@0 | 284 | nsCOMPtr<nsISelectionController> selCont; |
michael@0 | 285 | GetSelectionControllerFromWindow(piWindow, getter_AddRefs(selCont)); |
michael@0 | 286 | NS_ENSURE_TRUE(selCont, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 287 | |
michael@0 | 288 | nsresult rv = NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 289 | |
michael@0 | 290 | // These commands are so the browser can use caret navigation key bindings - |
michael@0 | 291 | // Helps with accessibility - aaronl@netscape.com |
michael@0 | 292 | if (!nsCRT::strcmp(aCommandName, sSelectCharPreviousString)) |
michael@0 | 293 | rv = selCont->CharacterMove(false, true); |
michael@0 | 294 | else if (!nsCRT::strcmp(aCommandName, sSelectCharNextString)) |
michael@0 | 295 | rv = selCont->CharacterMove(true, true); |
michael@0 | 296 | else if (!nsCRT::strcmp(aCommandName, sSelectWordPreviousString)) |
michael@0 | 297 | rv = selCont->WordMove(false, true); |
michael@0 | 298 | else if (!nsCRT::strcmp(aCommandName, sSelectWordNextString)) |
michael@0 | 299 | rv = selCont->WordMove(true, true); |
michael@0 | 300 | else if (!nsCRT::strcmp(aCommandName, sSelectBeginLineString)) |
michael@0 | 301 | rv = selCont->IntraLineMove(false, true); |
michael@0 | 302 | else if (!nsCRT::strcmp(aCommandName, sSelectEndLineString)) |
michael@0 | 303 | rv = selCont->IntraLineMove(true, true); |
michael@0 | 304 | else if (!nsCRT::strcmp(aCommandName, sSelectLinePreviousString)) |
michael@0 | 305 | rv = selCont->LineMove(false, true); |
michael@0 | 306 | else if (!nsCRT::strcmp(aCommandName, sSelectLineNextString)) |
michael@0 | 307 | rv = selCont->LineMove(true, true); |
michael@0 | 308 | else if (!nsCRT::strcmp(aCommandName, sSelectPageUpString)) |
michael@0 | 309 | rv = selCont->PageMove(false, true); |
michael@0 | 310 | else if (!nsCRT::strcmp(aCommandName, sSelectPageDownString)) |
michael@0 | 311 | rv = selCont->PageMove(true, true); |
michael@0 | 312 | else if (!nsCRT::strcmp(aCommandName, sSelectTopString)) |
michael@0 | 313 | rv = selCont->CompleteMove(false, true); |
michael@0 | 314 | else if (!nsCRT::strcmp(aCommandName, sSelectBottomString)) |
michael@0 | 315 | rv = selCont->CompleteMove(true, true); |
michael@0 | 316 | |
michael@0 | 317 | return rv; |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | #if 0 |
michael@0 | 321 | #pragma mark - |
michael@0 | 322 | #endif |
michael@0 | 323 | |
michael@0 | 324 | class nsClipboardCommand MOZ_FINAL : public nsIControllerCommand |
michael@0 | 325 | { |
michael@0 | 326 | public: |
michael@0 | 327 | |
michael@0 | 328 | NS_DECL_ISUPPORTS |
michael@0 | 329 | NS_DECL_NSICONTROLLERCOMMAND |
michael@0 | 330 | }; |
michael@0 | 331 | |
michael@0 | 332 | NS_IMPL_ISUPPORTS(nsClipboardCommand, nsIControllerCommand) |
michael@0 | 333 | |
michael@0 | 334 | nsresult |
michael@0 | 335 | nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aContext, bool *outCmdEnabled) |
michael@0 | 336 | { |
michael@0 | 337 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 338 | *outCmdEnabled = false; |
michael@0 | 339 | |
michael@0 | 340 | if (strcmp(aCommandName, "cmd_copy")) |
michael@0 | 341 | return NS_OK; |
michael@0 | 342 | |
michael@0 | 343 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContext); |
michael@0 | 344 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 345 | |
michael@0 | 346 | nsCOMPtr<nsIDocument> doc = window->GetExtantDoc(); |
michael@0 | 347 | *outCmdEnabled = nsCopySupport::CanCopy(doc); |
michael@0 | 348 | return NS_OK; |
michael@0 | 349 | } |
michael@0 | 350 | |
michael@0 | 351 | nsresult |
michael@0 | 352 | nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext) |
michael@0 | 353 | { |
michael@0 | 354 | if (strcmp(aCommandName, "cmd_copy")) |
michael@0 | 355 | return NS_OK; |
michael@0 | 356 | |
michael@0 | 357 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContext); |
michael@0 | 358 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 359 | |
michael@0 | 360 | nsIDocShell *docShell = window->GetDocShell(); |
michael@0 | 361 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 362 | |
michael@0 | 363 | nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); |
michael@0 | 364 | NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); |
michael@0 | 365 | |
michael@0 | 366 | nsCopySupport::FireClipboardEvent(NS_COPY, nsIClipboard::kGlobalClipboard, presShell, nullptr); |
michael@0 | 367 | return NS_OK; |
michael@0 | 368 | } |
michael@0 | 369 | |
michael@0 | 370 | NS_IMETHODIMP |
michael@0 | 371 | nsClipboardCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 372 | nsICommandParams *aParams, nsISupports *aCommandContext) |
michael@0 | 373 | { |
michael@0 | 374 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | nsresult |
michael@0 | 378 | nsClipboardCommand::DoCommandParams(const char *aCommandName, nsICommandParams* aParams, nsISupports *aContext) |
michael@0 | 379 | { |
michael@0 | 380 | return DoCommand(aCommandName, aContext); |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | #if 0 |
michael@0 | 384 | #pragma mark - |
michael@0 | 385 | #endif |
michael@0 | 386 | |
michael@0 | 387 | class nsSelectionCommand : public nsIControllerCommand |
michael@0 | 388 | { |
michael@0 | 389 | public: |
michael@0 | 390 | virtual ~nsSelectionCommand() {} |
michael@0 | 391 | |
michael@0 | 392 | NS_DECL_ISUPPORTS |
michael@0 | 393 | NS_DECL_NSICONTROLLERCOMMAND |
michael@0 | 394 | |
michael@0 | 395 | protected: |
michael@0 | 396 | |
michael@0 | 397 | virtual nsresult IsClipboardCommandEnabled(const char * aCommandName, nsIContentViewerEdit* aEdit, bool *outCmdEnabled) = 0; |
michael@0 | 398 | virtual nsresult DoClipboardCommand(const char *aCommandName, nsIContentViewerEdit* aEdit, nsICommandParams* aParams) = 0; |
michael@0 | 399 | |
michael@0 | 400 | static nsresult GetContentViewerEditFromContext(nsISupports *aContext, nsIContentViewerEdit **aEditInterface); |
michael@0 | 401 | |
michael@0 | 402 | // no member variables, please, we're stateless! |
michael@0 | 403 | }; |
michael@0 | 404 | |
michael@0 | 405 | |
michael@0 | 406 | NS_IMPL_ISUPPORTS(nsSelectionCommand, nsIControllerCommand) |
michael@0 | 407 | |
michael@0 | 408 | |
michael@0 | 409 | /*--------------------------------------------------------------------------- |
michael@0 | 410 | |
michael@0 | 411 | nsSelectionCommand |
michael@0 | 412 | |
michael@0 | 413 | ----------------------------------------------------------------------------*/ |
michael@0 | 414 | |
michael@0 | 415 | NS_IMETHODIMP |
michael@0 | 416 | nsSelectionCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 417 | nsISupports *aCommandContext, |
michael@0 | 418 | bool *outCmdEnabled) |
michael@0 | 419 | { |
michael@0 | 420 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 421 | *outCmdEnabled = false; |
michael@0 | 422 | |
michael@0 | 423 | nsCOMPtr<nsIContentViewerEdit> contentEdit; |
michael@0 | 424 | GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit)); |
michael@0 | 425 | NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 426 | |
michael@0 | 427 | return IsClipboardCommandEnabled(aCommandName, contentEdit, outCmdEnabled); |
michael@0 | 428 | } |
michael@0 | 429 | |
michael@0 | 430 | NS_IMETHODIMP |
michael@0 | 431 | nsSelectionCommand::DoCommand(const char *aCommandName, |
michael@0 | 432 | nsISupports *aCommandContext) |
michael@0 | 433 | { |
michael@0 | 434 | nsCOMPtr<nsIContentViewerEdit> contentEdit; |
michael@0 | 435 | GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit)); |
michael@0 | 436 | NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 437 | |
michael@0 | 438 | return DoClipboardCommand(aCommandName, contentEdit, nullptr); |
michael@0 | 439 | } |
michael@0 | 440 | |
michael@0 | 441 | NS_IMETHODIMP |
michael@0 | 442 | nsSelectionCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 443 | nsICommandParams *aParams, |
michael@0 | 444 | nsISupports *aCommandContext) |
michael@0 | 445 | { |
michael@0 | 446 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | NS_IMETHODIMP |
michael@0 | 450 | nsSelectionCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 451 | nsICommandParams *aParams, |
michael@0 | 452 | nsISupports *aCommandContext) |
michael@0 | 453 | { |
michael@0 | 454 | nsCOMPtr<nsIContentViewerEdit> contentEdit; |
michael@0 | 455 | GetContentViewerEditFromContext(aCommandContext, getter_AddRefs(contentEdit)); |
michael@0 | 456 | NS_ENSURE_TRUE(contentEdit, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 457 | |
michael@0 | 458 | return DoClipboardCommand(aCommandName, contentEdit, aParams); |
michael@0 | 459 | } |
michael@0 | 460 | |
michael@0 | 461 | nsresult |
michael@0 | 462 | nsSelectionCommand::GetContentViewerEditFromContext(nsISupports *aContext, |
michael@0 | 463 | nsIContentViewerEdit **aEditInterface) |
michael@0 | 464 | { |
michael@0 | 465 | NS_ENSURE_ARG(aEditInterface); |
michael@0 | 466 | *aEditInterface = nullptr; |
michael@0 | 467 | |
michael@0 | 468 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContext); |
michael@0 | 469 | NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG); |
michael@0 | 470 | |
michael@0 | 471 | nsIDocShell *docShell = window->GetDocShell(); |
michael@0 | 472 | NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); |
michael@0 | 473 | |
michael@0 | 474 | nsCOMPtr<nsIContentViewer> viewer; |
michael@0 | 475 | docShell->GetContentViewer(getter_AddRefs(viewer)); |
michael@0 | 476 | nsCOMPtr<nsIContentViewerEdit> edit(do_QueryInterface(viewer)); |
michael@0 | 477 | NS_ENSURE_TRUE(edit, NS_ERROR_FAILURE); |
michael@0 | 478 | |
michael@0 | 479 | *aEditInterface = edit; |
michael@0 | 480 | NS_ADDREF(*aEditInterface); |
michael@0 | 481 | return NS_OK; |
michael@0 | 482 | } |
michael@0 | 483 | |
michael@0 | 484 | #if 0 |
michael@0 | 485 | #pragma mark - |
michael@0 | 486 | #endif |
michael@0 | 487 | |
michael@0 | 488 | #define NS_DECL_CLIPBOARD_COMMAND(_cmd) \ |
michael@0 | 489 | class _cmd : public nsSelectionCommand \ |
michael@0 | 490 | { \ |
michael@0 | 491 | protected: \ |
michael@0 | 492 | \ |
michael@0 | 493 | virtual nsresult IsClipboardCommandEnabled(const char* aCommandName, \ |
michael@0 | 494 | nsIContentViewerEdit* aEdit, bool *outCmdEnabled); \ |
michael@0 | 495 | virtual nsresult DoClipboardCommand(const char* aCommandName, \ |
michael@0 | 496 | nsIContentViewerEdit* aEdit, nsICommandParams* aParams); \ |
michael@0 | 497 | /* no member variables, please, we're stateless! */ \ |
michael@0 | 498 | }; |
michael@0 | 499 | |
michael@0 | 500 | NS_DECL_CLIPBOARD_COMMAND(nsClipboardCopyLinkCommand) |
michael@0 | 501 | NS_DECL_CLIPBOARD_COMMAND(nsClipboardImageCommands) |
michael@0 | 502 | NS_DECL_CLIPBOARD_COMMAND(nsClipboardSelectAllNoneCommands) |
michael@0 | 503 | NS_DECL_CLIPBOARD_COMMAND(nsClipboardGetContentsCommand) |
michael@0 | 504 | |
michael@0 | 505 | nsresult |
michael@0 | 506 | nsClipboardCopyLinkCommand::IsClipboardCommandEnabled(const char* aCommandName, nsIContentViewerEdit* aEdit, bool *outCmdEnabled) |
michael@0 | 507 | { |
michael@0 | 508 | return aEdit->GetInLink(outCmdEnabled); |
michael@0 | 509 | } |
michael@0 | 510 | |
michael@0 | 511 | nsresult |
michael@0 | 512 | nsClipboardCopyLinkCommand::DoClipboardCommand(const char *aCommandName, nsIContentViewerEdit* aEdit, nsICommandParams* aParams) |
michael@0 | 513 | { |
michael@0 | 514 | return aEdit->CopyLinkLocation(); |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | #if 0 |
michael@0 | 518 | #pragma mark - |
michael@0 | 519 | #endif |
michael@0 | 520 | |
michael@0 | 521 | nsresult |
michael@0 | 522 | nsClipboardImageCommands::IsClipboardCommandEnabled(const char* aCommandName, nsIContentViewerEdit* aEdit, bool *outCmdEnabled) |
michael@0 | 523 | { |
michael@0 | 524 | return aEdit->GetInImage(outCmdEnabled); |
michael@0 | 525 | } |
michael@0 | 526 | |
michael@0 | 527 | nsresult |
michael@0 | 528 | nsClipboardImageCommands::DoClipboardCommand(const char *aCommandName, nsIContentViewerEdit* aEdit, nsICommandParams* aParams) |
michael@0 | 529 | { |
michael@0 | 530 | if (!nsCRT::strcmp(sCopyImageLocationString, aCommandName)) |
michael@0 | 531 | return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_TEXT); |
michael@0 | 532 | if (!nsCRT::strcmp(sCopyImageContentsString, aCommandName)) |
michael@0 | 533 | return aEdit->CopyImage(nsIContentViewerEdit::COPY_IMAGE_DATA); |
michael@0 | 534 | int32_t copyFlags = nsIContentViewerEdit::COPY_IMAGE_DATA | |
michael@0 | 535 | nsIContentViewerEdit::COPY_IMAGE_HTML; |
michael@0 | 536 | if (aParams) |
michael@0 | 537 | aParams->GetLongValue("imageCopy", ©Flags); |
michael@0 | 538 | return aEdit->CopyImage(copyFlags); |
michael@0 | 539 | } |
michael@0 | 540 | |
michael@0 | 541 | #if 0 |
michael@0 | 542 | #pragma mark - |
michael@0 | 543 | #endif |
michael@0 | 544 | |
michael@0 | 545 | nsresult |
michael@0 | 546 | nsClipboardSelectAllNoneCommands::IsClipboardCommandEnabled(const char* aCommandName, nsIContentViewerEdit* aEdit, bool *outCmdEnabled) |
michael@0 | 547 | { |
michael@0 | 548 | *outCmdEnabled = true; |
michael@0 | 549 | return NS_OK; |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | nsresult |
michael@0 | 553 | nsClipboardSelectAllNoneCommands::DoClipboardCommand(const char *aCommandName, nsIContentViewerEdit* aEdit, nsICommandParams* aParams) |
michael@0 | 554 | { |
michael@0 | 555 | if (!nsCRT::strcmp(sSelectAllString, aCommandName)) |
michael@0 | 556 | return aEdit->SelectAll(); |
michael@0 | 557 | |
michael@0 | 558 | return aEdit->ClearSelection(); |
michael@0 | 559 | } |
michael@0 | 560 | |
michael@0 | 561 | |
michael@0 | 562 | #if 0 |
michael@0 | 563 | #pragma mark - |
michael@0 | 564 | #endif |
michael@0 | 565 | |
michael@0 | 566 | nsresult |
michael@0 | 567 | nsClipboardGetContentsCommand::IsClipboardCommandEnabled(const char* aCommandName, nsIContentViewerEdit* aEdit, bool *outCmdEnabled) |
michael@0 | 568 | { |
michael@0 | 569 | return aEdit->GetCanGetContents(outCmdEnabled); |
michael@0 | 570 | } |
michael@0 | 571 | |
michael@0 | 572 | nsresult |
michael@0 | 573 | nsClipboardGetContentsCommand::DoClipboardCommand(const char *aCommandName, nsIContentViewerEdit* aEdit, nsICommandParams* aParams) |
michael@0 | 574 | { |
michael@0 | 575 | NS_ENSURE_ARG(aParams); |
michael@0 | 576 | |
michael@0 | 577 | nsAutoCString mimeType("text/plain"); |
michael@0 | 578 | |
michael@0 | 579 | nsXPIDLCString format; // nsICommandParams needs to use nsACString |
michael@0 | 580 | if (NS_SUCCEEDED(aParams->GetCStringValue("format", getter_Copies(format)))) |
michael@0 | 581 | mimeType.Assign(format); |
michael@0 | 582 | |
michael@0 | 583 | bool selectionOnly = false; |
michael@0 | 584 | aParams->GetBooleanValue("selection_only", &selectionOnly); |
michael@0 | 585 | |
michael@0 | 586 | nsAutoString contents; |
michael@0 | 587 | nsresult rv = aEdit->GetContents(mimeType.get(), selectionOnly, contents); |
michael@0 | 588 | if (NS_FAILED(rv)) |
michael@0 | 589 | return rv; |
michael@0 | 590 | |
michael@0 | 591 | return aParams->SetStringValue("result", contents); |
michael@0 | 592 | } |
michael@0 | 593 | |
michael@0 | 594 | #if 0 // Remove unless needed again, bug 204777 |
michael@0 | 595 | class nsWebNavigationBaseCommand : public nsIControllerCommand |
michael@0 | 596 | { |
michael@0 | 597 | public: |
michael@0 | 598 | virtual ~nsWebNavigationBaseCommand() {} |
michael@0 | 599 | |
michael@0 | 600 | NS_DECL_ISUPPORTS |
michael@0 | 601 | NS_DECL_NSICONTROLLERCOMMAND |
michael@0 | 602 | |
michael@0 | 603 | protected: |
michael@0 | 604 | |
michael@0 | 605 | virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled) = 0; |
michael@0 | 606 | virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation) = 0; |
michael@0 | 607 | |
michael@0 | 608 | static nsresult GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation); |
michael@0 | 609 | |
michael@0 | 610 | // no member variables, please, we're stateless! |
michael@0 | 611 | }; |
michael@0 | 612 | |
michael@0 | 613 | class nsGoForwardCommand : public nsWebNavigationBaseCommand |
michael@0 | 614 | { |
michael@0 | 615 | protected: |
michael@0 | 616 | |
michael@0 | 617 | virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled); |
michael@0 | 618 | virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation); |
michael@0 | 619 | // no member variables, please, we're stateless! |
michael@0 | 620 | }; |
michael@0 | 621 | |
michael@0 | 622 | class nsGoBackCommand : public nsWebNavigationBaseCommand |
michael@0 | 623 | { |
michael@0 | 624 | protected: |
michael@0 | 625 | |
michael@0 | 626 | virtual nsresult IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled); |
michael@0 | 627 | virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation); |
michael@0 | 628 | // no member variables, please, we're stateless! |
michael@0 | 629 | }; |
michael@0 | 630 | |
michael@0 | 631 | /*--------------------------------------------------------------------------- |
michael@0 | 632 | |
michael@0 | 633 | nsWebNavigationCommands |
michael@0 | 634 | no params |
michael@0 | 635 | ----------------------------------------------------------------------------*/ |
michael@0 | 636 | |
michael@0 | 637 | NS_IMPL_ISUPPORTS(nsWebNavigationBaseCommand, nsIControllerCommand) |
michael@0 | 638 | |
michael@0 | 639 | NS_IMETHODIMP |
michael@0 | 640 | nsWebNavigationBaseCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 641 | nsISupports *aCommandContext, |
michael@0 | 642 | bool *outCmdEnabled) |
michael@0 | 643 | { |
michael@0 | 644 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 645 | *outCmdEnabled = false; |
michael@0 | 646 | |
michael@0 | 647 | nsCOMPtr<nsIWebNavigation> webNav; |
michael@0 | 648 | GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav)); |
michael@0 | 649 | NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG); |
michael@0 | 650 | |
michael@0 | 651 | return IsCommandEnabled(aCommandName, webNav, outCmdEnabled); |
michael@0 | 652 | } |
michael@0 | 653 | |
michael@0 | 654 | NS_IMETHODIMP |
michael@0 | 655 | nsWebNavigationBaseCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 656 | nsICommandParams *aParams, nsISupports *aCommandContext) |
michael@0 | 657 | { |
michael@0 | 658 | // XXX we should probably return the enabled state |
michael@0 | 659 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 660 | } |
michael@0 | 661 | |
michael@0 | 662 | NS_IMETHODIMP |
michael@0 | 663 | nsWebNavigationBaseCommand::DoCommand(const char *aCommandName, |
michael@0 | 664 | nsISupports *aCommandContext) |
michael@0 | 665 | { |
michael@0 | 666 | nsCOMPtr<nsIWebNavigation> webNav; |
michael@0 | 667 | GetWebNavigationFromContext(aCommandContext, getter_AddRefs(webNav)); |
michael@0 | 668 | NS_ENSURE_TRUE(webNav, NS_ERROR_INVALID_ARG); |
michael@0 | 669 | |
michael@0 | 670 | return DoWebNavCommand(aCommandName, webNav); |
michael@0 | 671 | } |
michael@0 | 672 | |
michael@0 | 673 | /* void doCommandParams (in string aCommandName, in nsICommandParams aParams, in nsISupports aCommandContext); */ |
michael@0 | 674 | NS_IMETHODIMP |
michael@0 | 675 | nsWebNavigationBaseCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 676 | nsICommandParams *aParams, nsISupports *aCommandContext) |
michael@0 | 677 | { |
michael@0 | 678 | return DoCommand(aCommandName, aCommandContext); |
michael@0 | 679 | } |
michael@0 | 680 | |
michael@0 | 681 | nsresult |
michael@0 | 682 | nsWebNavigationBaseCommand::GetWebNavigationFromContext(nsISupports *aContext, nsIWebNavigation **aWebNavigation) |
michael@0 | 683 | { |
michael@0 | 684 | nsCOMPtr<nsIInterfaceRequestor> windowReq = do_QueryInterface(aContext); |
michael@0 | 685 | CallGetInterface(windowReq.get(), aWebNavigation); |
michael@0 | 686 | return (*aWebNavigation) ? NS_OK : NS_ERROR_FAILURE; |
michael@0 | 687 | } |
michael@0 | 688 | |
michael@0 | 689 | nsresult |
michael@0 | 690 | nsGoForwardCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled) |
michael@0 | 691 | { |
michael@0 | 692 | return aWebNavigation->GetCanGoForward(outCmdEnabled); |
michael@0 | 693 | } |
michael@0 | 694 | |
michael@0 | 695 | nsresult |
michael@0 | 696 | nsGoForwardCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation) |
michael@0 | 697 | { |
michael@0 | 698 | return aWebNavigation->GoForward(); |
michael@0 | 699 | } |
michael@0 | 700 | |
michael@0 | 701 | nsresult |
michael@0 | 702 | nsGoBackCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, bool *outCmdEnabled) |
michael@0 | 703 | { |
michael@0 | 704 | return aWebNavigation->GetCanGoBack(outCmdEnabled); |
michael@0 | 705 | } |
michael@0 | 706 | |
michael@0 | 707 | nsresult |
michael@0 | 708 | nsGoBackCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation) |
michael@0 | 709 | { |
michael@0 | 710 | return aWebNavigation->GoBack(); |
michael@0 | 711 | } |
michael@0 | 712 | #endif |
michael@0 | 713 | |
michael@0 | 714 | /*--------------------------------------------------------------------------- |
michael@0 | 715 | |
michael@0 | 716 | nsClipboardDragDropHookCommand |
michael@0 | 717 | params value type possible values |
michael@0 | 718 | "addhook" isupports nsIClipboardDragDropHooks as nsISupports |
michael@0 | 719 | "removehook" isupports nsIClipboardDragDropHooks as nsISupports |
michael@0 | 720 | |
michael@0 | 721 | ----------------------------------------------------------------------------*/ |
michael@0 | 722 | |
michael@0 | 723 | class nsClipboardDragDropHookCommand MOZ_FINAL : public nsIControllerCommand |
michael@0 | 724 | { |
michael@0 | 725 | public: |
michael@0 | 726 | |
michael@0 | 727 | NS_DECL_ISUPPORTS |
michael@0 | 728 | NS_DECL_NSICONTROLLERCOMMAND |
michael@0 | 729 | |
michael@0 | 730 | protected: |
michael@0 | 731 | // no member variables, please, we're stateless! |
michael@0 | 732 | }; |
michael@0 | 733 | |
michael@0 | 734 | |
michael@0 | 735 | NS_IMPL_ISUPPORTS(nsClipboardDragDropHookCommand, nsIControllerCommand) |
michael@0 | 736 | |
michael@0 | 737 | NS_IMETHODIMP |
michael@0 | 738 | nsClipboardDragDropHookCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 739 | nsISupports *aCommandContext, |
michael@0 | 740 | bool *outCmdEnabled) |
michael@0 | 741 | { |
michael@0 | 742 | *outCmdEnabled = true; |
michael@0 | 743 | return NS_OK; |
michael@0 | 744 | } |
michael@0 | 745 | |
michael@0 | 746 | NS_IMETHODIMP |
michael@0 | 747 | nsClipboardDragDropHookCommand::DoCommand(const char *aCommandName, |
michael@0 | 748 | nsISupports *aCommandContext) |
michael@0 | 749 | { |
michael@0 | 750 | return NS_ERROR_FAILURE; |
michael@0 | 751 | } |
michael@0 | 752 | |
michael@0 | 753 | NS_IMETHODIMP |
michael@0 | 754 | nsClipboardDragDropHookCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 755 | nsICommandParams *aParams, |
michael@0 | 756 | nsISupports *aCommandContext) |
michael@0 | 757 | { |
michael@0 | 758 | NS_ENSURE_ARG(aParams); |
michael@0 | 759 | |
michael@0 | 760 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aCommandContext); |
michael@0 | 761 | NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); |
michael@0 | 762 | |
michael@0 | 763 | nsIDocShell *docShell = window->GetDocShell(); |
michael@0 | 764 | |
michael@0 | 765 | nsCOMPtr<nsIClipboardDragDropHookList> obj = do_GetInterface(docShell); |
michael@0 | 766 | if (!obj) return NS_ERROR_INVALID_ARG; |
michael@0 | 767 | |
michael@0 | 768 | nsCOMPtr<nsISupports> isuppHook; |
michael@0 | 769 | |
michael@0 | 770 | nsresult returnValue = NS_OK; |
michael@0 | 771 | nsresult rv = aParams->GetISupportsValue("addhook", getter_AddRefs(isuppHook)); |
michael@0 | 772 | if (NS_SUCCEEDED(rv)) |
michael@0 | 773 | { |
michael@0 | 774 | nsCOMPtr<nsIClipboardDragDropHooks> hook = do_QueryInterface(isuppHook); |
michael@0 | 775 | if (hook) |
michael@0 | 776 | returnValue = obj->AddClipboardDragDropHooks(hook); |
michael@0 | 777 | else |
michael@0 | 778 | returnValue = NS_ERROR_INVALID_ARG; |
michael@0 | 779 | } |
michael@0 | 780 | |
michael@0 | 781 | rv = aParams->GetISupportsValue("removehook", getter_AddRefs(isuppHook)); |
michael@0 | 782 | if (NS_SUCCEEDED(rv)) |
michael@0 | 783 | { |
michael@0 | 784 | nsCOMPtr<nsIClipboardDragDropHooks> hook = do_QueryInterface(isuppHook); |
michael@0 | 785 | if (hook) |
michael@0 | 786 | { |
michael@0 | 787 | rv = obj->RemoveClipboardDragDropHooks(hook); |
michael@0 | 788 | if (NS_FAILED(rv) && NS_SUCCEEDED(returnValue)) |
michael@0 | 789 | returnValue = rv; |
michael@0 | 790 | } |
michael@0 | 791 | else |
michael@0 | 792 | returnValue = NS_ERROR_INVALID_ARG; |
michael@0 | 793 | } |
michael@0 | 794 | |
michael@0 | 795 | return returnValue; |
michael@0 | 796 | } |
michael@0 | 797 | |
michael@0 | 798 | NS_IMETHODIMP |
michael@0 | 799 | nsClipboardDragDropHookCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 800 | nsICommandParams *aParams, |
michael@0 | 801 | nsISupports *aCommandContext) |
michael@0 | 802 | { |
michael@0 | 803 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 804 | return aParams->SetBooleanValue("state_enabled", true); |
michael@0 | 805 | } |
michael@0 | 806 | |
michael@0 | 807 | /*--------------------------------------------------------------------------- |
michael@0 | 808 | |
michael@0 | 809 | RegisterWindowCommands |
michael@0 | 810 | |
michael@0 | 811 | ----------------------------------------------------------------------------*/ |
michael@0 | 812 | |
michael@0 | 813 | #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \ |
michael@0 | 814 | { \ |
michael@0 | 815 | _cmdClass* theCmd = new _cmdClass(); \ |
michael@0 | 816 | if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 817 | rv = inCommandTable->RegisterCommand(_cmdName, \ |
michael@0 | 818 | static_cast<nsIControllerCommand *>(theCmd)); \ |
michael@0 | 819 | } |
michael@0 | 820 | |
michael@0 | 821 | #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \ |
michael@0 | 822 | { \ |
michael@0 | 823 | _cmdClass* theCmd = new _cmdClass(); \ |
michael@0 | 824 | if (!theCmd) return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 825 | rv = inCommandTable->RegisterCommand(_cmdName, \ |
michael@0 | 826 | static_cast<nsIControllerCommand *>(theCmd)); |
michael@0 | 827 | |
michael@0 | 828 | #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \ |
michael@0 | 829 | rv = inCommandTable->RegisterCommand(_cmdName, \ |
michael@0 | 830 | static_cast<nsIControllerCommand *>(theCmd)); |
michael@0 | 831 | |
michael@0 | 832 | #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \ |
michael@0 | 833 | rv = inCommandTable->RegisterCommand(_cmdName, \ |
michael@0 | 834 | static_cast<nsIControllerCommand *>(theCmd)); \ |
michael@0 | 835 | } |
michael@0 | 836 | |
michael@0 | 837 | |
michael@0 | 838 | // static |
michael@0 | 839 | nsresult |
michael@0 | 840 | nsWindowCommandRegistration::RegisterWindowCommands( |
michael@0 | 841 | nsIControllerCommandTable *inCommandTable) |
michael@0 | 842 | { |
michael@0 | 843 | nsresult rv; |
michael@0 | 844 | |
michael@0 | 845 | // XXX rework the macros to use a loop is possible, reducing code size |
michael@0 | 846 | |
michael@0 | 847 | // this set of commands is affected by the 'browse with caret' setting |
michael@0 | 848 | NS_REGISTER_FIRST_COMMAND(nsSelectMoveScrollCommand, sScrollTopString); |
michael@0 | 849 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollBottomString); |
michael@0 | 850 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageUpString); |
michael@0 | 851 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollPageDownString); |
michael@0 | 852 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineUpString); |
michael@0 | 853 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLineDownString); |
michael@0 | 854 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollLeftString); |
michael@0 | 855 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sScrollRightString); |
michael@0 | 856 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveTopString); |
michael@0 | 857 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMoveBottomString); |
michael@0 | 858 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordPreviousString); |
michael@0 | 859 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sWordNextString); |
michael@0 | 860 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sBeginLineString); |
michael@0 | 861 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sEndLineString); |
michael@0 | 862 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageUpString); |
michael@0 | 863 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sMovePageDownString); |
michael@0 | 864 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLinePreviousString); |
michael@0 | 865 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sLineNextString); |
michael@0 | 866 | NS_REGISTER_NEXT_COMMAND(nsSelectMoveScrollCommand, sCharPreviousString); |
michael@0 | 867 | NS_REGISTER_LAST_COMMAND(nsSelectMoveScrollCommand, sCharNextString); |
michael@0 | 868 | |
michael@0 | 869 | NS_REGISTER_FIRST_COMMAND(nsSelectCommand, sSelectCharPreviousString); |
michael@0 | 870 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectCharNextString); |
michael@0 | 871 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordPreviousString); |
michael@0 | 872 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectWordNextString); |
michael@0 | 873 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectBeginLineString); |
michael@0 | 874 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectEndLineString); |
michael@0 | 875 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLinePreviousString); |
michael@0 | 876 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectLineNextString); |
michael@0 | 877 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageUpString); |
michael@0 | 878 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectPageDownString); |
michael@0 | 879 | NS_REGISTER_NEXT_COMMAND(nsSelectCommand, sSelectTopString); |
michael@0 | 880 | NS_REGISTER_LAST_COMMAND(nsSelectCommand, sSelectBottomString); |
michael@0 | 881 | |
michael@0 | 882 | NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_cut"); |
michael@0 | 883 | NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_copy"); |
michael@0 | 884 | NS_REGISTER_ONE_COMMAND(nsClipboardCommand, "cmd_paste"); |
michael@0 | 885 | NS_REGISTER_ONE_COMMAND(nsClipboardCopyLinkCommand, "cmd_copyLink"); |
michael@0 | 886 | NS_REGISTER_FIRST_COMMAND(nsClipboardImageCommands, sCopyImageLocationString); |
michael@0 | 887 | NS_REGISTER_NEXT_COMMAND(nsClipboardImageCommands, sCopyImageContentsString); |
michael@0 | 888 | NS_REGISTER_LAST_COMMAND(nsClipboardImageCommands, sCopyImageString); |
michael@0 | 889 | NS_REGISTER_FIRST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectAllString); |
michael@0 | 890 | NS_REGISTER_LAST_COMMAND(nsClipboardSelectAllNoneCommands, sSelectNoneString); |
michael@0 | 891 | |
michael@0 | 892 | NS_REGISTER_ONE_COMMAND(nsClipboardGetContentsCommand, "cmd_getContents"); |
michael@0 | 893 | |
michael@0 | 894 | #if 0 // Remove unless needed again, bug 204777 |
michael@0 | 895 | NS_REGISTER_ONE_COMMAND(nsGoBackCommand, "cmd_browserBack"); |
michael@0 | 896 | NS_REGISTER_ONE_COMMAND(nsGoForwardCommand, "cmd_browserForward"); |
michael@0 | 897 | #endif |
michael@0 | 898 | |
michael@0 | 899 | NS_REGISTER_ONE_COMMAND(nsClipboardDragDropHookCommand, "cmd_clipboardDragDropHook"); |
michael@0 | 900 | |
michael@0 | 901 | return rv; |
michael@0 | 902 | } |