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

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

Issue 18644008: Avoid adding placeholder when deleting last text in root (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple 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 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 // empty or unrendered parents). 1043 // empty or unrendered parents).
1044 1044
1045 void CompositeEditCommand::cleanupAfterDeletion(VisiblePosition destination) 1045 void CompositeEditCommand::cleanupAfterDeletion(VisiblePosition destination)
1046 { 1046 {
1047 VisiblePosition caretAfterDelete = endingSelection().visibleStart(); 1047 VisiblePosition caretAfterDelete = endingSelection().visibleStart();
1048 Node* destinationNode = destination.deepEquivalent().anchorNode(); 1048 Node* destinationNode = destination.deepEquivalent().anchorNode();
1049 if (caretAfterDelete != destination && isStartOfParagraph(caretAfterDelete) && isEndOfParagraph(caretAfterDelete)) { 1049 if (caretAfterDelete != destination && isStartOfParagraph(caretAfterDelete) && isEndOfParagraph(caretAfterDelete)) {
1050 // Note: We want the rightmost candidate. 1050 // Note: We want the rightmost candidate.
1051 Position position = caretAfterDelete.deepEquivalent().downstream(); 1051 Position position = caretAfterDelete.deepEquivalent().downstream();
1052 Node* node = position.deprecatedNode(); 1052 Node* node = position.deprecatedNode();
1053
1054 // Bail if we'd remove an ancestor of our destination.
yosin_UTC9 2013/07/12 01:55:28 Could you move this change in another CL? I think
1055 if (destinationNode->isDescendantOf(node))
1056 return;
1057
1053 // Normally deletion will leave a br as a placeholder. 1058 // Normally deletion will leave a br as a placeholder.
1054 if (node->hasTagName(brTag)) 1059 if (node->hasTagName(brTag)) {
1055 removeNodeAndPruneAncestors(node, destinationNode); 1060 removeNodeAndPruneAncestors(node, destinationNode);
1056 // If the selection to move was empty and in an empty block that 1061
1057 // doesn't require a placeholder to prop itself open (like a bordered 1062 // If the selection to move was empty and in an empty block that
1058 // div or an li), remove it during the move (the list removal code 1063 // doesn't require a placeholder to prop itself open (like a bordere d
1059 // expects this behavior). 1064 // div or an li), remove it during the move (the list removal code
1060 else if (isBlock(node)) { 1065 // expects this behavior).
1066 } else if (isBlock(node)) {
1061 // If caret position after deletion and destination position coincid es, 1067 // If caret position after deletion and destination position coincid es,
1062 // node should not be removed. 1068 // node should not be removed.
1063 if (!position.rendersInDifferentPosition(destination.deepEquivalent( ))) { 1069 if (!position.rendersInDifferentPosition(destination.deepEquivalent( ))) {
1064 prune(node, destinationNode); 1070 prune(node, destinationNode);
1065 return; 1071 return;
1066 } 1072 }
1067 removeNodeAndPruneAncestors(node, destinationNode); 1073 removeNodeAndPruneAncestors(node, destinationNode);
1068 } 1074 }
1069 else if (lineBreakExistsAtPosition(position)) { 1075 else if (lineBreakExistsAtPosition(position)) {
1070 // There is a preserved '\n' at caretAfterDelete. 1076 // There is a preserved '\n' at caretAfterDelete.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 return node.release(); 1464 return node.release();
1459 } 1465 }
1460 1466
1461 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) 1467 PassRefPtr<Element> createBlockPlaceholderElement(Document* document)
1462 { 1468 {
1463 RefPtr<Element> breakNode = document->createElement(brTag, false); 1469 RefPtr<Element> breakNode = document->createElement(brTag, false);
1464 return breakNode.release(); 1470 return breakNode.release();
1465 } 1471 }
1466 1472
1467 } // namespace WebCore 1473 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698