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

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

Issue 2952983002: Make Position::FirstPositionInNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-23T10:37:43 Created 3 years, 5 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, 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 .Collapse(Position::InParentAfterNode(*node_to_insert)) 162 .Collapse(Position::InParentAfterNode(*node_to_insert))
163 .SetIsDirectional(EndingSelection().IsDirectional()) 163 .SetIsDirectional(EndingSelection().IsDirectional())
164 .Build()); 164 .Build());
165 } else if (pos.AnchorNode()->IsTextNode()) { 165 } else if (pos.AnchorNode()->IsTextNode()) {
166 // Split a text node 166 // Split a text node
167 Text* text_node = ToText(pos.AnchorNode()); 167 Text* text_node = ToText(pos.AnchorNode());
168 SplitTextNode(text_node, pos.ComputeOffsetInContainerNode()); 168 SplitTextNode(text_node, pos.ComputeOffsetInContainerNode());
169 InsertNodeBefore(node_to_insert, text_node, editing_state); 169 InsertNodeBefore(node_to_insert, text_node, editing_state);
170 if (editing_state->IsAborted()) 170 if (editing_state->IsAborted())
171 return; 171 return;
172 Position ending_position = Position::FirstPositionInNode(text_node); 172 Position ending_position = Position::FirstPositionInNode(*text_node);
173 173
174 // Handle whitespace that occurs after the split 174 // Handle whitespace that occurs after the split
175 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 175 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
176 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should 176 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should
177 // use |VisiblePosition::characterAfter()|. 177 // use |VisiblePosition::characterAfter()|.
178 if (!IsRenderedCharacter(ending_position)) { 178 if (!IsRenderedCharacter(ending_position)) {
179 Position position_before_text_node( 179 Position position_before_text_node(
180 Position::InParentBeforeNode(*text_node)); 180 Position::InParentBeforeNode(*text_node));
181 // Clear out all whitespace and insert one non-breaking space 181 // Clear out all whitespace and insert one non-breaking space
182 DeleteInsignificantTextDownstream(ending_position); 182 DeleteInsignificantTextDownstream(ending_position);
183 // Deleting insignificant whitespace will remove textNode if it contains 183 // Deleting insignificant whitespace will remove textNode if it contains
184 // nothing but insignificant whitespace. 184 // nothing but insignificant whitespace.
185 if (text_node->isConnected()) { 185 if (text_node->isConnected()) {
186 InsertTextIntoNode(text_node, 0, NonBreakingSpaceString()); 186 InsertTextIntoNode(text_node, 0, NonBreakingSpaceString());
187 } else { 187 } else {
188 Text* nbsp_node = 188 Text* nbsp_node =
189 GetDocument().createTextNode(NonBreakingSpaceString()); 189 GetDocument().createTextNode(NonBreakingSpaceString());
190 InsertNodeAt(nbsp_node, position_before_text_node, editing_state); 190 InsertNodeAt(nbsp_node, position_before_text_node, editing_state);
191 if (editing_state->IsAborted()) 191 if (editing_state->IsAborted())
192 return; 192 return;
193 ending_position = Position::FirstPositionInNode(nbsp_node); 193 ending_position = Position::FirstPositionInNode(*nbsp_node);
194 } 194 }
195 } 195 }
196 196
197 SetEndingSelection(SelectionInDOMTree::Builder() 197 SetEndingSelection(SelectionInDOMTree::Builder()
198 .Collapse(ending_position) 198 .Collapse(ending_position)
199 .SetIsDirectional(EndingSelection().IsDirectional()) 199 .SetIsDirectional(EndingSelection().IsDirectional())
200 .Build()); 200 .Build());
201 } 201 }
202 202
203 // Handle the case where there is a typing style. 203 // Handle the case where there is a typing style.
(...skipping 22 matching lines...) Expand all
226 // block. 226 // block.
227 SetEndingSelection(SelectionInDOMTree::Builder() 227 SetEndingSelection(SelectionInDOMTree::Builder()
228 .Collapse(EndingSelection().End()) 228 .Collapse(EndingSelection().End())
229 .Build()); 229 .Build());
230 } 230 }
231 231
232 RebalanceWhitespace(); 232 RebalanceWhitespace();
233 } 233 }
234 234
235 } // namespace blink 235 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698