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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/InsertLineBreakCommand.cpp

Issue 2442673002: Get rid of createVisibleSelection() taking one Position (Closed)
Patch Set: 2016-10-24T17:42:38 Created 4 years, 1 month 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, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005, 2006 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Insert an extra br or '\n' if the just inserted one collapsed. 141 // Insert an extra br or '\n' if the just inserted one collapsed.
142 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) { 142 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) {
143 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, 143 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert,
144 editingState); 144 editingState);
145 if (editingState->isAborted()) 145 if (editingState->isAborted())
146 return; 146 return;
147 document().updateStyleAndLayoutIgnorePendingStylesheets(); 147 document().updateStyleAndLayoutIgnorePendingStylesheets();
148 } 148 }
149 149
150 setEndingSelection(createVisibleSelection( 150 setEndingSelection(createVisibleSelection(
151 Position::inParentAfterNode(*nodeToInsert), TextAffinity::Downstream, 151 SelectionInDOMTree::Builder()
152 endingSelection().isDirectional())); 152 .collapse(Position::inParentAfterNode(*nodeToInsert))
153 .setIsDirectional(endingSelection().isDirectional())
154 .build()));
153 // If we're inserting after all of the rendered text in a text node, or into 155 // If we're inserting after all of the rendered text in a text node, or into
154 // a non-text node, a simple insertion is sufficient. 156 // a non-text node, a simple insertion is sufficient.
155 } else if (!pos.anchorNode()->isTextNode() || 157 } else if (!pos.anchorNode()->isTextNode() ||
156 pos.computeOffsetInContainerNode() >= 158 pos.computeOffsetInContainerNode() >=
157 caretMaxOffset(pos.anchorNode())) { 159 caretMaxOffset(pos.anchorNode())) {
158 insertNodeAt(nodeToInsert, pos, editingState); 160 insertNodeAt(nodeToInsert, pos, editingState);
159 if (editingState->isAborted()) 161 if (editingState->isAborted())
160 return; 162 return;
161 document().updateStyleAndLayoutIgnorePendingStylesheets(); 163 document().updateStyleAndLayoutIgnorePendingStylesheets();
162 setEndingSelection(createVisibleSelection( 164 setEndingSelection(createVisibleSelection(
163 Position::inParentAfterNode(*nodeToInsert), TextAffinity::Downstream, 165 SelectionInDOMTree::Builder()
164 endingSelection().isDirectional())); 166 .collapse(Position::inParentAfterNode(*nodeToInsert))
167 .setIsDirectional(endingSelection().isDirectional())
168 .build()));
165 } else if (pos.anchorNode()->isTextNode()) { 169 } else if (pos.anchorNode()->isTextNode()) {
166 // Split a text node 170 // Split a text node
167 Text* textNode = toText(pos.anchorNode()); 171 Text* textNode = toText(pos.anchorNode());
168 splitTextNode(textNode, pos.computeOffsetInContainerNode()); 172 splitTextNode(textNode, pos.computeOffsetInContainerNode());
169 insertNodeBefore(nodeToInsert, textNode, editingState); 173 insertNodeBefore(nodeToInsert, textNode, editingState);
170 if (editingState->isAborted()) 174 if (editingState->isAborted())
171 return; 175 return;
172 Position endingPosition = Position::firstPositionInNode(textNode); 176 Position endingPosition = Position::firstPositionInNode(textNode);
173 177
174 // Handle whitespace that occurs after the split 178 // Handle whitespace that occurs after the split
(...skipping 13 matching lines...) Expand all
188 } else { 192 } else {
189 Text* nbspNode = document().createTextNode(nonBreakingSpaceString()); 193 Text* nbspNode = document().createTextNode(nonBreakingSpaceString());
190 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); 194 insertNodeAt(nbspNode, positionBeforeTextNode, editingState);
191 if (editingState->isAborted()) 195 if (editingState->isAborted())
192 return; 196 return;
193 endingPosition = Position::firstPositionInNode(nbspNode); 197 endingPosition = Position::firstPositionInNode(nbspNode);
194 } 198 }
195 } 199 }
196 200
197 document().updateStyleAndLayoutIgnorePendingStylesheets(); 201 document().updateStyleAndLayoutIgnorePendingStylesheets();
198 setEndingSelection( 202 setEndingSelection(createVisibleSelection(
199 createVisibleSelection(endingPosition, TextAffinity::Downstream, 203 SelectionInDOMTree::Builder()
200 endingSelection().isDirectional())); 204 .collapse(endingPosition)
205 .setIsDirectional(endingSelection().isDirectional())
206 .build()));
201 } 207 }
202 208
203 // Handle the case where there is a typing style. 209 // Handle the case where there is a typing style.
204 210
205 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); 211 EditingStyle* typingStyle = document().frame()->selection().typingStyle();
206 212
207 if (typingStyle && !typingStyle->isEmpty()) { 213 if (typingStyle && !typingStyle->isEmpty()) {
208 // Apply the typing style to the inserted line break, so that if the 214 // Apply the typing style to the inserted line break, so that if the
209 // selection leaves and then comes back, new input will have the right 215 // selection leaves and then comes back, new input will have the right
210 // style. 216 // style.
(...skipping 13 matching lines...) Expand all
224 // line break that we inserted, or just before it if it's at the end of a 230 // line break that we inserted, or just before it if it's at the end of a
225 // block. 231 // block.
226 document().updateStyleAndLayoutIgnorePendingStylesheets(); 232 document().updateStyleAndLayoutIgnorePendingStylesheets();
227 setEndingSelection(endingSelection().visibleEnd()); 233 setEndingSelection(endingSelection().visibleEnd());
228 } 234 }
229 235
230 rebalanceWhitespace(); 236 rebalanceWhitespace();
231 } 237 }
232 238
233 } // namespace blink 239 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698