Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | #include "mozFlushType.h" |
michael@0 | 8 | #include "mozilla/Assertions.h" |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsCRT.h" |
michael@0 | 11 | #include "nsDebug.h" |
michael@0 | 12 | #include "nsEditorCommands.h" |
michael@0 | 13 | #include "nsError.h" |
michael@0 | 14 | #include "nsIClipboard.h" |
michael@0 | 15 | #include "nsICommandParams.h" |
michael@0 | 16 | #include "nsID.h" |
michael@0 | 17 | #include "nsIDOMDocument.h" |
michael@0 | 18 | #include "nsIDocument.h" |
michael@0 | 19 | #include "nsIEditor.h" |
michael@0 | 20 | #include "nsIEditorMailSupport.h" |
michael@0 | 21 | #include "nsIPlaintextEditor.h" |
michael@0 | 22 | #include "nsISelection.h" |
michael@0 | 23 | #include "nsISelectionController.h" |
michael@0 | 24 | #include "nsITransferable.h" |
michael@0 | 25 | #include "nsString.h" |
michael@0 | 26 | #include "nsAString.h" |
michael@0 | 27 | |
michael@0 | 28 | class nsISupports; |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | #define STATE_ENABLED "state_enabled" |
michael@0 | 32 | #define STATE_DATA "state_data" |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | nsBaseEditorCommand::nsBaseEditorCommand() |
michael@0 | 36 | { |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | NS_IMPL_ISUPPORTS(nsBaseEditorCommand, nsIControllerCommand) |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | NS_IMETHODIMP |
michael@0 | 43 | nsUndoCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 44 | nsISupports *aCommandRefCon, |
michael@0 | 45 | bool *outCmdEnabled) |
michael@0 | 46 | { |
michael@0 | 47 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 48 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 49 | if (editor) |
michael@0 | 50 | { |
michael@0 | 51 | bool isEnabled, isEditable = false; |
michael@0 | 52 | nsresult rv = editor->GetIsSelectionEditable(&isEditable); |
michael@0 | 53 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 54 | if (isEditable) |
michael@0 | 55 | return editor->CanUndo(&isEnabled, outCmdEnabled); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | *outCmdEnabled = false; |
michael@0 | 59 | return NS_OK; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | nsUndoCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 65 | { |
michael@0 | 66 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 67 | if (editor) |
michael@0 | 68 | return editor->Undo(1); |
michael@0 | 69 | |
michael@0 | 70 | return NS_ERROR_FAILURE; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMETHODIMP |
michael@0 | 74 | nsUndoCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 75 | nsICommandParams *aParams, |
michael@0 | 76 | nsISupports *aCommandRefCon) |
michael@0 | 77 | { |
michael@0 | 78 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | NS_IMETHODIMP |
michael@0 | 82 | nsUndoCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 83 | nsICommandParams *aParams, |
michael@0 | 84 | nsISupports *aCommandRefCon) |
michael@0 | 85 | { |
michael@0 | 86 | bool canUndo; |
michael@0 | 87 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 88 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | nsRedoCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 93 | nsISupports *aCommandRefCon, |
michael@0 | 94 | bool *outCmdEnabled) |
michael@0 | 95 | { |
michael@0 | 96 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 97 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 98 | if (editor) |
michael@0 | 99 | { |
michael@0 | 100 | bool isEnabled, isEditable = false; |
michael@0 | 101 | nsresult rv = editor->GetIsSelectionEditable(&isEditable); |
michael@0 | 102 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 103 | if (isEditable) |
michael@0 | 104 | return editor->CanRedo(&isEnabled, outCmdEnabled); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | *outCmdEnabled = false; |
michael@0 | 108 | return NS_OK; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | |
michael@0 | 112 | NS_IMETHODIMP |
michael@0 | 113 | nsRedoCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 114 | { |
michael@0 | 115 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 116 | if (editor) |
michael@0 | 117 | return editor->Redo(1); |
michael@0 | 118 | |
michael@0 | 119 | return NS_ERROR_FAILURE; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | NS_IMETHODIMP |
michael@0 | 123 | nsRedoCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 124 | nsICommandParams *aParams, |
michael@0 | 125 | nsISupports *aCommandRefCon) |
michael@0 | 126 | { |
michael@0 | 127 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | NS_IMETHODIMP |
michael@0 | 131 | nsRedoCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 132 | nsICommandParams *aParams, |
michael@0 | 133 | nsISupports *aCommandRefCon) |
michael@0 | 134 | { |
michael@0 | 135 | bool canUndo; |
michael@0 | 136 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 137 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP |
michael@0 | 141 | nsClearUndoCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 142 | nsISupports *refCon, bool *outCmdEnabled) |
michael@0 | 143 | { |
michael@0 | 144 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 145 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 146 | if (editor) |
michael@0 | 147 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 148 | |
michael@0 | 149 | *outCmdEnabled = false; |
michael@0 | 150 | return NS_OK; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | |
michael@0 | 154 | NS_IMETHODIMP |
michael@0 | 155 | nsClearUndoCommand::DoCommand(const char *aCommandName, nsISupports *refCon) |
michael@0 | 156 | { |
michael@0 | 157 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 158 | NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED); |
michael@0 | 159 | |
michael@0 | 160 | editor->EnableUndo(false); // Turning off undo clears undo/redo stacks. |
michael@0 | 161 | editor->EnableUndo(true); // This re-enables undo/redo. |
michael@0 | 162 | |
michael@0 | 163 | return NS_OK; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | NS_IMETHODIMP |
michael@0 | 167 | nsClearUndoCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 168 | nsICommandParams *aParams, |
michael@0 | 169 | nsISupports *refCon) |
michael@0 | 170 | { |
michael@0 | 171 | return DoCommand(aCommandName, refCon); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | NS_IMETHODIMP |
michael@0 | 175 | nsClearUndoCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 176 | nsICommandParams *aParams, |
michael@0 | 177 | nsISupports *refCon) |
michael@0 | 178 | { |
michael@0 | 179 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 180 | |
michael@0 | 181 | bool enabled; |
michael@0 | 182 | nsresult rv = IsCommandEnabled(aCommandName, refCon, &enabled); |
michael@0 | 183 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 184 | |
michael@0 | 185 | return aParams->SetBooleanValue(STATE_ENABLED, enabled); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | NS_IMETHODIMP |
michael@0 | 189 | nsCutCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 190 | nsISupports *aCommandRefCon, |
michael@0 | 191 | bool *outCmdEnabled) |
michael@0 | 192 | { |
michael@0 | 193 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 194 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 195 | if (editor) |
michael@0 | 196 | { |
michael@0 | 197 | bool isEditable = false; |
michael@0 | 198 | nsresult rv = editor->GetIsSelectionEditable(&isEditable); |
michael@0 | 199 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 200 | if (isEditable) |
michael@0 | 201 | return editor->CanCut(outCmdEnabled); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | *outCmdEnabled = false; |
michael@0 | 205 | return NS_OK; |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | |
michael@0 | 209 | NS_IMETHODIMP |
michael@0 | 210 | nsCutCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 211 | { |
michael@0 | 212 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 213 | if (editor) |
michael@0 | 214 | return editor->Cut(); |
michael@0 | 215 | |
michael@0 | 216 | return NS_ERROR_FAILURE; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | NS_IMETHODIMP |
michael@0 | 220 | nsCutCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 221 | nsICommandParams *aParams, |
michael@0 | 222 | nsISupports *aCommandRefCon) |
michael@0 | 223 | { |
michael@0 | 224 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | NS_IMETHODIMP |
michael@0 | 228 | nsCutCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 229 | nsICommandParams *aParams, |
michael@0 | 230 | nsISupports *aCommandRefCon) |
michael@0 | 231 | { |
michael@0 | 232 | bool canUndo; |
michael@0 | 233 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 234 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | |
michael@0 | 238 | NS_IMETHODIMP |
michael@0 | 239 | nsCutOrDeleteCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 240 | nsISupports *aCommandRefCon, |
michael@0 | 241 | bool *outCmdEnabled) |
michael@0 | 242 | { |
michael@0 | 243 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 244 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 245 | if (editor) |
michael@0 | 246 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 247 | |
michael@0 | 248 | *outCmdEnabled = false; |
michael@0 | 249 | return NS_OK; |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | |
michael@0 | 253 | NS_IMETHODIMP |
michael@0 | 254 | nsCutOrDeleteCommand::DoCommand(const char *aCommandName, |
michael@0 | 255 | nsISupports *aCommandRefCon) |
michael@0 | 256 | { |
michael@0 | 257 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 258 | if (editor) |
michael@0 | 259 | { |
michael@0 | 260 | nsCOMPtr<nsISelection> selection; |
michael@0 | 261 | nsresult rv = editor->GetSelection(getter_AddRefs(selection)); |
michael@0 | 262 | if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) { |
michael@0 | 263 | return editor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip); |
michael@0 | 264 | } |
michael@0 | 265 | return editor->Cut(); |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | return NS_ERROR_FAILURE; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | NS_IMETHODIMP |
michael@0 | 272 | nsCutOrDeleteCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 273 | nsICommandParams *aParams, |
michael@0 | 274 | nsISupports *aCommandRefCon) |
michael@0 | 275 | { |
michael@0 | 276 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | NS_IMETHODIMP |
michael@0 | 280 | nsCutOrDeleteCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 281 | nsICommandParams *aParams, |
michael@0 | 282 | nsISupports *aCommandRefCon) |
michael@0 | 283 | { |
michael@0 | 284 | bool canUndo; |
michael@0 | 285 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 286 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | NS_IMETHODIMP |
michael@0 | 290 | nsCopyCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 291 | nsISupports *aCommandRefCon, |
michael@0 | 292 | bool *outCmdEnabled) |
michael@0 | 293 | { |
michael@0 | 294 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 295 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 296 | if (editor) |
michael@0 | 297 | return editor->CanCopy(outCmdEnabled); |
michael@0 | 298 | |
michael@0 | 299 | *outCmdEnabled = false; |
michael@0 | 300 | return NS_OK; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | |
michael@0 | 304 | NS_IMETHODIMP |
michael@0 | 305 | nsCopyCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 306 | { |
michael@0 | 307 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 308 | if (editor) |
michael@0 | 309 | return editor->Copy(); |
michael@0 | 310 | |
michael@0 | 311 | return NS_ERROR_FAILURE; |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | NS_IMETHODIMP |
michael@0 | 315 | nsCopyCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 316 | nsICommandParams *aParams, |
michael@0 | 317 | nsISupports *aCommandRefCon) |
michael@0 | 318 | { |
michael@0 | 319 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | NS_IMETHODIMP |
michael@0 | 323 | nsCopyCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 324 | nsICommandParams *aParams, |
michael@0 | 325 | nsISupports *aCommandRefCon) |
michael@0 | 326 | { |
michael@0 | 327 | bool canUndo; |
michael@0 | 328 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 329 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | NS_IMETHODIMP |
michael@0 | 333 | nsCopyOrDeleteCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 334 | nsISupports *aCommandRefCon, |
michael@0 | 335 | bool *outCmdEnabled) |
michael@0 | 336 | { |
michael@0 | 337 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 338 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 339 | if (editor) |
michael@0 | 340 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 341 | |
michael@0 | 342 | *outCmdEnabled = false; |
michael@0 | 343 | return NS_OK; |
michael@0 | 344 | } |
michael@0 | 345 | |
michael@0 | 346 | |
michael@0 | 347 | NS_IMETHODIMP |
michael@0 | 348 | nsCopyOrDeleteCommand::DoCommand(const char *aCommandName, |
michael@0 | 349 | nsISupports *aCommandRefCon) |
michael@0 | 350 | { |
michael@0 | 351 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 352 | if (editor) |
michael@0 | 353 | { |
michael@0 | 354 | nsCOMPtr<nsISelection> selection; |
michael@0 | 355 | nsresult rv = editor->GetSelection(getter_AddRefs(selection)); |
michael@0 | 356 | if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) { |
michael@0 | 357 | return editor->DeleteSelection(nsIEditor::eNextWord, nsIEditor::eStrip); |
michael@0 | 358 | } |
michael@0 | 359 | return editor->Copy(); |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | return NS_ERROR_FAILURE; |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | NS_IMETHODIMP |
michael@0 | 366 | nsCopyOrDeleteCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 367 | nsICommandParams *aParams, |
michael@0 | 368 | nsISupports *aCommandRefCon) |
michael@0 | 369 | { |
michael@0 | 370 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 371 | } |
michael@0 | 372 | |
michael@0 | 373 | NS_IMETHODIMP |
michael@0 | 374 | nsCopyOrDeleteCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 375 | nsICommandParams *aParams, |
michael@0 | 376 | nsISupports *aCommandRefCon) |
michael@0 | 377 | { |
michael@0 | 378 | bool canUndo; |
michael@0 | 379 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 380 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | NS_IMETHODIMP |
michael@0 | 384 | nsPasteCommand::IsCommandEnabled(const char *aCommandName, |
michael@0 | 385 | nsISupports *aCommandRefCon, |
michael@0 | 386 | bool *outCmdEnabled) |
michael@0 | 387 | { |
michael@0 | 388 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 389 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 390 | if (editor) |
michael@0 | 391 | { |
michael@0 | 392 | bool isEditable = false; |
michael@0 | 393 | nsresult rv = editor->GetIsSelectionEditable(&isEditable); |
michael@0 | 394 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 395 | if (isEditable) |
michael@0 | 396 | return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled); |
michael@0 | 397 | } |
michael@0 | 398 | |
michael@0 | 399 | *outCmdEnabled = false; |
michael@0 | 400 | return NS_OK; |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | |
michael@0 | 404 | NS_IMETHODIMP |
michael@0 | 405 | nsPasteCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 406 | { |
michael@0 | 407 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 408 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 409 | |
michael@0 | 410 | return editor->Paste(nsIClipboard::kGlobalClipboard); |
michael@0 | 411 | } |
michael@0 | 412 | |
michael@0 | 413 | NS_IMETHODIMP |
michael@0 | 414 | nsPasteCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 415 | nsICommandParams *aParams, |
michael@0 | 416 | nsISupports *aCommandRefCon) |
michael@0 | 417 | { |
michael@0 | 418 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | NS_IMETHODIMP |
michael@0 | 422 | nsPasteCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 423 | nsICommandParams *aParams, |
michael@0 | 424 | nsISupports *aCommandRefCon) |
michael@0 | 425 | { |
michael@0 | 426 | bool canUndo; |
michael@0 | 427 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 428 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 429 | } |
michael@0 | 430 | |
michael@0 | 431 | NS_IMETHODIMP |
michael@0 | 432 | nsPasteTransferableCommand::IsCommandEnabled(const char *aCommandName, |
michael@0 | 433 | nsISupports *aCommandRefCon, |
michael@0 | 434 | bool *outCmdEnabled) |
michael@0 | 435 | { |
michael@0 | 436 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 437 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 438 | if (editor) |
michael@0 | 439 | { |
michael@0 | 440 | bool isEditable = false; |
michael@0 | 441 | nsresult rv = editor->GetIsSelectionEditable(&isEditable); |
michael@0 | 442 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 443 | if (isEditable) |
michael@0 | 444 | return editor->CanPasteTransferable(nullptr, outCmdEnabled); |
michael@0 | 445 | } |
michael@0 | 446 | |
michael@0 | 447 | *outCmdEnabled = false; |
michael@0 | 448 | return NS_OK; |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | NS_IMETHODIMP |
michael@0 | 452 | nsPasteTransferableCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 453 | { |
michael@0 | 454 | return NS_ERROR_FAILURE; |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | NS_IMETHODIMP |
michael@0 | 458 | nsPasteTransferableCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 459 | nsICommandParams *aParams, |
michael@0 | 460 | nsISupports *aCommandRefCon) |
michael@0 | 461 | { |
michael@0 | 462 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 463 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 464 | |
michael@0 | 465 | nsCOMPtr<nsISupports> supports; |
michael@0 | 466 | aParams->GetISupportsValue("transferable", getter_AddRefs(supports)); |
michael@0 | 467 | NS_ENSURE_TRUE(supports, NS_ERROR_FAILURE); |
michael@0 | 468 | |
michael@0 | 469 | nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports); |
michael@0 | 470 | NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE); |
michael@0 | 471 | |
michael@0 | 472 | return editor->PasteTransferable(trans); |
michael@0 | 473 | } |
michael@0 | 474 | |
michael@0 | 475 | NS_IMETHODIMP |
michael@0 | 476 | nsPasteTransferableCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 477 | nsICommandParams *aParams, |
michael@0 | 478 | nsISupports *aCommandRefCon) |
michael@0 | 479 | { |
michael@0 | 480 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 481 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 482 | |
michael@0 | 483 | nsCOMPtr<nsITransferable> trans; |
michael@0 | 484 | |
michael@0 | 485 | nsCOMPtr<nsISupports> supports; |
michael@0 | 486 | aParams->GetISupportsValue("transferable", getter_AddRefs(supports)); |
michael@0 | 487 | if (supports) { |
michael@0 | 488 | trans = do_QueryInterface(supports); |
michael@0 | 489 | NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE); |
michael@0 | 490 | } |
michael@0 | 491 | |
michael@0 | 492 | bool canPaste; |
michael@0 | 493 | nsresult rv = editor->CanPasteTransferable(trans, &canPaste); |
michael@0 | 494 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 495 | |
michael@0 | 496 | return aParams->SetBooleanValue(STATE_ENABLED, canPaste); |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | NS_IMETHODIMP |
michael@0 | 500 | nsSwitchTextDirectionCommand::IsCommandEnabled(const char *aCommandName, |
michael@0 | 501 | nsISupports *aCommandRefCon, |
michael@0 | 502 | bool *outCmdEnabled) |
michael@0 | 503 | { |
michael@0 | 504 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 505 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 506 | if (editor) |
michael@0 | 507 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 508 | |
michael@0 | 509 | *outCmdEnabled = false; |
michael@0 | 510 | return NS_OK; |
michael@0 | 511 | } |
michael@0 | 512 | |
michael@0 | 513 | NS_IMETHODIMP |
michael@0 | 514 | nsSwitchTextDirectionCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) |
michael@0 | 515 | { |
michael@0 | 516 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 517 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 518 | |
michael@0 | 519 | return editor->SwitchTextDirection(); |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | NS_IMETHODIMP |
michael@0 | 523 | nsSwitchTextDirectionCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 524 | nsICommandParams *aParams, |
michael@0 | 525 | nsISupports *aCommandRefCon) |
michael@0 | 526 | { |
michael@0 | 527 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 528 | } |
michael@0 | 529 | |
michael@0 | 530 | NS_IMETHODIMP |
michael@0 | 531 | nsSwitchTextDirectionCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 532 | nsICommandParams *aParams, |
michael@0 | 533 | nsISupports *aCommandRefCon) |
michael@0 | 534 | { |
michael@0 | 535 | bool canSwitchTextDirection = true; |
michael@0 | 536 | IsCommandEnabled(aCommandName, aCommandRefCon, &canSwitchTextDirection); |
michael@0 | 537 | return aParams->SetBooleanValue(STATE_ENABLED, canSwitchTextDirection); |
michael@0 | 538 | } |
michael@0 | 539 | |
michael@0 | 540 | NS_IMETHODIMP |
michael@0 | 541 | nsDeleteCommand::IsCommandEnabled(const char* aCommandName, |
michael@0 | 542 | nsISupports* aCommandRefCon, |
michael@0 | 543 | bool* outCmdEnabled) |
michael@0 | 544 | { |
michael@0 | 545 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 546 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 547 | *outCmdEnabled = false; |
michael@0 | 548 | |
michael@0 | 549 | NS_ENSURE_TRUE(editor, NS_OK); |
michael@0 | 550 | |
michael@0 | 551 | // We can generally delete whenever the selection is editable. However, |
michael@0 | 552 | // cmd_delete doesn't make sense if the selection is collapsed because it's |
michael@0 | 553 | // directionless, which is the same condition under which we can't cut. |
michael@0 | 554 | nsresult rv = editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 555 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 556 | |
michael@0 | 557 | if (!nsCRT::strcmp("cmd_delete", aCommandName) && *outCmdEnabled) { |
michael@0 | 558 | rv = editor->CanCut(outCmdEnabled); |
michael@0 | 559 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | return NS_OK; |
michael@0 | 563 | } |
michael@0 | 564 | |
michael@0 | 565 | |
michael@0 | 566 | NS_IMETHODIMP |
michael@0 | 567 | nsDeleteCommand::DoCommand(const char* aCommandName, |
michael@0 | 568 | nsISupports* aCommandRefCon) |
michael@0 | 569 | { |
michael@0 | 570 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 571 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 572 | |
michael@0 | 573 | nsIEditor::EDirection deleteDir = nsIEditor::eNone; |
michael@0 | 574 | |
michael@0 | 575 | if (!nsCRT::strcmp("cmd_delete", aCommandName)) { |
michael@0 | 576 | // Really this should probably be eNone, but it only makes a difference if |
michael@0 | 577 | // the selection is collapsed, and then this command is disabled. So let's |
michael@0 | 578 | // keep it as it always was to avoid breaking things. |
michael@0 | 579 | deleteDir = nsIEditor::ePrevious; |
michael@0 | 580 | } else if (!nsCRT::strcmp("cmd_deleteCharForward", aCommandName)) { |
michael@0 | 581 | deleteDir = nsIEditor::eNext; |
michael@0 | 582 | } else if (!nsCRT::strcmp("cmd_deleteCharBackward", aCommandName)) { |
michael@0 | 583 | deleteDir = nsIEditor::ePrevious; |
michael@0 | 584 | } else if (!nsCRT::strcmp("cmd_deleteWordBackward", aCommandName)) { |
michael@0 | 585 | deleteDir = nsIEditor::ePreviousWord; |
michael@0 | 586 | } else if (!nsCRT::strcmp("cmd_deleteWordForward", aCommandName)) { |
michael@0 | 587 | deleteDir = nsIEditor::eNextWord; |
michael@0 | 588 | } else if (!nsCRT::strcmp("cmd_deleteToBeginningOfLine", aCommandName)) { |
michael@0 | 589 | deleteDir = nsIEditor::eToBeginningOfLine; |
michael@0 | 590 | } else if (!nsCRT::strcmp("cmd_deleteToEndOfLine", aCommandName)) { |
michael@0 | 591 | deleteDir = nsIEditor::eToEndOfLine; |
michael@0 | 592 | } else { |
michael@0 | 593 | MOZ_CRASH("Unrecognized nsDeleteCommand"); |
michael@0 | 594 | } |
michael@0 | 595 | |
michael@0 | 596 | return editor->DeleteSelection(deleteDir, nsIEditor::eStrip); |
michael@0 | 597 | } |
michael@0 | 598 | |
michael@0 | 599 | NS_IMETHODIMP |
michael@0 | 600 | nsDeleteCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 601 | nsICommandParams *aParams, |
michael@0 | 602 | nsISupports *aCommandRefCon) |
michael@0 | 603 | { |
michael@0 | 604 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 605 | } |
michael@0 | 606 | |
michael@0 | 607 | NS_IMETHODIMP |
michael@0 | 608 | nsDeleteCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 609 | nsICommandParams *aParams, |
michael@0 | 610 | nsISupports *aCommandRefCon) |
michael@0 | 611 | { |
michael@0 | 612 | bool canUndo; |
michael@0 | 613 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 614 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | NS_IMETHODIMP |
michael@0 | 618 | nsSelectAllCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 619 | nsISupports *aCommandRefCon, |
michael@0 | 620 | bool *outCmdEnabled) |
michael@0 | 621 | { |
michael@0 | 622 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 623 | |
michael@0 | 624 | nsresult rv = NS_OK; |
michael@0 | 625 | // You can always select all, unless the selection is editable, |
michael@0 | 626 | // and the editable region is empty! |
michael@0 | 627 | *outCmdEnabled = true; |
michael@0 | 628 | bool docIsEmpty; |
michael@0 | 629 | |
michael@0 | 630 | // you can select all if there is an editor which is non-empty |
michael@0 | 631 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 632 | if (editor) { |
michael@0 | 633 | rv = editor->GetDocumentIsEmpty(&docIsEmpty); |
michael@0 | 634 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 635 | *outCmdEnabled = !docIsEmpty; |
michael@0 | 636 | } |
michael@0 | 637 | |
michael@0 | 638 | return rv; |
michael@0 | 639 | } |
michael@0 | 640 | |
michael@0 | 641 | |
michael@0 | 642 | NS_IMETHODIMP |
michael@0 | 643 | nsSelectAllCommand::DoCommand(const char *aCommandName, |
michael@0 | 644 | nsISupports *aCommandRefCon) |
michael@0 | 645 | { |
michael@0 | 646 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 647 | if (editor) |
michael@0 | 648 | return editor->SelectAll(); |
michael@0 | 649 | |
michael@0 | 650 | return NS_ERROR_FAILURE; |
michael@0 | 651 | } |
michael@0 | 652 | |
michael@0 | 653 | NS_IMETHODIMP |
michael@0 | 654 | nsSelectAllCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 655 | nsICommandParams *aParams, |
michael@0 | 656 | nsISupports *aCommandRefCon) |
michael@0 | 657 | { |
michael@0 | 658 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 659 | } |
michael@0 | 660 | |
michael@0 | 661 | NS_IMETHODIMP |
michael@0 | 662 | nsSelectAllCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 663 | nsICommandParams *aParams, |
michael@0 | 664 | nsISupports *aCommandRefCon) |
michael@0 | 665 | { |
michael@0 | 666 | bool canUndo; |
michael@0 | 667 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 668 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 669 | } |
michael@0 | 670 | |
michael@0 | 671 | |
michael@0 | 672 | NS_IMETHODIMP |
michael@0 | 673 | nsSelectionMoveCommands::IsCommandEnabled(const char * aCommandName, |
michael@0 | 674 | nsISupports *aCommandRefCon, |
michael@0 | 675 | bool *outCmdEnabled) |
michael@0 | 676 | { |
michael@0 | 677 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 678 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 679 | if (editor) |
michael@0 | 680 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 681 | |
michael@0 | 682 | *outCmdEnabled = false; |
michael@0 | 683 | return NS_OK; |
michael@0 | 684 | } |
michael@0 | 685 | |
michael@0 | 686 | NS_IMETHODIMP |
michael@0 | 687 | nsSelectionMoveCommands::DoCommand(const char *aCommandName, |
michael@0 | 688 | nsISupports *aCommandRefCon) |
michael@0 | 689 | { |
michael@0 | 690 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon); |
michael@0 | 691 | NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); |
michael@0 | 692 | |
michael@0 | 693 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 694 | editor->GetDocument(getter_AddRefs(domDoc)); |
michael@0 | 695 | nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); |
michael@0 | 696 | if (doc) { |
michael@0 | 697 | // Most of the commands below (possibly all of them) need layout to |
michael@0 | 698 | // be up to date. |
michael@0 | 699 | doc->FlushPendingNotifications(Flush_Layout); |
michael@0 | 700 | } |
michael@0 | 701 | |
michael@0 | 702 | nsCOMPtr<nsISelectionController> selCont; |
michael@0 | 703 | nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont)); |
michael@0 | 704 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 705 | NS_ENSURE_TRUE(selCont, NS_ERROR_FAILURE); |
michael@0 | 706 | |
michael@0 | 707 | // complete scroll commands |
michael@0 | 708 | if (!nsCRT::strcmp(aCommandName,"cmd_scrollTop")) |
michael@0 | 709 | return selCont->CompleteScroll(false); |
michael@0 | 710 | else if (!nsCRT::strcmp(aCommandName,"cmd_scrollBottom")) |
michael@0 | 711 | return selCont->CompleteScroll(true); |
michael@0 | 712 | |
michael@0 | 713 | // complete move commands |
michael@0 | 714 | else if (!nsCRT::strcmp(aCommandName,"cmd_moveTop")) |
michael@0 | 715 | return selCont->CompleteMove(false, false); |
michael@0 | 716 | else if (!nsCRT::strcmp(aCommandName,"cmd_moveBottom")) |
michael@0 | 717 | return selCont->CompleteMove(true, false); |
michael@0 | 718 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectTop")) |
michael@0 | 719 | return selCont->CompleteMove(false, true); |
michael@0 | 720 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectBottom")) |
michael@0 | 721 | return selCont->CompleteMove(true, true); |
michael@0 | 722 | |
michael@0 | 723 | // line move commands |
michael@0 | 724 | else if (!nsCRT::strcmp(aCommandName,"cmd_lineNext")) |
michael@0 | 725 | return selCont->LineMove(true, false); |
michael@0 | 726 | else if (!nsCRT::strcmp(aCommandName,"cmd_linePrevious")) |
michael@0 | 727 | return selCont->LineMove(false, false); |
michael@0 | 728 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectLineNext")) |
michael@0 | 729 | return selCont->LineMove(true, true); |
michael@0 | 730 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectLinePrevious")) |
michael@0 | 731 | return selCont->LineMove(false, true); |
michael@0 | 732 | |
michael@0 | 733 | // character move commands |
michael@0 | 734 | else if (!nsCRT::strcmp(aCommandName,"cmd_charPrevious")) |
michael@0 | 735 | return selCont->CharacterMove(false, false); |
michael@0 | 736 | else if (!nsCRT::strcmp(aCommandName,"cmd_charNext")) |
michael@0 | 737 | return selCont->CharacterMove(true, false); |
michael@0 | 738 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectCharPrevious")) |
michael@0 | 739 | return selCont->CharacterMove(false, true); |
michael@0 | 740 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectCharNext")) |
michael@0 | 741 | return selCont->CharacterMove(true, true); |
michael@0 | 742 | |
michael@0 | 743 | // intra line move commands |
michael@0 | 744 | else if (!nsCRT::strcmp(aCommandName,"cmd_beginLine")) |
michael@0 | 745 | return selCont->IntraLineMove(false, false); |
michael@0 | 746 | else if (!nsCRT::strcmp(aCommandName,"cmd_endLine")) |
michael@0 | 747 | return selCont->IntraLineMove(true, false); |
michael@0 | 748 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectBeginLine")) |
michael@0 | 749 | return selCont->IntraLineMove(false, true); |
michael@0 | 750 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectEndLine")) |
michael@0 | 751 | return selCont->IntraLineMove(true, true); |
michael@0 | 752 | |
michael@0 | 753 | // word move commands |
michael@0 | 754 | else if (!nsCRT::strcmp(aCommandName,"cmd_wordPrevious")) |
michael@0 | 755 | return selCont->WordMove(false, false); |
michael@0 | 756 | else if (!nsCRT::strcmp(aCommandName,"cmd_wordNext")) |
michael@0 | 757 | return selCont->WordMove(true, false); |
michael@0 | 758 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectWordPrevious")) |
michael@0 | 759 | return selCont->WordMove(false, true); |
michael@0 | 760 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectWordNext")) |
michael@0 | 761 | return selCont->WordMove(true, true); |
michael@0 | 762 | |
michael@0 | 763 | // scroll page commands |
michael@0 | 764 | else if (!nsCRT::strcmp(aCommandName,"cmd_scrollPageUp")) |
michael@0 | 765 | return selCont->ScrollPage(false); |
michael@0 | 766 | else if (!nsCRT::strcmp(aCommandName,"cmd_scrollPageDown")) |
michael@0 | 767 | return selCont->ScrollPage(true); |
michael@0 | 768 | |
michael@0 | 769 | // scroll line commands |
michael@0 | 770 | else if (!nsCRT::strcmp(aCommandName,"cmd_scrollLineUp")) |
michael@0 | 771 | return selCont->ScrollLine(false); |
michael@0 | 772 | else if (!nsCRT::strcmp(aCommandName,"cmd_scrollLineDown")) |
michael@0 | 773 | return selCont->ScrollLine(true); |
michael@0 | 774 | |
michael@0 | 775 | // page move commands |
michael@0 | 776 | else if (!nsCRT::strcmp(aCommandName,"cmd_movePageUp")) |
michael@0 | 777 | return selCont->PageMove(false, false); |
michael@0 | 778 | else if (!nsCRT::strcmp(aCommandName,"cmd_movePageDown")) |
michael@0 | 779 | return selCont->PageMove(true, false); |
michael@0 | 780 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectPageUp")) |
michael@0 | 781 | return selCont->PageMove(false, true); |
michael@0 | 782 | else if (!nsCRT::strcmp(aCommandName,"cmd_selectPageDown")) |
michael@0 | 783 | return selCont->PageMove(true, true); |
michael@0 | 784 | |
michael@0 | 785 | return NS_ERROR_FAILURE; |
michael@0 | 786 | } |
michael@0 | 787 | |
michael@0 | 788 | NS_IMETHODIMP |
michael@0 | 789 | nsSelectionMoveCommands::DoCommandParams(const char *aCommandName, |
michael@0 | 790 | nsICommandParams *aParams, |
michael@0 | 791 | nsISupports *aCommandRefCon) |
michael@0 | 792 | { |
michael@0 | 793 | return DoCommand(aCommandName, aCommandRefCon); |
michael@0 | 794 | } |
michael@0 | 795 | |
michael@0 | 796 | NS_IMETHODIMP |
michael@0 | 797 | nsSelectionMoveCommands::GetCommandStateParams(const char *aCommandName, |
michael@0 | 798 | nsICommandParams *aParams, |
michael@0 | 799 | nsISupports *aCommandRefCon) |
michael@0 | 800 | { |
michael@0 | 801 | bool canUndo; |
michael@0 | 802 | IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo); |
michael@0 | 803 | return aParams->SetBooleanValue(STATE_ENABLED,canUndo); |
michael@0 | 804 | } |
michael@0 | 805 | |
michael@0 | 806 | |
michael@0 | 807 | NS_IMETHODIMP |
michael@0 | 808 | nsInsertPlaintextCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 809 | nsISupports *refCon, |
michael@0 | 810 | bool *outCmdEnabled) |
michael@0 | 811 | { |
michael@0 | 812 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 813 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 814 | if (editor) |
michael@0 | 815 | return editor->GetIsSelectionEditable(outCmdEnabled); |
michael@0 | 816 | |
michael@0 | 817 | *outCmdEnabled = false; |
michael@0 | 818 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 819 | } |
michael@0 | 820 | |
michael@0 | 821 | |
michael@0 | 822 | NS_IMETHODIMP |
michael@0 | 823 | nsInsertPlaintextCommand::DoCommand(const char *aCommandName, |
michael@0 | 824 | nsISupports *refCon) |
michael@0 | 825 | { |
michael@0 | 826 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 827 | } |
michael@0 | 828 | |
michael@0 | 829 | NS_IMETHODIMP |
michael@0 | 830 | nsInsertPlaintextCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 831 | nsICommandParams *aParams, |
michael@0 | 832 | nsISupports *refCon) |
michael@0 | 833 | { |
michael@0 | 834 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 835 | |
michael@0 | 836 | nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(refCon); |
michael@0 | 837 | NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED); |
michael@0 | 838 | |
michael@0 | 839 | // Get text to insert from command params |
michael@0 | 840 | nsAutoString text; |
michael@0 | 841 | nsresult rv = aParams->GetStringValue(STATE_DATA, text); |
michael@0 | 842 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 843 | |
michael@0 | 844 | if (!text.IsEmpty()) |
michael@0 | 845 | return editor->InsertText(text); |
michael@0 | 846 | |
michael@0 | 847 | return NS_OK; |
michael@0 | 848 | } |
michael@0 | 849 | |
michael@0 | 850 | NS_IMETHODIMP |
michael@0 | 851 | nsInsertPlaintextCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 852 | nsICommandParams *aParams, |
michael@0 | 853 | nsISupports *refCon) |
michael@0 | 854 | { |
michael@0 | 855 | NS_ENSURE_ARG_POINTER(aParams); |
michael@0 | 856 | |
michael@0 | 857 | bool outCmdEnabled = false; |
michael@0 | 858 | IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); |
michael@0 | 859 | return aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); |
michael@0 | 860 | } |
michael@0 | 861 | |
michael@0 | 862 | |
michael@0 | 863 | NS_IMETHODIMP |
michael@0 | 864 | nsPasteQuotationCommand::IsCommandEnabled(const char * aCommandName, |
michael@0 | 865 | nsISupports *refCon, |
michael@0 | 866 | bool *outCmdEnabled) |
michael@0 | 867 | { |
michael@0 | 868 | NS_ENSURE_ARG_POINTER(outCmdEnabled); |
michael@0 | 869 | |
michael@0 | 870 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 871 | nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon); |
michael@0 | 872 | if (editor && mailEditor) { |
michael@0 | 873 | uint32_t flags; |
michael@0 | 874 | editor->GetFlags(&flags); |
michael@0 | 875 | if (!(flags & nsIPlaintextEditor::eEditorSingleLineMask)) |
michael@0 | 876 | return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled); |
michael@0 | 877 | } |
michael@0 | 878 | |
michael@0 | 879 | *outCmdEnabled = false; |
michael@0 | 880 | return NS_OK; |
michael@0 | 881 | } |
michael@0 | 882 | |
michael@0 | 883 | |
michael@0 | 884 | NS_IMETHODIMP |
michael@0 | 885 | nsPasteQuotationCommand::DoCommand(const char *aCommandName, |
michael@0 | 886 | nsISupports *refCon) |
michael@0 | 887 | { |
michael@0 | 888 | nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon); |
michael@0 | 889 | if (mailEditor) |
michael@0 | 890 | return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard); |
michael@0 | 891 | |
michael@0 | 892 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 893 | } |
michael@0 | 894 | |
michael@0 | 895 | NS_IMETHODIMP |
michael@0 | 896 | nsPasteQuotationCommand::DoCommandParams(const char *aCommandName, |
michael@0 | 897 | nsICommandParams *aParams, |
michael@0 | 898 | nsISupports *refCon) |
michael@0 | 899 | { |
michael@0 | 900 | nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(refCon); |
michael@0 | 901 | if (mailEditor) |
michael@0 | 902 | return mailEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard); |
michael@0 | 903 | |
michael@0 | 904 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 905 | } |
michael@0 | 906 | |
michael@0 | 907 | NS_IMETHODIMP |
michael@0 | 908 | nsPasteQuotationCommand::GetCommandStateParams(const char *aCommandName, |
michael@0 | 909 | nsICommandParams *aParams, |
michael@0 | 910 | nsISupports *refCon) |
michael@0 | 911 | { |
michael@0 | 912 | nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); |
michael@0 | 913 | if (editor) |
michael@0 | 914 | { |
michael@0 | 915 | bool enabled = false; |
michael@0 | 916 | editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled); |
michael@0 | 917 | aParams->SetBooleanValue(STATE_ENABLED, enabled); |
michael@0 | 918 | } |
michael@0 | 919 | |
michael@0 | 920 | return NS_OK; |
michael@0 | 921 | } |
michael@0 | 922 |