| 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 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 ((!isEndOfParagraph(beforeParagraph) && | 1475 ((!isEndOfParagraph(beforeParagraph) && |
| 1476 !isStartOfParagraph(beforeParagraph)) || | 1476 !isStartOfParagraph(beforeParagraph)) || |
| 1477 beforeParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { | 1477 beforeParagraph.deepEquivalent() == afterParagraph.deepEquivalent())) { |
| 1478 // FIXME: Trim text between beforeParagraph and afterParagraph if they | 1478 // FIXME: Trim text between beforeParagraph and afterParagraph if they |
| 1479 // aren't equal. | 1479 // aren't equal. |
| 1480 insertNodeAt(HTMLBRElement::create(document()), | 1480 insertNodeAt(HTMLBRElement::create(document()), |
| 1481 beforeParagraph.deepEquivalent(), editingState); | 1481 beforeParagraph.deepEquivalent(), editingState); |
| 1482 } | 1482 } |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 // TODO(xiaochengh): Ensure valid VisiblePositions are passed to this function. | |
| 1486 void CompositeEditCommand::moveParagraph( | 1485 void CompositeEditCommand::moveParagraph( |
| 1487 const VisiblePosition& startOfParagraphToMove, | 1486 const VisiblePosition& startOfParagraphToMove, |
| 1488 const VisiblePosition& endOfParagraphToMove, | 1487 const VisiblePosition& endOfParagraphToMove, |
| 1489 const VisiblePosition& destination, | 1488 const VisiblePosition& destination, |
| 1490 EditingState* editingState, | 1489 EditingState* editingState, |
| 1491 ShouldPreserveSelection shouldPreserveSelection, | 1490 ShouldPreserveSelection shouldPreserveSelection, |
| 1492 ShouldPreserveStyle shouldPreserveStyle, | 1491 ShouldPreserveStyle shouldPreserveStyle, |
| 1493 Node* constrainingAncestor) { | 1492 Node* constrainingAncestor) { |
| 1494 DCHECK(isStartOfParagraphDeprecated(startOfParagraphToMove)) | 1493 DCHECK(!document().needsLayoutTreeUpdate()); |
| 1495 << startOfParagraphToMove; | 1494 DCHECK(isStartOfParagraph(startOfParagraphToMove)) << startOfParagraphToMove; |
| 1496 DCHECK(isEndOfParagraphDeprecated(endOfParagraphToMove)) | 1495 DCHECK(isEndOfParagraph(endOfParagraphToMove)) << endOfParagraphToMove; |
| 1497 << endOfParagraphToMove; | |
| 1498 moveParagraphs(startOfParagraphToMove, endOfParagraphToMove, destination, | 1496 moveParagraphs(startOfParagraphToMove, endOfParagraphToMove, destination, |
| 1499 editingState, shouldPreserveSelection, shouldPreserveStyle, | 1497 editingState, shouldPreserveSelection, shouldPreserveStyle, |
| 1500 constrainingAncestor); | 1498 constrainingAncestor); |
| 1501 } | 1499 } |
| 1502 | 1500 |
| 1503 // TODO(xiaochengh): Ensure valid VisiblePositions are passed to this function, | |
| 1504 // and do proper recalculation after mutations so that they are still valid when | |
| 1505 // being used. | |
| 1506 void CompositeEditCommand::moveParagraphs( | 1501 void CompositeEditCommand::moveParagraphs( |
| 1507 const VisiblePosition& startOfParagraphToMove, | 1502 const VisiblePosition& startOfParagraphToMove, |
| 1508 const VisiblePosition& endOfParagraphToMove, | 1503 const VisiblePosition& endOfParagraphToMove, |
| 1509 const VisiblePosition& destination, | 1504 const VisiblePosition& destination, |
| 1510 EditingState* editingState, | 1505 EditingState* editingState, |
| 1511 ShouldPreserveSelection shouldPreserveSelection, | 1506 ShouldPreserveSelection shouldPreserveSelection, |
| 1512 ShouldPreserveStyle shouldPreserveStyle, | 1507 ShouldPreserveStyle shouldPreserveStyle, |
| 1513 Node* constrainingAncestor) { | 1508 Node* constrainingAncestor) { |
| 1509 DCHECK(!document().needsLayoutTreeUpdate()); |
| 1514 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent() || | 1510 if (startOfParagraphToMove.deepEquivalent() == destination.deepEquivalent() || |
| 1515 startOfParagraphToMove.isNull()) | 1511 startOfParagraphToMove.isNull()) |
| 1516 return; | 1512 return; |
| 1517 | 1513 |
| 1518 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 1519 | |
| 1520 int startIndex = -1; | 1514 int startIndex = -1; |
| 1521 int endIndex = -1; | 1515 int endIndex = -1; |
| 1522 int destinationIndex = -1; | 1516 int destinationIndex = -1; |
| 1523 bool originalIsDirectional = endingSelection().isDirectional(); | 1517 bool originalIsDirectional = endingSelection().isDirectional(); |
| 1524 if (shouldPreserveSelection == PreserveSelection && | 1518 if (shouldPreserveSelection == PreserveSelection && |
| 1525 !endingSelection().isNone()) { | 1519 !endingSelection().isNone()) { |
| 1526 VisiblePosition visibleStart = endingSelection().visibleStart(); | 1520 VisiblePosition visibleStart = endingSelection().visibleStart(); |
| 1527 VisiblePosition visibleEnd = endingSelection().visibleEnd(); | 1521 VisiblePosition visibleEnd = endingSelection().visibleEnd(); |
| 1528 | 1522 |
| 1529 bool startAfterParagraph = | 1523 bool startAfterParagraph = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1545 | 1539 |
| 1546 endIndex = 0; | 1540 endIndex = 0; |
| 1547 if (endInParagraph) | 1541 if (endInParagraph) |
| 1548 endIndex = TextIterator::rangeLength( | 1542 endIndex = TextIterator::rangeLength( |
| 1549 startOfParagraphToMove.toParentAnchoredPosition(), | 1543 startOfParagraphToMove.toParentAnchoredPosition(), |
| 1550 visibleEnd.toParentAnchoredPosition(), true); | 1544 visibleEnd.toParentAnchoredPosition(), true); |
| 1551 } | 1545 } |
| 1552 } | 1546 } |
| 1553 | 1547 |
| 1554 RelocatablePosition beforeParagraphPosition( | 1548 RelocatablePosition beforeParagraphPosition( |
| 1555 previousPositionOfDeprecated(startOfParagraphToMove, | 1549 previousPositionOf(startOfParagraphToMove, CannotCrossEditingBoundary) |
| 1556 CannotCrossEditingBoundary) | |
| 1557 .deepEquivalent()); | 1550 .deepEquivalent()); |
| 1558 RelocatablePosition afterParagraphPosition( | 1551 RelocatablePosition afterParagraphPosition( |
| 1559 nextPositionOfDeprecated(endOfParagraphToMove, CannotCrossEditingBoundary) | 1552 nextPositionOf(endOfParagraphToMove, CannotCrossEditingBoundary) |
| 1560 .deepEquivalent()); | 1553 .deepEquivalent()); |
| 1561 | 1554 |
| 1562 // We upstream() the end and downstream() the start so that we don't include | 1555 // We upstream() the end and downstream() the start so that we don't include |
| 1563 // collapsed whitespace in the move. When we paste a fragment, spaces after | 1556 // collapsed whitespace in the move. When we paste a fragment, spaces after |
| 1564 // the end and before the start are treated as though they were rendered. | 1557 // the end and before the start are treated as though they were rendered. |
| 1565 Position start = | 1558 Position start = |
| 1566 mostForwardCaretPosition(startOfParagraphToMove.deepEquivalent()); | 1559 mostForwardCaretPosition(startOfParagraphToMove.deepEquivalent()); |
| 1567 Position end = | 1560 Position end = |
| 1568 mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent()); | 1561 mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent()); |
| 1569 | 1562 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 return; | 1637 return; |
| 1645 } | 1638 } |
| 1646 | 1639 |
| 1647 // TextIterator::rangeLength requires clean layout. | 1640 // TextIterator::rangeLength requires clean layout. |
| 1648 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1641 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1649 | 1642 |
| 1650 destinationIndex = TextIterator::rangeLength( | 1643 destinationIndex = TextIterator::rangeLength( |
| 1651 Position::firstPositionInNode(document().documentElement()), | 1644 Position::firstPositionInNode(document().documentElement()), |
| 1652 destination.toParentAnchoredPosition(), true); | 1645 destination.toParentAnchoredPosition(), true); |
| 1653 | 1646 |
| 1654 VisibleSelection destinationSelection = | 1647 VisibleSelection destinationSelection = createVisibleSelection( |
| 1655 createVisibleSelectionDeprecated(destination, originalIsDirectional); | 1648 destination.toPositionWithAffinity(), originalIsDirectional); |
| 1656 if (endingSelection().isNone()) { | 1649 if (endingSelection().isNone()) { |
| 1657 // We abort executing command since |destination| becomes invisible. | 1650 // We abort executing command since |destination| becomes invisible. |
| 1658 editingState->abort(); | 1651 editingState->abort(); |
| 1659 return; | 1652 return; |
| 1660 } | 1653 } |
| 1661 setEndingSelection(destinationSelection); | 1654 setEndingSelection(destinationSelection); |
| 1662 ReplaceSelectionCommand::CommandOptions options = | 1655 ReplaceSelectionCommand::CommandOptions options = |
| 1663 ReplaceSelectionCommand::SelectReplacement | | 1656 ReplaceSelectionCommand::SelectReplacement | |
| 1664 ReplaceSelectionCommand::MovingParagraph; | 1657 ReplaceSelectionCommand::MovingParagraph; |
| 1665 if (shouldPreserveStyle == DoNotPreserveStyle) | 1658 if (shouldPreserveStyle == DoNotPreserveStyle) |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 return node; | 2014 return node; |
| 2022 } | 2015 } |
| 2023 | 2016 |
| 2024 DEFINE_TRACE(CompositeEditCommand) { | 2017 DEFINE_TRACE(CompositeEditCommand) { |
| 2025 visitor->trace(m_commands); | 2018 visitor->trace(m_commands); |
| 2026 visitor->trace(m_composition); | 2019 visitor->trace(m_composition); |
| 2027 EditCommand::trace(visitor); | 2020 EditCommand::trace(visitor); |
| 2028 } | 2021 } |
| 2029 | 2022 |
| 2030 } // namespace blink | 2023 } // namespace blink |
| OLD | NEW |