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

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

Issue 224113002: Oilpan: move Range object to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use STACK_ALLOCATED() + incorporate ager's overview of macros in this area. Created 6 years, 8 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 markers.append(*markerPointers[i]); 495 markers.append(*markerPointers[i]);
496 } 496 }
497 497
498 void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p rpNode, unsigned offset, unsigned count, const String& replacementText) 498 void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p rpNode, unsigned offset, unsigned count, const String& replacementText)
499 { 499 {
500 RefPtr<Text> node(prpNode); 500 RefPtr<Text> node(prpNode);
501 DocumentMarkerController& markerController = document().markers(); 501 DocumentMarkerController& markerController = document().markers();
502 Vector<DocumentMarker> markers; 502 Vector<DocumentMarker> markers;
503 copyMarkers(markerController.markersInRange(Range::create(document(), node.g et(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()), markers); 503 copyMarkers(markerController.markersInRange(Range::create(document(), node.g et(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()), markers);
504 replaceTextInNode(node, offset, count, replacementText); 504 replaceTextInNode(node, offset, count, replacementText);
505 RefPtr<Range> newRange = Range::create(document(), node.get(), offset, node. get(), offset + replacementText.length()); 505 RefPtrWillBeRawPtr<Range> newRange = Range::create(document(), node.get(), o ffset, node.get(), offset + replacementText.length());
506 for (size_t i = 0; i < markers.size(); ++i) 506 for (size_t i = 0; i < markers.size(); ++i)
507 markerController.addMarker(newRange.get(), markers[i].type(), markers[i] .description()); 507 markerController.addMarker(newRange.get(), markers[i].type(), markers[i] .description());
508 } 508 }
509 509
510 Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos) 510 Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos)
511 { 511 {
512 if (!isTabSpanTextNode(pos.anchorNode())) 512 if (!isTabSpanTextNode(pos.anchorNode()))
513 return pos; 513 return pos;
514 514
515 switch (pos.anchorType()) { 515 switch (pos.anchorType()) {
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1146
1147 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0; 1147 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0;
1148 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0; 1148 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0;
1149 1149
1150 if (!startAfterParagraph && !endBeforeParagraph) { 1150 if (!startAfterParagraph && !endBeforeParagraph) {
1151 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0; 1151 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0;
1152 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0; 1152 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0;
1153 1153
1154 startIndex = 0; 1154 startIndex = 0;
1155 if (startInParagraph) { 1155 if (startInParagraph) {
1156 RefPtr<Range> startRange = Range::create(document(), startOfPara graphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquiva lent().parentAnchoredEquivalent()); 1156 RefPtrWillBeRawPtr<Range> startRange = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStar t.deepEquivalent().parentAnchoredEquivalent());
1157 startIndex = TextIterator::rangeLength(startRange.get(), true); 1157 startIndex = TextIterator::rangeLength(startRange.get(), true);
1158 } 1158 }
1159 1159
1160 endIndex = 0; 1160 endIndex = 0;
1161 if (endInParagraph) { 1161 if (endInParagraph) {
1162 RefPtr<Range> endRange = Range::create(document(), startOfParagr aphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent ().parentAnchoredEquivalent()); 1162 RefPtrWillBeRawPtr<Range> endRange = Range::create(document(), s tartOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.de epEquivalent().parentAnchoredEquivalent());
1163 endIndex = TextIterator::rangeLength(endRange.get(), true); 1163 endIndex = TextIterator::rangeLength(endRange.get(), true);
1164 } 1164 }
1165 } 1165 }
1166 } 1166 }
1167 1167
1168 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCros sEditingBoundary); 1168 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCros sEditingBoundary);
1169 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary)); 1169 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary));
1170 1170
1171 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. 1171 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
1172 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. 1172 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered.
1173 Position start = startOfParagraphToMove.deepEquivalent().downstream(); 1173 Position start = startOfParagraphToMove.deepEquivalent().downstream();
1174 Position end = endOfParagraphToMove.deepEquivalent().upstream(); 1174 Position end = endOfParagraphToMove.deepEquivalent().upstream();
1175 1175
1176 // start and end can't be used directly to create a Range; they are "editing positions" 1176 // start and end can't be used directly to create a Range; they are "editing positions"
1177 Position startRangeCompliant = start.parentAnchoredEquivalent(); 1177 Position startRangeCompliant = start.parentAnchoredEquivalent();
1178 Position endRangeCompliant = end.parentAnchoredEquivalent(); 1178 Position endRangeCompliant = end.parentAnchoredEquivalent();
1179 RefPtr<Range> range = Range::create(document(), startRangeCompliant.deprecat edNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.depre catedNode(), endRangeCompliant.deprecatedEditingOffset()); 1179 RefPtrWillBeRawPtr<Range> range = Range::create(document(), startRangeCompli ant.deprecatedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCom pliant.deprecatedNode(), endRangeCompliant.deprecatedEditingOffset());
1180 1180
1181 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It 1181 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It
1182 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. 1182 // shouldn't matter though, since moved paragraphs will usually be quite sma ll.
1183 RefPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraph ToMove ? 1183 RefPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraph ToMove ?
1184 createFragmentFromMarkup(document(), createMarkup(range.get(), 0, DoNotA nnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : null ptr; 1184 createFragmentFromMarkup(document(), createMarkup(range.get(), 0, DoNotA nnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : null ptr;
1185 1185
1186 // A non-empty paragraph's style is moved when we copy and move it. We don' t move 1186 // A non-empty paragraph's style is moved when we copy and move it. We don' t move
1187 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style 1187 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style
1188 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later. 1188 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later.
1189 RefPtr<EditingStyle> styleInEmptyParagraph; 1189 RefPtr<EditingStyle> styleInEmptyParagraph;
(...skipping 23 matching lines...) Expand all
1213 // Must recononicalize these two VisiblePositions after the pruning above. 1213 // Must recononicalize these two VisiblePositions after the pruning above.
1214 beforeParagraph = VisiblePosition(beforeParagraph.deepEquivalent()); 1214 beforeParagraph = VisiblePosition(beforeParagraph.deepEquivalent());
1215 afterParagraph = VisiblePosition(afterParagraph.deepEquivalent()); 1215 afterParagraph = VisiblePosition(afterParagraph.deepEquivalent());
1216 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph == afterParagraph)) { 1216 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph == afterParagraph)) {
1217 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal. 1217 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal.
1218 insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquival ent()); 1218 insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquival ent());
1219 // Need an updateLayout here in case inserting the br has split a text n ode. 1219 // Need an updateLayout here in case inserting the br has split a text n ode.
1220 document().updateLayoutIgnorePendingStylesheets(); 1220 document().updateLayoutIgnorePendingStylesheets();
1221 } 1221 }
1222 1222
1223 RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositio nInNode(document().documentElement()), destination.deepEquivalent().parentAnchor edEquivalent())); 1223 RefPtrWillBeRawPtr<Range> startToDestinationRange(Range::create(document(), firstPositionInNode(document().documentElement()), destination.deepEquivalent(). parentAnchoredEquivalent()));
1224 destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true); 1224 destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
1225 1225
1226 setEndingSelection(VisibleSelection(destination, originalIsDirectional)); 1226 setEndingSelection(VisibleSelection(destination, originalIsDirectional));
1227 ASSERT(endingSelection().isCaretOrRange()); 1227 ASSERT(endingSelection().isCaretOrRange());
1228 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph; 1228 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph;
1229 if (!preserveStyle) 1229 if (!preserveStyle)
1230 options |= ReplaceSelectionCommand::MatchStyle; 1230 options |= ReplaceSelectionCommand::MatchStyle;
1231 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options)); 1231 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options));
1232 1232
1233 document().frame()->spellChecker().markMisspellingsAndBadGrammar(endingSelec tion()); 1233 document().frame()->spellChecker().markMisspellingsAndBadGrammar(endingSelec tion());
1234 1234
1235 // If the selection is in an empty paragraph, restore styles from the old em pty paragraph to the new empty paragraph. 1235 // If the selection is in an empty paragraph, restore styles from the old em pty paragraph to the new empty paragraph.
1236 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar agraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().v isibleStart()); 1236 bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfPar agraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().v isibleStart());
1237 if (styleInEmptyParagraph && selectionIsEmptyParagraph) 1237 if (styleInEmptyParagraph && selectionIsEmptyParagraph)
1238 applyStyle(styleInEmptyParagraph.get()); 1238 applyStyle(styleInEmptyParagraph.get());
1239 1239
1240 if (preserveSelection && startIndex != -1) { 1240 if (preserveSelection && startIndex != -1) {
1241 if (Element* documentElement = document().documentElement()) { 1241 if (Element* documentElement = document().documentElement()) {
1242 // Fragment creation (using createMarkup) incorrectly uses regular 1242 // Fragment creation (using createMarkup) incorrectly uses regular
1243 // spaces instead of nbsps for some spaces that were rendered (11475 ), which 1243 // spaces instead of nbsps for some spaces that were rendered (11475 ), which
1244 // causes spaces to be collapsed during the move operation. This res ults 1244 // causes spaces to be collapsed during the move operation. This res ults
1245 // in a call to rangeFromLocationAndLength with a location past the end 1245 // in a call to rangeFromLocationAndLength with a location past the end
1246 // of the document (which will return null). 1246 // of the document (which will return null).
1247 RefPtr<Range> start = PlainTextRange(destinationIndex + startIndex). createRangeForSelection(*documentElement); 1247 RefPtrWillBeRawPtr<Range> start = PlainTextRange(destinationIndex + startIndex).createRangeForSelection(*documentElement);
1248 RefPtr<Range> end = PlainTextRange(destinationIndex + endIndex).crea teRangeForSelection(*documentElement); 1248 RefPtrWillBeRawPtr<Range> end = PlainTextRange(destinationIndex + en dIndex).createRangeForSelection(*documentElement);
1249 if (start && end) 1249 if (start && end)
1250 setEndingSelection(VisibleSelection(start->startPosition(), end- >startPosition(), DOWNSTREAM, originalIsDirectional)); 1250 setEndingSelection(VisibleSelection(start->startPosition(), end- >startPosition(), DOWNSTREAM, originalIsDirectional));
1251 } 1251 }
1252 } 1252 }
1253 } 1253 }
1254 1254
1255 // FIXME: Send an appropriate shouldDeleteRange call. 1255 // FIXME: Send an appropriate shouldDeleteRange call.
1256 bool CompositeEditCommand::breakOutOfEmptyListItem() 1256 bool CompositeEditCommand::breakOutOfEmptyListItem()
1257 { 1257 {
1258 RefPtr<Node> emptyListItem = enclosingEmptyListItem(endingSelection().visibl eStart()); 1258 RefPtr<Node> emptyListItem = enclosingEmptyListItem(endingSelection().visibl eStart());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 return node.release(); 1460 return node.release();
1461 } 1461 }
1462 1462
1463 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) 1463 PassRefPtr<Element> createBlockPlaceholderElement(Document& document)
1464 { 1464 {
1465 RefPtr<Element> breakNode = document.createElement(brTag, false); 1465 RefPtr<Element> breakNode = document.createElement(brTag, false);
1466 return breakNode.release(); 1466 return breakNode.release();
1467 } 1467 }
1468 1468
1469 } // namespace WebCore 1469 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698