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

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

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 Created 5 years, 3 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
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 222
223 // skip smart delete if the selection to delete already starts or ends w ith whitespace 223 // skip smart delete if the selection to delete already starts or ends w ith whitespace
224 Position pos = VisiblePosition(m_upstreamStart, m_selectionToDelete.affi nity()).deepEquivalent(); 224 Position pos = VisiblePosition(m_upstreamStart, m_selectionToDelete.affi nity()).deepEquivalent();
225 bool skipSmartDelete = trailingWhitespacePosition(pos, VP_DEFAULT_AFFINI TY, ConsiderNonCollapsibleWhitespace).isNotNull(); 225 bool skipSmartDelete = trailingWhitespacePosition(pos, VP_DEFAULT_AFFINI TY, ConsiderNonCollapsibleWhitespace).isNotNull();
226 if (!skipSmartDelete) 226 if (!skipSmartDelete)
227 skipSmartDelete = leadingWhitespacePosition(m_downstreamEnd, VP_DEFA ULT_AFFINITY, ConsiderNonCollapsibleWhitespace).isNotNull(); 227 skipSmartDelete = leadingWhitespacePosition(m_downstreamEnd, VP_DEFA ULT_AFFINITY, ConsiderNonCollapsibleWhitespace).isNotNull();
228 228
229 // extend selection upstream if there is whitespace there 229 // extend selection upstream if there is whitespace there
230 bool hasLeadingWhitespaceBeforeAdjustment = leadingWhitespacePosition(m_ upstreamStart, m_selectionToDelete.affinity(), ConsiderNonCollapsibleWhitespace) .isNotNull(); 230 bool hasLeadingWhitespaceBeforeAdjustment = leadingWhitespacePosition(m_ upstreamStart, m_selectionToDelete.affinity(), ConsiderNonCollapsibleWhitespace) .isNotNull();
231 if (!skipSmartDelete && hasLeadingWhitespaceBeforeAdjustment) { 231 if (!skipSmartDelete && hasLeadingWhitespaceBeforeAdjustment) {
232 VisiblePosition visiblePos = VisiblePosition(m_upstreamStart, VP_DEF AULT_AFFINITY).previous(); 232 VisiblePosition visiblePos = previousPositionOf(VisiblePosition(m_up streamStart, VP_DEFAULT_AFFINITY));
233 pos = visiblePos.deepEquivalent(); 233 pos = visiblePos.deepEquivalent();
234 // Expand out one character upstream for smart delete and recalculat e 234 // Expand out one character upstream for smart delete and recalculat e
235 // positions based on this change. 235 // positions based on this change.
236 m_upstreamStart = mostBackwardCaretPosition(pos); 236 m_upstreamStart = mostBackwardCaretPosition(pos);
237 m_downstreamStart = mostForwardCaretPosition(pos); 237 m_downstreamStart = mostForwardCaretPosition(pos);
238 m_leadingWhitespace = leadingWhitespacePosition(m_upstreamStart, vis iblePos.affinity()); 238 m_leadingWhitespace = leadingWhitespacePosition(m_upstreamStart, vis iblePos.affinity());
239 239
240 setStartingSelectionOnSmartDelete(m_upstreamStart, m_upstreamEnd); 240 setStartingSelectionOnSmartDelete(m_upstreamStart, m_upstreamEnd);
241 } 241 }
242 242
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 LayoutObject* r = node->layoutObject(); 377 LayoutObject* r = node->layoutObject();
378 if (r && r->isTableCell() && toLayoutTableCell(r)->contentHeight() <= 0) { 378 if (r && r->isTableCell() && toLayoutTableCell(r)->contentHeight() <= 0) {
379 Position firstEditablePosition = firstEditablePositionInNode(node.ge t()); 379 Position firstEditablePosition = firstEditablePositionInNode(node.ge t());
380 if (firstEditablePosition.isNotNull()) 380 if (firstEditablePosition.isNotNull())
381 insertBlockPlaceholder(firstEditablePosition); 381 insertBlockPlaceholder(firstEditablePosition);
382 } 382 }
383 return; 383 return;
384 } 384 }
385 385
386 if (node == m_startBlock) { 386 if (node == m_startBlock) {
387 VisiblePosition previous = VisiblePosition(firstPositionInNode(m_startBl ock.get())).previous(); 387 VisiblePosition previous = previousPositionOf(VisiblePosition(firstPosit ionInNode(m_startBlock.get())));
388 if (previous.isNotNull() && !isEndOfBlock(previous)) 388 if (previous.isNotNull() && !isEndOfBlock(previous))
389 m_needPlaceholder = true; 389 m_needPlaceholder = true;
390 } 390 }
391 if (node == m_endBlock) { 391 if (node == m_endBlock) {
392 VisiblePosition next = VisiblePosition(lastPositionInNode(m_endBlock.get ())).next(); 392 VisiblePosition next = VisiblePosition(lastPositionInNode(m_endBlock.get ())).next();
393 if (next.isNotNull() && !isStartOfBlock(next)) 393 if (next.isNotNull() && !isStartOfBlock(next))
394 m_needPlaceholder = true; 394 m_needPlaceholder = true;
395 } 395 }
396 396
397 // FIXME: Update the endpoints of the range being deleted. 397 // FIXME: Update the endpoints of the range being deleted.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 if (Element* table = isLastPositionBeforeTable(m_selectionToDelete.visib leStart())) { 809 if (Element* table = isLastPositionBeforeTable(m_selectionToDelete.visib leStart())) {
810 if (m_selectionToDelete.end().anchorNode()->isDescendantOf(table)) 810 if (m_selectionToDelete.end().anchorNode()->isDescendantOf(table))
811 m_needPlaceholder = false; 811 m_needPlaceholder = false;
812 } 812 }
813 } 813 }
814 814
815 815
816 // set up our state 816 // set up our state
817 initializePositionData(); 817 initializePositionData();
818 818
819 bool lineBreakBeforeStart = lineBreakExistsAtVisiblePosition(VisiblePosition (m_upstreamStart).previous()); 819 bool lineBreakBeforeStart = lineBreakExistsAtVisiblePosition(previousPositio nOf(VisiblePosition(m_upstreamStart)));
820 820
821 // Delete any text that may hinder our ability to fixup whitespace after the delete 821 // Delete any text that may hinder our ability to fixup whitespace after the
822 // delete
822 deleteInsignificantTextDownstream(m_trailingWhitespace); 823 deleteInsignificantTextDownstream(m_trailingWhitespace);
823 824
824 saveTypingStyleState(); 825 saveTypingStyleState();
825 826
826 // deleting just a BR is handled specially, at least because we do not 827 // deleting just a BR is handled specially, at least because we do not
827 // want to replace it with a placeholder BR! 828 // want to replace it with a placeholder BR!
828 if (handleSpecialCaseBRDelete()) { 829 if (handleSpecialCaseBRDelete()) {
829 calculateTypingStyleAfterDelete(); 830 calculateTypingStyleAfterDelete();
830 setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSe lection().isDirectional())); 831 setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSe lection().isDirectional()));
831 clearTransientState(); 832 clearTransientState();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 visitor->trace(m_deleteIntoBlockquoteStyle); 900 visitor->trace(m_deleteIntoBlockquoteStyle);
900 visitor->trace(m_startRoot); 901 visitor->trace(m_startRoot);
901 visitor->trace(m_endRoot); 902 visitor->trace(m_endRoot);
902 visitor->trace(m_startTableRow); 903 visitor->trace(m_startTableRow);
903 visitor->trace(m_endTableRow); 904 visitor->trace(m_endTableRow);
904 visitor->trace(m_temporaryPlaceholder); 905 visitor->trace(m_temporaryPlaceholder);
905 CompositeEditCommand::trace(visitor); 906 CompositeEditCommand::trace(visitor);
906 } 907 }
907 908
908 } // namespace blink 909 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/commands/CompositeEditCommand.cpp ('k') | Source/core/editing/commands/InsertListCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698