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

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

Issue 2370253002: Mark calls of visible{Start,End} with dirty layout deprecated (Closed)
Patch Set: Created 4 years, 2 months 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 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005 Apple Computer, 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (text.contains('\t') || text.contains(' ') || text.contains('\n')) 94 if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
95 return false; 95 return false;
96 96
97 Position start = endingSelection().start(); 97 Position start = endingSelection().start();
98 Position endPosition = replaceSelectedTextInNode(text); 98 Position endPosition = replaceSelectedTextInNode(text);
99 if (endPosition.isNull()) 99 if (endPosition.isNull())
100 return false; 100 return false;
101 101
102 setEndingSelectionWithoutValidation(start, endPosition); 102 setEndingSelectionWithoutValidation(start, endPosition);
103 if (!selectInsertedText) 103 if (!selectInsertedText)
104 setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endi ngSelection().isDirectional())); 104 setEndingSelection(VisibleSelection(endingSelection().visibleEndDeprecat ed(), endingSelection().isDirectional()));
105 105
106 return true; 106 return true;
107 } 107 }
108 108
109 bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted Text) 109 bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted Text)
110 { 110 {
111 Position start = endingSelection().start(); 111 Position start = endingSelection().start();
112 if (start.isNull() || !start.isOffsetInAnchor() || !start.computeContainerNo de()->isTextNode()) 112 if (start.isNull() || !start.isOffsetInAnchor() || !start.computeContainerNo de()->isTextNode())
113 return false; 113 return false;
114 Text* textNode = toText(start.computeContainerNode()); 114 Text* textNode = toText(start.computeContainerNode());
115 if (!textNode) 115 if (!textNode)
116 return false; 116 return false;
117 117
118 unsigned count = std::min(text.length(), textNode->length() - start.offsetIn ContainerNode()); 118 unsigned count = std::min(text.length(), textNode->length() - start.offsetIn ContainerNode());
119 if (!count) 119 if (!count)
120 return false; 120 return false;
121 121
122 replaceTextInNode(textNode, start.offsetInContainerNode(), count, text); 122 replaceTextInNode(textNode, start.offsetInContainerNode(), count, text);
123 123
124 Position endPosition = Position(textNode, start.offsetInContainerNode() + te xt.length()); 124 Position endPosition = Position(textNode, start.offsetInContainerNode() + te xt.length());
125 setEndingSelectionWithoutValidation(start, endPosition); 125 setEndingSelectionWithoutValidation(start, endPosition);
126 if (!selectInsertedText) 126 if (!selectInsertedText)
127 setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endi ngSelection().isDirectional())); 127 setEndingSelection(VisibleSelection(endingSelection().visibleEndDeprecat ed(), endingSelection().isDirectional()));
128 128
129 return true; 129 return true;
130 } 130 }
131 131
132 void InsertTextCommand::doApply(EditingState* editingState) 132 void InsertTextCommand::doApply(EditingState* editingState)
133 { 133 {
134 DCHECK_EQ(m_text.find('\n'), kNotFound); 134 DCHECK_EQ(m_text.find('\n'), kNotFound);
135 135
136 if (!endingSelection().isNonOrphanedCaretOrRange()) 136 if (!endingSelection().isNonOrphanedCaretOrRange())
137 return; 137 return;
138 138
139 // Delete the current selection. 139 // Delete the current selection.
140 // FIXME: This delete operation blows away the typing style. 140 // FIXME: This delete operation blows away the typing style.
141 if (endingSelection().isRange()) { 141 if (endingSelection().isRange()) {
142 if (performTrivialReplace(m_text, m_selectInsertedText)) 142 if (performTrivialReplace(m_text, m_selectInsertedText))
143 return; 143 return;
144 bool endOfSelectionWasAtStartOfBlock = isStartOfBlock(endingSelection(). visibleEnd()); 144 bool endOfSelectionWasAtStartOfBlock = isStartOfBlock(endingSelection(). visibleEndDeprecated());
145 deleteSelection(editingState, false, true, false, false); 145 deleteSelection(editingState, false, true, false, false);
146 if (editingState->isAborted()) 146 if (editingState->isAborted())
147 return; 147 return;
148 // deleteSelection eventually makes a new endingSelection out of a Posit ion. If that Position doesn't have 148 // deleteSelection eventually makes a new endingSelection out of a Posit ion. If that Position doesn't have
149 // a layoutObject (e.g. it is on a <frameset> in the DOM), the VisibleSe lection cannot be canonicalized to 149 // a layoutObject (e.g. it is on a <frameset> in the DOM), the VisibleSe lection cannot be canonicalized to
150 // anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out. 150 // anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out.
151 if (endingSelection().isNone()) 151 if (endingSelection().isNone())
152 return; 152 return;
153 if (endOfSelectionWasAtStartOfBlock) { 153 if (endOfSelectionWasAtStartOfBlock) {
154 if (EditingStyle* typingStyle = document().frame()->selection().typi ngStyle()) 154 if (EditingStyle* typingStyle = document().frame()->selection().typi ngStyle())
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 285 }
286 } 286 }
287 if (editingState->isAborted()) 287 if (editingState->isAborted())
288 return Position(); 288 return Position();
289 289
290 // return the position following the new tab 290 // return the position following the new tab
291 return Position::lastPositionInNode(spanElement); 291 return Position::lastPositionInNode(spanElement);
292 } 292 }
293 293
294 } // namespace blink 294 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698