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

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingUtilities.cpp

Issue 2437873008: Get rid of flat tree version of createVisibleSelection() taking two VisiblePosition (Closed)
Patch Set: 2016-10-24T13:35:49 Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 const VisibleSelection& original) { 1782 const VisibleSelection& original) {
1783 VisibleSelection newSelection(original); 1783 VisibleSelection newSelection(original);
1784 VisiblePosition startOfSelection(newSelection.visibleStart()); 1784 VisiblePosition startOfSelection(newSelection.visibleStart());
1785 VisiblePosition endOfSelection(newSelection.visibleEnd()); 1785 VisiblePosition endOfSelection(newSelection.visibleEnd());
1786 1786
1787 // If the end of the selection to modify is just after a table, and if the 1787 // If the end of the selection to modify is just after a table, and if the
1788 // start of the selection is inside that table, then the last paragraph that 1788 // start of the selection is inside that table, then the last paragraph that
1789 // we'll want modify is the last one inside the table, not the table itself (a 1789 // we'll want modify is the last one inside the table, not the table itself (a
1790 // table is itself a paragraph). 1790 // table is itself a paragraph).
1791 if (Element* table = tableElementJustBefore(endOfSelection)) { 1791 if (Element* table = tableElementJustBefore(endOfSelection)) {
1792 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table)) 1792 if (startOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table)) {
1793 newSelection = createVisibleSelection( 1793 const VisiblePosition& newEnd =
1794 startOfSelection, 1794 previousPositionOf(endOfSelection, CannotCrossEditingBoundary);
1795 previousPositionOf(endOfSelection, CannotCrossEditingBoundary)); 1795 if (newEnd.isNotNull()) {
1796 newSelection = createVisibleSelection(
1797 SelectionInDOMTree::Builder()
1798 .collapse(startOfSelection.toPositionWithAffinity())
1799 .extend(newEnd.deepEquivalent())
1800 .build());
1801 } else {
1802 newSelection = createVisibleSelection(
1803 SelectionInDOMTree::Builder()
1804 .collapse(startOfSelection.toPositionWithAffinity())
1805 .build());
1806 }
1807 }
1796 } 1808 }
1797 1809
1798 // If the start of the selection to modify is just before a table, and if the 1810 // If the start of the selection to modify is just before a table, and if the
1799 // end of the selection is inside that table, then the first paragraph we'll 1811 // end of the selection is inside that table, then the first paragraph we'll
1800 // want to modify is the first one inside the table, not the paragraph 1812 // want to modify is the first one inside the table, not the paragraph
1801 // containing the table itself. 1813 // containing the table itself.
1802 if (Element* table = tableElementJustAfter(startOfSelection)) { 1814 if (Element* table = tableElementJustAfter(startOfSelection)) {
1803 if (endOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table)) 1815 if (endOfSelection.deepEquivalent().anchorNode()->isDescendantOf(table)) {
1804 newSelection = createVisibleSelection( 1816 const VisiblePosition newStart =
1805 nextPositionOf(startOfSelection, CannotCrossEditingBoundary), 1817 nextPositionOf(startOfSelection, CannotCrossEditingBoundary);
1806 endOfSelection); 1818 if (newStart.isNotNull()) {
1819 newSelection = createVisibleSelection(
1820 SelectionInDOMTree::Builder()
1821 .collapse(newStart.toPositionWithAffinity())
1822 .extend(endOfSelection.deepEquivalent())
1823 .build());
1824 } else {
1825 newSelection = createVisibleSelection(
1826 SelectionInDOMTree::Builder()
1827 .collapse(endOfSelection.toPositionWithAffinity())
1828 .build());
1829 }
1830 }
1807 } 1831 }
1808 1832
1809 return newSelection; 1833 return newSelection;
1810 } 1834 }
1811 1835
1812 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators 1836 // FIXME: indexForVisiblePosition and visiblePositionForIndex use TextIterators
1813 // to convert between VisiblePositions and indices. But TextIterator iteration 1837 // to convert between VisiblePositions and indices. But TextIterator iteration
1814 // using TextIteratorEmitsCharactersBetweenAllVisiblePositions does not exactly 1838 // using TextIteratorEmitsCharactersBetweenAllVisiblePositions does not exactly
1815 // match VisiblePosition iteration, so using them to preserve a selection during 1839 // match VisiblePosition iteration, so using them to preserve a selection during
1816 // an editing opertion is unreliable. TextIterator's 1840 // an editing opertion is unreliable. TextIterator's
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 return InputType::DeleteWordBackward; 2107 return InputType::DeleteWordBackward;
2084 if (granularity == LineBoundary) 2108 if (granularity == LineBoundary)
2085 return InputType::DeleteLineBackward; 2109 return InputType::DeleteLineBackward;
2086 return InputType::DeleteContentBackward; 2110 return InputType::DeleteContentBackward;
2087 default: 2111 default:
2088 return InputType::None; 2112 return InputType::None;
2089 } 2113 }
2090 } 2114 }
2091 2115
2092 } // namespace blink 2116 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698