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

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: Yosi's review Created 4 years, 9 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return false; 162 return false;
163 163
164 // If text is empty, then delete the old composition here. If text is 164 // If text is empty, then delete the old composition here. If text is
165 // non-empty, InsertTextCommand::input will delete the old composition with 165 // non-empty, InsertTextCommand::input will delete the old composition with
166 // an optimized replace operation. 166 // an optimized replace operation.
167 if (text.isEmpty()) 167 if (text.isEmpty())
168 TypingCommand::deleteSelection(*frame().document(), 0); 168 TypingCommand::deleteSelection(*frame().document(), 0);
169 169
170 clear(); 170 clear();
171 171
172 // According to spec 'beforeinput' should not be sent along with Compositio nEnd, so
173 // dispatch after CompositionEnd if there is any update.
174 // https://w3c.github.io/uievents/#h-events-composition-event-input-events
175 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text ) != DispatchEventResult::NotCanceled)
176 return false;
177
172 insertTextForConfirmedComposition(text); 178 insertTextForConfirmedComposition(text);
173 179
174 return true; 180 return true;
175 } 181 }
176 182
177 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) 183 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior)
178 { 184 {
179 if (!hasComposition()) { 185 if (!hasComposition()) {
180 if (!text.length()) 186 if (!text.length())
181 return false; 187 return false;
188
189 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
190 return false;
191
182 editor().insertText(text, 0); 192 editor().insertText(text, 0);
183 return true; 193 return true;
184 } 194 }
185 195
186 if (text.length()) { 196 if (text.length()) {
187 confirmComposition(text); 197 confirmComposition(text);
188 return true; 198 return true;
189 } 199 }
190 200
191 if (confirmBehavior != KeepSelection) 201 if (confirmBehavior != KeepSelection)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (!text.isEmpty()) { 278 if (!text.isEmpty()) {
269 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText())); 279 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText()));
270 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 280 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
271 } 281 }
272 } else { 282 } else {
273 if (!text.isEmpty()) 283 if (!text.isEmpty())
274 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 284 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
275 else 285 else
276 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text); 286 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text);
277 } 287 }
278 if (event.get()) 288 if (event.get()) {
289 // TODO(chongz): Support canceling IME composition.
290 if (event->type() == EventTypeNames::compositionupdate)
291 dispatchBeforeInputCompositionUpdate(target, text);
279 target->dispatchEvent(event); 292 target->dispatchEvent(event);
293 }
280 } 294 }
281 295
282 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input 296 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input
yosin_UTC9 2016/03/16 01:46:51 We also dispatch "beforeInput" with "deleteCompose
chongz 2016/03/16 21:51:44 Acknowledged.
chongz 2016/04/13 00:34:28 Done. But I tried several keyboard layouts and Chi
283 // will delete the old composition with an optimized replace operation. 297 // will delete the old composition with an optimized replace operation.
284 if (text.isEmpty()) { 298 if (text.isEmpty()) {
285 ASSERT(frame().document()); 299 ASSERT(frame().document());
286 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); 300 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking);
287 } 301 }
288 302
289 clear(); 303 clear();
290 304
291 if (text.isEmpty()) 305 if (text.isEmpty())
292 return; 306 return;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 TypingCommand::deleteSelection(*frame().document()); 467 TypingCommand::deleteSelection(*frame().document());
454 } 468 }
455 469
456 DEFINE_TRACE(InputMethodController) 470 DEFINE_TRACE(InputMethodController)
457 { 471 {
458 visitor->trace(m_frame); 472 visitor->trace(m_frame);
459 visitor->trace(m_compositionRange); 473 visitor->trace(m_compositionRange);
460 } 474 }
461 475
462 } // namespace blink 476 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698