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

Side by Side Diff: Source/core/editing/commands/CompositeEditCommand.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) 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 for (const auto& node : nodes) { 831 for (const auto& node : nodes) {
832 Text* textNode = node.get(); 832 Text* textNode = node.get();
833 int startOffset = textNode == start.anchorNode() ? start.computeOffsetIn ContainerNode() : 0; 833 int startOffset = textNode == start.anchorNode() ? start.computeOffsetIn ContainerNode() : 0;
834 int endOffset = textNode == end.anchorNode() ? end.computeOffsetInContai nerNode() : static_cast<int>(textNode->length()); 834 int endOffset = textNode == end.anchorNode() ? end.computeOffsetInContai nerNode() : static_cast<int>(textNode->length());
835 deleteInsignificantText(textNode, startOffset, endOffset); 835 deleteInsignificantText(textNode, startOffset, endOffset);
836 } 836 }
837 } 837 }
838 838
839 void CompositeEditCommand::deleteInsignificantTextDownstream(const Position& pos ) 839 void CompositeEditCommand::deleteInsignificantTextDownstream(const Position& pos )
840 { 840 {
841 Position end = mostForwardCaretPosition(VisiblePosition(pos, VP_DEFAULT_AFFI NITY).next().deepEquivalent()); 841 Position end = mostForwardCaretPosition(nextPositionOf(VisiblePosition(pos, VP_DEFAULT_AFFINITY)).deepEquivalent());
842 deleteInsignificantText(pos, end); 842 deleteInsignificantText(pos, end);
843 } 843 }
844 844
845 PassRefPtrWillBeRawPtr<HTMLBRElement> CompositeEditCommand::appendBlockPlacehold er(PassRefPtrWillBeRawPtr<Element> container) 845 PassRefPtrWillBeRawPtr<HTMLBRElement> CompositeEditCommand::appendBlockPlacehold er(PassRefPtrWillBeRawPtr<Element> container)
846 { 846 {
847 if (!container) 847 if (!container)
848 return nullptr; 848 return nullptr;
849 849
850 document().updateLayoutIgnorePendingStylesheets(); 850 document().updateLayoutIgnorePendingStylesheets();
851 851
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 // it, and return that block. Otherwise return 0. 916 // it, and return that block. Otherwise return 0.
917 PassRefPtrWillBeRawPtr<HTMLElement> CompositeEditCommand::moveParagraphContentsT oNewBlockIfNecessary(const Position& pos) 917 PassRefPtrWillBeRawPtr<HTMLElement> CompositeEditCommand::moveParagraphContentsT oNewBlockIfNecessary(const Position& pos)
918 { 918 {
919 ASSERT(isEditablePosition(pos, ContentIsEditable, DoNotUpdateStyle)); 919 ASSERT(isEditablePosition(pos, ContentIsEditable, DoNotUpdateStyle));
920 920
921 // It's strange that this function is responsible for verifying that pos has not been invalidated 921 // It's strange that this function is responsible for verifying that pos has not been invalidated
922 // by an earlier call to this function. The caller, applyBlockStyle, should do this. 922 // by an earlier call to this function. The caller, applyBlockStyle, should do this.
923 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); 923 VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY);
924 VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos)); 924 VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos));
925 VisiblePosition visibleParagraphEnd = endOfParagraph(visiblePos); 925 VisiblePosition visibleParagraphEnd = endOfParagraph(visiblePos);
926 VisiblePosition next = visibleParagraphEnd.next(); 926 VisiblePosition next = nextPositionOf(visibleParagraphEnd);
927 VisiblePosition visibleEnd = next.isNotNull() ? next : visibleParagraphEnd; 927 VisiblePosition visibleEnd = next.isNotNull() ? next : visibleParagraphEnd;
928 928
929 Position upstreamStart = mostBackwardCaretPosition(visibleParagraphStart.dee pEquivalent()); 929 Position upstreamStart = mostBackwardCaretPosition(visibleParagraphStart.dee pEquivalent());
930 Position upstreamEnd = mostBackwardCaretPosition(visibleEnd.deepEquivalent() ); 930 Position upstreamEnd = mostBackwardCaretPosition(visibleEnd.deepEquivalent() );
931 931
932 // If there are no VisiblePositions in the same block as pos then 932 // If there are no VisiblePositions in the same block as pos then
933 // upstreamStart will be outside the paragraph 933 // upstreamStart will be outside the paragraph
934 if (comparePositions(pos, upstreamStart) < 0) 934 if (comparePositions(pos, upstreamStart) < 0)
935 return nullptr; 935 return nullptr;
936 936
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = previousPositionOf(startOfParagraphToMove) ; 1133 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove) ;
1134 VisiblePosition afterParagraph(endOfParagraphToMove.next()); 1134 VisiblePosition afterParagraph(nextPositionOf(endOfParagraphToMove));
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);
1144 1144
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary); 1208 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary);
1209 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary)); 1209 VisiblePosition afterParagraph(nextPositionOf(endOfParagraphToMove, CannotCr ossEditingBoundary));
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() ?
1219 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ; 1219 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ;
(...skipping 282 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