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

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

Issue 170603003: Use nullptr_t for RefPtr, PassRefPtr and RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final rebase Created 6 years, 10 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/CompositeEditCommand.cpp ('k') | Source/core/editing/EditingStyle.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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDel ete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMa rkup) 69 DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDel ete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMa rkup)
70 : CompositeEditCommand(document) 70 : CompositeEditCommand(document)
71 , m_hasSelectionToDelete(false) 71 , m_hasSelectionToDelete(false)
72 , m_smartDelete(smartDelete) 72 , m_smartDelete(smartDelete)
73 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete) 73 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete)
74 , m_needPlaceholder(false) 74 , m_needPlaceholder(false)
75 , m_expandForSpecialElements(expandForSpecialElements) 75 , m_expandForSpecialElements(expandForSpecialElements)
76 , m_pruneStartBlockIfNecessary(false) 76 , m_pruneStartBlockIfNecessary(false)
77 , m_startsAtEmptyLine(false) 77 , m_startsAtEmptyLine(false)
78 , m_sanitizeMarkup(sanitizeMarkup) 78 , m_sanitizeMarkup(sanitizeMarkup)
79 , m_startBlock(0) 79 , m_startBlock(nullptr)
80 , m_endBlock(0) 80 , m_endBlock(nullptr)
81 , m_typingStyle(0) 81 , m_typingStyle(nullptr)
82 , m_deleteIntoBlockquoteStyle(0) 82 , m_deleteIntoBlockquoteStyle(nullptr)
83 { 83 {
84 } 84 }
85 85
86 DeleteSelectionCommand::DeleteSelectionCommand(const VisibleSelection& selection , bool smartDelete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMarkup) 86 DeleteSelectionCommand::DeleteSelectionCommand(const VisibleSelection& selection , bool smartDelete, bool mergeBlocksAfterDelete, bool expandForSpecialElements, bool sanitizeMarkup)
87 : CompositeEditCommand(*selection.start().document()) 87 : CompositeEditCommand(*selection.start().document())
88 , m_hasSelectionToDelete(true) 88 , m_hasSelectionToDelete(true)
89 , m_smartDelete(smartDelete) 89 , m_smartDelete(smartDelete)
90 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete) 90 , m_mergeBlocksAfterDelete(mergeBlocksAfterDelete)
91 , m_needPlaceholder(false) 91 , m_needPlaceholder(false)
92 , m_expandForSpecialElements(expandForSpecialElements) 92 , m_expandForSpecialElements(expandForSpecialElements)
93 , m_pruneStartBlockIfNecessary(false) 93 , m_pruneStartBlockIfNecessary(false)
94 , m_startsAtEmptyLine(false) 94 , m_startsAtEmptyLine(false)
95 , m_sanitizeMarkup(sanitizeMarkup) 95 , m_sanitizeMarkup(sanitizeMarkup)
96 , m_selectionToDelete(selection) 96 , m_selectionToDelete(selection)
97 , m_startBlock(0) 97 , m_startBlock(nullptr)
98 , m_endBlock(0) 98 , m_endBlock(nullptr)
99 , m_typingStyle(0) 99 , m_typingStyle(nullptr)
100 , m_deleteIntoBlockquoteStyle(0) 100 , m_deleteIntoBlockquoteStyle(nullptr)
101 { 101 {
102 } 102 }
103 103
104 void DeleteSelectionCommand::initializeStartEnd(Position& start, Position& end) 104 void DeleteSelectionCommand::initializeStartEnd(Position& start, Position& end)
105 { 105 {
106 Node* startSpecialContainer = 0; 106 Node* startSpecialContainer = 0;
107 Node* endSpecialContainer = 0; 107 Node* endSpecialContainer = 0;
108 108
109 start = m_selectionToDelete.start(); 109 start = m_selectionToDelete.start();
110 end = m_selectionToDelete.end(); 110 end = m_selectionToDelete.end();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 // Figure out the typing style in effect before the delete is done. 291 // Figure out the typing style in effect before the delete is done.
292 m_typingStyle = EditingStyle::create(m_selectionToDelete.start(), EditingSty le::EditingPropertiesInEffect); 292 m_typingStyle = EditingStyle::create(m_selectionToDelete.start(), EditingSty le::EditingPropertiesInEffect);
293 m_typingStyle->removeStyleAddedByNode(enclosingAnchorElement(m_selectionToDe lete.start())); 293 m_typingStyle->removeStyleAddedByNode(enclosingAnchorElement(m_selectionToDe lete.start()));
294 294
295 // If we're deleting into a Mail blockquote, save the style at end() instead of start() 295 // If we're deleting into a Mail blockquote, save the style at end() instead of start()
296 // We'll use this later in computeTypingStyleAfterDelete if we end up outsid e of a Mail blockquote 296 // We'll use this later in computeTypingStyleAfterDelete if we end up outsid e of a Mail blockquote
297 if (enclosingNodeOfType(m_selectionToDelete.start(), isMailBlockquote)) 297 if (enclosingNodeOfType(m_selectionToDelete.start(), isMailBlockquote))
298 m_deleteIntoBlockquoteStyle = EditingStyle::create(m_selectionToDelete.e nd()); 298 m_deleteIntoBlockquoteStyle = EditingStyle::create(m_selectionToDelete.e nd());
299 else 299 else
300 m_deleteIntoBlockquoteStyle = 0; 300 m_deleteIntoBlockquoteStyle = nullptr;
301 } 301 }
302 302
303 bool DeleteSelectionCommand::handleSpecialCaseBRDelete() 303 bool DeleteSelectionCommand::handleSpecialCaseBRDelete()
304 { 304 {
305 Node* nodeAfterUpstreamStart = m_upstreamStart.computeNodeAfterPosition(); 305 Node* nodeAfterUpstreamStart = m_upstreamStart.computeNodeAfterPosition();
306 Node* nodeAfterDownstreamStart = m_downstreamStart.computeNodeAfterPosition( ); 306 Node* nodeAfterDownstreamStart = m_downstreamStart.computeNodeAfterPosition( );
307 // Upstream end will appear before BR due to canonicalization 307 // Upstream end will appear before BR due to canonicalization
308 Node* nodeAfterUpstreamEnd = m_upstreamEnd.computeNodeAfterPosition(); 308 Node* nodeAfterUpstreamEnd = m_upstreamEnd.computeNodeAfterPosition();
309 309
310 if (!nodeAfterUpstreamStart || !nodeAfterDownstreamStart) 310 if (!nodeAfterUpstreamStart || !nodeAfterDownstreamStart)
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 505 }
506 } else if (startNode == m_upstreamEnd.deprecatedNode() && startNode->isT extNode()) { 506 } else if (startNode == m_upstreamEnd.deprecatedNode() && startNode->isT extNode()) {
507 Text* text = toText(m_upstreamEnd.deprecatedNode()); 507 Text* text = toText(m_upstreamEnd.deprecatedNode());
508 deleteTextFromNode(text, 0, m_upstreamEnd.deprecatedEditingOffset()) ; 508 deleteTextFromNode(text, 0, m_upstreamEnd.deprecatedEditingOffset()) ;
509 } 509 }
510 510
511 // handle deleting all nodes that are completely selected 511 // handle deleting all nodes that are completely selected
512 while (node && node != m_downstreamEnd.deprecatedNode()) { 512 while (node && node != m_downstreamEnd.deprecatedNode()) {
513 if (comparePositions(firstPositionInOrBeforeNode(node.get()), m_down streamEnd) >= 0) { 513 if (comparePositions(firstPositionInOrBeforeNode(node.get()), m_down streamEnd) >= 0) {
514 // NodeTraversal::nextSkippingChildren just blew past the end po sition, so stop deleting 514 // NodeTraversal::nextSkippingChildren just blew past the end po sition, so stop deleting
515 node = 0; 515 node = nullptr;
516 } else if (!m_downstreamEnd.deprecatedNode()->isDescendantOf(node.ge t())) { 516 } else if (!m_downstreamEnd.deprecatedNode()->isDescendantOf(node.ge t())) {
517 RefPtr<Node> nextNode = NodeTraversal::nextSkippingChildren(*nod e); 517 RefPtr<Node> nextNode = NodeTraversal::nextSkippingChildren(*nod e);
518 // if we just removed a node from the end container, update end position so the 518 // if we just removed a node from the end container, update end position so the
519 // check above will work 519 // check above will work
520 updatePositionForNodeRemoval(m_downstreamEnd, node.get()); 520 updatePositionForNodeRemoval(m_downstreamEnd, node.get());
521 removeNode(node.get()); 521 removeNode(node.get());
522 node = nextNode.get(); 522 node = nextNode.get();
523 } else { 523 } else {
524 Node& n = node->lastDescendant(); 524 Node& n = node->lastDescendant();
525 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(&n)) { 525 if (m_downstreamEnd.deprecatedNode() == n && m_downstreamEnd.dep recatedEditingOffset() >= caretMaxOffset(&n)) {
526 removeNode(node.get()); 526 removeNode(node.get());
527 node = 0; 527 node = nullptr;
528 } else { 528 } else {
529 node = NodeTraversal::next(*node); 529 node = NodeTraversal::next(*node);
530 } 530 }
531 } 531 }
532 } 532 }
533 533
534 if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.de precatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstream End.inDocument() && m_downstreamEnd.deprecatedEditingOffset() >= caretMinOffset( m_downstreamEnd.deprecatedNode())) { 534 if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.de precatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstream End.inDocument() && m_downstreamEnd.deprecatedEditingOffset() >= caretMinOffset( m_downstreamEnd.deprecatedNode())) {
535 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr enForEditing(m_downstreamEnd.deprecatedNode())) { 535 if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildr enForEditing(m_downstreamEnd.deprecatedNode())) {
536 // The node itself is fully selected, not just its contents. De lete it. 536 // The node itself is fully selected, not just its contents. De lete it.
537 removeNode(m_downstreamEnd.deprecatedNode()); 537 removeNode(m_downstreamEnd.deprecatedNode());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 721
722 // Compute the difference between the style before the delete and the style now 722 // Compute the difference between the style before the delete and the style now
723 // after the delete has been done. Set this style on the frame, so other edi ting 723 // after the delete has been done. Set this style on the frame, so other edi ting
724 // commands being composed with this one will work, and also cache it on the command, 724 // commands being composed with this one will work, and also cache it on the command,
725 // so the Frame::appliedEditing can set it after the whole composite command 725 // so the Frame::appliedEditing can set it after the whole composite command
726 // has completed. 726 // has completed.
727 727
728 // If we deleted into a blockquote, but are now no longer in a blockquote, u se the alternate typing style 728 // If we deleted into a blockquote, but are now no longer in a blockquote, u se the alternate typing style
729 if (m_deleteIntoBlockquoteStyle && !enclosingNodeOfType(m_endingPosition, is MailBlockquote, CanCrossEditingBoundary)) 729 if (m_deleteIntoBlockquoteStyle && !enclosingNodeOfType(m_endingPosition, is MailBlockquote, CanCrossEditingBoundary))
730 m_typingStyle = m_deleteIntoBlockquoteStyle; 730 m_typingStyle = m_deleteIntoBlockquoteStyle;
731 m_deleteIntoBlockquoteStyle = 0; 731 m_deleteIntoBlockquoteStyle = nullptr;
732 732
733 m_typingStyle->prepareToApplyAt(m_endingPosition); 733 m_typingStyle->prepareToApplyAt(m_endingPosition);
734 if (m_typingStyle->isEmpty()) 734 if (m_typingStyle->isEmpty())
735 m_typingStyle = 0; 735 m_typingStyle = nullptr;
736 // This is where we've deleted all traces of a style but not a whole paragra ph (that's handled above). 736 // This is where we've deleted all traces of a style but not a whole paragra ph (that's handled above).
737 // In this case if we start typing, the new characters should have the same style as the just deleted ones, 737 // In this case if we start typing, the new characters should have the same style as the just deleted ones,
738 // but, if we change the selection, come back and start typing that style sh ould be lost. Also see 738 // but, if we change the selection, come back and start typing that style sh ould be lost. Also see
739 // preserveTypingStyle() below. 739 // preserveTypingStyle() below.
740 document().frame()->selection().setTypingStyle(m_typingStyle); 740 document().frame()->selection().setTypingStyle(m_typingStyle);
741 } 741 }
742 742
743 void DeleteSelectionCommand::clearTransientState() 743 void DeleteSelectionCommand::clearTransientState()
744 { 744 {
745 m_selectionToDelete = VisibleSelection(); 745 m_selectionToDelete = VisibleSelection();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 862
863 // Normally deletion doesn't preserve the typing style that was present before i t. For example, 863 // Normally deletion doesn't preserve the typing style that was present before i t. For example,
864 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't 864 // type a character, Bold, then delete the character and start typing. The Bold typing style shouldn't
865 // stick around. Deletion should preserve a typing style that *it* sets, howeve r. 865 // stick around. Deletion should preserve a typing style that *it* sets, howeve r.
866 bool DeleteSelectionCommand::preservesTypingStyle() const 866 bool DeleteSelectionCommand::preservesTypingStyle() const
867 { 867 {
868 return m_typingStyle; 868 return m_typingStyle;
869 } 869 }
870 870
871 } // namespace WebCore 871 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/CompositeEditCommand.cpp ('k') | Source/core/editing/EditingStyle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698