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

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

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 case InputEvent::InputType::InsertText: 194 case InputEvent::InputType::InsertText:
195 case InputEvent::InputType::InsertLineBreak: 195 case InputEvent::InputType::InsertLineBreak:
196 case InputEvent::InputType::InsertParagraph: 196 case InputEvent::InputType::InsertParagraph:
197 case InputEvent::InputType::InsertFromPaste: 197 case InputEvent::InputType::InsertFromPaste:
198 case InputEvent::InputType::InsertFromDrop: 198 case InputEvent::InputType::InsertFromDrop:
199 case InputEvent::InputType::InsertReplacementText: 199 case InputEvent::InputType::InsertReplacementText:
200 case InputEvent::InputType::DeleteComposedCharacterForward: 200 case InputEvent::InputType::DeleteComposedCharacterForward:
201 case InputEvent::InputType::DeleteComposedCharacterBackward: 201 case InputEvent::InputType::DeleteComposedCharacterBackward:
202 case InputEvent::InputType::DeleteWordBackward: 202 case InputEvent::InputType::DeleteWordBackward:
203 case InputEvent::InputType::DeleteWordForward: 203 case InputEvent::InputType::DeleteWordForward:
204 case InputEvent::InputType::DeleteLineBackward: 204 case InputEvent::InputType::DeleteSoftLineBackward:
205 case InputEvent::InputType::DeleteLineForward: 205 case InputEvent::InputType::DeleteSoftLineForward:
206 case InputEvent::InputType::DeleteContent:
206 case InputEvent::InputType::DeleteContentBackward: 207 case InputEvent::InputType::DeleteContentBackward:
207 case InputEvent::InputType::DeleteContentForward: 208 case InputEvent::InputType::DeleteContentForward:
208 case InputEvent::InputType::DeleteByCut: 209 case InputEvent::InputType::DeleteByCut:
209 case InputEvent::InputType::DeleteByDrag: 210 case InputEvent::InputType::DeleteByDrag:
210 case InputEvent::InputType::None: 211 case InputEvent::InputType::None:
211 break; 212 break;
212 default: 213 default:
213 NOTREACHED(); 214 NOTREACHED();
214 return false; 215 return false;
215 } 216 }
216 } 217 }
217 ensureComposition(); 218 ensureComposition();
218 219
219 // Changes to the document may have been made since the last editing operation 220 // Changes to the document may have been made since the last editing operation
220 // that require a layout, as in <rdar://problem/5658603>. Low level 221 // that require a layout, as in <rdar://problem/5658603>. Low level
221 // operations, like RemoveNodeCommand, don't require a layout because the high 222 // operations, like RemoveNodeCommand, don't require a layout because the high
222 // level operations that use them perform one if one is necessary (like for 223 // level operations that use them perform one if one is necessary (like for
223 // the creation of VisiblePositions). 224 // the creation of VisiblePositions).
224 document().updateStyleAndLayoutIgnorePendingStylesheets(); 225 document().updateStyleAndLayoutIgnorePendingStylesheets();
225 226
227 // Covers the initial TypingCommand and other top-level commands.
228 // See TypingCommand::willAddTypingToOpenCommand().
229 if (!willApply())
230 return false;
231
226 LocalFrame* frame = document().frame(); 232 LocalFrame* frame = document().frame();
227 DCHECK(frame); 233 DCHECK(frame);
228 EditingState editingState; 234 EditingState editingState;
229 { 235 {
230 EventQueueScope eventQueueScope; 236 EventQueueScope eventQueueScope;
231 doApply(&editingState); 237 doApply(&editingState);
232 } 238 }
233 239
234 // Only need to call appliedEditing for top-level commands, and TypingCommands 240 // Only need to call appliedEditing for top-level commands, and TypingCommands
235 // do it on their own (see TypingCommand::typingAddedToOpenCommand). 241 // do it on their own (see TypingCommand::typingAddedToOpenCommand).
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // Mutation events (bug 22634) from the text node insertion may have removed 429 // Mutation events (bug 22634) from the text node insertion may have removed
424 // the refChild 430 // the refChild
425 if (!refChild->isConnected()) 431 if (!refChild->isConnected())
426 return; 432 return;
427 insertNodeBefore(insertChild, refChild, editingState); 433 insertNodeBefore(insertChild, refChild, editingState);
428 } else { 434 } else {
429 insertNodeAfter(insertChild, refChild, editingState); 435 insertNodeAfter(insertChild, refChild, editingState);
430 } 436 }
431 } 437 }
432 438
439 bool CompositeEditCommand::willApply() {
440 LocalFrame* frame = document().frame();
441 DCHECK(frame);
yosin_UTC9 2016/12/07 07:51:27 No need to have |DCHECK(frame)| since next line us
chongz 2016/12/07 15:22:21 Done.
442 return frame->editor().willApplyEditing(this);
443 }
444
433 void CompositeEditCommand::appendNode(Node* node, 445 void CompositeEditCommand::appendNode(Node* node,
434 ContainerNode* parent, 446 ContainerNode* parent,
435 EditingState* editingState) { 447 EditingState* editingState) {
436 // When cloneParagraphUnderNewElement() clones the fallback content 448 // When cloneParagraphUnderNewElement() clones the fallback content
437 // of an OBJECT element, the ASSERT below may fire since the return 449 // of an OBJECT element, the ASSERT below may fire since the return
438 // value of canHaveChildrenForEditing is not reliable until the layout 450 // value of canHaveChildrenForEditing is not reliable until the layout
439 // object of the OBJECT is created. Hence we ignore this check for OBJECTs. 451 // object of the OBJECT is created. Hence we ignore this check for OBJECTs.
440 // TODO(yosin): We should move following |ABORT_EDITING_COMMAND_IF|s to 452 // TODO(yosin): We should move following |ABORT_EDITING_COMMAND_IF|s to
441 // |AppendNodeCommand|. 453 // |AppendNodeCommand|.
442 // TODO(yosin): We should get rid of |canHaveChildrenForEditing()|, since 454 // TODO(yosin): We should get rid of |canHaveChildrenForEditing()|, since
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 return node; 2041 return node;
2030 } 2042 }
2031 2043
2032 DEFINE_TRACE(CompositeEditCommand) { 2044 DEFINE_TRACE(CompositeEditCommand) {
2033 visitor->trace(m_commands); 2045 visitor->trace(m_commands);
2034 visitor->trace(m_composition); 2046 visitor->trace(m_composition);
2035 EditCommand::trace(visitor); 2047 EditCommand::trace(visitor);
2036 } 2048 }
2037 2049
2038 } // namespace blink 2050 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698