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

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

Issue 1305963003: Introduce {next,previous}PositionOf() as replacement of {next,previous}() member functions in Positi (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-22T00:12:04 Rebase Created 5 years, 4 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 // If we're inserting the break at the end of the quoted content, we don't n eed to break the quote. 120 // If we're inserting the break at the end of the quoted content, we don't n eed to break the quote.
121 if (isLastVisPosInNode) { 121 if (isLastVisPosInNode) {
122 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get( )), TextAffinity::Downstream, endingSelection().isDirectional())); 122 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get( )), TextAffinity::Downstream, endingSelection().isDirectional()));
123 rebalanceWhitespace(); 123 rebalanceWhitespace();
124 return; 124 return;
125 } 125 }
126 126
127 // Don't move a line break just after the caret. Doing so would create an e xtra, empty paragraph 127 // Don't move a line break just after the caret. Doing so would create an e xtra, empty paragraph
128 // in the new blockquote. 128 // in the new blockquote.
129 if (lineBreakExistsAtVisiblePosition(visiblePos)) 129 if (lineBreakExistsAtVisiblePosition(visiblePos)) {
130 pos = pos.next(); 130 // TODO(yosin) We should use |PositionMoveType::Character| for
131 // |nextPositionOf()| to avoid editing middle of character.
132 pos = nextPositionOf(pos, PositionMoveType::CodePoint);
133 }
131 134
132 // Adjust the position so we don't split at the beginning of a quote. 135 // Adjust the position so we don't split at the beginning of a quote.
133 while (isFirstVisiblePositionInNode(VisiblePosition(pos), toHTMLQuoteElement (enclosingNodeOfType(pos, isMailHTMLBlockquoteElement)))) 136 while (isFirstVisiblePositionInNode(VisiblePosition(pos), toHTMLQuoteElement (enclosingNodeOfType(pos, isMailHTMLBlockquoteElement)))) {
134 pos = pos.previous(); 137 // TODO(yosin) We should use |PositionMoveType::Character| for
138 // |previousPositionOf()| to avoid editing middle character.
139 pos = previousPositionOf(pos, PositionMoveType::CodePoint);
140 }
135 141
136 // startNode is the first node that we need to move to the new blockquote. 142 // startNode is the first node that we need to move to the new blockquote.
137 Node* startNode = pos.anchorNode(); 143 Node* startNode = pos.anchorNode();
138 ASSERT(startNode); 144 ASSERT(startNode);
139 145
140 // Split at pos if in the middle of a text node. 146 // Split at pos if in the middle of a text node.
141 if (startNode->isTextNode()) { 147 if (startNode->isTextNode()) {
142 Text* textNode = toText(startNode); 148 Text* textNode = toText(startNode);
143 int textOffset = pos.computeOffsetInContainerNode(); 149 int textOffset = pos.computeOffsetInContainerNode();
144 if ((unsigned)textOffset >= textNode->length()) { 150 if ((unsigned)textOffset >= textNode->length()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 218
213 // Make sure the cloned block quote renders. 219 // Make sure the cloned block quote renders.
214 addBlockPlaceholderIfNeeded(clonedBlockquote.get()); 220 addBlockPlaceholderIfNeeded(clonedBlockquote.get());
215 221
216 // Put the selection right before the break. 222 // Put the selection right before the break.
217 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()), TextAffinity::Downstream, endingSelection().isDirectional())); 223 setEndingSelection(VisibleSelection(positionBeforeNode(breakElement.get()), TextAffinity::Downstream, endingSelection().isDirectional()));
218 rebalanceWhitespace(); 224 rebalanceWhitespace();
219 } 225 }
220 226
221 } // namespace blink 227 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/commands/ApplyBlockElementCommand.cpp ('k') | Source/core/editing/commands/InsertTextCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698