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

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

Issue 1752933002: [InputEvent] Fire 'beforeinput' during typing, pressing hot keys and IME composition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on WebEditingCommandType & Yosin's review 2 Created 4 years, 8 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) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return false; 165 return false;
166 166
167 // If text is empty, then delete the old composition here. If text is 167 // If text is empty, then delete the old composition here. If text is
168 // non-empty, InsertTextCommand::input will delete the old composition with 168 // non-empty, InsertTextCommand::input will delete the old composition with
169 // an optimized replace operation. 169 // an optimized replace operation.
170 if (text.isEmpty()) 170 if (text.isEmpty())
171 TypingCommand::deleteSelection(*frame().document(), 0); 171 TypingCommand::deleteSelection(*frame().document(), 0);
172 172
173 clear(); 173 clear();
174 174
175 // According to spec 'beforeinput' should not be sent along with Compositio nEnd, so
176 // dispatch after CompositionEnd if there is any update.
177 // https://w3c.github.io/uievents/#h-events-composition-event-input-events
178 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text ) != DispatchEventResult::NotCanceled)
179 return false;
180
175 insertTextForConfirmedComposition(text); 181 insertTextForConfirmedComposition(text);
176 182
177 return true; 183 return true;
178 } 184 }
179 185
180 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) 186 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior)
181 { 187 {
182 if (!hasComposition()) { 188 if (!hasComposition()) {
183 if (!text.length()) 189 if (!text.length())
184 return false; 190 return false;
191
192 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
193 return false;
194
185 editor().insertText(text, 0); 195 editor().insertText(text, 0);
186 return true; 196 return true;
187 } 197 }
188 198
189 if (text.length()) { 199 if (text.length()) {
190 confirmComposition(text); 200 confirmComposition(text);
191 return true; 201 return true;
192 } 202 }
193 203
194 if (confirmBehavior == DoNotKeepSelection) 204 if (confirmBehavior == DoNotKeepSelection)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (!text.isEmpty()) { 281 if (!text.isEmpty()) {
272 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText())); 282 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText()));
273 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 283 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
274 } 284 }
275 } else { 285 } else {
276 if (!text.isEmpty()) 286 if (!text.isEmpty())
277 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 287 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
278 else 288 else
279 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text); 289 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text);
280 } 290 }
281 if (event) 291 if (event) {
292 // TODO(chongz): Support canceling IME composition.
293 if (event->type() == EventTypeNames::compositionupdate)
294 dispatchBeforeInputFromComposition(target, InputEvent::InputType ::ReplaceContent, text);
282 target->dispatchEvent(event); 295 target->dispatchEvent(event);
296 }
283 } 297 }
284 298
285 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input 299 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input
286 // will delete the old composition with an optimized replace operation. 300 // will delete the old composition with an optimized replace operation.
287 if (text.isEmpty()) { 301 if (text.isEmpty()) {
288 ASSERT(frame().document()); 302 ASSERT(frame().document());
289 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); 303 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking);
290 } 304 }
291 305
292 clear(); 306 clear();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // only the last code-point so that it's possible for a user to correct 460 // only the last code-point so that it's possible for a user to correct
447 // a composition without starting it from the beginning. 461 // a composition without starting it from the beginning.
448 // http://crbug.com/37993 462 // http://crbug.com/37993
449 do { 463 do {
450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) 464 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after)))
451 return; 465 return;
452 if (before == 0) 466 if (before == 0)
453 break; 467 break;
454 ++before; 468 ++before;
455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); 469 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
470 // TODO(chongz): According to spec |data| should be "forward" or "backward".
471 dispatchBeforeInputFromComposition(frame().document()->focusedElement(), Inp utEvent::InputType::DeleteComposedCharacter, "backward");
chongz 2016/04/13 00:34:28 Not sure when will this code path get called...?
yosin_UTC9 2016/04/13 06:13:09 Backspace emulation? Or, Thai keyboard? I remember
chongz 2016/04/13 23:53:08 Actually it will always go into here by pressing b
456 TypingCommand::deleteSelection(*frame().document()); 472 TypingCommand::deleteSelection(*frame().document());
457 } 473 }
458 474
459 DEFINE_TRACE(InputMethodController) 475 DEFINE_TRACE(InputMethodController)
460 { 476 {
461 visitor->trace(m_frame); 477 visitor->trace(m_frame);
462 visitor->trace(m_compositionRange); 478 visitor->trace(m_compositionRange);
463 } 479 }
464 480
465 } // namespace blink 481 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698