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

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

Issue 2073643002: Use enum instead of "bool preserveSelection and bool preserveStyle" of moveParagraph() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 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 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 } 1237 }
1238 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent()); 1238 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent());
1239 1239
1240 if (beforeParagraph.isNotNull() && !isDisplayInsideTable(beforeParagraph.dee pEquivalent().anchorNode()) 1240 if (beforeParagraph.isNotNull() && !isDisplayInsideTable(beforeParagraph.dee pEquivalent().anchorNode())
1241 && ((!isEndOfParagraph(beforeParagraph) && !isStartOfParagraph(beforePar agraph)) || beforeParagraph.deepEquivalent() == afterParagraph.deepEquivalent()) ) { 1241 && ((!isEndOfParagraph(beforeParagraph) && !isStartOfParagraph(beforePar agraph)) || beforeParagraph.deepEquivalent() == afterParagraph.deepEquivalent()) ) {
1242 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal. 1242 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal.
1243 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui valent(), editingState); 1243 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui valent(), editingState);
1244 } 1244 }
1245 } 1245 }
1246 1246
1247 void CompositeEditCommand::moveParagraph(const VisiblePosition& startOfParagraph ToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& dest ination, EditingState* editingState, bool preserveSelection, bool preserveStyle, Node* constrainingAncestor) 1247 void CompositeEditCommand::moveParagraph(const VisiblePosition& startOfParagraph ToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& dest ination, EditingState* editingState, ShouldPreserveSelection shouldPreserveSelec tion, ShouldPreserveStyle shouldPreserveStyle, Node* constrainingAncestor)
1248 { 1248 {
1249 DCHECK(isStartOfParagraph(startOfParagraphToMove)) << startOfParagraphToMove ; 1249 DCHECK(isStartOfParagraph(startOfParagraphToMove)) << startOfParagraphToMove ;
1250 DCHECK(isEndOfParagraph(endOfParagraphToMove)) << endOfParagraphToMove; 1250 DCHECK(isEndOfParagraph(endOfParagraphToMove)) << endOfParagraphToMove;
1251 moveParagraphs(startOfParagraphToMove, endOfParagraphToMove, destination, ed itingState, preserveSelection, preserveStyle, constrainingAncestor); 1251 moveParagraphs(startOfParagraphToMove, endOfParagraphToMove, destination, ed itingState, shouldPreserveSelection, shouldPreserveStyle, constrainingAncestor);
1252 } 1252 }
1253 1253
1254 void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap hToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& des tination, EditingState* editingState, bool preserveSelection, bool preserveStyle , Node* constrainingAncestor) 1254 void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap hToMove, const VisiblePosition& endOfParagraphToMove, const VisiblePosition& des tination, EditingState* editingState, ShouldPreserveSelection shouldPreserveSele ction, ShouldPreserveStyle shouldPreserveStyle, Node* constrainingAncestor)
1255 { 1255 {
1256 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent() || startOfParagraphToMove.isNull()) 1256 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent() || startOfParagraphToMove.isNull())
1257 return; 1257 return;
1258 1258
1259 int startIndex = -1; 1259 int startIndex = -1;
1260 int endIndex = -1; 1260 int endIndex = -1;
1261 int destinationIndex = -1; 1261 int destinationIndex = -1;
1262 bool originalIsDirectional = endingSelection().isDirectional(); 1262 bool originalIsDirectional = endingSelection().isDirectional();
1263 if (preserveSelection && !endingSelection().isNone()) { 1263 if (shouldPreserveSelection == PreserveSelection && !endingSelection().isNon e()) {
1264 VisiblePosition visibleStart = endingSelection().visibleStart(); 1264 VisiblePosition visibleStart = endingSelection().visibleStart();
1265 VisiblePosition visibleEnd = endingSelection().visibleEnd(); 1265 VisiblePosition visibleEnd = endingSelection().visibleEnd();
1266 1266
1267 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0; 1267 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0;
1268 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0; 1268 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0;
1269 1269
1270 if (!startAfterParagraph && !endBeforeParagraph) { 1270 if (!startAfterParagraph && !endBeforeParagraph) {
1271 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0; 1271 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0;
1272 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0; 1272 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0;
1273 1273
(...skipping 17 matching lines...) Expand all
1291 1291
1292 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It 1292 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It
1293 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. 1293 // shouldn't matter though, since moved paragraphs will usually be quite sma ll.
1294 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO fParagraphToMove.deepEquivalent() ? 1294 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO fParagraphToMove.deepEquivalent() ?
1295 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ; 1295 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ;
1296 1296
1297 // A non-empty paragraph's style is moved when we copy and move it. We don' t move 1297 // A non-empty paragraph's style is moved when we copy and move it. We don' t move
1298 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style 1298 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style
1299 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later. 1299 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later.
1300 EditingStyle* styleInEmptyParagraph = nullptr; 1300 EditingStyle* styleInEmptyParagraph = nullptr;
1301 if (startOfParagraphToMove.deepEquivalent() == endOfParagraphToMove.deepEqui valent() && preserveStyle) { 1301 if (startOfParagraphToMove.deepEquivalent() == endOfParagraphToMove.deepEqui valent() && shouldPreserveStyle == PreserveStyle) {
1302 styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deep Equivalent()); 1302 styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deep Equivalent());
1303 styleInEmptyParagraph->mergeTypingStyle(&document()); 1303 styleInEmptyParagraph->mergeTypingStyle(&document());
1304 // The moved paragraph should assume the block style of the destination. 1304 // The moved paragraph should assume the block style of the destination.
1305 styleInEmptyParagraph->removeBlockProperties(); 1305 styleInEmptyParagraph->removeBlockProperties();
1306 } 1306 }
1307 1307
1308 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo ved" and call shouldInsertFragment here. 1308 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo ved" and call shouldInsertFragment here.
1309 1309
1310 setEndingSelection(VisibleSelection(start, end)); 1310 setEndingSelection(VisibleSelection(start, end));
1311 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele ction()); 1311 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele ction());
(...skipping 23 matching lines...) Expand all
1335 return; 1335 return;
1336 // Need an updateLayout here in case inserting the br has split a text n ode. 1336 // Need an updateLayout here in case inserting the br has split a text n ode.
1337 document().updateStyleAndLayoutIgnorePendingStylesheets(); 1337 document().updateStyleAndLayoutIgnorePendingStylesheets();
1338 } 1338 }
1339 1339
1340 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d ocument().documentElement()), destination.toParentAnchoredPosition(), true); 1340 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d ocument().documentElement()), destination.toParentAnchoredPosition(), true);
1341 1341
1342 setEndingSelection(VisibleSelection(destination, originalIsDirectional)); 1342 setEndingSelection(VisibleSelection(destination, originalIsDirectional));
1343 DCHECK(!endingSelection().isNone()); 1343 DCHECK(!endingSelection().isNone());
1344 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph; 1344 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph;
1345 if (!preserveStyle) 1345 if (shouldPreserveStyle == DoNotPreserveStyle)
1346 options |= ReplaceSelectionCommand::MatchStyle; 1346 options |= ReplaceSelectionCommand::MatchStyle;
1347 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options), editingState); 1347 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options), editingState);
1348 if (editingState->isAborted()) 1348 if (editingState->isAborted())
1349 return; 1349 return;
1350 1350
1351 document().frame()->spellChecker().markMisspellingsAndBadGrammar(endingSelec tion()); 1351 document().frame()->spellChecker().markMisspellingsAndBadGrammar(endingSelec tion());
1352 1352
1353 // If the selection is in an empty paragraph, restore styles from the old em pty paragraph to the new empty paragraph. 1353 // If the selection is in an empty paragraph, restore styles from the old em pty paragraph to the new empty paragraph.
1354 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar agraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().v isibleStart()); 1354 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar agraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().v isibleStart());
1355 if (styleInEmptyParagraph && selectionIsEmptyParagraph) { 1355 if (styleInEmptyParagraph && selectionIsEmptyParagraph) {
1356 applyStyle(styleInEmptyParagraph, editingState); 1356 applyStyle(styleInEmptyParagraph, editingState);
1357 if (editingState->isAborted()) 1357 if (editingState->isAborted())
1358 return; 1358 return;
1359 } 1359 }
1360 1360
1361 if (!preserveSelection || startIndex == -1) 1361 if (shouldPreserveSelection == DoNotPreserveSelection || startIndex == -1)
1362 return; 1362 return;
1363 Element* documentElement = document().documentElement(); 1363 Element* documentElement = document().documentElement();
1364 if (!documentElement) 1364 if (!documentElement)
1365 return; 1365 return;
1366 // Fragment creation (using createMarkup) incorrectly uses regular spaces 1366 // Fragment creation (using createMarkup) incorrectly uses regular spaces
1367 // instead of nbsps for some spaces that were rendered (11475), which causes 1367 // instead of nbsps for some spaces that were rendered (11475), which causes
1368 // spaces to be collapsed during the move operation. This results in a call 1368 // spaces to be collapsed during the move operation. This results in a call
1369 // to rangeFromLocationAndLength with a location past the end of the 1369 // to rangeFromLocationAndLength with a location past the end of the
1370 // document (which will return null). 1370 // document (which will return null).
1371 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex).cr eateRangeForSelection(*documentElement); 1371 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex).cr eateRangeForSelection(*documentElement);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 } 1617 }
1618 1618
1619 DEFINE_TRACE(CompositeEditCommand) 1619 DEFINE_TRACE(CompositeEditCommand)
1620 { 1620 {
1621 visitor->trace(m_commands); 1621 visitor->trace(m_commands);
1622 visitor->trace(m_composition); 1622 visitor->trace(m_composition);
1623 EditCommand::trace(visitor); 1623 EditCommand::trace(visitor);
1624 } 1624 }
1625 1625
1626 } // namespace blink 1626 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698