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

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: xiaocheng's review 3: Rebase and remove updateStyleAndLayoutIgnorePendingStylesheets() Created 3 years, 12 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, 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/editing/commands/MergeIdenticalElementsCommand.h" 49 #include "core/editing/commands/MergeIdenticalElementsCommand.h"
50 #include "core/editing/commands/RemoveCSSPropertyCommand.h" 50 #include "core/editing/commands/RemoveCSSPropertyCommand.h"
51 #include "core/editing/commands/RemoveNodeCommand.h" 51 #include "core/editing/commands/RemoveNodeCommand.h"
52 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h" 52 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h"
53 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h" 53 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h"
54 #include "core/editing/commands/ReplaceSelectionCommand.h" 54 #include "core/editing/commands/ReplaceSelectionCommand.h"
55 #include "core/editing/commands/SetNodeAttributeCommand.h" 55 #include "core/editing/commands/SetNodeAttributeCommand.h"
56 #include "core/editing/commands/SplitElementCommand.h" 56 #include "core/editing/commands/SplitElementCommand.h"
57 #include "core/editing/commands/SplitTextNodeCommand.h" 57 #include "core/editing/commands/SplitTextNodeCommand.h"
58 #include "core/editing/commands/SplitTextNodeContainingElementCommand.h" 58 #include "core/editing/commands/SplitTextNodeContainingElementCommand.h"
59 #include "core/editing/commands/TypingCommand.h"
59 #include "core/editing/commands/WrapContentsInDummySpanCommand.h" 60 #include "core/editing/commands/WrapContentsInDummySpanCommand.h"
60 #include "core/editing/iterators/TextIterator.h" 61 #include "core/editing/iterators/TextIterator.h"
61 #include "core/editing/markers/DocumentMarkerController.h" 62 #include "core/editing/markers/DocumentMarkerController.h"
62 #include "core/editing/serializers/Serialization.h" 63 #include "core/editing/serializers/Serialization.h"
63 #include "core/editing/spellcheck/SpellChecker.h" 64 #include "core/editing/spellcheck/SpellChecker.h"
64 #include "core/events/ScopedEventQueue.h" 65 #include "core/events/ScopedEventQueue.h"
65 #include "core/frame/LocalFrame.h" 66 #include "core/frame/LocalFrame.h"
66 #include "core/html/HTMLBRElement.h" 67 #include "core/html/HTMLBRElement.h"
67 #include "core/html/HTMLDivElement.h" 68 #include "core/html/HTMLDivElement.h"
68 #include "core/html/HTMLElement.h" 69 #include "core/html/HTMLElement.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); 143 m_document->updateStyleAndLayoutIgnorePendingStylesheets();
143 144
144 { 145 {
145 for (const auto& command : m_commands) 146 for (const auto& command : m_commands)
146 command->doReapply(); 147 command->doReapply();
147 } 148 }
148 149
149 frame->editor().reappliedEditing(this); 150 frame->editor().reappliedEditing(this);
150 } 151 }
151 152
152 bool EditCommandComposition::willUnapply(EditCommandSource) { 153 bool EditCommandComposition::willUnapply(EditCommandSource source) {
153 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. 154 return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
154 return true; 155 InputEvent::InputType::HistoryUndo, nullAtom,
156 nullptr, InputEvent::IsCancelable,
157 InputEvent::NotComposing, nullptr);
155 } 158 }
156 159
157 bool EditCommandComposition::willReapply(EditCommandSource) { 160 bool EditCommandComposition::willReapply(EditCommandSource source) {
158 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. 161 return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
159 return true; 162 InputEvent::InputType::HistoryRedo, nullAtom,
163 nullptr, InputEvent::IsCancelable,
164 InputEvent::NotComposing, nullptr);
160 } 165 }
161 166
162 void EditCommandComposition::append(SimpleEditCommand* command) { 167 void EditCommandComposition::append(SimpleEditCommand* command) {
163 m_commands.push_back(command); 168 m_commands.push_back(command);
164 } 169 }
165 170
166 void EditCommandComposition::append(EditCommandComposition* composition) { 171 void EditCommandComposition::append(EditCommandComposition* composition) {
167 m_commands.appendVector(composition->m_commands); 172 m_commands.appendVector(composition->m_commands);
168 } 173 }
169 174
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 case InputEvent::InputType::DeleteByDrag: 223 case InputEvent::InputType::DeleteByDrag:
219 case InputEvent::InputType::None: 224 case InputEvent::InputType::None:
220 break; 225 break;
221 default: 226 default:
222 NOTREACHED(); 227 NOTREACHED();
223 return false; 228 return false;
224 } 229 }
225 } 230 }
226 ensureComposition(); 231 ensureComposition();
227 232
233 // Covers the initial TypingCommand and other top-level commands.
234 // TypingCommand::willAddTypingToOpenCommand() also calls willApplyEditing().
235 if (!willApplyEditing(source))
236 return false;
237
228 // Changes to the document may have been made since the last editing operation 238 // Changes to the document may have been made since the last editing operation
229 // that require a layout, as in <rdar://problem/5658603>. Low level 239 // that require a layout, as in <rdar://problem/5658603>. Low level
230 // operations, like RemoveNodeCommand, don't require a layout because the high 240 // operations, like RemoveNodeCommand, don't require a layout because the high
231 // level operations that use them perform one if one is necessary (like for 241 // level operations that use them perform one if one is necessary (like for
232 // the creation of VisiblePositions). 242 // the creation of VisiblePositions).
233 document().updateStyleAndLayoutIgnorePendingStylesheets(); 243 document().updateStyleAndLayoutIgnorePendingStylesheets();
234 244
235 if (!willApplyEditing(source))
236 return false;
237
238 LocalFrame* frame = document().frame(); 245 LocalFrame* frame = document().frame();
239 DCHECK(frame); 246 DCHECK(frame);
240 EditingState editingState; 247 EditingState editingState;
241 { 248 {
242 EventQueueScope eventQueueScope; 249 EventQueueScope eventQueueScope;
243 doApply(&editingState); 250 doApply(&editingState);
244 } 251 }
245 252
246 // Only need to call appliedEditing for top-level commands, and TypingCommands 253 // Only need to call appliedEditing for top-level commands, and TypingCommands
247 // do it on their own (see TypingCommand::typingAddedToOpenCommand). 254 // do it on their own (see TypingCommand::typingAddedToOpenCommand).
248 if (!isTypingCommand()) 255 if (!isTypingCommand())
249 frame->editor().appliedEditing(this); 256 frame->editor().appliedEditing(this);
250 setShouldRetainAutocorrectionIndicator(false); 257 setShouldRetainAutocorrectionIndicator(false);
251 return !editingState.isAborted(); 258 return !editingState.isAborted();
252 } 259 }
253 260
254 EditCommandComposition* CompositeEditCommand::ensureComposition() { 261 EditCommandComposition* CompositeEditCommand::ensureComposition() {
255 CompositeEditCommand* command = this; 262 CompositeEditCommand* command = this;
256 while (command && command->parent()) 263 while (command && command->parent())
257 command = command->parent(); 264 command = command->parent();
258 if (!command->m_composition) { 265 if (!command->m_composition) {
259 command->m_composition = EditCommandComposition::create( 266 command->m_composition = EditCommandComposition::create(
260 &document(), startingSelection(), endingSelection()); 267 &document(), startingSelection(), endingSelection());
261 } 268 }
262 return command->m_composition.get(); 269 return command->m_composition.get();
263 } 270 }
264 271
265 bool CompositeEditCommand::willApplyEditing(EditCommandSource) { 272 bool CompositeEditCommand::willApplyEditing(EditCommandSource source) {
266 // TODO(chongz): Move all the 'beforeinput' dispatching logic here. 273 // TODO(chongz): Remove the following code after we have ensured it's OK to
267 return true; 274 // fire 'beforeinput' after 'compositionupdate'.
275 // https://crbug.com/675820
276 if (isTypingCommand() && (toTypingCommand(this)->compositionType() ==
277 TypingCommand::TextCompositionUpdate ||
278 toTypingCommand(this)->compositionType() ==
279 TypingCommand::TextCompositionConfirm))
280 return true;
281 return dispatchBeforeInputEvent(
282 source, document().frame(), eventTargetNodeForDocument(&document()),
283 inputType(), textDataForInputEvent(), dataTransferForInputEvent(),
284 isCancelableFromCommand(this), isComposingFromCommand(this),
285 targetRangesForInputEvent());
286 }
287
288 InputEvent::InputType CompositeEditCommand::inputType() const {
289 return InputEvent::InputType::None;
290 }
291
292 String CompositeEditCommand::textDataForInputEvent() const {
293 return nullAtom;
294 }
295
296 DataTransfer* CompositeEditCommand::dataTransferForInputEvent() const {
297 return nullptr;
298 }
299
300 RangeVector* CompositeEditCommand::targetRangesForInputEvent() const {
301 // TODO(chongz): We should always return current selection for ContentEditable
302 // if no better choice.
303 // https://crbug.com/652429
304 if (inputType() == InputEvent::InputType::InsertReplacementText &&
305 document().frame()->editor().canEditRichly())
306 return new RangeVector(1, document().frame()->selection().firstRange());
307 return nullptr;
268 } 308 }
269 309
270 bool CompositeEditCommand::preservesTypingStyle() const { 310 bool CompositeEditCommand::preservesTypingStyle() const {
271 return false; 311 return false;
272 } 312 }
273 313
274 bool CompositeEditCommand::isTypingCommand() const { 314 bool CompositeEditCommand::isTypingCommand() const {
275 return false; 315 return false;
276 } 316 }
277 317
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 return node; 2087 return node;
2048 } 2088 }
2049 2089
2050 DEFINE_TRACE(CompositeEditCommand) { 2090 DEFINE_TRACE(CompositeEditCommand) {
2051 visitor->trace(m_commands); 2091 visitor->trace(m_commands);
2052 visitor->trace(m_composition); 2092 visitor->trace(m_composition);
2053 EditCommand::trace(visitor); 2093 EditCommand::trace(visitor);
2054 } 2094 }
2055 2095
2056 } // namespace blink 2096 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698