| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 removeNode(node, editingState); | 550 removeNode(node, editingState); |
| 551 if (editingState->isAborted()) | 551 if (editingState->isAborted()) |
| 552 return; | 552 return; |
| 553 node = nullptr; | 553 node = nullptr; |
| 554 } else { | 554 } else { |
| 555 node = NodeTraversal::next(*node); | 555 node = NodeTraversal::next(*node); |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 | 559 |
| 560 if (m_downstreamEnd.anchorNode() != startNode && !m_upstreamStart.anchor
Node()->isDescendantOf(m_downstreamEnd.anchorNode()) && m_downstreamEnd.inShadow
IncludingDocument() && m_downstreamEnd.computeEditingOffset() >= caretMinOffset(
m_downstreamEnd.anchorNode())) { | 560 if (m_downstreamEnd.anchorNode() != startNode && !m_upstreamStart.anchor
Node()->isDescendantOf(m_downstreamEnd.anchorNode()) && m_downstreamEnd.isConnec
ted() && m_downstreamEnd.computeEditingOffset() >= caretMinOffset(m_downstreamEn
d.anchorNode())) { |
| 561 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr
enForEditing(m_downstreamEnd.anchorNode())) { | 561 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr
enForEditing(m_downstreamEnd.anchorNode())) { |
| 562 // The node itself is fully selected, not just its contents. De
lete it. | 562 // The node itself is fully selected, not just its contents. De
lete it. |
| 563 removeNode(m_downstreamEnd.anchorNode(), editingState); | 563 removeNode(m_downstreamEnd.anchorNode(), editingState); |
| 564 } else { | 564 } else { |
| 565 if (m_downstreamEnd.anchorNode()->isTextNode()) { | 565 if (m_downstreamEnd.anchorNode()->isTextNode()) { |
| 566 // in a text node that needs to be trimmed | 566 // in a text node that needs to be trimmed |
| 567 Text* text = toText(m_downstreamEnd.anchorNode()); | 567 Text* text = toText(m_downstreamEnd.anchorNode()); |
| 568 if (m_downstreamEnd.computeEditingOffset() > 0) { | 568 if (m_downstreamEnd.computeEditingOffset() > 0) { |
| 569 deleteTextFromNode(text, 0, m_downstreamEnd.computeEditi
ngOffset()); | 569 deleteTextFromNode(text, 0, m_downstreamEnd.computeEditi
ngOffset()); |
| 570 } | 570 } |
| 571 // Remove children of m_downstreamEnd.anchorNode() that come aft
er m_upstreamStart. | 571 // Remove children of m_downstreamEnd.anchorNode() that come aft
er m_upstreamStart. |
| 572 // Don't try to remove children if m_upstreamStart was inside m_
downstreamEnd.anchorNode() | 572 // Don't try to remove children if m_upstreamStart was inside m_
downstreamEnd.anchorNode() |
| 573 // and m_upstreamStart has been removed from the document, becau
se then we don't | 573 // and m_upstreamStart has been removed from the document, becau
se then we don't |
| 574 // know how many children to remove. | 574 // know how many children to remove. |
| 575 // FIXME: Make m_upstreamStart a position we update as we remove
content, then we can | 575 // FIXME: Make m_upstreamStart a position we update as we remove
content, then we can |
| 576 // always know which children to remove. | 576 // always know which children to remove. |
| 577 } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart
.inShadowIncludingDocument())) { | 577 } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart
.isConnected())) { |
| 578 int offset = 0; | 578 int offset = 0; |
| 579 if (m_upstreamStart.anchorNode()->isDescendantOf(m_downstrea
mEnd.anchorNode())) { | 579 if (m_upstreamStart.anchorNode()->isDescendantOf(m_downstrea
mEnd.anchorNode())) { |
| 580 Node* n = m_upstreamStart.anchorNode(); | 580 Node* n = m_upstreamStart.anchorNode(); |
| 581 while (n && n->parentNode() != m_downstreamEnd.anchorNod
e()) | 581 while (n && n->parentNode() != m_downstreamEnd.anchorNod
e()) |
| 582 n = n->parentNode(); | 582 n = n->parentNode(); |
| 583 if (n) | 583 if (n) |
| 584 offset = n->nodeIndex() + 1; | 584 offset = n->nodeIndex() + 1; |
| 585 } | 585 } |
| 586 removeChildrenInRange(m_downstreamEnd.anchorNode(), offset,
m_downstreamEnd.computeEditingOffset(), editingState); | 586 removeChildrenInRange(m_downstreamEnd.anchorNode(), offset,
m_downstreamEnd.computeEditingOffset(), editingState); |
| 587 if (editingState->isAborted()) | 587 if (editingState->isAborted()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // a placeholder, but not in this case. | 625 // a placeholder, but not in this case. |
| 626 m_needPlaceholder = false; | 626 m_needPlaceholder = false; |
| 627 } | 627 } |
| 628 return; | 628 return; |
| 629 } | 629 } |
| 630 | 630 |
| 631 // It shouldn't have been asked to both try and merge content into the start
block and prune it. | 631 // It shouldn't have been asked to both try and merge content into the start
block and prune it. |
| 632 DCHECK(!m_pruneStartBlockIfNecessary); | 632 DCHECK(!m_pruneStartBlockIfNecessary); |
| 633 | 633 |
| 634 // FIXME: Deletion should adjust selection endpoints as it removes nodes so
that we never get into this state (4099839). | 634 // FIXME: Deletion should adjust selection endpoints as it removes nodes so
that we never get into this state (4099839). |
| 635 if (!m_downstreamEnd.inShadowIncludingDocument() || !m_upstreamStart.inShado
wIncludingDocument()) | 635 if (!m_downstreamEnd.isConnected() || !m_upstreamStart.isConnected()) |
| 636 return; | 636 return; |
| 637 | 637 |
| 638 // FIXME: The deletion algorithm shouldn't let this happen. | 638 // FIXME: The deletion algorithm shouldn't let this happen. |
| 639 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0) | 639 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0) |
| 640 return; | 640 return; |
| 641 | 641 |
| 642 // There's nothing to merge. | 642 // There's nothing to merge. |
| 643 if (m_upstreamStart == m_downstreamEnd) | 643 if (m_upstreamStart == m_downstreamEnd) |
| 644 return; | 644 return; |
| 645 | 645 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, mergeDestination
, editingState, DoNotPreserveSelection, paragraphToMergeIsEmpty ? DoNotPreserveS
tyle : PreserveStyle); | 710 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, mergeDestination
, editingState, DoNotPreserveSelection, paragraphToMergeIsEmpty ? DoNotPreserveS
tyle : PreserveStyle); |
| 711 if (editingState->isAborted()) | 711 if (editingState->isAborted()) |
| 712 return; | 712 return; |
| 713 m_needPlaceholder = needPlaceholder; | 713 m_needPlaceholder = needPlaceholder; |
| 714 // The endingPosition was likely clobbered by the move, so recompute it (mov
eParagraph selects the moved paragraph). | 714 // The endingPosition was likely clobbered by the move, so recompute it (mov
eParagraph selects the moved paragraph). |
| 715 m_endingPosition = endingSelection().start(); | 715 m_endingPosition = endingSelection().start(); |
| 716 } | 716 } |
| 717 | 717 |
| 718 void DeleteSelectionCommand::removePreviouslySelectedEmptyTableRows(EditingState
* editingState) | 718 void DeleteSelectionCommand::removePreviouslySelectedEmptyTableRows(EditingState
* editingState) |
| 719 { | 719 { |
| 720 if (m_endTableRow && m_endTableRow->inShadowIncludingDocument() && m_endTabl
eRow != m_startTableRow) { | 720 if (m_endTableRow && m_endTableRow->isConnected() && m_endTableRow != m_star
tTableRow) { |
| 721 Node* row = m_endTableRow->previousSibling(); | 721 Node* row = m_endTableRow->previousSibling(); |
| 722 while (row && row != m_startTableRow) { | 722 while (row && row != m_startTableRow) { |
| 723 Node* previousRow = row->previousSibling(); | 723 Node* previousRow = row->previousSibling(); |
| 724 if (isTableRowEmpty(row)) { | 724 if (isTableRowEmpty(row)) { |
| 725 // Use a raw removeNode, instead of DeleteSelectionCommand's, | 725 // Use a raw removeNode, instead of DeleteSelectionCommand's, |
| 726 // because that won't remove rows, it only empties them in | 726 // because that won't remove rows, it only empties them in |
| 727 // preparation for this function. | 727 // preparation for this function. |
| 728 CompositeEditCommand::removeNode(row, editingState); | 728 CompositeEditCommand::removeNode(row, editingState); |
| 729 if (editingState->isAborted()) | 729 if (editingState->isAborted()) |
| 730 return; | 730 return; |
| 731 } | 731 } |
| 732 row = previousRow; | 732 row = previousRow; |
| 733 } | 733 } |
| 734 } | 734 } |
| 735 | 735 |
| 736 // Remove empty rows after the start row. | 736 // Remove empty rows after the start row. |
| 737 if (m_startTableRow && m_startTableRow->inShadowIncludingDocument() && m_sta
rtTableRow != m_endTableRow) { | 737 if (m_startTableRow && m_startTableRow->isConnected() && m_startTableRow !=
m_endTableRow) { |
| 738 Node* row = m_startTableRow->nextSibling(); | 738 Node* row = m_startTableRow->nextSibling(); |
| 739 while (row && row != m_endTableRow) { | 739 while (row && row != m_endTableRow) { |
| 740 Node* nextRow = row->nextSibling(); | 740 Node* nextRow = row->nextSibling(); |
| 741 if (isTableRowEmpty(row)) { | 741 if (isTableRowEmpty(row)) { |
| 742 CompositeEditCommand::removeNode(row, editingState); | 742 CompositeEditCommand::removeNode(row, editingState); |
| 743 if (editingState->isAborted()) | 743 if (editingState->isAborted()) |
| 744 return; | 744 return; |
| 745 } | 745 } |
| 746 row = nextRow; | 746 row = nextRow; |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 if (m_endTableRow && m_endTableRow->inShadowIncludingDocument() && m_endTabl
eRow != m_startTableRow) { | 750 if (m_endTableRow && m_endTableRow->isConnected() && m_endTableRow != m_star
tTableRow) { |
| 751 if (isTableRowEmpty(m_endTableRow.get())) { | 751 if (isTableRowEmpty(m_endTableRow.get())) { |
| 752 // Don't remove m_endTableRow if it's where we're putting the ending | 752 // Don't remove m_endTableRow if it's where we're putting the ending |
| 753 // selection. | 753 // selection. |
| 754 if (!m_endingPosition.anchorNode()->isDescendantOf(m_endTableRow.get
())) { | 754 if (!m_endingPosition.anchorNode()->isDescendantOf(m_endTableRow.get
())) { |
| 755 // FIXME: We probably shouldn't remove m_endTableRow unless it's | 755 // FIXME: We probably shouldn't remove m_endTableRow unless it's |
| 756 // fully selected, even if it is empty. We'll need to start | 756 // fully selected, even if it is empty. We'll need to start |
| 757 // adjusting the selection endpoints during deletion to know | 757 // adjusting the selection endpoints during deletion to know |
| 758 // whether or not m_endTableRow was fully selected here. | 758 // whether or not m_endTableRow was fully selected here. |
| 759 CompositeEditCommand::removeNode(m_endTableRow.get(), editingSta
te); | 759 CompositeEditCommand::removeNode(m_endTableRow.get(), editingSta
te); |
| 760 if (editingState->isAborted()) | 760 if (editingState->isAborted()) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 HTMLBRElement* placeholder = m_needPlaceholder ? HTMLBRElement::create(docum
ent()) : nullptr; | 907 HTMLBRElement* placeholder = m_needPlaceholder ? HTMLBRElement::create(docum
ent()) : nullptr; |
| 908 | 908 |
| 909 if (placeholder) { | 909 if (placeholder) { |
| 910 if (m_sanitizeMarkup) { | 910 if (m_sanitizeMarkup) { |
| 911 removeRedundantBlocks(editingState); | 911 removeRedundantBlocks(editingState); |
| 912 if (editingState->isAborted()) | 912 if (editingState->isAborted()) |
| 913 return; | 913 return; |
| 914 } | 914 } |
| 915 // handleGeneralDelete cause DOM mutation events so |m_endingPosition| | 915 // handleGeneralDelete cause DOM mutation events so |m_endingPosition| |
| 916 // can be out of document. | 916 // can be out of document. |
| 917 if (m_endingPosition.inShadowIncludingDocument()) { | 917 if (m_endingPosition.isConnected()) { |
| 918 insertNodeAt(placeholder, m_endingPosition, editingState); | 918 insertNodeAt(placeholder, m_endingPosition, editingState); |
| 919 if (editingState->isAborted()) | 919 if (editingState->isAborted()) |
| 920 return; | 920 return; |
| 921 } | 921 } |
| 922 } | 922 } |
| 923 | 923 |
| 924 rebalanceWhitespaceAt(m_endingPosition); | 924 rebalanceWhitespaceAt(m_endingPosition); |
| 925 | 925 |
| 926 calculateTypingStyleAfterDelete(); | 926 calculateTypingStyleAfterDelete(); |
| 927 | 927 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 visitor->trace(m_deleteIntoBlockquoteStyle); | 961 visitor->trace(m_deleteIntoBlockquoteStyle); |
| 962 visitor->trace(m_startRoot); | 962 visitor->trace(m_startRoot); |
| 963 visitor->trace(m_endRoot); | 963 visitor->trace(m_endRoot); |
| 964 visitor->trace(m_startTableRow); | 964 visitor->trace(m_startTableRow); |
| 965 visitor->trace(m_endTableRow); | 965 visitor->trace(m_endTableRow); |
| 966 visitor->trace(m_temporaryPlaceholder); | 966 visitor->trace(m_temporaryPlaceholder); |
| 967 CompositeEditCommand::trace(visitor); | 967 CompositeEditCommand::trace(visitor); |
| 968 } | 968 } |
| 969 | 969 |
| 970 } // namespace blink | 970 } // namespace blink |
| OLD | NEW |