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