EditAction.h (40852B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_EditAction_h 7 #define mozilla_EditAction_h 8 9 #include "mozilla/EventForwards.h" 10 #include "mozilla/StaticPrefs_dom.h" 11 12 namespace mozilla { 13 14 /** 15 * EditAction indicates which operation or command causes running the methods 16 * of editors. 17 */ 18 enum class EditAction { 19 // eNone indicates no edit action is being handled. 20 eNone, 21 22 // eNotEditing indicates that something is retrieved, doing something at 23 // destroying or focus move etc, i.e., not edit action is being handled but 24 // editor is doing something. 25 eNotEditing, 26 27 // eInitializing indicates that the editor instance is being initialized. 28 eInitializing, 29 30 // eInsertText indicates to insert some characters. 31 eInsertText, 32 33 // eInsertParagraphSeparator indicates to insert a paragraph separator such 34 // as <p>, <div>. 35 eInsertParagraphSeparator, 36 37 // eInsertLineBreak indicates to insert \n into TextEditor or a <br> element 38 // in HTMLEditor. 39 eInsertLineBreak, 40 41 // eDeleteSelection indicates to delete selected content or content around 42 // caret if selection is collapsed. 43 eDeleteSelection, 44 45 // eDeleteBackward indicates to remove previous character element of caret. 46 // This may be set even when Selection is not collapsed. 47 eDeleteBackward, 48 49 // eDeleteForward indicates to remove next character or element of caret. 50 // This may be set even when Selection is not collapsed. 51 eDeleteForward, 52 53 // eDeleteWordBackward indicates to remove previous word. If caret is in 54 // a word, remove characters between word start and caret. 55 // This may be set even when Selection is not collapsed. 56 eDeleteWordBackward, 57 58 // eDeleteWordForward indicates to remove next word. If caret is in a 59 // word, remove characters between caret and word end. 60 // This may be set even when Selection is not collapsed. 61 eDeleteWordForward, 62 63 // eDeleteToBeginningOfSoftLine indicates to remove characters between 64 // caret and previous visual line break. 65 // This may be set even when Selection is not collapsed. 66 eDeleteToBeginningOfSoftLine, 67 68 // eDeleteToEndOfSoftLine indicates to remove characters between caret and 69 // next visual line break. 70 // This may be set even when Selection is not collapsed. 71 eDeleteToEndOfSoftLine, 72 73 // eDeleteByDrag indicates to remove selection by dragging the content 74 // to different place. 75 eDeleteByDrag, 76 77 // eStartComposition indicates that user starts composition. 78 eStartComposition, 79 80 // eUpdateComposition indicates that user updates composition with 81 // new non-empty composition string and IME selections. 82 eUpdateComposition, 83 84 // eUpdateCompositionToCommit indicates that user commits composition with 85 // the new data. That means that there will be no IME selections, but the 86 // composition continues until the following eCompositionEnd event. 87 eUpdateCompositionToCommit, 88 89 // eCommitComposition indicates that user commits composition and ends the 90 // composition. 91 eCommitComposition, 92 93 // eCancelComposition indicates that user cancels composition and ends the 94 // composition with empty string. 95 eCancelComposition, 96 97 // eUndo/eRedo indicate to undo/redo a transaction. 98 eUndo, 99 eRedo, 100 101 // eSetTextDirection indicates that setting text direction (LTR or RTL). 102 eSetTextDirection, 103 104 // eCut indicates to delete selected content and copy it to the clipboard. 105 eCut, 106 107 // eCopy indicates to copy selected content to the clipboard. 108 eCopy, 109 110 // ePaste indicates to paste clipboard data. 111 ePaste, 112 113 // ePasteAsQuotation indicates to paste clipboard data as quotation. 114 ePasteAsQuotation, 115 116 // eDrop indicates that user drops dragging item into the editor. 117 eDrop, 118 119 // eIndent indicates that to indent selected line(s). 120 eIndent, 121 122 // eOutdent indicates that to outdent selected line(s). 123 eOutdent, 124 125 // eReplaceText indicates to replace a part of range in editor with 126 // specific text. For example, user select a correct word in suggestions 127 // of spellchecker or a suggestion in list of autocomplete. 128 eReplaceText, 129 130 // eInsertTableRowElement indicates to insert table rows (i.e., <tr> 131 // elements). 132 eInsertTableRowElement, 133 134 // eRemoveTableRowElement indicates to remove table row elements. 135 eRemoveTableRowElement, 136 137 // eInsertTableColumn indicates to insert cell elements to each row. 138 eInsertTableColumn, 139 140 // eRemoveTableColumn indicates to remove cell elements from each row. 141 eRemoveTableColumn, 142 143 // eResizingElement indicates that user starts to resize or keep resizing 144 // with dragging a resizer which is provided by Gecko. 145 eResizingElement, 146 147 // eResizeElement indicates that user resizes an element size with finishing 148 // dragging a resizer which is provided by Gecko. 149 eResizeElement, 150 151 // eMovingElement indicates that user starts to move or keep moving an 152 // element with grabber which is provided by Gecko. 153 eMovingElement, 154 155 // eMoveElement indicates that user finishes moving an element with grabber 156 // which is provided by Gecko. 157 eMoveElement, 158 159 // The following edit actions are not user's operation. They are caused 160 // by if UI does something or web apps does something with JS. 161 162 // eUnknown indicates some special edit actions, e.g., batching of some 163 // nsI*Editor method calls. This shouldn't be set while handling a user 164 // operation. 165 eUnknown, 166 167 // eSetAttribute indicates to set attribute value of an element node. 168 eSetAttribute, 169 170 // eRemoveAttribute indicates to remove attribute from an element node. 171 eRemoveAttribute, 172 173 // eInsertNode indicates to insert a node into the tree. 174 eInsertNode, 175 176 // eDeleteNode indicates to remove a node form the tree. 177 eRemoveNode, 178 179 // eInsertBlockElement indicates to insert a block-level element like <div>, 180 // <pre>, <li>, <dd> etc. 181 eInsertBlockElement, 182 183 // eInsertHorizontalRuleElement indicates to insert a <hr> element. 184 eInsertHorizontalRuleElement, 185 186 // eInsertLinkElement indicates to insert an anchor element which has 187 // href attribute. 188 eInsertLinkElement, 189 190 // eInsertUnorderedListElement and eInsertOrderedListElement indicate to 191 // insert <ul> or <ol> element. 192 eInsertUnorderedListElement, 193 eInsertOrderedListElement, 194 195 // eRemoveUnorderedListElement and eRemoveOrderedListElement indicate to 196 // remove <ul> or <ol> element. 197 eRemoveUnorderedListElement, 198 eRemoveOrderedListElement, 199 200 // eRemoveListElement indicates to remove <ul>, <ol> and/or <dl> element. 201 eRemoveListElement, 202 203 // eInsertBlockquoteElement indicates to insert a <blockquote> element. 204 eInsertBlockquoteElement, 205 206 // eNormalizeTable indicates to normalize table. E.g., if a row does 207 // not have enough number of cells, inserts empty cells. 208 eNormalizeTable, 209 210 // eRemoveTableElement indicates to remove <table> element. 211 eRemoveTableElement, 212 213 // eRemoveTableCellContents indicates to remove any children in a table 214 // cell element. 215 eDeleteTableCellContents, 216 217 // eInsertTableCellElement indicates to insert table cell elements (i.e., 218 // <td> or <th>). 219 eInsertTableCellElement, 220 221 // eRemoveTableCellEelement indicates to remove table cell elements. 222 eRemoveTableCellElement, 223 224 // eJoinTableCellElements indicates to join table cell elements. 225 eJoinTableCellElements, 226 227 // eSplitTableCellElement indicates to split table cell elements. 228 eSplitTableCellElement, 229 230 // eSetTableCellElementType indicates to set table cell element type to 231 // <td> or <th>. 232 eSetTableCellElementType, 233 234 // Those edit actions are mapped to the methods in nsITableEditor which 235 // access table layout information. 236 eSelectTableCell, 237 eSelectTableRow, 238 eSelectTableColumn, 239 eSelectTable, 240 eSelectAllTableCells, 241 eGetCellIndexes, 242 eGetTableSize, 243 eGetCellAt, 244 eGetCellDataAt, 245 eGetFirstRow, 246 eGetSelectedOrParentTableElement, 247 eGetSelectedCellsType, 248 eGetFirstSelectedCellInTable, 249 eGetSelectedCells, 250 251 // eSetInlineStyleProperty indicates to set CSS another inline style property 252 // which is not defined below. 253 eSetInlineStyleProperty, 254 255 // eRemoveInlineStyleProperty indicates to remove a CSS text property which 256 // is not defined below. 257 eRemoveInlineStyleProperty, 258 259 // <b> or font-weight. 260 eSetFontWeightProperty, 261 eRemoveFontWeightProperty, 262 263 // <i> or text-style: italic/oblique. 264 eSetTextStyleProperty, 265 eRemoveTextStyleProperty, 266 267 // <u> or text-decoration: underline. 268 eSetTextDecorationPropertyUnderline, 269 eRemoveTextDecorationPropertyUnderline, 270 271 // <strike> or text-decoration: line-through. 272 eSetTextDecorationPropertyLineThrough, 273 eRemoveTextDecorationPropertyLineThrough, 274 275 // <sup> or text-align: super. 276 eSetVerticalAlignPropertySuper, 277 eRemoveVerticalAlignPropertySuper, 278 279 // <sub> or text-align: sub. 280 eSetVerticalAlignPropertySub, 281 eRemoveVerticalAlignPropertySub, 282 283 // <font face="foo"> or font-family. 284 eSetFontFamilyProperty, 285 eRemoveFontFamilyProperty, 286 287 // <font color="foo"> or color. 288 eSetColorProperty, 289 eRemoveColorProperty, 290 291 // <span style="background-color: foo"> 292 eSetBackgroundColorPropertyInline, 293 eRemoveBackgroundColorPropertyInline, 294 295 // eRemoveAllInlineStyleProperties indicates to remove all CSS inline 296 // style properties. 297 eRemoveAllInlineStyleProperties, 298 299 // eIncrementFontSize indicates to increment font-size. 300 eIncrementFontSize, 301 302 // eDecrementFontSize indicates to decrement font-size. 303 eDecrementFontSize, 304 305 // eSetAlignment indicates to set alignment of selected content but different 306 // from the following. 307 eSetAlignment, 308 309 // eAlign* and eJustify indicates to align contents in block with left 310 // edge, right edge, center or justify the text. 311 eAlignLeft, 312 eAlignRight, 313 eAlignCenter, 314 eJustify, 315 316 // eSetBackgroundColor indicates to set background color. 317 eSetBackgroundColor, 318 319 // eSetPositionToAbsoluteOrStatic indicates to set position property value 320 // to "absolute" or "static". 321 eSetPositionToAbsoluteOrStatic, 322 323 // eIncreaseOrDecreaseZIndex indicates to change z-index of an element. 324 eIncreaseOrDecreaseZIndex, 325 326 // eEnableOrDisableCSS indicates to enable or disable CSS mode of HTMLEditor. 327 eEnableOrDisableCSS, 328 329 // eEnableOrDisableAbsolutePositionEditor indicates to enable or disable 330 // absolute positioned element editing UI. 331 eEnableOrDisableAbsolutePositionEditor, 332 333 // eEnableOrDisableResizer indicates to enable or disable resizers of 334 // <img>, <table> and absolutely positioned element. 335 eEnableOrDisableResizer, 336 337 // eEnableOrDisableInlineTableEditingUI indicates to enable or disable 338 // inline table editing UI. 339 eEnableOrDisableInlineTableEditingUI, 340 341 // eSetCharacterSet indicates to set character-set of the document. 342 eSetCharacterSet, 343 344 // eSetWrapWidth indicates to set wrap width. 345 eSetWrapWidth, 346 347 // eRewrap indicates to rewrap for current wrap width. 348 eRewrap, 349 350 // eSetText indicates to set new text of TextEditor, e.g., setting 351 // HTMLInputElement.value. 352 eSetText, 353 354 // eInsertHTML indicates to insert HTML source code. 355 eInsertHTML, 356 357 // eHidePassword indicates that editor hides password with mask characters. 358 eHidePassword, 359 360 // eCreatePaddingBRElementForEmptyEditor indicates that editor wants to 361 // create a padding <br> element for empty editor after it modifies its 362 // content. 363 eCreatePaddingBRElementForEmptyEditor, 364 }; 365 366 // This is int32_t instead of int16_t because nsIInlineSpellChecker.idl's 367 // spellCheckAfterEditorChange is defined to take it as a long. 368 // TODO: Make each name eFoo and investigate whether the numeric values 369 // still have some meaning. 370 enum class EditSubAction : int32_t { 371 // eNone indicates not edit sub-action is being handled. This is useful 372 // of initial value of member variables. 373 eNone, 374 375 // eUndo and eRedo indicate entire actions of undo/redo operation. 376 eUndo, 377 eRedo, 378 379 // eInsertNode indicates to insert a new node into the DOM tree. 380 eInsertNode, 381 382 // eCreateNode indicates to create a new node and insert it into the DOM tree. 383 eCreateNode, 384 385 // eDeleteNode indicates to remove a node from the DOM tree. 386 eDeleteNode, 387 388 // eMoveNode indicates to move a node connected in the DOM tree to different 389 // place. 390 eMoveNode, 391 392 // eSplitNode indicates to split a node to 2 nodes. 393 eSplitNode, 394 395 // eJoinNodes indicates to join 2 nodes. 396 eJoinNodes, 397 398 // eDeleteText indicates to delete some characters form a text node. 399 eDeleteText, 400 401 // eInsertText indicates to insert some characters. 402 eInsertText, 403 404 // eInsertTextComingFromIME indicates to insert or update composition string 405 // with new text which is new composition string or commit string. 406 eInsertTextComingFromIME, 407 408 // eDeleteSelectedContent indicates to remove selected content. 409 eDeleteSelectedContent, 410 411 // eSetTextProperty indicates to set a style from text. 412 eSetTextProperty, 413 414 // eRemoveTextProperty indicates to remove a style from text. 415 eRemoveTextProperty, 416 417 // eRemoveAllTextProperties indicate to remove all styles from text. 418 eRemoveAllTextProperties, 419 420 // eComputeTextToOutput indicates to compute the editor value as plain text 421 // or something requested format. 422 eComputeTextToOutput, 423 424 // eSetText indicates to set editor value to new value. 425 eSetText, 426 427 // eInsertLineBreak indicates to insert a line break, <br> or \n to break 428 // current line. 429 eInsertLineBreak, 430 431 // eInsertParagraphSeparator indicates to insert paragraph separator, <br> or 432 // \n at least to break current line in HTMLEditor. 433 eInsertParagraphSeparator, 434 435 // eCreateOrChangeList indicates to create new list or change existing list 436 // type. 437 eCreateOrChangeList, 438 439 // eIndent and eOutdent indicates to indent or outdent the target with 440 // using <blockquote>, <ul>, <ol> or just margin of start edge. 441 eIndent, 442 eOutdent, 443 444 // eSetOrClearAlignment aligns content or clears alignment with align 445 // attribute or text-align. 446 eSetOrClearAlignment, 447 448 // eCreateOrRemoveBlock creates new block or removes existing block and 449 // move its descendants to where the block was. 450 eCreateOrRemoveBlock, 451 452 // eFormatBlockForHTMLCommand wraps selected lines into format block, replaces 453 // format blocks around selection with new format block or deletes format 454 // blocks around selection. 455 eFormatBlockForHTMLCommand, 456 457 // eMergeBlockContents is not an actual sub-action, but this is used by 458 // HTMLEditor::MoveBlock() to request special handling in 459 // HTMLEditor::MaybeSplitElementsAtEveryBRElement(). 460 eMergeBlockContents, 461 462 // eRemoveList removes specific type of list but keep its content. 463 eRemoveList, 464 465 // eCreateOrChangeDefinitionListItem indicates to format current hard line(s) 466 // `<dd>` or `<dt>`. This may cause creating or changing existing list 467 // element to new `<dl>` element. 468 eCreateOrChangeDefinitionListItem, 469 470 // eInsertElement indicates to insert an element. 471 eInsertElement, 472 473 // eInsertQuotation indicates to insert an element and make it "quoted text". 474 eInsertQuotation, 475 476 // eInsertQuotedText indicates to insert text which has already been quoted. 477 eInsertQuotedText, 478 479 // ePasteHTMLContent indicates to paste HTML content in clipboard. 480 ePasteHTMLContent, 481 482 // eInsertHTMLSource indicates to create a document fragment from given HTML 483 // source and insert into the DOM tree. So, this is similar to innerHTML. 484 eInsertHTMLSource, 485 486 // eSetPositionToAbsolute and eSetPositionToStatic indicates to set position 487 // property to absolute or static. 488 eSetPositionToAbsolute, 489 eSetPositionToStatic, 490 491 // eDecreaseZIndex and eIncreaseZIndex indicate to decrease and increase 492 // z-index value. 493 eDecreaseZIndex, 494 eIncreaseZIndex, 495 496 // eCreatePaddingBRElementForEmptyEditor indicates to create a padding <br> 497 // element for empty editor. 498 eCreatePaddingBRElementForEmptyEditor, 499 500 // eMaintainWhiteSpaceVisibility indicates that editor updates `Text` nodes 501 // to make visible white-spaces keep visible even if web apps deletes padding 502 // <br>s for the preceding white-space. 503 eMaintainWhiteSpaceVisibility, 504 }; 505 506 // You can use this macro as: 507 // case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING: 508 // clang-format off 509 #define NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING \ 510 mozilla::EditAction::eSelectTableCell: \ 511 case mozilla::EditAction::eSelectTableRow: \ 512 case mozilla::EditAction::eSelectTableColumn: \ 513 case mozilla::EditAction::eSelectTable: \ 514 case mozilla::EditAction::eSelectAllTableCells: \ 515 case mozilla::EditAction::eGetCellIndexes: \ 516 case mozilla::EditAction::eGetTableSize: \ 517 case mozilla::EditAction::eGetCellAt: \ 518 case mozilla::EditAction::eGetCellDataAt: \ 519 case mozilla::EditAction::eGetFirstRow: \ 520 case mozilla::EditAction::eGetSelectedOrParentTableElement: \ 521 case mozilla::EditAction::eGetSelectedCellsType: \ 522 case mozilla::EditAction::eGetFirstSelectedCellInTable: \ 523 case mozilla::EditAction::eGetSelectedCells 524 // clang-format on 525 526 inline EditorInputType ToInputType(EditAction aEditAction) { 527 switch (aEditAction) { 528 case EditAction::eInsertText: 529 return EditorInputType::eInsertText; 530 case EditAction::eReplaceText: 531 return EditorInputType::eInsertReplacementText; 532 case EditAction::eInsertLineBreak: 533 return EditorInputType::eInsertLineBreak; 534 case EditAction::eInsertParagraphSeparator: 535 return EditorInputType::eInsertParagraph; 536 case EditAction::eInsertOrderedListElement: 537 case EditAction::eRemoveOrderedListElement: 538 return EditorInputType::eInsertOrderedList; 539 case EditAction::eInsertUnorderedListElement: 540 case EditAction::eRemoveUnorderedListElement: 541 return EditorInputType::eInsertUnorderedList; 542 case EditAction::eInsertHorizontalRuleElement: 543 return EditorInputType::eInsertHorizontalRule; 544 case EditAction::eDrop: 545 return EditorInputType::eInsertFromDrop; 546 case EditAction::ePaste: 547 return EditorInputType::eInsertFromPaste; 548 case EditAction::ePasteAsQuotation: 549 return EditorInputType::eInsertFromPasteAsQuotation; 550 case EditAction::eUpdateComposition: 551 case EditAction::eUpdateCompositionToCommit: 552 return EditorInputType::eInsertCompositionText; 553 case EditAction::eCommitComposition: 554 if (StaticPrefs::dom_input_events_conform_to_level_1()) { 555 return EditorInputType::eInsertCompositionText; 556 } 557 return EditorInputType::eInsertFromComposition; 558 case EditAction::eCancelComposition: 559 if (StaticPrefs::dom_input_events_conform_to_level_1()) { 560 return EditorInputType::eInsertCompositionText; 561 } 562 return EditorInputType::eDeleteCompositionText; 563 case EditAction::eInsertLinkElement: 564 return EditorInputType::eInsertLink; 565 case EditAction::eDeleteWordBackward: 566 return EditorInputType::eDeleteWordBackward; 567 case EditAction::eDeleteWordForward: 568 return EditorInputType::eDeleteWordForward; 569 case EditAction::eDeleteToBeginningOfSoftLine: 570 return EditorInputType::eDeleteSoftLineBackward; 571 case EditAction::eDeleteToEndOfSoftLine: 572 return EditorInputType::eDeleteSoftLineForward; 573 case EditAction::eDeleteByDrag: 574 return EditorInputType::eDeleteByDrag; 575 case EditAction::eCut: 576 return EditorInputType::eDeleteByCut; 577 case EditAction::eDeleteSelection: 578 case EditAction::eRemoveTableRowElement: 579 case EditAction::eRemoveTableColumn: 580 case EditAction::eRemoveTableElement: 581 case EditAction::eDeleteTableCellContents: 582 case EditAction::eRemoveTableCellElement: 583 return EditorInputType::eDeleteContent; 584 case EditAction::eDeleteBackward: 585 return EditorInputType::eDeleteContentBackward; 586 case EditAction::eDeleteForward: 587 return EditorInputType::eDeleteContentForward; 588 case EditAction::eUndo: 589 return EditorInputType::eHistoryUndo; 590 case EditAction::eRedo: 591 return EditorInputType::eHistoryRedo; 592 case EditAction::eSetFontWeightProperty: 593 case EditAction::eRemoveFontWeightProperty: 594 return EditorInputType::eFormatBold; 595 case EditAction::eSetTextStyleProperty: 596 case EditAction::eRemoveTextStyleProperty: 597 return EditorInputType::eFormatItalic; 598 case EditAction::eSetTextDecorationPropertyUnderline: 599 case EditAction::eRemoveTextDecorationPropertyUnderline: 600 return EditorInputType::eFormatUnderline; 601 case EditAction::eSetTextDecorationPropertyLineThrough: 602 case EditAction::eRemoveTextDecorationPropertyLineThrough: 603 return EditorInputType::eFormatStrikeThrough; 604 case EditAction::eSetVerticalAlignPropertySuper: 605 case EditAction::eRemoveVerticalAlignPropertySuper: 606 return EditorInputType::eFormatSuperscript; 607 case EditAction::eSetVerticalAlignPropertySub: 608 case EditAction::eRemoveVerticalAlignPropertySub: 609 return EditorInputType::eFormatSubscript; 610 case EditAction::eJustify: 611 return EditorInputType::eFormatJustifyFull; 612 case EditAction::eAlignCenter: 613 return EditorInputType::eFormatJustifyCenter; 614 case EditAction::eAlignRight: 615 return EditorInputType::eFormatJustifyRight; 616 case EditAction::eAlignLeft: 617 return EditorInputType::eFormatJustifyLeft; 618 case EditAction::eIndent: 619 return EditorInputType::eFormatIndent; 620 case EditAction::eOutdent: 621 return EditorInputType::eFormatOutdent; 622 case EditAction::eRemoveAllInlineStyleProperties: 623 return EditorInputType::eFormatRemove; 624 case EditAction::eSetTextDirection: 625 return EditorInputType::eFormatSetBlockTextDirection; 626 case EditAction::eSetBackgroundColorPropertyInline: 627 case EditAction::eRemoveBackgroundColorPropertyInline: 628 return EditorInputType::eFormatBackColor; 629 case EditAction::eSetColorProperty: 630 case EditAction::eRemoveColorProperty: 631 return EditorInputType::eFormatFontColor; 632 case EditAction::eSetFontFamilyProperty: 633 case EditAction::eRemoveFontFamilyProperty: 634 return EditorInputType::eFormatFontName; 635 default: 636 return EditorInputType::eUnknown; 637 } 638 } 639 640 inline bool MayEditActionDeleteAroundCollapsedSelection( 641 const EditAction aEditAction) { 642 switch (aEditAction) { 643 case EditAction::eCut: 644 case EditAction::eDeleteSelection: 645 case EditAction::eDeleteBackward: 646 case EditAction::eDeleteForward: 647 case EditAction::eDeleteWordBackward: 648 case EditAction::eDeleteWordForward: 649 case EditAction::eDeleteToBeginningOfSoftLine: 650 case EditAction::eDeleteToEndOfSoftLine: 651 return true; 652 default: 653 return false; 654 } 655 } 656 657 inline bool IsEditActionInOrderToEditSomething(const EditAction aEditAction) { 658 switch (aEditAction) { 659 case EditAction::eNotEditing: 660 case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING: 661 return false; 662 default: 663 return true; 664 } 665 } 666 667 inline bool IsEditActionTableEditing(const EditAction aEditAction) { 668 switch (aEditAction) { 669 case EditAction::eInsertTableRowElement: 670 case EditAction::eRemoveTableRowElement: 671 case EditAction::eInsertTableColumn: 672 case EditAction::eRemoveTableColumn: 673 case EditAction::eRemoveTableElement: 674 case EditAction::eRemoveTableCellElement: 675 case EditAction::eDeleteTableCellContents: 676 case EditAction::eInsertTableCellElement: 677 case EditAction::eJoinTableCellElements: 678 case EditAction::eSplitTableCellElement: 679 case EditAction::eSetTableCellElementType: 680 return true; 681 default: 682 return false; 683 } 684 } 685 686 inline bool MayEditActionDeleteSelection(const EditAction aEditAction) { 687 switch (aEditAction) { 688 case EditAction::eNone: 689 case EditAction::eNotEditing: 690 case EditAction::eInitializing: 691 case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING: 692 return false; 693 694 // EditActions modifying around selection. 695 case EditAction::eInsertText: 696 case EditAction::eInsertParagraphSeparator: 697 case EditAction::eInsertLineBreak: 698 case EditAction::eDeleteSelection: 699 case EditAction::eDeleteBackward: 700 case EditAction::eDeleteForward: 701 case EditAction::eDeleteWordBackward: 702 case EditAction::eDeleteWordForward: 703 case EditAction::eDeleteToBeginningOfSoftLine: 704 case EditAction::eDeleteToEndOfSoftLine: 705 case EditAction::eDeleteByDrag: 706 return true; 707 708 case EditAction::eStartComposition: 709 return false; 710 711 case EditAction::eUpdateComposition: 712 case EditAction::eUpdateCompositionToCommit: 713 case EditAction::eCommitComposition: 714 case EditAction::eCancelComposition: 715 return true; 716 717 case EditAction::eUndo: 718 case EditAction::eRedo: 719 case EditAction::eSetTextDirection: 720 return false; 721 722 case EditAction::eCut: 723 return true; 724 725 case EditAction::eCopy: 726 return false; 727 728 case EditAction::ePaste: 729 case EditAction::ePasteAsQuotation: 730 return true; 731 732 case EditAction::eDrop: 733 return false; // Not deleting selection at drop. 734 735 // EditActions changing format around selection. 736 case EditAction::eIndent: 737 case EditAction::eOutdent: 738 return false; 739 740 // EditActions inserting or deleting something at specified position. 741 case EditAction::eInsertTableRowElement: 742 case EditAction::eRemoveTableRowElement: 743 case EditAction::eInsertTableColumn: 744 case EditAction::eRemoveTableColumn: 745 case EditAction::eResizingElement: 746 case EditAction::eResizeElement: 747 case EditAction::eMovingElement: 748 case EditAction::eMoveElement: 749 case EditAction::eUnknown: 750 case EditAction::eSetAttribute: 751 case EditAction::eRemoveAttribute: 752 case EditAction::eRemoveNode: 753 case EditAction::eInsertBlockElement: 754 return false; 755 756 // EditActions inserting someting around selection or replacing selection 757 // with something. 758 case EditAction::eReplaceText: 759 case EditAction::eInsertNode: 760 case EditAction::eInsertHorizontalRuleElement: 761 return true; 762 763 // EditActions changing format around selection or inserting or deleting 764 // something at specific position. 765 case EditAction::eInsertLinkElement: 766 case EditAction::eInsertUnorderedListElement: 767 case EditAction::eInsertOrderedListElement: 768 case EditAction::eRemoveUnorderedListElement: 769 case EditAction::eRemoveOrderedListElement: 770 case EditAction::eRemoveListElement: 771 case EditAction::eInsertBlockquoteElement: 772 case EditAction::eNormalizeTable: 773 case EditAction::eRemoveTableElement: 774 case EditAction::eRemoveTableCellElement: 775 case EditAction::eDeleteTableCellContents: 776 case EditAction::eInsertTableCellElement: 777 case EditAction::eJoinTableCellElements: 778 case EditAction::eSplitTableCellElement: 779 case EditAction::eSetTableCellElementType: 780 case EditAction::eSetInlineStyleProperty: 781 case EditAction::eRemoveInlineStyleProperty: 782 case EditAction::eSetFontWeightProperty: 783 case EditAction::eRemoveFontWeightProperty: 784 case EditAction::eSetTextStyleProperty: 785 case EditAction::eRemoveTextStyleProperty: 786 case EditAction::eSetTextDecorationPropertyUnderline: 787 case EditAction::eRemoveTextDecorationPropertyUnderline: 788 case EditAction::eSetTextDecorationPropertyLineThrough: 789 case EditAction::eRemoveTextDecorationPropertyLineThrough: 790 case EditAction::eSetVerticalAlignPropertySuper: 791 case EditAction::eRemoveVerticalAlignPropertySuper: 792 case EditAction::eSetVerticalAlignPropertySub: 793 case EditAction::eRemoveVerticalAlignPropertySub: 794 case EditAction::eSetFontFamilyProperty: 795 case EditAction::eRemoveFontFamilyProperty: 796 case EditAction::eSetColorProperty: 797 case EditAction::eRemoveColorProperty: 798 case EditAction::eSetBackgroundColorPropertyInline: 799 case EditAction::eRemoveBackgroundColorPropertyInline: 800 case EditAction::eRemoveAllInlineStyleProperties: 801 case EditAction::eIncrementFontSize: 802 case EditAction::eDecrementFontSize: 803 case EditAction::eSetAlignment: 804 case EditAction::eAlignLeft: 805 case EditAction::eAlignRight: 806 case EditAction::eAlignCenter: 807 case EditAction::eJustify: 808 case EditAction::eSetBackgroundColor: 809 case EditAction::eSetPositionToAbsoluteOrStatic: 810 case EditAction::eIncreaseOrDecreaseZIndex: 811 return false; 812 813 // EditActions controlling editor feature or state. 814 case EditAction::eEnableOrDisableCSS: 815 case EditAction::eEnableOrDisableAbsolutePositionEditor: 816 case EditAction::eEnableOrDisableResizer: 817 case EditAction::eEnableOrDisableInlineTableEditingUI: 818 case EditAction::eSetCharacterSet: 819 case EditAction::eSetWrapWidth: 820 return false; 821 822 case EditAction::eRewrap: 823 case EditAction::eSetText: 824 case EditAction::eInsertHTML: 825 return true; 826 827 case EditAction::eHidePassword: 828 case EditAction::eCreatePaddingBRElementForEmptyEditor: 829 return false; 830 } 831 return false; 832 } 833 834 inline bool MayEditActionRequireLayout(const EditAction aEditAction) { 835 switch (aEditAction) { 836 // Table editing require layout information for referring table cell data 837 // such as row/column number and rowspan/colspan. 838 case EditAction::eInsertTableRowElement: 839 case EditAction::eRemoveTableRowElement: 840 case EditAction::eInsertTableColumn: 841 case EditAction::eRemoveTableColumn: 842 case EditAction::eRemoveTableElement: 843 case EditAction::eRemoveTableCellElement: 844 case EditAction::eDeleteTableCellContents: 845 case EditAction::eInsertTableCellElement: 846 case EditAction::eJoinTableCellElements: 847 case EditAction::eSplitTableCellElement: 848 case EditAction::eSetTableCellElementType: 849 case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING: 850 return true; 851 default: 852 return false; 853 } 854 } 855 856 inline std::ostream& operator<<(std::ostream& aStream, 857 const EditAction& aEditAction) { 858 switch (aEditAction) { 859 case EditAction::eNone: 860 return aStream << "eNone"; 861 case EditAction::eNotEditing: 862 return aStream << "eNotEditing"; 863 case EditAction::eInitializing: 864 return aStream << "eInitializing"; 865 case EditAction::eInsertText: 866 return aStream << "eInsertText"; 867 case EditAction::eInsertParagraphSeparator: 868 return aStream << "eInsertParagraphSeparator"; 869 case EditAction::eInsertLineBreak: 870 return aStream << "eInsertLineBreak"; 871 case EditAction::eDeleteSelection: 872 return aStream << "eDeleteSelection"; 873 case EditAction::eDeleteBackward: 874 return aStream << "eDeleteBackward"; 875 case EditAction::eDeleteForward: 876 return aStream << "eDeleteForward"; 877 case EditAction::eDeleteWordBackward: 878 return aStream << "eDeleteWordBackward"; 879 case EditAction::eDeleteWordForward: 880 return aStream << "eDeleteWordForward"; 881 case EditAction::eDeleteToBeginningOfSoftLine: 882 return aStream << "eDeleteToBeginningOfSoftLine"; 883 case EditAction::eDeleteToEndOfSoftLine: 884 return aStream << "eDeleteToEndOfSoftLine"; 885 case EditAction::eDeleteByDrag: 886 return aStream << "eDeleteByDrag"; 887 case EditAction::eStartComposition: 888 return aStream << "eStartComposition"; 889 case EditAction::eUpdateComposition: 890 return aStream << "eUpdateComposition"; 891 case EditAction::eUpdateCompositionToCommit: 892 return aStream << "eUpdateCompositionToCommit"; 893 case EditAction::eCommitComposition: 894 return aStream << "eCommitComposition"; 895 case EditAction::eCancelComposition: 896 return aStream << "eCancelComposition"; 897 case EditAction::eUndo: 898 return aStream << "eUndo"; 899 case EditAction::eRedo: 900 return aStream << "eRedo"; 901 case EditAction::eSetTextDirection: 902 return aStream << "eSetTextDirection"; 903 case EditAction::eCut: 904 return aStream << "eCut"; 905 case EditAction::eCopy: 906 return aStream << "eCopy"; 907 case EditAction::ePaste: 908 return aStream << "ePaste"; 909 case EditAction::ePasteAsQuotation: 910 return aStream << "ePasteAsQuotation"; 911 case EditAction::eDrop: 912 return aStream << "eDrop"; 913 case EditAction::eIndent: 914 return aStream << "eIndent"; 915 case EditAction::eOutdent: 916 return aStream << "eOutdent"; 917 case EditAction::eReplaceText: 918 return aStream << "eReplaceText"; 919 case EditAction::eInsertTableRowElement: 920 return aStream << "eInsertTableRowElement"; 921 case EditAction::eRemoveTableRowElement: 922 return aStream << "eRemoveTableRowElement"; 923 case EditAction::eInsertTableColumn: 924 return aStream << "eInsertTableColumn"; 925 case EditAction::eRemoveTableColumn: 926 return aStream << "eRemoveTableColumn"; 927 case EditAction::eResizingElement: 928 return aStream << "eResizingElement"; 929 case EditAction::eResizeElement: 930 return aStream << "eResizeElement"; 931 case EditAction::eMovingElement: 932 return aStream << "eMovingElement"; 933 case EditAction::eMoveElement: 934 return aStream << "eMoveElement"; 935 case EditAction::eUnknown: 936 return aStream << "eUnknown"; 937 case EditAction::eSetAttribute: 938 return aStream << "eSetAttribute"; 939 case EditAction::eRemoveAttribute: 940 return aStream << "eRemoveAttribute"; 941 case EditAction::eInsertNode: 942 return aStream << "eInsertNode"; 943 case EditAction::eRemoveNode: 944 return aStream << "eRemoveNode"; 945 case EditAction::eInsertBlockElement: 946 return aStream << "eInsertBlockElement"; 947 case EditAction::eInsertHorizontalRuleElement: 948 return aStream << "eInsertHorizontalRuleElement"; 949 case EditAction::eInsertLinkElement: 950 return aStream << "eInsertLinkElement"; 951 case EditAction::eInsertUnorderedListElement: 952 return aStream << "eInsertUnorderedListElement"; 953 case EditAction::eInsertOrderedListElement: 954 return aStream << "eInsertOrderedListElement"; 955 case EditAction::eRemoveUnorderedListElement: 956 return aStream << "eRemoveUnorderedListElement"; 957 case EditAction::eRemoveOrderedListElement: 958 return aStream << "eRemoveOrderedListElement"; 959 case EditAction::eRemoveListElement: 960 return aStream << "eRemoveListElement"; 961 case EditAction::eInsertBlockquoteElement: 962 return aStream << "eInsertBlockquoteElement"; 963 case EditAction::eNormalizeTable: 964 return aStream << "eNormalizeTable"; 965 case EditAction::eRemoveTableElement: 966 return aStream << "eRemoveTableElement"; 967 case EditAction::eDeleteTableCellContents: 968 return aStream << "eDeleteTableCellContents"; 969 case EditAction::eInsertTableCellElement: 970 return aStream << "eInsertTableCellElement"; 971 case EditAction::eRemoveTableCellElement: 972 return aStream << "eRemoveTableCellElement"; 973 case EditAction::eJoinTableCellElements: 974 return aStream << "eJoinTableCellElements"; 975 case EditAction::eSplitTableCellElement: 976 return aStream << "eSplitTableCellElement"; 977 case EditAction::eSetTableCellElementType: 978 return aStream << "eSetTableCellElementType"; 979 case EditAction::eSelectTableCell: 980 return aStream << "eSelectTableCell"; 981 case EditAction::eSelectTableRow: 982 return aStream << "eSelectTableRow"; 983 case EditAction::eSelectTableColumn: 984 return aStream << "eSelectTableColumn"; 985 case EditAction::eSelectTable: 986 return aStream << "eSelectTable"; 987 case EditAction::eSelectAllTableCells: 988 return aStream << "eSelectAllTableCells"; 989 case EditAction::eGetCellIndexes: 990 return aStream << "eGetCellIndexes"; 991 case EditAction::eGetTableSize: 992 return aStream << "eGetTableSize"; 993 case EditAction::eGetCellAt: 994 return aStream << "eGetCellAt"; 995 case EditAction::eGetCellDataAt: 996 return aStream << "eGetCellDataAt"; 997 case EditAction::eGetFirstRow: 998 return aStream << "eGetFirstRow"; 999 case EditAction::eGetSelectedOrParentTableElement: 1000 return aStream << "eGetSelectedOrParentTableElement"; 1001 case EditAction::eGetSelectedCellsType: 1002 return aStream << "eGetSelectedCellsType"; 1003 case EditAction::eGetFirstSelectedCellInTable: 1004 return aStream << "eGetFirstSelectedCellInTable"; 1005 case EditAction::eGetSelectedCells: 1006 return aStream << "eGetSelectedCells"; 1007 case EditAction::eSetInlineStyleProperty: 1008 return aStream << "eSetInlineStyleProperty"; 1009 case EditAction::eRemoveInlineStyleProperty: 1010 return aStream << "eRemoveInlineStyleProperty"; 1011 case EditAction::eSetFontWeightProperty: 1012 return aStream << "eSetFontWeightProperty"; 1013 case EditAction::eRemoveFontWeightProperty: 1014 return aStream << "eRemoveFontWeightProperty"; 1015 case EditAction::eSetTextStyleProperty: 1016 return aStream << "eSetTextStyleProperty"; 1017 case EditAction::eRemoveTextStyleProperty: 1018 return aStream << "eRemoveTextStyleProperty"; 1019 case EditAction::eSetTextDecorationPropertyUnderline: 1020 return aStream << "eSetTextDecorationPropertyUnderline"; 1021 case EditAction::eRemoveTextDecorationPropertyUnderline: 1022 return aStream << "eRemoveTextDecorationPropertyUnderline"; 1023 case EditAction::eSetTextDecorationPropertyLineThrough: 1024 return aStream << "eSetTextDecorationPropertyLineThrough"; 1025 case EditAction::eRemoveTextDecorationPropertyLineThrough: 1026 return aStream << "eRemoveTextDecorationPropertyLineThrough"; 1027 case EditAction::eSetVerticalAlignPropertySuper: 1028 return aStream << "eSetVerticalAlignPropertySuper"; 1029 case EditAction::eRemoveVerticalAlignPropertySuper: 1030 return aStream << "eRemoveVerticalAlignPropertySuper"; 1031 case EditAction::eSetVerticalAlignPropertySub: 1032 return aStream << "eSetVerticalAlignPropertySub"; 1033 case EditAction::eRemoveVerticalAlignPropertySub: 1034 return aStream << "eRemoveVerticalAlignPropertySub"; 1035 case EditAction::eSetFontFamilyProperty: 1036 return aStream << "eSetFontFamilyProperty"; 1037 case EditAction::eRemoveFontFamilyProperty: 1038 return aStream << "eRemoveFontFamilyProperty"; 1039 case EditAction::eSetColorProperty: 1040 return aStream << "eSetColorProperty"; 1041 case EditAction::eRemoveColorProperty: 1042 return aStream << "eRemoveColorProperty"; 1043 case EditAction::eSetBackgroundColorPropertyInline: 1044 return aStream << "eSetBackgroundColorPropertyInline"; 1045 case EditAction::eRemoveBackgroundColorPropertyInline: 1046 return aStream << "eRemoveBackgroundColorPropertyInline"; 1047 case EditAction::eRemoveAllInlineStyleProperties: 1048 return aStream << "eRemoveAllInlineStyleProperties"; 1049 case EditAction::eIncrementFontSize: 1050 return aStream << "eIncrementFontSize"; 1051 case EditAction::eDecrementFontSize: 1052 return aStream << "eDecrementFontSize"; 1053 case EditAction::eSetAlignment: 1054 return aStream << "eSetAlignment"; 1055 case EditAction::eAlignLeft: 1056 return aStream << "eAlignLeft"; 1057 case EditAction::eAlignRight: 1058 return aStream << "eAlignRight"; 1059 case EditAction::eAlignCenter: 1060 return aStream << "eAlignCenter"; 1061 case EditAction::eJustify: 1062 return aStream << "eJustify"; 1063 case EditAction::eSetBackgroundColor: 1064 return aStream << "eSetBackgroundColor"; 1065 case EditAction::eSetPositionToAbsoluteOrStatic: 1066 return aStream << "eSetPositionToAbsoluteOrStatic"; 1067 case EditAction::eIncreaseOrDecreaseZIndex: 1068 return aStream << "eIncreaseOrDecreaseZIndex"; 1069 case EditAction::eEnableOrDisableCSS: 1070 return aStream << "eEnableOrDisableCSS"; 1071 case EditAction::eEnableOrDisableAbsolutePositionEditor: 1072 return aStream << "eEnableOrDisableAbsolutePositionEditor"; 1073 case EditAction::eEnableOrDisableResizer: 1074 return aStream << "eEnableOrDisableResizer"; 1075 case EditAction::eEnableOrDisableInlineTableEditingUI: 1076 return aStream << "eEnableOrDisableInlineTableEditingUI"; 1077 case EditAction::eSetCharacterSet: 1078 return aStream << "eSetCharacterSet"; 1079 case EditAction::eSetWrapWidth: 1080 return aStream << "eSetWrapWidth"; 1081 case EditAction::eRewrap: 1082 return aStream << "eRewrap"; 1083 case EditAction::eSetText: 1084 return aStream << "eSetText"; 1085 case EditAction::eInsertHTML: 1086 return aStream << "eInsertHTML"; 1087 case EditAction::eHidePassword: 1088 return aStream << "eHidePassword"; 1089 case EditAction::eCreatePaddingBRElementForEmptyEditor: 1090 return aStream << "eCreatePaddingBRElementForEmptyEditor"; 1091 } 1092 MOZ_ASSERT_UNREACHABLE("Ensure no invalid EditAction!"); 1093 return aStream << "<invalid value: " << static_cast<uint32_t>(aEditAction) 1094 << ">"; 1095 } 1096 1097 } // namespace mozilla 1098 1099 inline bool operator!(const mozilla::EditSubAction& aEditSubAction) { 1100 return aEditSubAction == mozilla::EditSubAction::eNone; 1101 } 1102 1103 #endif // #ifdef mozilla_EditAction_h