Chromium Code Reviews| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Used to insert/replace text during composition update and confirm composition . | 69 // Used to insert/replace text during composition update and confirm composition . |
| 70 // Procedure: | 70 // Procedure: |
| 71 // 1. Fire 'beforeinput' event for (TODO(chongz): deleted composed text) and i nserted text | 71 // 1. Fire 'beforeinput' event for (TODO(chongz): deleted composed text) and i nserted text |
| 72 // 2. Fire 'compositionupdate' event | 72 // 2. Fire 'compositionupdate' event |
| 73 // 3. Fire TextEvent and modify DOM | 73 // 3. Fire TextEvent and modify DOM |
| 74 // TODO(chongz): 4. Fire 'input' event | 74 // TODO(chongz): 4. Fire 'input' event |
| 75 void insertTextDuringCompositionWithEvents(LocalFrame& frame, const String& text , TypingCommand::Options options, TypingCommand::TextCompositionType composition Type) | 75 void insertTextDuringCompositionWithEvents(LocalFrame& frame, const String& text , TypingCommand::Options options, TypingCommand::TextCompositionType composition Type) |
| 76 { | 76 { |
| 77 DCHECK(compositionType == TypingCommand::TextCompositionType::TextCompositio nUpdate || compositionType == TypingCommand::TextCompositionType::TextCompositio nConfirm) | 77 DCHECK(compositionType == TypingCommand::TextCompositionType::TextCompositio nUpdate || compositionType == TypingCommand::TextCompositionType::TextCompositio nConfirm || compositionType == TypingCommand::TextCompositionType::TextCompositi onCancel) |
| 78 << "compositionType should be TextCompositionUpdate or TextCompositionCo nfirm, but got " << static_cast<int>(compositionType); | 78 << "compositionType should be TextCompositionUpdate or TextCompositionCo nfirm or TextCompositionCancel, but got " << static_cast<int>(compositionType); |
| 79 if (!frame.document()) | 79 if (!frame.document()) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 Element* target = frame.document()->focusedElement(); | 82 Element* target = frame.document()->focusedElement(); |
| 83 if (!target) | 83 if (!target) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 // TODO(chongz): Fire 'beforeinput' for the composed text being replaced/del eted. | 86 // TODO(chongz): Fire 'beforeinput' for the composed text being replaced/del eted. |
| 87 | 87 |
| 88 // Only the last confirmed text is cancelable. | 88 // Only the last confirmed text is cancelable. |
| 89 InputEvent::EventCancelable beforeInputCancelable = (compositionType == Typi ngCommand::TextCompositionType::TextCompositionUpdate) ? InputEvent::EventCancel able::NotCancelable : InputEvent::EventCancelable::IsCancelable; | 89 InputEvent::EventCancelable beforeInputCancelable = (compositionType == Typi ngCommand::TextCompositionType::TextCompositionUpdate) ? InputEvent::EventCancel able::NotCancelable : InputEvent::EventCancelable::IsCancelable; |
| 90 DispatchEventResult result = dispatchBeforeInputFromComposition(target, Inpu tEvent::InputType::InsertText, text, beforeInputCancelable); | 90 DispatchEventResult result = dispatchBeforeInputFromComposition(target, Inpu tEvent::InputType::InsertText, text, beforeInputCancelable); |
| 91 | 91 |
| 92 if (beforeInputCancelable == InputEvent::EventCancelable::IsCancelable && re sult != DispatchEventResult::NotCanceled) | 92 if (beforeInputCancelable == InputEvent::EventCancelable::IsCancelable && re sult != DispatchEventResult::NotCanceled) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 // 'beforeinput' event handler may destroy document. | 95 // 'beforeinput' event handler may destroy document. |
| 96 if (!frame.document()) | 96 if (!frame.document()) |
| 97 return; | 97 return; |
| 98 | 98 |
| 99 dispatchCompositionUpdateEvent(frame, text); | 99 dispatchCompositionUpdateEvent(frame, text); |
| 100 // 'compositionupdate' event handler may destroy document. | 100 // 'compositionupdate' event handler may destroy document. |
| 101 if (!frame.document()) | 101 if (!frame.document()) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 switch (compositionType) { | 104 switch (compositionType) { |
| 105 case TypingCommand::TextCompositionType::TextCompositionUpdate: | 105 case TypingCommand::TextCompositionType::TextCompositionUpdate: |
| 106 case TypingCommand::TextCompositionType::TextCompositionConfirm: | |
| 106 TypingCommand::insertText(*frame.document(), text, options, compositionT ype); | 107 TypingCommand::insertText(*frame.document(), text, options, compositionT ype); |
| 107 break; | 108 break; |
| 108 case TypingCommand::TextCompositionType::TextCompositionConfirm: | 109 case TypingCommand::TextCompositionType::TextCompositionCancel: |
| 109 // TODO(chongz): Use TypingCommand::insertText after TextEvent was remov ed. (Removed from spec since 2012) | 110 // TODO(chongz): Use TypingCommand::insertText after TextEvent was remov ed. (Removed from spec since 2012) |
| 110 // See TextEvent.idl. | 111 // See TextEvent.idl. |
| 111 frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputComposi tion); | 112 frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputComposi tion); |
| 112 break; | 113 break; |
| 113 default: | 114 default: |
| 114 NOTREACHED(); | 115 NOTREACHED(); |
| 115 } | 116 } |
| 116 // TODO(chongz): Fire 'input' event. | 117 // TODO(chongz): Fire 'input' event. |
| 117 } | 118 } |
| 118 | 119 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 267 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 267 | 268 |
| 268 if (frame().selection().isNone()) | 269 if (frame().selection().isNone()) |
| 269 return; | 270 return; |
| 270 | 271 |
| 271 clear(); | 272 clear(); |
| 272 | 273 |
| 273 // TODO(chongz): Update InputType::DeleteComposedCharacter with latest discu ssion. | 274 // TODO(chongz): Update InputType::DeleteComposedCharacter with latest discu ssion. |
| 274 dispatchBeforeInputFromComposition(frame().document()->focusedElement(), Inp utEvent::InputType::DeleteComposedCharacter, emptyString(), InputEvent::EventCan celable::NotCancelable); | 275 dispatchBeforeInputFromComposition(frame().document()->focusedElement(), Inp utEvent::InputType::DeleteComposedCharacter, emptyString(), InputEvent::EventCan celable::NotCancelable); |
| 275 dispatchCompositionUpdateEvent(frame(), emptyString()); | 276 dispatchCompositionUpdateEvent(frame(), emptyString()); |
| 276 insertTextDuringCompositionWithEvents(frame(), emptyString(), 0, TypingComma nd::TextCompositionType::TextCompositionConfirm); | 277 insertTextDuringCompositionWithEvents(frame(), emptyString(), 0, TypingComma nd::TextCompositionType::TextCompositionCancel); |
|
Changwan Ryu
2016/07/14 02:11:08
any chance that we incorrectly adjust selection fo
| |
| 277 // Event handler might destroy document. | 278 // Event handler might destroy document. |
| 278 if (!frame().document()) | 279 if (!frame().document()) |
| 279 return; | 280 return; |
| 280 | 281 |
| 281 // An open typing command that disagrees about current selection would cause | 282 // An open typing command that disagrees about current selection would cause |
| 282 // issues with typing later on. | 283 // issues with typing later on. |
| 283 TypingCommand::closeTyping(m_frame); | 284 TypingCommand::closeTyping(m_frame); |
| 284 | 285 |
| 285 // No DOM update after 'compositionend'. | 286 // No DOM update after 'compositionend'. |
| 286 dispatchCompositionEndEvent(frame(), emptyString()); | 287 dispatchCompositionEndEvent(frame(), emptyString()); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 TypingCommand::deleteSelection(*frame().document()); | 561 TypingCommand::deleteSelection(*frame().document()); |
| 561 } | 562 } |
| 562 | 563 |
| 563 DEFINE_TRACE(InputMethodController) | 564 DEFINE_TRACE(InputMethodController) |
| 564 { | 565 { |
| 565 visitor->trace(m_frame); | 566 visitor->trace(m_frame); |
| 566 visitor->trace(m_compositionRange); | 567 visitor->trace(m_compositionRange); |
| 567 } | 568 } |
| 568 | 569 |
| 569 } // namespace blink | 570 } // namespace blink |
| OLD | NEW |