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

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

Issue 1302353002: Get rid of redundant member function PositionAlgorithm<Strategy>::{upstream,downstream} (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-22T04:51:20 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return; 149 return;
150 } 150 }
151 151
152 Position startPosition(endingSelection().start()); 152 Position startPosition(endingSelection().start());
153 153
154 Position placeholder; 154 Position placeholder;
155 // We want to remove preserved newlines and brs that will collapse (and thus become unnecessary) when content 155 // We want to remove preserved newlines and brs that will collapse (and thus become unnecessary) when content
156 // is inserted just before them. 156 // is inserted just before them.
157 // FIXME: We shouldn't really have to do this, but removing placeholders is a workaround for 9661. 157 // FIXME: We shouldn't really have to do this, but removing placeholders is a workaround for 9661.
158 // If the caret is just before a placeholder, downstream will normalize the caret to it. 158 // If the caret is just before a placeholder, downstream will normalize the caret to it.
159 Position downstream(startPosition.downstream()); 159 Position downstream(mostForwardCaretPosition(startPosition));
160 if (lineBreakExistsAtPosition(downstream)) { 160 if (lineBreakExistsAtPosition(downstream)) {
161 // FIXME: This doesn't handle placeholders at the end of anonymous block s. 161 // FIXME: This doesn't handle placeholders at the end of anonymous block s.
162 VisiblePosition caret(startPosition); 162 VisiblePosition caret(startPosition);
163 if (isEndOfBlock(caret) && isStartOfParagraph(caret)) 163 if (isEndOfBlock(caret) && isStartOfParagraph(caret))
164 placeholder = downstream; 164 placeholder = downstream;
165 // Don't remove the placeholder yet, otherwise the block we're inserting into would collapse before 165 // Don't remove the placeholder yet, otherwise the block we're inserting into would collapse before
166 // we get a chance to insert into it. We check for a placeholder now, t hough, because doing so requires 166 // we get a chance to insert into it. We check for a placeholder now, t hough, because doing so requires
167 // the creation of a VisiblePosition, and if we did that post-insertion it would force a layout. 167 // the creation of a VisiblePosition, and if we did that post-insertion it would force a layout.
168 } 168 }
169 169
170 // Insert the character at the leftmost candidate. 170 // Insert the character at the leftmost candidate.
171 startPosition = startPosition.upstream(); 171 startPosition = mostBackwardCaretPosition(startPosition);
172 172
173 // It is possible for the node that contains startPosition to contain only u nrendered whitespace, 173 // It is possible for the node that contains startPosition to contain only u nrendered whitespace,
174 // and so deleteInsignificantText could remove it. Save the position before the node in case that happens. 174 // and so deleteInsignificantText could remove it. Save the position before the node in case that happens.
175 ASSERT(startPosition.computeContainerNode()); 175 ASSERT(startPosition.computeContainerNode());
176 Position positionBeforeStartNode(positionInParentBeforeNode(*startPosition.c omputeContainerNode())); 176 Position positionBeforeStartNode(positionInParentBeforeNode(*startPosition.c omputeContainerNode()));
177 deleteInsignificantText(startPosition, startPosition.downstream()); 177 deleteInsignificantText(startPosition, mostForwardCaretPosition(startPositio n));
178 if (!startPosition.inDocument()) 178 if (!startPosition.inDocument())
179 startPosition = positionBeforeStartNode; 179 startPosition = positionBeforeStartNode;
180 if (!isVisuallyEquivalentCandidate(startPosition)) 180 if (!isVisuallyEquivalentCandidate(startPosition))
181 startPosition = startPosition.downstream(); 181 startPosition = mostForwardCaretPosition(startPosition);
182 182
183 startPosition = positionAvoidingSpecialElementBoundary(startPosition); 183 startPosition = positionAvoidingSpecialElementBoundary(startPosition);
184 184
185 Position endPosition; 185 Position endPosition;
186 186
187 if (m_text == "\t") { 187 if (m_text == "\t") {
188 endPosition = insertTab(startPosition); 188 endPosition = insertTab(startPosition);
189 // TODO(yosin) We should use |PositionMoveType::Character| for 189 // TODO(yosin) We should use |PositionMoveType::Character| for
190 // |previousPositionOf()|. 190 // |previousPositionOf()|.
191 startPosition = previousPositionOf(endPosition, PositionMoveType::Charac ter); 191 startPosition = previousPositionOf(endPosition, PositionMoveType::Charac ter);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 splitTextNode(textNode, offset); 266 splitTextNode(textNode, offset);
267 insertNodeBefore(spanElement, textNode.release()); 267 insertNodeBefore(spanElement, textNode.release());
268 } 268 }
269 } 269 }
270 270
271 // return the position following the new tab 271 // return the position following the new tab
272 return lastPositionInNode(spanElement.get()); 272 return lastPositionInNode(spanElement.get());
273 } 273 }
274 274
275 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698