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

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

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 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) 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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 LayoutText* layoutText = textNode->layoutObject(); 698 LayoutText* layoutText = textNode->layoutObject();
699 if (layoutText && !layoutText->style()->collapseWhiteSpace()) 699 if (layoutText && !layoutText->style()->collapseWhiteSpace())
700 return; 700 return;
701 701
702 // Delete collapsed whitespace so that inserting nbsps doesn't uncollapse it . 702 // Delete collapsed whitespace so that inserting nbsps doesn't uncollapse it .
703 Position upstreamPos = mostBackwardCaretPosition(position); 703 Position upstreamPos = mostBackwardCaretPosition(position);
704 deleteInsignificantText(upstreamPos, mostForwardCaretPosition(position)); 704 deleteInsignificantText(upstreamPos, mostForwardCaretPosition(position));
705 position = mostForwardCaretPosition(upstreamPos); 705 position = mostForwardCaretPosition(upstreamPos);
706 706
707 VisiblePosition visiblePos(position); 707 VisiblePosition visiblePos(position);
708 VisiblePosition previousVisiblePos(visiblePos.previous()); 708 VisiblePosition previousVisiblePos(previousPositionOf(visiblePos));
709 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(previousVisiblePos) ; 709 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(previousVisiblePos) ;
710 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(visiblePos); 710 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(visiblePos);
711 } 711 }
712 712
713 void CompositeEditCommand::replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNee ded(const VisiblePosition& visiblePosition) 713 void CompositeEditCommand::replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNee ded(const VisiblePosition& visiblePosition)
714 { 714 {
715 if (!isCollapsibleWhitespace(visiblePosition.characterAfter())) 715 if (!isCollapsibleWhitespace(visiblePosition.characterAfter()))
716 return; 716 return;
717 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent()); 717 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent());
718 if (!pos.computeContainerNode() || !pos.computeContainerNode()->isTextNode() ) 718 if (!pos.computeContainerNode() || !pos.computeContainerNode()->isTextNode() )
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 // It is currently used only by IndentOutdentCommand but it is meant to be used in the 1123 // It is currently used only by IndentOutdentCommand but it is meant to be used in the
1124 // future by several other commands such as InsertList and the align commands. 1124 // future by several other commands such as InsertList and the align commands.
1125 // The blockElement parameter is the element to move the paragraph to, 1125 // The blockElement parameter is the element to move the paragraph to,
1126 // outerNode is the top element of the paragraph hierarchy. 1126 // outerNode is the top element of the paragraph hierarchy.
1127 1127
1128 void CompositeEditCommand::moveParagraphWithClones(const VisiblePosition& startO fParagraphToMove, const VisiblePosition& endOfParagraphToMove, HTMLElement* bloc kElement, Node* outerNode) 1128 void CompositeEditCommand::moveParagraphWithClones(const VisiblePosition& startO fParagraphToMove, const VisiblePosition& endOfParagraphToMove, HTMLElement* bloc kElement, Node* outerNode)
1129 { 1129 {
1130 ASSERT(outerNode); 1130 ASSERT(outerNode);
1131 ASSERT(blockElement); 1131 ASSERT(blockElement);
1132 1132
1133 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(); 1133 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove) ;
1134 VisiblePosition afterParagraph(endOfParagraphToMove.next()); 1134 VisiblePosition afterParagraph(endOfParagraphToMove.next());
1135 1135
1136 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. 1136 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
1137 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. 1137 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered.
1138 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent()); 1138 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent());
1139 Position end = startOfParagraphToMove.deepEquivalent() == endOfParagraphToMo ve.deepEquivalent() ? start : mostBackwardCaretPosition(endOfParagraphToMove.dee pEquivalent()); 1139 Position end = startOfParagraphToMove.deepEquivalent() == endOfParagraphToMo ve.deepEquivalent() ? start : mostBackwardCaretPosition(endOfParagraphToMove.dee pEquivalent());
1140 if (comparePositions(start, end) > 0) 1140 if (comparePositions(start, end) > 0)
1141 end = start; 1141 end = start;
1142 1142
1143 cloneParagraphUnderNewElement(start, end, outerNode, blockElement); 1143 cloneParagraphUnderNewElement(start, end, outerNode, blockElement);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 startIndex = 0; 1198 startIndex = 0;
1199 if (startInParagraph) 1199 if (startInParagraph)
1200 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true); 1200 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true);
1201 1201
1202 endIndex = 0; 1202 endIndex = 0;
1203 if (endInParagraph) 1203 if (endInParagraph)
1204 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true); 1204 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true);
1205 } 1205 }
1206 } 1206 }
1207 1207
1208 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCros sEditingBoundary); 1208 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary);
1209 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary)); 1209 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary));
1210 1210
1211 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. 1211 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
1212 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. 1212 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered.
1213 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent()); 1213 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent());
1214 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent ()); 1214 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent ());
1215 1215
1216 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It 1216 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It
1217 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. 1217 // shouldn't matter though, since moved paragraphs will usually be quite sma ll.
1218 RefPtrWillBeRawPtr<DocumentFragment> fragment = startOfParagraphToMove.deepE quivalent() != endOfParagraphToMove.deepEquivalent() ? 1218 RefPtrWillBeRawPtr<DocumentFragment> fragment = startOfParagraphToMove.deepE quivalent() != endOfParagraphToMove.deepEquivalent() ?
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 return false; 1365 return false;
1366 1366
1367 VisiblePosition caret(endingSelection().visibleStart()); 1367 VisiblePosition caret(endingSelection().visibleStart());
1368 HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNod eOfType(caret.deepEquivalent(), &isMailHTMLBlockquoteElement)); 1368 HTMLQuoteElement* highestBlockquote = toHTMLQuoteElement(highestEnclosingNod eOfType(caret.deepEquivalent(), &isMailHTMLBlockquoteElement));
1369 if (!highestBlockquote) 1369 if (!highestBlockquote)
1370 return false; 1370 return false;
1371 1371
1372 if (!isStartOfParagraph(caret) || !isEndOfParagraph(caret)) 1372 if (!isStartOfParagraph(caret) || !isEndOfParagraph(caret))
1373 return false; 1373 return false;
1374 1374
1375 VisiblePosition previous(caret.previous(CannotCrossEditingBoundary)); 1375 VisiblePosition previous(previousPositionOf(caret, CannotCrossEditingBoundar y));
1376 // Only move forward if there's nothing before the caret, or if there's unqu oted content before it. 1376 // Only move forward if there's nothing before the caret, or if there's unqu oted content before it.
1377 if (enclosingNodeOfType(previous.deepEquivalent(), &isMailHTMLBlockquoteElem ent)) 1377 if (enclosingNodeOfType(previous.deepEquivalent(), &isMailHTMLBlockquoteElem ent))
1378 return false; 1378 return false;
1379 1379
1380 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document()); 1380 RefPtrWillBeRawPtr<HTMLBRElement> br = createBreakElement(document());
1381 // We want to replace this quoted paragraph with an unquoted one, so insert a br 1381 // We want to replace this quoted paragraph with an unquoted one, so insert a br
1382 // to hold the caret before the highest blockquote. 1382 // to hold the caret before the highest blockquote.
1383 insertNodeBefore(br, highestBlockquote); 1383 insertNodeBefore(br, highestBlockquote);
1384 VisiblePosition atBR(positionBeforeNode(br.get())); 1384 VisiblePosition atBR(positionBeforeNode(br.get()));
1385 // If the br we inserted collapsed, for example foo<br><blockquote>...</bloc kquote>, insert 1385 // If the br we inserted collapsed, for example foo<br><blockquote>...</bloc kquote>, insert
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } 1502 }
1503 1503
1504 DEFINE_TRACE(CompositeEditCommand) 1504 DEFINE_TRACE(CompositeEditCommand)
1505 { 1505 {
1506 visitor->trace(m_commands); 1506 visitor->trace(m_commands);
1507 visitor->trace(m_composition); 1507 visitor->trace(m_composition);
1508 EditCommand::trace(visitor); 1508 EditCommand::trace(visitor);
1509 } 1509 }
1510 1510
1511 } // namespace blink 1511 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/commands/BreakBlockquoteCommand.cpp ('k') | Source/core/editing/commands/DeleteSelectionCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698