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

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

Issue 2583993002: [Editing] Introduce |CompositeEditCommand::willApplyEditing()| in prepare for 'beforeinput' (1/3) (Closed)
Patch Set: Created 4 years 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, 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 UndoStep::trace(visitor); 180 UndoStep::trace(visitor);
181 } 181 }
182 182
183 CompositeEditCommand::CompositeEditCommand(Document& document) 183 CompositeEditCommand::CompositeEditCommand(Document& document)
184 : EditCommand(document) {} 184 : EditCommand(document) {}
185 185
186 CompositeEditCommand::~CompositeEditCommand() { 186 CompositeEditCommand::~CompositeEditCommand() {
187 DCHECK(isTopLevelCommand() || !m_composition); 187 DCHECK(isTopLevelCommand() || !m_composition);
188 } 188 }
189 189
190 // TODO(chongz): Fire 'beforeinput' based on |EditCommandSource|. 190 bool CompositeEditCommand::apply(EditCommandSource source) {
191 bool CompositeEditCommand::apply(EditCommandSource) {
192 DCHECK(!isCommandGroupWrapper()); 191 DCHECK(!isCommandGroupWrapper());
193 if (!endingSelection().isContentRichlyEditable()) { 192 if (!endingSelection().isContentRichlyEditable()) {
194 switch (inputType()) { 193 switch (inputType()) {
195 case InputEvent::InputType::InsertText: 194 case InputEvent::InputType::InsertText:
196 case InputEvent::InputType::InsertLineBreak: 195 case InputEvent::InputType::InsertLineBreak:
197 case InputEvent::InputType::InsertParagraph: 196 case InputEvent::InputType::InsertParagraph:
198 case InputEvent::InputType::InsertFromPaste: 197 case InputEvent::InputType::InsertFromPaste:
199 case InputEvent::InputType::InsertFromDrop: 198 case InputEvent::InputType::InsertFromDrop:
200 case InputEvent::InputType::InsertReplacementText: 199 case InputEvent::InputType::InsertReplacementText:
201 case InputEvent::InputType::DeleteComposedCharacterForward: 200 case InputEvent::InputType::DeleteComposedCharacterForward:
(...skipping 15 matching lines...) Expand all
217 } 216 }
218 ensureComposition(); 217 ensureComposition();
219 218
220 // Changes to the document may have been made since the last editing operation 219 // Changes to the document may have been made since the last editing operation
221 // that require a layout, as in <rdar://problem/5658603>. Low level 220 // that require a layout, as in <rdar://problem/5658603>. Low level
222 // operations, like RemoveNodeCommand, don't require a layout because the high 221 // operations, like RemoveNodeCommand, don't require a layout because the high
223 // level operations that use them perform one if one is necessary (like for 222 // level operations that use them perform one if one is necessary (like for
224 // the creation of VisiblePositions). 223 // the creation of VisiblePositions).
225 document().updateStyleAndLayoutIgnorePendingStylesheets(); 224 document().updateStyleAndLayoutIgnorePendingStylesheets();
226 225
226 if (!willApply(source))
227 return false;
228
227 LocalFrame* frame = document().frame(); 229 LocalFrame* frame = document().frame();
228 DCHECK(frame); 230 DCHECK(frame);
229 EditingState editingState; 231 EditingState editingState;
230 { 232 {
231 EventQueueScope eventQueueScope; 233 EventQueueScope eventQueueScope;
232 doApply(&editingState); 234 doApply(&editingState);
233 } 235 }
234 236
235 // Only need to call appliedEditing for top-level commands, and TypingCommands 237 // Only need to call appliedEditing for top-level commands, and TypingCommands
236 // do it on their own (see TypingCommand::typingAddedToOpenCommand). 238 // do it on their own (see TypingCommand::typingAddedToOpenCommand).
237 if (!isTypingCommand()) 239 if (!isTypingCommand())
238 frame->editor().appliedEditing(this); 240 frame->editor().appliedEditing(this);
239 setShouldRetainAutocorrectionIndicator(false); 241 setShouldRetainAutocorrectionIndicator(false);
240 return !editingState.isAborted(); 242 return !editingState.isAborted();
241 } 243 }
242 244
243 EditCommandComposition* CompositeEditCommand::ensureComposition() { 245 EditCommandComposition* CompositeEditCommand::ensureComposition() {
244 CompositeEditCommand* command = this; 246 CompositeEditCommand* command = this;
245 while (command && command->parent()) 247 while (command && command->parent())
246 command = command->parent(); 248 command = command->parent();
247 if (!command->m_composition) 249 if (!command->m_composition)
248 command->m_composition = EditCommandComposition::create( 250 command->m_composition = EditCommandComposition::create(
249 &document(), startingSelection(), endingSelection(), inputType()); 251 &document(), startingSelection(), endingSelection(), inputType());
250 return command->m_composition.get(); 252 return command->m_composition.get();
251 } 253 }
252 254
255 bool CompositeEditCommand::willApply(EditCommandSource source) {
256 return willApplyEditing(source);
tkent 2016/12/19 03:43:24 What's the difference between willApply() and will
chongz 2016/12/19 06:48:57 The reason is both |TypingCommand::willAddTypingTo
tkent 2016/12/19 08:22:18 It didn't convince me. Why CompositeEditCommand::
chongz 2016/12/19 20:55:22 Oh I got what you mean. Yeah we don't need |willAp
257 }
258
259 bool CompositeEditCommand::willApplyEditing(EditCommandSource) {
260 // TODO(chongz): Move all the 'beforeinput' dispatching logic here.
261 return true;
262 }
263
253 bool CompositeEditCommand::preservesTypingStyle() const { 264 bool CompositeEditCommand::preservesTypingStyle() const {
254 return false; 265 return false;
255 } 266 }
256 267
257 bool CompositeEditCommand::isTypingCommand() const { 268 bool CompositeEditCommand::isTypingCommand() const {
258 return false; 269 return false;
259 } 270 }
260 271
261 bool CompositeEditCommand::isCommandGroupWrapper() const { 272 bool CompositeEditCommand::isCommandGroupWrapper() const {
262 return false; 273 return false;
(...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 return node; 2041 return node;
2031 } 2042 }
2032 2043
2033 DEFINE_TRACE(CompositeEditCommand) { 2044 DEFINE_TRACE(CompositeEditCommand) {
2034 visitor->trace(m_commands); 2045 visitor->trace(m_commands);
2035 visitor->trace(m_composition); 2046 visitor->trace(m_composition);
2036 EditCommand::trace(visitor); 2047 EditCommand::trace(visitor);
2037 } 2048 }
2038 2049
2039 } // namespace blink 2050 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698