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

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

Issue 23467007: Have Range constructor take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 markers.reserveCapacity(arraySize); 512 markers.reserveCapacity(arraySize);
513 for (size_t i = 0; i < arraySize; ++i) 513 for (size_t i = 0; i < arraySize; ++i)
514 markers.append(*markerPointers[i]); 514 markers.append(*markerPointers[i]);
515 } 515 }
516 516
517 void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p rpNode, unsigned offset, unsigned count, const String& replacementText) 517 void CompositeEditCommand::replaceTextInNodePreservingMarkers(PassRefPtr<Text> p rpNode, unsigned offset, unsigned count, const String& replacementText)
518 { 518 {
519 RefPtr<Text> node(prpNode); 519 RefPtr<Text> node(prpNode);
520 DocumentMarkerController* markerController = document().markers(); 520 DocumentMarkerController* markerController = document().markers();
521 Vector<DocumentMarker> markers; 521 Vector<DocumentMarker> markers;
522 copyMarkers(markerController->markersInRange(Range::create(&document(), node .get(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()) , markers); 522 copyMarkers(markerController->markersInRange(Range::create(document(), node. get(), offset, node.get(), offset + count).get(), DocumentMarker::AllMarkers()), markers);
523 replaceTextInNode(node, offset, count, replacementText); 523 replaceTextInNode(node, offset, count, replacementText);
524 RefPtr<Range> newRange = Range::create(&document(), node.get(), offset, node .get(), offset + replacementText.length()); 524 RefPtr<Range> newRange = Range::create(document(), node.get(), offset, node. get(), offset + replacementText.length());
525 for (size_t i = 0; i < markers.size(); ++i) 525 for (size_t i = 0; i < markers.size(); ++i)
526 markerController->addMarker(newRange.get(), markers[i].type(), markers[i ].description()); 526 markerController->addMarker(newRange.get(), markers[i].type(), markers[i ].description());
527 } 527 }
528 528
529 Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos) 529 Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos)
530 { 530 {
531 if (!isTabSpanTextNode(pos.anchorNode())) 531 if (!isTabSpanTextNode(pos.anchorNode()))
532 return pos; 532 return pos;
533 533
534 switch (pos.anchorType()) { 534 switch (pos.anchorType()) {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 1152
1153 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0; 1153 bool startAfterParagraph = comparePositions(visibleStart, endOfParagraph ToMove) > 0;
1154 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0; 1154 bool endBeforeParagraph = comparePositions(visibleEnd, startOfParagraphT oMove) < 0;
1155 1155
1156 if (!startAfterParagraph && !endBeforeParagraph) { 1156 if (!startAfterParagraph && !endBeforeParagraph) {
1157 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0; 1157 bool startInParagraph = comparePositions(visibleStart, startOfParagr aphToMove) >= 0;
1158 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0; 1158 bool endInParagraph = comparePositions(visibleEnd, endOfParagraphToM ove) <= 0;
1159 1159
1160 startIndex = 0; 1160 startIndex = 0;
1161 if (startInParagraph) { 1161 if (startInParagraph) {
1162 RefPtr<Range> startRange = Range::create(&document(), startOfPar agraphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquiv alent().parentAnchoredEquivalent()); 1162 RefPtr<Range> startRange = Range::create(document(), startOfPara graphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleStart.deepEquiva lent().parentAnchoredEquivalent());
1163 startIndex = TextIterator::rangeLength(startRange.get(), true); 1163 startIndex = TextIterator::rangeLength(startRange.get(), true);
1164 } 1164 }
1165 1165
1166 endIndex = 0; 1166 endIndex = 0;
1167 if (endInParagraph) { 1167 if (endInParagraph) {
1168 RefPtr<Range> endRange = Range::create(&document(), startOfParag raphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalen t().parentAnchoredEquivalent()); 1168 RefPtr<Range> endRange = Range::create(document(), startOfParagr aphToMove.deepEquivalent().parentAnchoredEquivalent(), visibleEnd.deepEquivalent ().parentAnchoredEquivalent());
1169 endIndex = TextIterator::rangeLength(endRange.get(), true); 1169 endIndex = TextIterator::rangeLength(endRange.get(), true);
1170 } 1170 }
1171 } 1171 }
1172 } 1172 }
1173 1173
1174 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCros sEditingBoundary); 1174 VisiblePosition beforeParagraph = startOfParagraphToMove.previous(CannotCros sEditingBoundary);
1175 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary)); 1175 VisiblePosition afterParagraph(endOfParagraphToMove.next(CannotCrossEditingB oundary));
1176 1176
1177 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. 1177 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
1178 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. 1178 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered.
1179 Position start = startOfParagraphToMove.deepEquivalent().downstream(); 1179 Position start = startOfParagraphToMove.deepEquivalent().downstream();
1180 Position end = endOfParagraphToMove.deepEquivalent().upstream(); 1180 Position end = endOfParagraphToMove.deepEquivalent().upstream();
1181 1181
1182 // start and end can't be used directly to create a Range; they are "editing positions" 1182 // start and end can't be used directly to create a Range; they are "editing positions"
1183 Position startRangeCompliant = start.parentAnchoredEquivalent(); 1183 Position startRangeCompliant = start.parentAnchoredEquivalent();
1184 Position endRangeCompliant = end.parentAnchoredEquivalent(); 1184 Position endRangeCompliant = end.parentAnchoredEquivalent();
1185 RefPtr<Range> range = Range::create(&document(), startRangeCompliant.depreca tedNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.depr ecatedNode(), endRangeCompliant.deprecatedEditingOffset()); 1185 RefPtr<Range> range = Range::create(document(), startRangeCompliant.deprecat edNode(), startRangeCompliant.deprecatedEditingOffset(), endRangeCompliant.depre catedNode(), endRangeCompliant.deprecatedEditingOffset());
1186 1186
1187 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It 1187 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It
1188 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. 1188 // shouldn't matter though, since moved paragraphs will usually be quite sma ll.
1189 RefPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraph ToMove ? 1189 RefPtr<DocumentFragment> fragment = startOfParagraphToMove != endOfParagraph ToMove ?
1190 createFragmentFromMarkup(&document(), createMarkup(range.get(), 0, DoNot AnnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : 0; 1190 createFragmentFromMarkup(&document(), createMarkup(range.get(), 0, DoNot AnnotateForInterchange, true, DoNotResolveURLs, constrainingAncestor), "") : 0;
1191 1191
1192 // A non-empty paragraph's style is moved when we copy and move it. We don' t move 1192 // A non-empty paragraph's style is moved when we copy and move it. We don' t move
1193 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style 1193 // anything if we're given an empty paragraph, but an empty paragraph can ha ve style
1194 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later. 1194 // too, <div><b><br></b></div> for example. Save it so that we can preserve it later.
1195 RefPtr<EditingStyle> styleInEmptyParagraph; 1195 RefPtr<EditingStyle> styleInEmptyParagraph;
(...skipping 23 matching lines...) Expand all
1219 // Must recononicalize these two VisiblePositions after the pruning above. 1219 // Must recononicalize these two VisiblePositions after the pruning above.
1220 beforeParagraph = VisiblePosition(beforeParagraph.deepEquivalent()); 1220 beforeParagraph = VisiblePosition(beforeParagraph.deepEquivalent());
1221 afterParagraph = VisiblePosition(afterParagraph.deepEquivalent()); 1221 afterParagraph = VisiblePosition(afterParagraph.deepEquivalent());
1222 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph == afterParagraph)) { 1222 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph == afterParagraph)) {
1223 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal. 1223 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal.
1224 insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquival ent()); 1224 insertNodeAt(createBreakElement(document()), beforeParagraph.deepEquival ent());
1225 // Need an updateLayout here in case inserting the br has split a text n ode. 1225 // Need an updateLayout here in case inserting the br has split a text n ode.
1226 document().updateLayoutIgnorePendingStylesheets(); 1226 document().updateLayoutIgnorePendingStylesheets();
1227 } 1227 }
1228 1228
1229 RefPtr<Range> startToDestinationRange(Range::create(&document(), firstPositi onInNode(document().documentElement()), destination.deepEquivalent().parentAncho redEquivalent())); 1229 RefPtr<Range> startToDestinationRange(Range::create(document(), firstPositio nInNode(document().documentElement()), destination.deepEquivalent().parentAnchor edEquivalent()));
1230 destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true); 1230 destinationIndex = TextIterator::rangeLength(startToDestinationRange.get(), true);
1231 1231
1232 setEndingSelection(VisibleSelection(destination, originalIsDirectional)); 1232 setEndingSelection(VisibleSelection(destination, originalIsDirectional));
1233 ASSERT(endingSelection().isCaretOrRange()); 1233 ASSERT(endingSelection().isCaretOrRange());
1234 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph; 1234 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::MovingParagraph;
1235 if (!preserveStyle) 1235 if (!preserveStyle)
1236 options |= ReplaceSelectionCommand::MatchStyle; 1236 options |= ReplaceSelectionCommand::MatchStyle;
1237 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options)); 1237 applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment , options));
1238 1238
1239 document().frame()->editor().markMisspellingsAndBadGrammar(endingSelection() ); 1239 document().frame()->editor().markMisspellingsAndBadGrammar(endingSelection() );
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 return node.release(); 1464 return node.release();
1465 } 1465 }
1466 1466
1467 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) 1467 PassRefPtr<Element> createBlockPlaceholderElement(Document& document)
1468 { 1468 {
1469 RefPtr<Element> breakNode = document.createElement(brTag, false); 1469 RefPtr<Element> breakNode = document.createElement(brTag, false);
1470 return breakNode.release(); 1470 return breakNode.release();
1471 } 1471 }
1472 1472
1473 } // namespace WebCore 1473 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698