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

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

Issue 2450213002: Utilize EditCommand::setEndingSelection() taking SelectionInDOMTree (Closed)
Patch Set: 2016-10-28T14:44:14 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) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 return; 1865 return;
1866 } else if (lastPositionToSelect.isNotNull()) { 1866 } else if (lastPositionToSelect.isNotNull()) {
1867 start = end = lastPositionToSelect; 1867 start = end = lastPositionToSelect;
1868 } else { 1868 } else {
1869 return; 1869 return;
1870 } 1870 }
1871 1871
1872 m_startOfInsertedRange = start; 1872 m_startOfInsertedRange = start;
1873 m_endOfInsertedRange = end; 1873 m_endOfInsertedRange = end;
1874 1874
1875 document().updateStyleAndLayoutIgnorePendingStylesheets();
1876
1877 if (m_selectReplacement) { 1875 if (m_selectReplacement) {
1878 setEndingSelection(createVisibleSelection( 1876 setEndingSelection(SelectionInDOMTree::Builder()
1879 SelectionInDOMTree::Builder() 1877 .setBaseAndExtentDeprecated(start, end)
1880 .setBaseAndExtentDeprecated(start, end) 1878 .setIsDirectional(endingSelection().isDirectional())
1881 .setIsDirectional(endingSelection().isDirectional()) 1879 .build());
1882 .build()));
1883 return; 1880 return;
1884 } 1881 }
1885 1882
1886 if (end.isNotNull()) { 1883 if (end.isNotNull()) {
1887 setEndingSelection(createVisibleSelection( 1884 setEndingSelection(SelectionInDOMTree::Builder()
1888 SelectionInDOMTree::Builder() 1885 .collapse(end)
1889 .collapse(end) 1886 .setIsDirectional(endingSelection().isDirectional())
1890 .setIsDirectional(endingSelection().isDirectional()) 1887 .build());
1891 .build()));
1892 return; 1888 return;
1893 } 1889 }
1894 setEndingSelection(createVisibleSelection(SelectionInDOMTree())); 1890 setEndingSelection(SelectionInDOMTree());
1895 } 1891 }
1896 1892
1897 void ReplaceSelectionCommand::mergeTextNodesAroundPosition( 1893 void ReplaceSelectionCommand::mergeTextNodesAroundPosition(
1898 Position& position, 1894 Position& position,
1899 Position& positionOnlyToBeUpdated, 1895 Position& positionOnlyToBeUpdated,
1900 EditingState* editingState) { 1896 EditingState* editingState) {
1901 bool positionIsOffsetInAnchor = position.isOffsetInAnchor(); 1897 bool positionIsOffsetInAnchor = position.isOffsetInAnchor();
1902 bool positionOnlyToBeUpdatedIsOffsetInAnchor = 1898 bool positionOnlyToBeUpdatedIsOffsetInAnchor =
1903 positionOnlyToBeUpdated.isOffsetInAnchor(); 1899 positionOnlyToBeUpdated.isOffsetInAnchor();
1904 Text* text = nullptr; 1900 Text* text = nullptr;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 shouldRemoveEndBR(toHTMLBRElement(nodeAfterInsertionPos), 2088 shouldRemoveEndBR(toHTMLBRElement(nodeAfterInsertionPos),
2093 VisiblePosition::beforeNode(nodeAfterInsertionPos))) { 2089 VisiblePosition::beforeNode(nodeAfterInsertionPos))) {
2094 removeNodeAndPruneAncestors(nodeAfterInsertionPos, editingState); 2090 removeNodeAndPruneAncestors(nodeAfterInsertionPos, editingState);
2095 if (editingState->isAborted()) 2091 if (editingState->isAborted())
2096 return false; 2092 return false;
2097 } 2093 }
2098 2094
2099 m_startOfInsertedRange = start; 2095 m_startOfInsertedRange = start;
2100 m_endOfInsertedRange = end; 2096 m_endOfInsertedRange = end;
2101 2097
2102 document().updateStyleAndLayoutIgnorePendingStylesheets(); 2098 setEndingSelection(
2103 VisibleSelection selectionAfterReplace = createVisibleSelection(
2104 SelectionInDOMTree::Builder() 2099 SelectionInDOMTree::Builder()
2105 .setBaseAndExtentDeprecated(m_selectReplacement ? start : end, end) 2100 .setBaseAndExtentDeprecated(m_selectReplacement ? start : end, end)
2106 .build()); 2101 .build());
2107 2102
2108 setEndingSelection(selectionAfterReplace);
2109
2110 return true; 2103 return true;
2111 } 2104 }
2112 2105
2113 bool ReplaceSelectionCommand::isReplaceSelectionCommand() const { 2106 bool ReplaceSelectionCommand::isReplaceSelectionCommand() const {
2114 return true; 2107 return true;
2115 } 2108 }
2116 2109
2117 EphemeralRange ReplaceSelectionCommand::insertedRange() const { 2110 EphemeralRange ReplaceSelectionCommand::insertedRange() const {
2118 return EphemeralRange(m_startOfInsertedRange, m_endOfInsertedRange); 2111 return EphemeralRange(m_startOfInsertedRange, m_endOfInsertedRange);
2119 } 2112 }
2120 2113
2121 DEFINE_TRACE(ReplaceSelectionCommand) { 2114 DEFINE_TRACE(ReplaceSelectionCommand) {
2122 visitor->trace(m_startOfInsertedContent); 2115 visitor->trace(m_startOfInsertedContent);
2123 visitor->trace(m_endOfInsertedContent); 2116 visitor->trace(m_endOfInsertedContent);
2124 visitor->trace(m_insertionStyle); 2117 visitor->trace(m_insertionStyle);
2125 visitor->trace(m_documentFragment); 2118 visitor->trace(m_documentFragment);
2126 visitor->trace(m_startOfInsertedRange); 2119 visitor->trace(m_startOfInsertedRange);
2127 visitor->trace(m_endOfInsertedRange); 2120 visitor->trace(m_endOfInsertedRange);
2128 CompositeEditCommand::trace(visitor); 2121 CompositeEditCommand::trace(visitor);
2129 } 2122 }
2130 2123
2131 } // namespace blink 2124 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698