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 18 matching lines...) Expand all Loading... |
29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
31 #include "core/dom/DocumentFragment.h" | 31 #include "core/dom/DocumentFragment.h" |
32 #include "core/dom/ElementTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
33 #include "core/dom/NodeTraversal.h" | 33 #include "core/dom/NodeTraversal.h" |
34 #include "core/dom/Range.h" | 34 #include "core/dom/Range.h" |
35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
36 #include "core/editing/EditingUtilities.h" | 36 #include "core/editing/EditingUtilities.h" |
37 #include "core/editing/Editor.h" | 37 #include "core/editing/Editor.h" |
38 #include "core/editing/PlainTextRange.h" | 38 #include "core/editing/PlainTextRange.h" |
| 39 #include "core/editing/RelocatablePosition.h" |
39 #include "core/editing/VisibleUnits.h" | 40 #include "core/editing/VisibleUnits.h" |
40 #include "core/editing/commands/AppendNodeCommand.h" | 41 #include "core/editing/commands/AppendNodeCommand.h" |
41 #include "core/editing/commands/ApplyStyleCommand.h" | 42 #include "core/editing/commands/ApplyStyleCommand.h" |
42 #include "core/editing/commands/DeleteFromTextNodeCommand.h" | 43 #include "core/editing/commands/DeleteFromTextNodeCommand.h" |
43 #include "core/editing/commands/DeleteSelectionCommand.h" | 44 #include "core/editing/commands/DeleteSelectionCommand.h" |
44 #include "core/editing/commands/InsertIntoTextNodeCommand.h" | 45 #include "core/editing/commands/InsertIntoTextNodeCommand.h" |
45 #include "core/editing/commands/InsertLineBreakCommand.h" | 46 #include "core/editing/commands/InsertLineBreakCommand.h" |
46 #include "core/editing/commands/InsertNodeBeforeCommand.h" | 47 #include "core/editing/commands/InsertNodeBeforeCommand.h" |
47 #include "core/editing/commands/InsertParagraphSeparatorCommand.h" | 48 #include "core/editing/commands/InsertParagraphSeparatorCommand.h" |
48 #include "core/editing/commands/MergeIdenticalElementsCommand.h" | 49 #include "core/editing/commands/MergeIdenticalElementsCommand.h" |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 startIndex = 0; | 1276 startIndex = 0; |
1276 if (startInParagraph) | 1277 if (startInParagraph) |
1277 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to
ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true); | 1278 startIndex = TextIterator::rangeLength(startOfParagraphToMove.to
ParentAnchoredPosition(), visibleStart.toParentAnchoredPosition(), true); |
1278 | 1279 |
1279 endIndex = 0; | 1280 endIndex = 0; |
1280 if (endInParagraph) | 1281 if (endInParagraph) |
1281 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa
rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true); | 1282 endIndex = TextIterator::rangeLength(startOfParagraphToMove.toPa
rentAnchoredPosition(), visibleEnd.toParentAnchoredPosition(), true); |
1282 } | 1283 } |
1283 } | 1284 } |
1284 | 1285 |
1285 VisiblePosition beforeParagraph = previousPositionOf(startOfParagraphToMove,
CannotCrossEditingBoundary); | 1286 RelocatablePosition beforeParagraphPosition(previousPositionOf(startOfParagr
aphToMove, CannotCrossEditingBoundary).deepEquivalent()); |
1286 VisiblePosition afterParagraph = nextPositionOf(endOfParagraphToMove, Cannot
CrossEditingBoundary); | 1287 RelocatablePosition afterParagraphPosition(nextPositionOf(endOfParagraphToMo
ve, CannotCrossEditingBoundary).deepEquivalent()); |
1287 | 1288 |
1288 // We upstream() the end and downstream() the start so that we don't include
collapsed whitespace in the move. | 1289 // 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. | 1290 // 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()); | 1291 Position start = mostForwardCaretPosition(startOfParagraphToMove.deepEquival
ent()); |
1291 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent
()); | 1292 Position end = mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent
()); |
1292 | 1293 |
1293 // FIXME: This is an inefficient way to preserve style on nodes in the parag
raph to move. It | 1294 // 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. | 1295 // shouldn't matter though, since moved paragraphs will usually be quite sma
ll. |
1295 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO
fParagraphToMove.deepEquivalent() ? | 1296 DocumentFragment* fragment = startOfParagraphToMove.deepEquivalent() != endO
fParagraphToMove.deepEquivalent() ? |
1296 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq
uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert
BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr
; | 1297 createFragmentFromMarkup(document(), createMarkup(start.parentAnchoredEq
uivalent(), end.parentAnchoredEquivalent(), DoNotAnnotateForInterchange, Convert
BlocksToInlines::Convert, DoNotResolveURLs, constrainingAncestor), "") : nullptr
; |
(...skipping 23 matching lines...) Expand all Loading... |
1320 return; | 1321 return; |
1321 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat
ion; | 1322 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat
ion; |
1322 | 1323 |
1323 // Add a br if pruning an empty block level element caused a collapse. For e
xample: | 1324 // Add a br if pruning an empty block level element caused a collapse. For e
xample: |
1324 // foo^ | 1325 // foo^ |
1325 // <div>bar</div> | 1326 // <div>bar</div> |
1326 // baz | 1327 // baz |
1327 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That
would | 1328 // 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
. | 1329 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br
. |
1329 // Must recononicalize these two VisiblePositions after the pruning above. | 1330 // Must recononicalize these two VisiblePositions after the pruning above. |
1330 beforeParagraph = createVisiblePosition(beforeParagraph.deepEquivalent()); | 1331 VisiblePosition beforeParagraph = createVisiblePosition(beforeParagraphPosit
ion.position()); |
1331 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent()); | 1332 VisiblePosition afterParagraph = createVisiblePosition(afterParagraphPositio
n.position()); |
1332 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be
foreParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { | 1333 if (beforeParagraph.isNotNull() && (!isEndOfParagraph(beforeParagraph) || be
foreParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { |
1333 // FIXME: Trim text between beforeParagraph and afterParagraph if they a
ren't equal. | 1334 // FIXME: Trim text between beforeParagraph and afterParagraph if they a
ren't equal. |
1334 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui
valent(), editingState); | 1335 insertNodeAt(HTMLBRElement::create(document()), beforeParagraph.deepEqui
valent(), editingState); |
1335 if (editingState->isAborted()) | 1336 if (editingState->isAborted()) |
1336 return; | 1337 return; |
1337 // Need an updateLayout here in case inserting the br has split a text n
ode. | 1338 // Need an updateLayout here in case inserting the br has split a text n
ode. |
1338 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1339 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
1339 } | 1340 } |
1340 | 1341 |
1341 destinationIndex = TextIterator::rangeLength(Position::firstPositionInNode(d
ocument().documentElement()), destination.toParentAnchoredPosition(), true); | 1342 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 } | 1619 } |
1619 | 1620 |
1620 DEFINE_TRACE(CompositeEditCommand) | 1621 DEFINE_TRACE(CompositeEditCommand) |
1621 { | 1622 { |
1622 visitor->trace(m_commands); | 1623 visitor->trace(m_commands); |
1623 visitor->trace(m_composition); | 1624 visitor->trace(m_composition); |
1624 EditCommand::trace(visitor); | 1625 EditCommand::trace(visitor); |
1625 } | 1626 } |
1626 | 1627 |
1627 } // namespace blink | 1628 } // namespace blink |
OLD | NEW |