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

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

Issue 1307803003: Introduce nextPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T18:13:02 Created 5 years, 3 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) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 { 213 {
214 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); 214 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
215 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); 215 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection);
216 216
217 if (endOfCurrentParagraph.deepEquivalent() == endOfLastParagraph.deepEquival ent()) { 217 if (endOfCurrentParagraph.deepEquivalent() == endOfLastParagraph.deepEquival ent()) {
218 outdentParagraph(); 218 outdentParagraph();
219 return; 219 return;
220 } 220 }
221 221
222 Position originalSelectionEnd = endingSelection().end(); 222 Position originalSelectionEnd = endingSelection().end();
223 VisiblePosition endAfterSelection = endOfParagraph(endOfLastParagraph.next() ); 223 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP aragraph));
224 224
225 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent()) { 225 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent()) {
226 VisiblePosition endOfNextParagraph = endOfParagraph(endOfCurrentParagrap h.next()); 226 VisiblePosition endOfNextParagraph = endOfParagraph(nextPositionOf(endOf CurrentParagraph));
227 if (endOfCurrentParagraph.deepEquivalent() == endOfLastParagraph.deepEqu ivalent()) 227 if (endOfCurrentParagraph.deepEquivalent() == endOfLastParagraph.deepEqu ivalent())
228 setEndingSelection(VisibleSelection(originalSelectionEnd, TextAffini ty::Downstream)); 228 setEndingSelection(VisibleSelection(originalSelectionEnd, TextAffini ty::Downstream));
229 else 229 else
230 setEndingSelection(endOfCurrentParagraph); 230 setEndingSelection(endOfCurrentParagraph);
231 231
232 outdentParagraph(); 232 outdentParagraph();
233 233
234 // outdentParagraph could move more than one paragraph if the paragraph 234 // outdentParagraph could move more than one paragraph if the paragraph
235 // is in a list item. As a result, endAfterSelection and endOfNextParagr aph 235 // is in a list item. As a result, endAfterSelection and endOfNextParagr aph
236 // could refer to positions no longer in the document. 236 // could refer to positions no longer in the document.
237 if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent() .inDocument()) 237 if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent() .inDocument())
238 break; 238 break;
239 239
240 if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent ().inDocument()) { 240 if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent ().inDocument()) {
241 endOfCurrentParagraph = VisiblePosition(endingSelection().end()); 241 endOfCurrentParagraph = VisiblePosition(endingSelection().end());
242 endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.next()); 242 endOfNextParagraph = endOfParagraph(nextPositionOf(endOfCurrentParag raph));
243 } 243 }
244 endOfCurrentParagraph = endOfNextParagraph; 244 endOfCurrentParagraph = endOfNextParagraph;
245 } 245 }
246 } 246 }
247 247
248 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti on, const VisiblePosition& endOfSelection) 248 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti on, const VisiblePosition& endOfSelection)
249 { 249 {
250 if (m_typeOfAction == Indent) 250 if (m_typeOfAction == Indent)
251 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti on); 251 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti on);
252 else 252 else
253 outdentRegion(startOfSelection, endOfSelection); 253 outdentRegion(startOfSelection, endOfSelection);
254 } 254 }
255 255
256 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent) 256 void IndentOutdentCommand::formatRange(const Position& start, const Position& en d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent)
257 { 257 {
258 if (tryIndentingAsListItem(start, end)) 258 if (tryIndentingAsListItem(start, end))
259 blockquoteForNextIndent = nullptr; 259 blockquoteForNextIndent = nullptr;
260 else 260 else
261 indentIntoBlockquote(start, end, blockquoteForNextIndent); 261 indentIntoBlockquote(start, end, blockquoteForNextIndent);
262 } 262 }
263 263
264 } 264 }
OLDNEW
« no previous file with comments | « Source/core/editing/commands/DeleteSelectionCommand.cpp ('k') | Source/core/editing/commands/InsertListCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698