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

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

Issue 2618583003: [InputEvent] Add 'beforeinput' logic in |will*()| and guarded by a flag (3/11) (Closed)
Patch Set: Change target to |startingRootEditableElement()| Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "core/html/HTMLQuoteElement.h" 71 #include "core/html/HTMLQuoteElement.h"
72 #include "core/html/HTMLSpanElement.h" 72 #include "core/html/HTMLSpanElement.h"
73 #include "core/layout/LayoutBlock.h" 73 #include "core/layout/LayoutBlock.h"
74 #include "core/layout/LayoutListItem.h" 74 #include "core/layout/LayoutListItem.h"
75 #include "core/layout/LayoutText.h" 75 #include "core/layout/LayoutText.h"
76 #include "core/layout/line/InlineTextBox.h" 76 #include "core/layout/line/InlineTextBox.h"
77 #include <algorithm> 77 #include <algorithm>
78 78
79 namespace blink { 79 namespace blink {
80 80
81 namespace {
82
83 InputEvent::EventCancelable isCancelableFromCommand(
84 const CompositeEditCommand* command) {
85 if (command->isTypingCommand() &&
86 toTypingCommand(command)->compositionType() ==
87 TypingCommand::TextCompositionUpdate)
88 return InputEvent::NotCancelable;
89 return InputEvent::IsCancelable;
90 }
91
92 } // anonymous namespace
93
81 using namespace HTMLNames; 94 using namespace HTMLNames;
82 95
83 EditCommandComposition* EditCommandComposition::create( 96 EditCommandComposition* EditCommandComposition::create(
84 Document* document, 97 Document* document,
85 const VisibleSelection& startingSelection, 98 const VisibleSelection& startingSelection,
86 const VisibleSelection& endingSelection) { 99 const VisibleSelection& endingSelection) {
87 return new EditCommandComposition(document, startingSelection, 100 return new EditCommandComposition(document, startingSelection,
88 endingSelection); 101 endingSelection);
89 } 102 }
90 103
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); 156 m_document->updateStyleAndLayoutIgnorePendingStylesheets();
144 157
145 { 158 {
146 for (const auto& command : m_commands) 159 for (const auto& command : m_commands)
147 command->doReapply(); 160 command->doReapply();
148 } 161 }
149 162
150 frame->editor().reappliedEditing(this); 163 frame->editor().reappliedEditing(this);
151 } 164 }
152 165
153 bool EditCommandComposition::willUnapply(EditCommandSource, BeforeInputTiming) { 166 bool EditCommandComposition::willUnapply(EditCommandSource source,
154 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. 167 BeforeInputTiming beforeInputTiming) {
155 return true; 168 if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
169 return true;
170 return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
171 InputEvent::InputType::HistoryUndo, nullAtom,
172 nullptr, InputEvent::IsCancelable,
173 InputEvent::NotComposing, nullptr);
156 } 174 }
157 175
158 bool EditCommandComposition::willReapply(EditCommandSource, BeforeInputTiming) { 176 bool EditCommandComposition::willReapply(EditCommandSource source,
159 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. 177 BeforeInputTiming beforeInputTiming) {
160 return true; 178 if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
179 return true;
180 return dispatchBeforeInputEvent(source, m_document->frame(), m_document,
181 InputEvent::InputType::HistoryRedo, nullAtom,
182 nullptr, InputEvent::IsCancelable,
183 InputEvent::NotComposing, nullptr);
161 } 184 }
162 185
163 void EditCommandComposition::append(SimpleEditCommand* command) { 186 void EditCommandComposition::append(SimpleEditCommand* command) {
164 m_commands.push_back(command); 187 m_commands.push_back(command);
165 } 188 }
166 189
167 void EditCommandComposition::append(EditCommandComposition* composition) { 190 void EditCommandComposition::append(EditCommandComposition* composition) {
168 m_commands.appendVector(composition->m_commands); 191 m_commands.appendVector(composition->m_commands);
169 } 192 }
170 193
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 case InputEvent::InputType::DeleteByDrag: 243 case InputEvent::InputType::DeleteByDrag:
221 case InputEvent::InputType::None: 244 case InputEvent::InputType::None:
222 break; 245 break;
223 default: 246 default:
224 NOTREACHED(); 247 NOTREACHED();
225 return false; 248 return false;
226 } 249 }
227 } 250 }
228 ensureComposition(); 251 ensureComposition();
229 252
253 // Covers the initial TypingCommand and other top-level commands.
254 // TypingCommand::willAddTypingToOpenCommand() also calls willApplyEditing().
255 if (!willApplyEditing(source, beforeInputTiming))
256 return false;
257
230 // Changes to the document may have been made since the last editing operation 258 // Changes to the document may have been made since the last editing operation
231 // that require a layout, as in <rdar://problem/5658603>. Low level 259 // that require a layout, as in <rdar://problem/5658603>. Low level
232 // operations, like RemoveNodeCommand, don't require a layout because the high 260 // operations, like RemoveNodeCommand, don't require a layout because the high
233 // level operations that use them perform one if one is necessary (like for 261 // level operations that use them perform one if one is necessary (like for
234 // the creation of VisiblePositions). 262 // the creation of VisiblePositions).
235 document().updateStyleAndLayoutIgnorePendingStylesheets(); 263 document().updateStyleAndLayoutIgnorePendingStylesheets();
236 264
237 if (!willApplyEditing(source, beforeInputTiming))
238 return false;
239
240 LocalFrame* frame = document().frame(); 265 LocalFrame* frame = document().frame();
241 DCHECK(frame); 266 DCHECK(frame);
242 EditingState editingState; 267 EditingState editingState;
243 { 268 {
244 EventQueueScope eventQueueScope; 269 EventQueueScope eventQueueScope;
245 doApply(&editingState); 270 doApply(&editingState);
246 } 271 }
247 272
248 // Only need to call appliedEditing for top-level commands, and TypingCommands 273 // Only need to call appliedEditing for top-level commands, and TypingCommands
249 // do it on their own (see TypingCommand::typingAddedToOpenCommand). 274 // do it on their own (see TypingCommand::typingAddedToOpenCommand).
250 if (!isTypingCommand()) 275 if (!isTypingCommand())
251 frame->editor().appliedEditing(this); 276 frame->editor().appliedEditing(this);
252 setShouldRetainAutocorrectionIndicator(false); 277 setShouldRetainAutocorrectionIndicator(false);
253 return !editingState.isAborted(); 278 return !editingState.isAborted();
254 } 279 }
255 280
256 EditCommandComposition* CompositeEditCommand::ensureComposition() { 281 EditCommandComposition* CompositeEditCommand::ensureComposition() {
257 CompositeEditCommand* command = this; 282 CompositeEditCommand* command = this;
258 while (command && command->parent()) 283 while (command && command->parent())
259 command = command->parent(); 284 command = command->parent();
260 if (!command->m_composition) { 285 if (!command->m_composition) {
261 command->m_composition = EditCommandComposition::create( 286 command->m_composition = EditCommandComposition::create(
262 &document(), startingSelection(), endingSelection()); 287 &document(), startingSelection(), endingSelection());
263 } 288 }
264 return command->m_composition.get(); 289 return command->m_composition.get();
265 } 290 }
266 291
267 bool CompositeEditCommand::willApplyEditing(EditCommandSource, 292 bool CompositeEditCommand::willApplyEditing(
268 BeforeInputTiming) { 293 EditCommandSource source,
269 // TODO(chongz): Move all the 'beforeinput' dispatching logic here. 294 BeforeInputTiming beforeInputTiming) {
270 return true; 295 if (beforeInputTiming != BeforeInputTiming::kShouldFireInCommand)
296 return true;
297 return dispatchBeforeInputEvent(
298 source, document().frame(),
299 ensureComposition()->startingRootEditableElement(), inputType(),
300 textDataForInputEvent(), dataTransferForInputEvent(),
301 isCancelableFromCommand(this), isComposingFromCommand(this),
302 targetRangesForInputEvent());
271 } 303 }
272 304
273 InputEvent::InputType CompositeEditCommand::inputType() const { 305 InputEvent::InputType CompositeEditCommand::inputType() const {
274 return InputEvent::InputType::None; 306 return InputEvent::InputType::None;
275 } 307 }
276 308
277 String CompositeEditCommand::textDataForInputEvent() const { 309 String CompositeEditCommand::textDataForInputEvent() const {
278 return nullAtom; 310 return nullAtom;
279 } 311 }
280 312
(...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 return node; 2104 return node;
2073 } 2105 }
2074 2106
2075 DEFINE_TRACE(CompositeEditCommand) { 2107 DEFINE_TRACE(CompositeEditCommand) {
2076 visitor->trace(m_commands); 2108 visitor->trace(m_commands);
2077 visitor->trace(m_composition); 2109 visitor->trace(m_composition);
2078 EditCommand::trace(visitor); 2110 EditCommand::trace(visitor);
2079 } 2111 }
2080 2112
2081 } // namespace blink 2113 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698