OLD | NEW |
---|---|
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 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 startIndex = 0; | 1275 startIndex = 0; |
1276 if (startInParagraph) | 1276 if (startInParagraph) |
1277 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true); | 1277 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true); |
1278 | 1278 |
1279 endIndex = 0; | 1279 endIndex = 0; |
1280 if (endInParagraph) | 1280 if (endInParagraph) |
1281 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true); | 1281 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true); |
1282 } | 1282 } |
1283 } | 1283 } |
1284 | 1284 |
1285 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary); | 1285 // Create a temporary Range to keep track of the "hole" left by moving away the paragraph. |
1286 VisiblePosition afterParagraph = nextPositionOf(endOfParagraphToMove, Cannot CrossEditingBoundary); | 1286 Position beforeParagraphPos = previousPositionOf(startOfParagraphToMove, Can notCrossEditingBoundary).deepEquivalent(); |
1287 Range* beforeParagraphTempRange = beforeParagraphPos.isNull() ? nullptr : Ra nge::create(document(), beforeParagraphPos, beforeParagraphPos); | |
yosin_UTC9
2016/07/06 01:52:25
The rule is when we use temporary range, it should
| |
1288 | |
1289 Position afterParagraphPos = nextPositionOf(endOfParagraphToMove, CannotCros sEditingBoundary).deepEquivalent(); | |
1290 Range* afterParagraphTempRange = afterParagraphPos.isNull() ? nullptr : Rang e::create(document(), afterParagraphPos, afterParagraphPos); | |
1287 | 1291 |
1288 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. | 1292 // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move. |
1289 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. | 1293 // When we paste a fragment, spaces after the end and before the start are t reated as though they were rendered. |
1290 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent()); | 1294 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival ent()); |
1291 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent ()); | 1295 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent ()); |
1292 | 1296 |
1293 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It | 1297 // FIXME: This is an inefficient way to preserve style on nodes in the parag raph to move. It |
1294 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. | 1298 // shouldn't matter though, since moved paragraphs will usually be quite sma ll. |
1295 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO fParagraphToMove.deepEquivalent() ? | 1299 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO fParagraphToMove.deepEquivalent() ? |
1296 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ; | 1300 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr ; |
(...skipping 23 matching lines...) Expand all Loading... | |
1320 return; | 1324 return; |
1321 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat ion; | 1325 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat ion; |
1322 | 1326 |
1323 // Add a br if pruning an empty block level element caused a collapse. For e xample: | 1327 // Add a br if pruning an empty block level element caused a collapse. For e xample: |
1324 // foo^ | 1328 // foo^ |
1325 // <div>bar</div> | 1329 // <div>bar</div> |
1326 // baz | 1330 // baz |
1327 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That would | 1331 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That would |
1328 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br . | 1332 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br . |
1329 // Must recononicalize these two VisiblePositions after the pruning above. | 1333 // Must recononicalize these two VisiblePositions after the pruning above. |
1330 beforeParagraph = createVisiblePosition(beforeParagraph.deepEquivalent()); | 1334 VisiblePosition beforeParagraph = beforeParagraphTempRange ? createVisiblePo sition(beforeParagraphTempRange->startPosition()) : VisiblePosition(); |
1331 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent()); | 1335 VisiblePosition afterParagraph = afterParagraphTempRange ? createVisiblePosi tion(afterParagraphTempRange->startPosition()) : VisiblePosition(); |
1332 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { | 1336 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be foreParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { |
1333 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal. | 1337 // FIXME: Trim text between beforeParagraph and afterParagraph if they a ren't equal. |
1334 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui valent(), editingState); | 1338 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui valent(), editingState); |
1335 if (editingState->isAborted()) | 1339 if (editingState->isAborted()) |
1336 return; | 1340 return; |
1337 // Need an updateLayout here in case inserting the br has split a text n ode. | 1341 // Need an updateLayout here in case inserting the br has split a text n ode. |
1338 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1342 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
1339 } | 1343 } |
1340 | 1344 |
1341 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d ocument().documentElement()), destination.toParentAnchoredPosition(), true); | 1345 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d ocument().documentElement()), destination.toParentAnchoredPosition(), true); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1618 } | 1622 } |
1619 | 1623 |
1620 DEFINE_TRACE(CompositeEditCommand) | 1624 DEFINE_TRACE(CompositeEditCommand) |
1621 { | 1625 { |
1622 visitor->trace(m_commands); | 1626 visitor->trace(m_commands); |
1623 visitor->trace(m_composition); | 1627 visitor->trace(m_composition); |
1624 EditCommand::trace(visitor); | 1628 EditCommand::trace(visitor); |
1625 } | 1629 } |
1626 | 1630 |
1627 } // namespace blink | 1631 } // namespace blink |
OLD | NEW |