| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 m_commands.append(command); | 290 m_commands.append(command); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void CompositeEditCommand::applyCommandToComposite( | 293 void CompositeEditCommand::applyCommandToComposite( |
| 294 CompositeEditCommand* command, | 294 CompositeEditCommand* command, |
| 295 const VisibleSelection& selection, | 295 const VisibleSelection& selection, |
| 296 EditingState* editingState) { | 296 EditingState* editingState) { |
| 297 command->setParent(this); | 297 command->setParent(this); |
| 298 if (selection != command->endingSelection()) { | 298 if (selection != command->endingSelection()) { |
| 299 command->setStartingSelection(selection); | 299 command->setStartingSelection(selection); |
| 300 command->setEndingSelection(selection); | 300 command->setEndingVisibleSelection(selection); |
| 301 } | 301 } |
| 302 command->doApply(editingState); | 302 command->doApply(editingState); |
| 303 if (!editingState->isAborted()) | 303 if (!editingState->isAborted()) |
| 304 m_commands.append(command); | 304 m_commands.append(command); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void CompositeEditCommand::appendCommandToComposite( | 307 void CompositeEditCommand::appendCommandToComposite( |
| 308 CompositeEditCommand* command) { | 308 CompositeEditCommand* command) { |
| 309 ensureComposition()->append(command->ensureComposition()); | 309 ensureComposition()->append(command->ensureComposition()); |
| 310 command->m_composition = nullptr; | 310 command->m_composition = nullptr; |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 return newBlock; | 1235 return newBlock; |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 void CompositeEditCommand::pushAnchorElementDown(Element* anchorNode, | 1238 void CompositeEditCommand::pushAnchorElementDown(Element* anchorNode, |
| 1239 EditingState* editingState) { | 1239 EditingState* editingState) { |
| 1240 if (!anchorNode) | 1240 if (!anchorNode) |
| 1241 return; | 1241 return; |
| 1242 | 1242 |
| 1243 DCHECK(anchorNode->isLink()) << anchorNode; | 1243 DCHECK(anchorNode->isLink()) << anchorNode; |
| 1244 | 1244 |
| 1245 setEndingSelection(createVisibleSelection( | 1245 setEndingSelection( |
| 1246 SelectionInDOMTree::Builder().selectAllChildren(*anchorNode).build())); | 1246 SelectionInDOMTree::Builder().selectAllChildren(*anchorNode).build()); |
| 1247 applyStyledElement(anchorNode, editingState); | 1247 applyStyledElement(anchorNode, editingState); |
| 1248 if (editingState->isAborted()) | 1248 if (editingState->isAborted()) |
| 1249 return; | 1249 return; |
| 1250 // Clones of anchorNode have been pushed down, now remove it. | 1250 // Clones of anchorNode have been pushed down, now remove it. |
| 1251 if (anchorNode->isConnected()) | 1251 if (anchorNode->isConnected()) |
| 1252 removeNodePreservingChildren(anchorNode, editingState); | 1252 removeNodePreservingChildren(anchorNode, editingState); |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 // Clone the paragraph between start and end under blockElement, | 1255 // Clone the paragraph between start and end under blockElement, |
| 1256 // preserving the hierarchy up to outerNode. | 1256 // preserving the hierarchy up to outerNode. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 startOfParagraphToMove.deepEquivalent() == | 1430 startOfParagraphToMove.deepEquivalent() == |
| 1431 endOfParagraphToMove.deepEquivalent() | 1431 endOfParagraphToMove.deepEquivalent() |
| 1432 ? start | 1432 ? start |
| 1433 : mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent()); | 1433 : mostBackwardCaretPosition(endOfParagraphToMove.deepEquivalent()); |
| 1434 if (comparePositions(start, end) > 0) | 1434 if (comparePositions(start, end) > 0) |
| 1435 end = start; | 1435 end = start; |
| 1436 | 1436 |
| 1437 cloneParagraphUnderNewElement(start, end, outerNode, blockElement, | 1437 cloneParagraphUnderNewElement(start, end, outerNode, blockElement, |
| 1438 editingState); | 1438 editingState); |
| 1439 | 1439 |
| 1440 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1440 setEndingSelection( |
| 1441 | 1441 SelectionInDOMTree::Builder().collapse(start).extend(end).build()); |
| 1442 setEndingSelection(createVisibleSelection( | |
| 1443 SelectionInDOMTree::Builder().collapse(start).extend(end).build())); | |
| 1444 deleteSelection(editingState, false, false, false); | 1442 deleteSelection(editingState, false, false, false); |
| 1445 if (editingState->isAborted()) | 1443 if (editingState->isAborted()) |
| 1446 return; | 1444 return; |
| 1447 | 1445 |
| 1448 // There are bugs in deletion when it removes a fully selected table/list. | 1446 // There are bugs in deletion when it removes a fully selected table/list. |
| 1449 // It expands and removes the entire table/list, but will let content | 1447 // It expands and removes the entire table/list, but will let content |
| 1450 // before and after the table/list collapse onto one line. | 1448 // before and after the table/list collapse onto one line. |
| 1451 | 1449 |
| 1452 cleanupAfterDeletion(editingState); | 1450 cleanupAfterDeletion(editingState); |
| 1453 if (editingState->isAborted()) | 1451 if (editingState->isAborted()) |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 styleInEmptyParagraph->mergeTypingStyle(&document()); | 1590 styleInEmptyParagraph->mergeTypingStyle(&document()); |
| 1593 // The moved paragraph should assume the block style of the destination. | 1591 // The moved paragraph should assume the block style of the destination. |
| 1594 styleInEmptyParagraph->removeBlockProperties(); | 1592 styleInEmptyParagraph->removeBlockProperties(); |
| 1595 } | 1593 } |
| 1596 | 1594 |
| 1597 // FIXME (5098931): We should add a new insert action | 1595 // FIXME (5098931): We should add a new insert action |
| 1598 // "WebViewInsertActionMoved" and call shouldInsertFragment here. | 1596 // "WebViewInsertActionMoved" and call shouldInsertFragment here. |
| 1599 | 1597 |
| 1600 DCHECK(!document().needsLayoutTreeUpdate()); | 1598 DCHECK(!document().needsLayoutTreeUpdate()); |
| 1601 | 1599 |
| 1602 setEndingSelection(createVisibleSelection( | 1600 setEndingSelection( |
| 1603 SelectionInDOMTree::Builder().collapse(start).extend(end).build())); | 1601 SelectionInDOMTree::Builder().collapse(start).extend(end).build()); |
| 1604 document() | 1602 document() |
| 1605 .frame() | 1603 .frame() |
| 1606 ->spellChecker() | 1604 ->spellChecker() |
| 1607 .clearMisspellingsAndBadGrammarForMovingParagraphs(endingSelection()); | 1605 .clearMisspellingsAndBadGrammarForMovingParagraphs(endingSelection()); |
| 1608 deleteSelection(editingState, false, false, false); | 1606 deleteSelection(editingState, false, false, false); |
| 1609 if (editingState->isAborted()) | 1607 if (editingState->isAborted()) |
| 1610 return; | 1608 return; |
| 1611 | 1609 |
| 1612 DCHECK(destination.deepEquivalent().isConnected()) << destination; | 1610 DCHECK(destination.deepEquivalent().isConnected()) << destination; |
| 1613 cleanupAfterDeletion(editingState, destination); | 1611 cleanupAfterDeletion(editingState, destination); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1641 return; | 1639 return; |
| 1642 } | 1640 } |
| 1643 | 1641 |
| 1644 // TextIterator::rangeLength requires clean layout. | 1642 // TextIterator::rangeLength requires clean layout. |
| 1645 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1643 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1646 | 1644 |
| 1647 destinationIndex = TextIterator::rangeLength( | 1645 destinationIndex = TextIterator::rangeLength( |
| 1648 Position::firstPositionInNode(document().documentElement()), | 1646 Position::firstPositionInNode(document().documentElement()), |
| 1649 destination.toParentAnchoredPosition(), true); | 1647 destination.toParentAnchoredPosition(), true); |
| 1650 | 1648 |
| 1651 VisibleSelection destinationSelection = | 1649 const SelectionInDOMTree& destinationSelection = |
| 1652 createVisibleSelection(SelectionInDOMTree::Builder() | 1650 SelectionInDOMTree::Builder() |
| 1653 .collapse(destination.toPositionWithAffinity()) | 1651 .collapse(destination.toPositionWithAffinity()) |
| 1654 .setIsDirectional(originalIsDirectional) | 1652 .setIsDirectional(originalIsDirectional) |
| 1655 .build()); | 1653 .build(); |
| 1656 if (endingSelection().isNone()) { | 1654 if (endingSelection().isNone()) { |
| 1657 // We abort executing command since |destination| becomes invisible. | 1655 // We abort executing command since |destination| becomes invisible. |
| 1658 editingState->abort(); | 1656 editingState->abort(); |
| 1659 return; | 1657 return; |
| 1660 } | 1658 } |
| 1661 setEndingSelection(destinationSelection); | 1659 setEndingSelection(destinationSelection); |
| 1662 ReplaceSelectionCommand::CommandOptions options = | 1660 ReplaceSelectionCommand::CommandOptions options = |
| 1663 ReplaceSelectionCommand::SelectReplacement | | 1661 ReplaceSelectionCommand::SelectReplacement | |
| 1664 ReplaceSelectionCommand::MovingParagraph; | 1662 ReplaceSelectionCommand::MovingParagraph; |
| 1665 if (shouldPreserveStyle == DoNotPreserveStyle) | 1663 if (shouldPreserveStyle == DoNotPreserveStyle) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 // to rangeFromLocationAndLength with a location past the end of the | 1702 // to rangeFromLocationAndLength with a location past the end of the |
| 1705 // document (which will return null). | 1703 // document (which will return null). |
| 1706 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex) | 1704 EphemeralRange startRange = PlainTextRange(destinationIndex + startIndex) |
| 1707 .createRangeForSelection(*documentElement); | 1705 .createRangeForSelection(*documentElement); |
| 1708 if (startRange.isNull()) | 1706 if (startRange.isNull()) |
| 1709 return; | 1707 return; |
| 1710 EphemeralRange endRange = PlainTextRange(destinationIndex + endIndex) | 1708 EphemeralRange endRange = PlainTextRange(destinationIndex + endIndex) |
| 1711 .createRangeForSelection(*documentElement); | 1709 .createRangeForSelection(*documentElement); |
| 1712 if (endRange.isNull()) | 1710 if (endRange.isNull()) |
| 1713 return; | 1711 return; |
| 1714 setEndingSelection( | 1712 setEndingSelection(SelectionInDOMTree::Builder() |
| 1715 createVisibleSelection(SelectionInDOMTree::Builder() | 1713 .collapse(startRange.startPosition()) |
| 1716 .collapse(startRange.startPosition()) | 1714 .extend(endRange.startPosition()) |
| 1717 .extend(endRange.startPosition()) | 1715 .setIsDirectional(originalIsDirectional) |
| 1718 .setIsDirectional(originalIsDirectional) | 1716 .build()); |
| 1719 .build())); | |
| 1720 } | 1717 } |
| 1721 | 1718 |
| 1722 // FIXME: Send an appropriate shouldDeleteRange call. | 1719 // FIXME: Send an appropriate shouldDeleteRange call. |
| 1723 bool CompositeEditCommand::breakOutOfEmptyListItem(EditingState* editingState) { | 1720 bool CompositeEditCommand::breakOutOfEmptyListItem(EditingState* editingState) { |
| 1724 DCHECK(!document().needsLayoutTreeUpdate()); | 1721 DCHECK(!document().needsLayoutTreeUpdate()); |
| 1725 Node* emptyListItem = | 1722 Node* emptyListItem = |
| 1726 enclosingEmptyListItem(endingSelection().visibleStart()); | 1723 enclosingEmptyListItem(endingSelection().visibleStart()); |
| 1727 if (!emptyListItem) | 1724 if (!emptyListItem) |
| 1728 return false; | 1725 return false; |
| 1729 | 1726 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 : listNode, | 1807 : listNode, |
| 1811 editingState); | 1808 editingState); |
| 1812 if (editingState->isAborted()) | 1809 if (editingState->isAborted()) |
| 1813 return false; | 1810 return false; |
| 1814 } | 1811 } |
| 1815 | 1812 |
| 1816 appendBlockPlaceholder(newBlock, editingState); | 1813 appendBlockPlaceholder(newBlock, editingState); |
| 1817 if (editingState->isAborted()) | 1814 if (editingState->isAborted()) |
| 1818 return false; | 1815 return false; |
| 1819 | 1816 |
| 1820 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1817 setEndingSelection(SelectionInDOMTree::Builder() |
| 1821 setEndingSelection(createVisibleSelection( | 1818 .collapse(Position::firstPositionInNode(newBlock)) |
| 1822 SelectionInDOMTree::Builder() | 1819 .setIsDirectional(endingSelection().isDirectional()) |
| 1823 .collapse(Position::firstPositionInNode(newBlock)) | 1820 .build()); |
| 1824 .setIsDirectional(endingSelection().isDirectional()) | |
| 1825 .build())); | |
| 1826 | 1821 |
| 1827 style->prepareToApplyAt(endingSelection().start()); | 1822 style->prepareToApplyAt(endingSelection().start()); |
| 1828 if (!style->isEmpty()) { | 1823 if (!style->isEmpty()) { |
| 1829 applyStyle(style, editingState); | 1824 applyStyle(style, editingState); |
| 1830 if (editingState->isAborted()) | 1825 if (editingState->isAborted()) |
| 1831 return false; | 1826 return false; |
| 1832 } | 1827 } |
| 1833 | 1828 |
| 1834 return true; | 1829 return true; |
| 1835 } | 1830 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 VisiblePosition atBR = VisiblePosition::beforeNode(br); | 1869 VisiblePosition atBR = VisiblePosition::beforeNode(br); |
| 1875 // If the br we inserted collapsed, for example: | 1870 // If the br we inserted collapsed, for example: |
| 1876 // foo<br><blockquote>...</blockquote> | 1871 // foo<br><blockquote>...</blockquote> |
| 1877 // insert a second one. | 1872 // insert a second one. |
| 1878 if (!isStartOfParagraph(atBR)) { | 1873 if (!isStartOfParagraph(atBR)) { |
| 1879 insertNodeBefore(HTMLBRElement::create(document()), br, editingState); | 1874 insertNodeBefore(HTMLBRElement::create(document()), br, editingState); |
| 1880 if (editingState->isAborted()) | 1875 if (editingState->isAborted()) |
| 1881 return false; | 1876 return false; |
| 1882 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 1877 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1883 } | 1878 } |
| 1884 setEndingSelection(createVisibleSelection( | 1879 setEndingSelection(SelectionInDOMTree::Builder() |
| 1885 SelectionInDOMTree::Builder() | 1880 .collapse(atBR.toPositionWithAffinity()) |
| 1886 .collapse(atBR.toPositionWithAffinity()) | 1881 .setIsDirectional(endingSelection().isDirectional()) |
| 1887 .setIsDirectional(endingSelection().isDirectional()) | 1882 .build()); |
| 1888 .build())); | |
| 1889 | 1883 |
| 1890 // If this is an empty paragraph there must be a line break here. | 1884 // If this is an empty paragraph there must be a line break here. |
| 1891 if (!lineBreakExistsAtVisiblePosition(caret)) | 1885 if (!lineBreakExistsAtVisiblePosition(caret)) |
| 1892 return false; | 1886 return false; |
| 1893 | 1887 |
| 1894 Position caretPos(mostForwardCaretPosition(caret.deepEquivalent())); | 1888 Position caretPos(mostForwardCaretPosition(caret.deepEquivalent())); |
| 1895 // A line break is either a br or a preserved newline. | 1889 // A line break is either a br or a preserved newline. |
| 1896 DCHECK(isHTMLBRElement(caretPos.anchorNode()) || | 1890 DCHECK(isHTMLBRElement(caretPos.anchorNode()) || |
| 1897 (caretPos.anchorNode()->isTextNode() && | 1891 (caretPos.anchorNode()->isTextNode() && |
| 1898 caretPos.anchorNode()->layoutObject()->style()->preserveNewline())) | 1892 caretPos.anchorNode()->layoutObject()->style()->preserveNewline())) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2032 return node; | 2026 return node; |
| 2033 } | 2027 } |
| 2034 | 2028 |
| 2035 DEFINE_TRACE(CompositeEditCommand) { | 2029 DEFINE_TRACE(CompositeEditCommand) { |
| 2036 visitor->trace(m_commands); | 2030 visitor->trace(m_commands); |
| 2037 visitor->trace(m_composition); | 2031 visitor->trace(m_composition); |
| 2038 EditCommand::trace(visitor); | 2032 EditCommand::trace(visitor); |
| 2039 } | 2033 } |
| 2040 | 2034 |
| 2041 } // namespace blink | 2035 } // namespace blink |
| OLD | NEW |