Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: Source/core/editing/DeleteSelectionCommand.cpp

Issue 182383012: Have positionInParentBeforeNode() / positionInParentAfterNode() take a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/CreateLinkCommand.cpp ('k') | Source/core/editing/FormatBlockCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Position s = positionBeforeContainingSpecialElement(start, &startSpecial Container); 127 Position s = positionBeforeContainingSpecialElement(start, &startSpecial Container);
128 Position e = positionAfterContainingSpecialElement(end, &endSpecialConta iner); 128 Position e = positionAfterContainingSpecialElement(end, &endSpecialConta iner);
129 129
130 if (!startSpecialContainer && !endSpecialContainer) 130 if (!startSpecialContainer && !endSpecialContainer)
131 break; 131 break;
132 132
133 if (VisiblePosition(start) != m_selectionToDelete.visibleStart() || Visi blePosition(end) != m_selectionToDelete.visibleEnd()) 133 if (VisiblePosition(start) != m_selectionToDelete.visibleStart() || Visi blePosition(end) != m_selectionToDelete.visibleEnd())
134 break; 134 break;
135 135
136 // If we're going to expand to include the startSpecialContainer, it mus t be fully selected. 136 // If we're going to expand to include the startSpecialContainer, it mus t be fully selected.
137 if (startSpecialContainer && !endSpecialContainer && comparePositions(po sitionInParentAfterNode(startSpecialContainer), end) > -1) 137 if (startSpecialContainer && !endSpecialContainer && comparePositions(po sitionInParentAfterNode(*startSpecialContainer), end) > -1)
138 break; 138 break;
139 139
140 // If we're going to expand to include the endSpecialContainer, it must be fully selected. 140 // If we're going to expand to include the endSpecialContainer, it must be fully selected.
141 if (endSpecialContainer && !startSpecialContainer && comparePositions(st art, positionInParentBeforeNode(endSpecialContainer)) > -1) 141 if (endSpecialContainer && !startSpecialContainer && comparePositions(st art, positionInParentBeforeNode(*endSpecialContainer)) > -1)
142 break; 142 break;
143 143
144 if (startSpecialContainer && startSpecialContainer->isDescendantOf(endSp ecialContainer)) 144 if (startSpecialContainer && startSpecialContainer->isDescendantOf(endSp ecialContainer))
145 // Don't adjust the end yet, it is the end of a special element that contains the start 145 // Don't adjust the end yet, it is the end of a special element that contains the start
146 // special element (which may or may not be fully selected). 146 // special element (which may or may not be fully selected).
147 start = s; 147 start = s;
148 else if (endSpecialContainer && endSpecialContainer->isDescendantOf(star tSpecialContainer)) 148 else if (endSpecialContainer && endSpecialContainer->isDescendantOf(star tSpecialContainer))
149 // Don't adjust the start yet, it is the start of a special element that contains the end 149 // Don't adjust the start yet, it is the start of a special element that contains the end
150 // special element (which may or may not be fully selected). 150 // special element (which may or may not be fully selected).
151 end = e; 151 end = e;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 379 }
380 return; 380 return;
381 } 381 }
382 382
383 if (node == m_startBlock && !isEndOfBlock(VisiblePosition(firstPositionInNod e(m_startBlock.get())).previous())) 383 if (node == m_startBlock && !isEndOfBlock(VisiblePosition(firstPositionInNod e(m_startBlock.get())).previous()))
384 m_needPlaceholder = true; 384 m_needPlaceholder = true;
385 else if (node == m_endBlock && !isStartOfBlock(VisiblePosition(lastPositionI nNode(m_startBlock.get())).next())) 385 else if (node == m_endBlock && !isStartOfBlock(VisiblePosition(lastPositionI nNode(m_startBlock.get())).next()))
386 m_needPlaceholder = true; 386 m_needPlaceholder = true;
387 387
388 // FIXME: Update the endpoints of the range being deleted. 388 // FIXME: Update the endpoints of the range being deleted.
389 updatePositionForNodeRemoval(m_endingPosition, node.get()); 389 updatePositionForNodeRemoval(m_endingPosition, *node);
390 updatePositionForNodeRemoval(m_leadingWhitespace, node.get()); 390 updatePositionForNodeRemoval(m_leadingWhitespace, *node);
391 updatePositionForNodeRemoval(m_trailingWhitespace, node.get()); 391 updatePositionForNodeRemoval(m_trailingWhitespace, *node);
392 392
393 CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable); 393 CompositeEditCommand::removeNode(node, shouldAssumeContentIsAlwaysEditable);
394 } 394 }
395 395
396 static void updatePositionForTextRemoval(Node* node, int offset, int count, Posi tion& position) 396 static void updatePositionForTextRemoval(Node* node, int offset, int count, Posi tion& position)
397 { 397 {
398 if (position.anchorType() != Position::PositionIsOffsetInAnchor || position. containerNode() != node) 398 if (position.anchorType() != Position::PositionIsOffsetInAnchor || position. containerNode() != node)
399 return; 399 return;
400 400
401 if (position.offsetInContainerNode() > offset + count) 401 if (position.offsetInContainerNode() > offset + count)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 // handle deleting all nodes that are completely selected 505 // handle deleting all nodes that are completely selected
506 while (node && node != m_downstreamEnd.deprecatedNode()) { 506 while (node && node != m_downstreamEnd.deprecatedNode()) {
507 if (comparePositions(firstPositionInOrBeforeNode(node.get()), m_down streamEnd) >= 0) { 507 if (comparePositions(firstPositionInOrBeforeNode(node.get()), m_down streamEnd) >= 0) {
508 // NodeTraversal::nextSkippingChildren just blew past the end po sition, so stop deleting 508 // NodeTraversal::nextSkippingChildren just blew past the end po sition, so stop deleting
509 node = nullptr; 509 node = nullptr;
510 } else if (!m_downstreamEnd.deprecatedNode()->isDescendantOf(node.ge t())) { 510 } else if (!m_downstreamEnd.deprecatedNode()->isDescendantOf(node.ge t())) {
511 RefPtr<Node> nextNode = NodeTraversal::nextSkippingChildren(*nod e); 511 RefPtr<Node> nextNode = NodeTraversal::nextSkippingChildren(*nod e);
512 // if we just removed a node from the end container, update end position so the 512 // if we just removed a node from the end container, update end position so the
513 // check above will work 513 // check above will work
514 updatePositionForNodeRemoval(m_downstreamEnd, node.get()); 514 updatePositionForNodeRemoval(m_downstreamEnd, *node);
515 removeNode(node.get()); 515 removeNode(node.get());
516 node = nextNode.get(); 516 node = nextNode.get();
517 } else { 517 } else {
518 Node& n = node->lastDescendant(); 518 Node& n = node->lastDescendant();
519 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(&n)) { 519 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(&n)) {
520 removeNode(node.get()); 520 removeNode(node.get());
521 node = nullptr; 521 node = nullptr;
522 } else { 522 } else {
523 node = NodeTraversal::next(*node); 523 node = NodeTraversal::next(*node);
524 } 524 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 748
749 // This method removes div elements with no attributes that have only one child or no children at all. 749 // This method removes div elements with no attributes that have only one child or no children at all.
750 void DeleteSelectionCommand::removeRedundantBlocks() 750 void DeleteSelectionCommand::removeRedundantBlocks()
751 { 751 {
752 Node* node = m_endingPosition.containerNode(); 752 Node* node = m_endingPosition.containerNode();
753 Node* rootNode = node->rootEditableElement(); 753 Node* rootNode = node->rootEditableElement();
754 754
755 while (node != rootNode) { 755 while (node != rootNode) {
756 if (isRemovableBlock(node)) { 756 if (isRemovableBlock(node)) {
757 if (node == m_endingPosition.anchorNode()) 757 if (node == m_endingPosition.anchorNode())
758 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, node); 758 updatePositionForNodeRemovalPreservingChildren(m_endingPosition, *node);
759 759
760 CompositeEditCommand::removeNodePreservingChildren(node); 760 CompositeEditCommand::removeNodePreservingChildren(node);
761 node = m_endingPosition.anchorNode(); 761 node = m_endingPosition.anchorNode();
762 } else 762 } else
763 node = node->parentNode(); 763 node = node->parentNode();
764 } 764 }
765 } 765 }
766 766
767 void DeleteSelectionCommand::doApply() 767 void DeleteSelectionCommand::doApply()
768 { 768 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 856
857 // Normally deletion doesn't preserve the typing style that was present before i t. For example, 857 // Normally deletion doesn't preserve the typing style that was present before i t. For example,
858 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't 858 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't
859 // stick around. Deletion should preserve a typing style that *it* sets, howeve r. 859 // stick around. Deletion should preserve a typing style that *it* sets, howeve r.
860 bool DeleteSelectionCommand::preservesTypingStyle() const 860 bool DeleteSelectionCommand::preservesTypingStyle() const
861 { 861 {
862 return m_typingStyle; 862 return m_typingStyle;
863 } 863 }
864 864
865 } // namespace WebCore 865 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/CreateLinkCommand.cpp ('k') | Source/core/editing/FormatBlockCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698