OLD | NEW |
---|---|
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 Loading... | |
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 | |
ojan
2016/04/16 00:11:45
Nit: two spaces before CompositionEnd
chongz
2016/04/18 22:54:47
Done.
| |
176 // dispatch after CompositionEnd if there is any update. | |
177 // https://w3c.github.io/uievents/#h-events-composition-event-input-events | |
ojan
2016/04/16 00:11:45
I believe the point of this part of the spec is th
chongz
2016/04/18 22:54:47
Yes we shouldn't modify DOM after 'compositionend'
| |
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 Loading... | |
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 // TODO(chongz): Should fire InsertText or DeleteComposedCharacter b ased on action. | |
294 if (event->type() == EventTypeNames::compositionupdate) | |
295 dispatchBeforeInputFromComposition(target, InputEvent::InputType ::InsertText, text); | |
chongz
2016/04/13 23:53:09
Based on discussion on GitHub DeleteComposedCharac
| |
282 target->dispatchEvent(event); | 296 target->dispatchEvent(event); |
297 } | |
283 } | 298 } |
284 | 299 |
285 // If text is empty, then delete the old composition here. If text is non-em pty, InsertTextCommand::input | 300 // 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. | 301 // will delete the old composition with an optimized replace operation. |
287 if (text.isEmpty()) { | 302 if (text.isEmpty()) { |
288 ASSERT(frame().document()); | 303 ASSERT(frame().document()); |
289 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); | 304 TypingCommand::deleteSelection(*frame().document(), TypingCommand::Preve ntSpellChecking); |
290 } | 305 } |
291 | 306 |
292 clear(); | 307 clear(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 // only the last code-point so that it's possible for a user to correct | 461 // only the last code-point so that it's possible for a user to correct |
447 // a composition without starting it from the beginning. | 462 // a composition without starting it from the beginning. |
448 // http://crbug.com/37993 | 463 // http://crbug.com/37993 |
449 do { | 464 do { |
450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) | 465 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) |
451 return; | 466 return; |
452 if (before == 0) | 467 if (before == 0) |
453 break; | 468 break; |
454 ++before; | 469 ++before; |
455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 470 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); |
471 // TODO(chongz): According to spec |data| should be "forward" or "backward". | |
ojan
2016/04/16 00:11:45
Shouldn't data be the text that's going to be dele
chongz
2016/04/18 22:54:47
Spec says:
```
6. If the user indicated deletion o
ojan
2016/04/20 16:58:57
Whoops. I forgot to respond to this. That behavior
| |
472 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent); | |
456 TypingCommand::deleteSelection(*frame().document()); | 473 TypingCommand::deleteSelection(*frame().document()); |
457 } | 474 } |
458 | 475 |
459 DEFINE_TRACE(InputMethodController) | 476 DEFINE_TRACE(InputMethodController) |
460 { | 477 { |
461 visitor->trace(m_frame); | 478 visitor->trace(m_frame); |
462 visitor->trace(m_compositionRange); | 479 visitor->trace(m_compositionRange); |
463 } | 480 } |
464 | 481 |
465 } // namespace blink | 482 } // namespace blink |
OLD | NEW |