| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 compositionType == | 99 compositionType == |
| 100 TypingCommand::TextCompositionType::TextCompositionConfirm || | 100 TypingCommand::TextCompositionType::TextCompositionConfirm || |
| 101 compositionType == | 101 compositionType == |
| 102 TypingCommand::TextCompositionType::TextCompositionCancel) | 102 TypingCommand::TextCompositionType::TextCompositionCancel) |
| 103 << "compositionType should be TextCompositionUpdate or " | 103 << "compositionType should be TextCompositionUpdate or " |
| 104 "TextCompositionConfirm or TextCompositionCancel, but got " | 104 "TextCompositionConfirm or TextCompositionCancel, but got " |
| 105 << static_cast<int>(compositionType); | 105 << static_cast<int>(compositionType); |
| 106 if (!frame.document()) | 106 if (!frame.document()) |
| 107 return; | 107 return; |
| 108 | 108 |
| 109 Element* target = frame.document()->focusedElement(); | 109 // TODO(chongz): Remove the following code after we have ensured it's OK to |
| 110 if (!target) | 110 // fire 'beforeinput' after 'compositionupdate'. |
| 111 return; | 111 // https://crbug.com/675820 |
| 112 | 112 if (compositionType == TypingCommand::TextCompositionUpdate || |
| 113 // TODO(chongz): Fire 'beforeinput' for the composed text being | 113 compositionType == TypingCommand::TextCompositionConfirm) { |
| 114 // replaced/deleted. | 114 Element* target = frame.document()->focusedElement(); |
| 115 | 115 if (!target) |
| 116 // Only the last confirmed text is cancelable. | 116 return; |
| 117 InputEvent::EventCancelable beforeInputCancelable = | 117 // Only the last confirmed text is cancelable. |
| 118 (compositionType == | 118 const InputEvent::EventCancelable beforeInputCancelable = |
| 119 TypingCommand::TextCompositionType::TextCompositionUpdate) | 119 (compositionType == TypingCommand::TextCompositionUpdate) |
| 120 ? InputEvent::EventCancelable::NotCancelable | 120 ? InputEvent::EventCancelable::NotCancelable |
| 121 : InputEvent::EventCancelable::IsCancelable; | 121 : InputEvent::EventCancelable::IsCancelable; |
| 122 DispatchEventResult result = dispatchBeforeInputFromComposition( | 122 RangeVector* targetRanges = nullptr; |
| 123 target, InputEvent::InputType::InsertText, text, beforeInputCancelable); | 123 if (frame.editor().canEditRichly()) |
| 124 | 124 targetRanges = new RangeVector(1, frame.selection().firstRange()); |
| 125 if (beforeInputCancelable == InputEvent::EventCancelable::IsCancelable && | 125 const bool isCanceled = !dispatchBeforeInputEvent( |
| 126 result != DispatchEventResult::NotCanceled) | 126 EditCommandSource::kMenuOrKeyBinding, &frame, target, |
| 127 return; | 127 InputEvent::InputType::InsertText, text, nullptr, beforeInputCancelable, |
| 128 | 128 InputEvent::IsComposing, targetRanges); |
| 129 // 'beforeinput' event handler may destroy document. | 129 if (isCanceled) |
| 130 if (!frame.document()) | 130 return; |
| 131 return; | 131 } |
| 132 | 132 |
| 133 dispatchCompositionUpdateEvent(frame, text); | 133 dispatchCompositionUpdateEvent(frame, text); |
| 134 // 'compositionupdate' event handler may destroy document. | 134 // 'compositionupdate' event handler may destroy document. |
| 135 if (!frame.document()) | 135 if (!frame.document()) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 138 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 139 // needs to be audited. see http://crbug.com/590369 for more details. | 139 // needs to be audited. see http://crbug.com/590369 for more details. |
| 140 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 140 frame.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 141 | 141 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (!moveCaret(absoluteCaretPosition)) | 345 if (!moveCaret(absoluteCaretPosition)) |
| 346 return false; | 346 return false; |
| 347 | 347 |
| 348 // No DOM update after 'compositionend'. | 348 // No DOM update after 'compositionend'. |
| 349 dispatchCompositionEndEvent(frame(), text); | 349 dispatchCompositionEndEvent(frame(), text); |
| 350 | 350 |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool InputMethodController::insertText(const String& text) { | 354 bool InputMethodController::insertText(const String& text) { |
| 355 if (dispatchBeforeInputInsertText(document().focusedElement(), text) != | |
| 356 DispatchEventResult::NotCanceled) | |
| 357 return false; | |
| 358 editor().insertText(text, 0); | 355 editor().insertText(text, 0); |
| 359 return true; | 356 return true; |
| 360 } | 357 } |
| 361 | 358 |
| 362 bool InputMethodController::insertTextAndMoveCaret(const String& text, | 359 bool InputMethodController::insertTextAndMoveCaret(const String& text, |
| 363 int relativeCaretPosition) { | 360 int relativeCaretPosition) { |
| 364 PlainTextRange selectionRange = getSelectionOffsets(); | 361 PlainTextRange selectionRange = getSelectionOffsets(); |
| 365 if (selectionRange.isNull()) | 362 if (selectionRange.isNull()) |
| 366 return false; | 363 return false; |
| 367 int textStart = selectionRange.start(); | 364 int textStart = selectionRange.start(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 380 if (!hasComposition()) | 377 if (!hasComposition()) |
| 381 return; | 378 return; |
| 382 | 379 |
| 383 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 380 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 384 | 381 |
| 385 if (frame().selection().isNone()) | 382 if (frame().selection().isNone()) |
| 386 return; | 383 return; |
| 387 | 384 |
| 388 clear(); | 385 clear(); |
| 389 | 386 |
| 390 // TODO(chongz): Figure out which InputType should we use here. | |
| 391 dispatchBeforeInputFromComposition( | |
| 392 document().focusedElement(), | |
| 393 InputEvent::InputType::DeleteComposedCharacterBackward, nullAtom, | |
| 394 InputEvent::EventCancelable::NotCancelable); | |
| 395 dispatchCompositionUpdateEvent(frame(), emptyString()); | 387 dispatchCompositionUpdateEvent(frame(), emptyString()); |
| 396 insertTextDuringCompositionWithEvents( | 388 insertTextDuringCompositionWithEvents( |
| 397 frame(), emptyString(), 0, | 389 frame(), emptyString(), 0, |
| 398 TypingCommand::TextCompositionType::TextCompositionCancel); | 390 TypingCommand::TextCompositionType::TextCompositionCancel); |
| 399 // Event handler might destroy document. | 391 // Event handler might destroy document. |
| 400 if (!isAvailable()) | 392 if (!isAvailable()) |
| 401 return; | 393 return; |
| 402 | 394 |
| 403 // An open typing command that disagrees about current selection would cause | 395 // An open typing command that disagrees about current selection would cause |
| 404 // issues with typing later on. | 396 // issues with typing later on. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 do { | 761 do { |
| 770 if (!setSelectionOffsets(PlainTextRange( | 762 if (!setSelectionOffsets(PlainTextRange( |
| 771 std::max(static_cast<int>(selectionOffsets.start()) - before, 0), | 763 std::max(static_cast<int>(selectionOffsets.start()) - before, 0), |
| 772 selectionOffsets.end() + after))) | 764 selectionOffsets.end() + after))) |
| 773 return; | 765 return; |
| 774 if (before == 0) | 766 if (before == 0) |
| 775 break; | 767 break; |
| 776 ++before; | 768 ++before; |
| 777 } while (frame().selection().start() == frame().selection().end() && | 769 } while (frame().selection().start() == frame().selection().end() && |
| 778 before <= static_cast<int>(selectionOffsets.start())); | 770 before <= static_cast<int>(selectionOffsets.start())); |
| 779 // TODO(chongz): Find a way to distinguish Forward and Backward. | |
| 780 dispatchBeforeInputEditorCommand( | |
| 781 document().focusedElement(), InputEvent::InputType::DeleteContentBackward, | |
| 782 new RangeVector(1, m_frame->selection().firstRange())); | |
| 783 TypingCommand::deleteSelection(document(), | 771 TypingCommand::deleteSelection(document(), |
| 784 EditCommandSource::kMenuOrKeyBinding); | 772 EditCommandSource::kMenuOrKeyBinding); |
| 785 } | 773 } |
| 786 | 774 |
| 787 // TODO(yabinh): We should reduce the number of selectionchange events. | 775 // TODO(yabinh): We should reduce the number of selectionchange events. |
| 788 void InputMethodController::deleteSurroundingText(int before, int after) { | 776 void InputMethodController::deleteSurroundingText(int before, int after) { |
| 789 if (!editor().canEdit()) | 777 if (!editor().canEdit()) |
| 790 return; | 778 return; |
| 791 const PlainTextRange selectionOffsets(getSelectionOffsets()); | 779 const PlainTextRange selectionOffsets(getSelectionOffsets()); |
| 792 if (selectionOffsets.isNull()) | 780 if (selectionOffsets.isNull()) |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 frame().chromeClient().resetInputMethod(); | 1051 frame().chromeClient().resetInputMethod(); |
| 1064 } | 1052 } |
| 1065 | 1053 |
| 1066 DEFINE_TRACE(InputMethodController) { | 1054 DEFINE_TRACE(InputMethodController) { |
| 1067 visitor->trace(m_frame); | 1055 visitor->trace(m_frame); |
| 1068 visitor->trace(m_compositionRange); | 1056 visitor->trace(m_compositionRange); |
| 1069 SynchronousMutationObserver::trace(visitor); | 1057 SynchronousMutationObserver::trace(visitor); |
| 1070 } | 1058 } |
| 1071 | 1059 |
| 1072 } // namespace blink | 1060 } // namespace blink |
| OLD | NEW |