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

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

Issue 2450213002: Utilize EditCommand::setEndingSelection() taking SelectionInDOMTree (Closed)
Patch Set: 2016-10-27T18:27:07 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 appendNode(extraNode, nodeToInsert->parentNode(), editingState); 119 appendNode(extraNode, nodeToInsert->parentNode(), editingState);
120 } else { 120 } else {
121 extraNode = nodeToInsert->cloneNode(false); 121 extraNode = nodeToInsert->cloneNode(false);
122 insertNodeAfter(extraNode, nodeToInsert, editingState); 122 insertNodeAfter(extraNode, nodeToInsert, editingState);
123 } 123 }
124 if (editingState->isAborted()) 124 if (editingState->isAborted())
125 return; 125 return;
126 nodeToInsert = extraNode; 126 nodeToInsert = extraNode;
127 } 127 }
128 128
129 document().updateStyleAndLayoutIgnorePendingStylesheets(); 129 setEndingSelection(SelectionInDOMTree::Builder()
130 setEndingSelection(createVisibleSelection( 130 .collapse(Position::beforeNode(nodeToInsert))
131 SelectionInDOMTree::Builder() 131 .setIsDirectional(endingSelection().isDirectional())
132 .collapse(Position::beforeNode(nodeToInsert)) 132 .build());
133 .setIsDirectional(endingSelection().isDirectional())
134 .build()));
135 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { 133 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) {
136 insertNodeAt(nodeToInsert, pos, editingState); 134 insertNodeAt(nodeToInsert, pos, editingState);
137 if (editingState->isAborted()) 135 if (editingState->isAborted())
138 return; 136 return;
139 document().updateStyleAndLayoutIgnorePendingStylesheets(); 137 document().updateStyleAndLayoutIgnorePendingStylesheets();
140 138
141 // Insert an extra br or '\n' if the just inserted one collapsed. 139 // Insert an extra br or '\n' if the just inserted one collapsed.
142 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) { 140 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) {
143 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, 141 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert,
144 editingState); 142 editingState);
145 if (editingState->isAborted()) 143 if (editingState->isAborted())
146 return; 144 return;
147 document().updateStyleAndLayoutIgnorePendingStylesheets(); 145 document().updateStyleAndLayoutIgnorePendingStylesheets();
Xiaocheng 2016/10/28 02:25:26 This can also be removed.
yosin_UTC9 2016/10/28 06:06:49 Done.
148 } 146 }
149 147
150 setEndingSelection(createVisibleSelection( 148 setEndingSelection(SelectionInDOMTree::Builder()
151 SelectionInDOMTree::Builder() 149 .collapse(Position::inParentAfterNode(*nodeToInsert))
152 .collapse(Position::inParentAfterNode(*nodeToInsert)) 150 .setIsDirectional(endingSelection().isDirectional())
153 .setIsDirectional(endingSelection().isDirectional()) 151 .build());
154 .build()));
155 // If we're inserting after all of the rendered text in a text node, or into 152 // If we're inserting after all of the rendered text in a text node, or into
156 // a non-text node, a simple insertion is sufficient. 153 // a non-text node, a simple insertion is sufficient.
157 } else if (!pos.anchorNode()->isTextNode() || 154 } else if (!pos.anchorNode()->isTextNode() ||
158 pos.computeOffsetInContainerNode() >= 155 pos.computeOffsetInContainerNode() >=
159 caretMaxOffset(pos.anchorNode())) { 156 caretMaxOffset(pos.anchorNode())) {
160 insertNodeAt(nodeToInsert, pos, editingState); 157 insertNodeAt(nodeToInsert, pos, editingState);
161 if (editingState->isAborted()) 158 if (editingState->isAborted())
162 return; 159 return;
163 document().updateStyleAndLayoutIgnorePendingStylesheets(); 160 setEndingSelection(SelectionInDOMTree::Builder()
164 setEndingSelection(createVisibleSelection( 161 .collapse(Position::inParentAfterNode(*nodeToInsert))
165 SelectionInDOMTree::Builder() 162 .setIsDirectional(endingSelection().isDirectional())
166 .collapse(Position::inParentAfterNode(*nodeToInsert)) 163 .build());
167 .setIsDirectional(endingSelection().isDirectional())
168 .build()));
169 } else if (pos.anchorNode()->isTextNode()) { 164 } else if (pos.anchorNode()->isTextNode()) {
170 // Split a text node 165 // Split a text node
171 Text* textNode = toText(pos.anchorNode()); 166 Text* textNode = toText(pos.anchorNode());
172 splitTextNode(textNode, pos.computeOffsetInContainerNode()); 167 splitTextNode(textNode, pos.computeOffsetInContainerNode());
173 insertNodeBefore(nodeToInsert, textNode, editingState); 168 insertNodeBefore(nodeToInsert, textNode, editingState);
174 if (editingState->isAborted()) 169 if (editingState->isAborted())
175 return; 170 return;
176 Position endingPosition = Position::firstPositionInNode(textNode); 171 Position endingPosition = Position::firstPositionInNode(textNode);
177 172
178 // Handle whitespace that occurs after the split 173 // Handle whitespace that occurs after the split
(...skipping 12 matching lines...) Expand all
191 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); 186 insertTextIntoNode(textNode, 0, nonBreakingSpaceString());
192 } else { 187 } else {
193 Text* nbspNode = document().createTextNode(nonBreakingSpaceString()); 188 Text* nbspNode = document().createTextNode(nonBreakingSpaceString());
194 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); 189 insertNodeAt(nbspNode, positionBeforeTextNode, editingState);
195 if (editingState->isAborted()) 190 if (editingState->isAborted())
196 return; 191 return;
197 endingPosition = Position::firstPositionInNode(nbspNode); 192 endingPosition = Position::firstPositionInNode(nbspNode);
198 } 193 }
199 } 194 }
200 195
201 document().updateStyleAndLayoutIgnorePendingStylesheets(); 196 setEndingSelection(SelectionInDOMTree::Builder()
202 setEndingSelection(createVisibleSelection( 197 .collapse(endingPosition)
203 SelectionInDOMTree::Builder() 198 .setIsDirectional(endingSelection().isDirectional())
204 .collapse(endingPosition) 199 .build());
205 .setIsDirectional(endingSelection().isDirectional())
206 .build()));
207 } 200 }
208 201
209 // Handle the case where there is a typing style. 202 // Handle the case where there is a typing style.
210 203
211 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); 204 EditingStyle* typingStyle = document().frame()->selection().typingStyle();
212 205
213 if (typingStyle && !typingStyle->isEmpty()) { 206 if (typingStyle && !typingStyle->isEmpty()) {
214 // Apply the typing style to the inserted line break, so that if the 207 // Apply the typing style to the inserted line break, so that if the
215 // selection leaves and then comes back, new input will have the right 208 // selection leaves and then comes back, new input will have the right
216 // style. 209 // style.
(...skipping 14 matching lines...) Expand all
231 // block. 224 // block.
232 setEndingSelection(SelectionInDOMTree::Builder() 225 setEndingSelection(SelectionInDOMTree::Builder()
233 .collapse(endingSelection().end()) 226 .collapse(endingSelection().end())
234 .build()); 227 .build());
235 } 228 }
236 229
237 rebalanceWhitespace(); 230 rebalanceWhitespace();
238 } 231 }
239 232
240 } // namespace blink 233 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698