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

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 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 // TODO(chongz): DOM update should happen before 'compositionend' and along with 'compositionupdate'.
176 // https://crbug.com/575294
177 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text ) != DispatchEventResult::NotCanceled)
178 return false;
179
175 insertTextForConfirmedComposition(text); 180 insertTextForConfirmedComposition(text);
176 181
177 return true; 182 return true;
178 } 183 }
179 184
180 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) 185 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior)
181 { 186 {
182 if (!hasComposition()) { 187 if (!hasComposition()) {
183 if (!text.length()) 188 if (!text.length())
184 return false; 189 return false;
190
191 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
192 return false;
193
185 editor().insertText(text, 0); 194 editor().insertText(text, 0);
186 return true; 195 return true;
187 } 196 }
188 197
189 if (text.length()) { 198 if (text.length()) {
190 confirmComposition(text); 199 confirmComposition(text);
191 return true; 200 return true;
192 } 201 }
193 202
194 if (confirmBehavior == DoNotKeepSelection) 203 if (confirmBehavior == DoNotKeepSelection)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (!text.isEmpty()) { 280 if (!text.isEmpty()) {
272 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText())); 281 target->dispatchEvent(CompositionEvent::create(EventTypeNames::c ompositionstart, frame().domWindow(), frame().selectedText()));
273 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 282 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
274 } 283 }
275 } else { 284 } else {
276 if (!text.isEmpty()) 285 if (!text.isEmpty())
277 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text); 286 event = CompositionEvent::create(EventTypeNames::compositionupda te, frame().domWindow(), text);
278 else 287 else
279 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text); 288 event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text);
280 } 289 }
281 if (event) 290 if (event) {
291 // TODO(chongz): Support canceling IME composition.
292 // TODO(chongz): Should fire InsertText or DeleteComposedCharacter b ased on action.
293 if (event->type() == EventTypeNames::compositionupdate)
294 dispatchBeforeInputFromComposition(target, InputEvent::InputType ::InsertText, 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 DCHECK(frame().document()); 302 DCHECK(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 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent);
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