| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (!frame.document()) | 117 if (!frame.document()) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 dispatchCompositionUpdateEvent(frame, text); | 120 dispatchCompositionUpdateEvent(frame, text); |
| 121 // 'compositionupdate' event handler may destroy document. | 121 // 'compositionupdate' event handler may destroy document. |
| 122 if (!frame.document()) | 122 if (!frame.document()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 switch (compositionType) { | 125 switch (compositionType) { |
| 126 case TypingCommand::TextCompositionType::TextCompositionUpdate: | 126 case TypingCommand::TextCompositionType::TextCompositionUpdate: |
| 127 TypingCommand::insertText(*frame.document(), text, options, | 127 TypingCommand::insertText(*frame.document(), |
| 128 CommandSource::MenuOrKeyBinding, text, options, |
| 128 compositionType); | 129 compositionType); |
| 129 break; | 130 break; |
| 130 case TypingCommand::TextCompositionType::TextCompositionConfirm: | 131 case TypingCommand::TextCompositionType::TextCompositionConfirm: |
| 131 case TypingCommand::TextCompositionType::TextCompositionCancel: | 132 case TypingCommand::TextCompositionType::TextCompositionCancel: |
| 132 // TODO(chongz): Use TypingCommand::insertText after TextEvent was | 133 // TODO(chongz): Use TypingCommand::insertText after TextEvent was |
| 133 // removed. (Removed from spec since 2012) | 134 // removed. (Removed from spec since 2012) |
| 134 // See TextEvent.idl. | 135 // See TextEvent.idl. |
| 135 frame.eventHandler().handleTextInputEvent(text, 0, | 136 frame.eventHandler().handleTextInputEvent(text, 0, |
| 136 TextEventInputComposition); | 137 TextEventInputComposition); |
| 137 break; | 138 break; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 if (frame().selection().isNone()) | 284 if (frame().selection().isNone()) |
| 284 return false; | 285 return false; |
| 285 | 286 |
| 286 if (!isAvailable()) | 287 if (!isAvailable()) |
| 287 return false; | 288 return false; |
| 288 | 289 |
| 289 // If text is empty, then delete the old composition here. If text is | 290 // If text is empty, then delete the old composition here. If text is |
| 290 // non-empty, InsertTextCommand::input will delete the old composition with | 291 // non-empty, InsertTextCommand::input will delete the old composition with |
| 291 // an optimized replace operation. | 292 // an optimized replace operation. |
| 292 if (text.isEmpty()) | 293 if (text.isEmpty()) { |
| 293 TypingCommand::deleteSelection(document(), 0); | 294 TypingCommand::deleteSelection(document(), CommandSource::MenuOrKeyBinding, |
| 295 0); |
| 296 } |
| 294 | 297 |
| 295 clear(); | 298 clear(); |
| 296 | 299 |
| 297 insertTextDuringCompositionWithEvents( | 300 insertTextDuringCompositionWithEvents( |
| 298 frame(), text, 0, | 301 frame(), text, 0, |
| 299 TypingCommand::TextCompositionType::TextCompositionConfirm); | 302 TypingCommand::TextCompositionType::TextCompositionConfirm); |
| 300 // Event handler might destroy document. | 303 // Event handler might destroy document. |
| 301 if (!isAvailable()) | 304 if (!isAvailable()) |
| 302 return false; | 305 return false; |
| 303 | 306 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // composition node, i.e. !hasComposition() && test.isEmpty(). | 633 // composition node, i.e. !hasComposition() && test.isEmpty(). |
| 631 if (text.isEmpty()) { | 634 if (text.isEmpty()) { |
| 632 if (hasComposition()) { | 635 if (hasComposition()) { |
| 633 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 636 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 634 replaceComposition(emptyString()); | 637 replaceComposition(emptyString()); |
| 635 } else { | 638 } else { |
| 636 // It's weird to call |setComposition()| with empty text outside | 639 // It's weird to call |setComposition()| with empty text outside |
| 637 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so | 640 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so |
| 638 // we simply delete selection without sending extra events. | 641 // we simply delete selection without sending extra events. |
| 639 TypingCommand::deleteSelection(document(), | 642 TypingCommand::deleteSelection(document(), |
| 643 CommandSource::MenuOrKeyBinding, |
| 640 TypingCommand::PreventSpellChecking); | 644 TypingCommand::PreventSpellChecking); |
| 641 } | 645 } |
| 642 | 646 |
| 643 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 647 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 644 // needs to be audited. see http://crbug.com/590369 for more details. | 648 // needs to be audited. see http://crbug.com/590369 for more details. |
| 645 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 649 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 646 | 650 |
| 647 setEditableSelectionOffsets(selectedRange); | 651 setEditableSelectionOffsets(selectedRange); |
| 648 | 652 |
| 649 // No DOM update after 'compositionend'. | 653 // No DOM update after 'compositionend'. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 return; | 916 return; |
| 913 if (before == 0) | 917 if (before == 0) |
| 914 break; | 918 break; |
| 915 ++before; | 919 ++before; |
| 916 } while (frame().selection().start() == frame().selection().end() && | 920 } while (frame().selection().start() == frame().selection().end() && |
| 917 before <= static_cast<int>(selectionOffsets.start())); | 921 before <= static_cast<int>(selectionOffsets.start())); |
| 918 // TODO(chongz): Find a way to distinguish Forward and Backward. | 922 // TODO(chongz): Find a way to distinguish Forward and Backward. |
| 919 dispatchBeforeInputEditorCommand( | 923 dispatchBeforeInputEditorCommand( |
| 920 document().focusedElement(), InputEvent::InputType::DeleteContentBackward, | 924 document().focusedElement(), InputEvent::InputType::DeleteContentBackward, |
| 921 new RangeVector(1, m_frame->selection().firstRange())); | 925 new RangeVector(1, m_frame->selection().firstRange())); |
| 922 TypingCommand::deleteSelection(document()); | 926 TypingCommand::deleteSelection(document(), CommandSource::MenuOrKeyBinding); |
| 923 } | 927 } |
| 924 | 928 |
| 925 // TODO(yabinh): We should reduce the number of selectionchange events. | 929 // TODO(yabinh): We should reduce the number of selectionchange events. |
| 926 void InputMethodController::deleteSurroundingText(int before, int after) { | 930 void InputMethodController::deleteSurroundingText(int before, int after) { |
| 927 if (!editor().canEdit()) | 931 if (!editor().canEdit()) |
| 928 return; | 932 return; |
| 929 const PlainTextRange selectionOffsets(getSelectionOffsets()); | 933 const PlainTextRange selectionOffsets(getSelectionOffsets()); |
| 930 if (selectionOffsets.isNull()) | 934 if (selectionOffsets.isNull()) |
| 931 return; | 935 return; |
| 932 Element* const rootEditableElement = | 936 Element* const rootEditableElement = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 947 return; | 951 return; |
| 948 const Position& position = range.endPosition(); | 952 const Position& position = range.endPosition(); |
| 949 | 953 |
| 950 // Adjust the start of selection for multi-code text(a grapheme cluster | 954 // Adjust the start of selection for multi-code text(a grapheme cluster |
| 951 // contains more than one code point). TODO(yabinh): Adjustment should be | 955 // contains more than one code point). TODO(yabinh): Adjustment should be |
| 952 // based on code point instead of grapheme cluster. | 956 // based on code point instead of grapheme cluster. |
| 953 const size_t diff = computeDistanceToLeftGraphemeBoundary(position); | 957 const size_t diff = computeDistanceToLeftGraphemeBoundary(position); |
| 954 const int adjustedStart = start - static_cast<int>(diff); | 958 const int adjustedStart = start - static_cast<int>(diff); |
| 955 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart))) | 959 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart))) |
| 956 return; | 960 return; |
| 957 TypingCommand::deleteSelection(document()); | 961 TypingCommand::deleteSelection(document(), CommandSource::MenuOrKeyBinding); |
| 958 | 962 |
| 959 selectionEnd = selectionEnd - (selectionStart - adjustedStart); | 963 selectionEnd = selectionEnd - (selectionStart - adjustedStart); |
| 960 selectionStart = adjustedStart; | 964 selectionStart = adjustedStart; |
| 961 } | 965 } |
| 962 | 966 |
| 963 // Select the text to be deleted after selectionEnd. | 967 // Select the text to be deleted after selectionEnd. |
| 964 if (after > 0) { | 968 if (after > 0) { |
| 965 // Adjust the deleted range in case of exceeding the right boundary. | 969 // Adjust the deleted range in case of exceeding the right boundary. |
| 966 const PlainTextRange range(0, selectionEnd + after); | 970 const PlainTextRange range(0, selectionEnd + after); |
| 967 if (range.isNull()) | 971 if (range.isNull()) |
| 968 return; | 972 return; |
| 969 const EphemeralRange& validRange = range.createRange(*rootEditableElement); | 973 const EphemeralRange& validRange = range.createRange(*rootEditableElement); |
| 970 if (validRange.isNull()) | 974 if (validRange.isNull()) |
| 971 return; | 975 return; |
| 972 const int end = | 976 const int end = |
| 973 PlainTextRange::create(*rootEditableElement, validRange).end(); | 977 PlainTextRange::create(*rootEditableElement, validRange).end(); |
| 974 const Position& position = validRange.endPosition(); | 978 const Position& position = validRange.endPosition(); |
| 975 | 979 |
| 976 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment | 980 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment |
| 977 // should be based on code point instead of grapheme cluster. | 981 // should be based on code point instead of grapheme cluster. |
| 978 const size_t diff = computeDistanceToRightGraphemeBoundary(position); | 982 const size_t diff = computeDistanceToRightGraphemeBoundary(position); |
| 979 const int adjustedEnd = end + static_cast<int>(diff); | 983 const int adjustedEnd = end + static_cast<int>(diff); |
| 980 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd))) | 984 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd))) |
| 981 return; | 985 return; |
| 982 TypingCommand::deleteSelection(document()); | 986 TypingCommand::deleteSelection(document(), CommandSource::MenuOrKeyBinding); |
| 983 } | 987 } |
| 984 | 988 |
| 985 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | 989 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); |
| 986 } | 990 } |
| 987 | 991 |
| 988 WebTextInputInfo InputMethodController::textInputInfo() const { | 992 WebTextInputInfo InputMethodController::textInputInfo() const { |
| 989 WebTextInputInfo info; | 993 WebTextInputInfo info; |
| 990 if (!isAvailable()) | 994 if (!isAvailable()) |
| 991 return info; | 995 return info; |
| 992 | 996 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 return WebTextInputTypeNone; | 1197 return WebTextInputTypeNone; |
| 1194 } | 1198 } |
| 1195 | 1199 |
| 1196 DEFINE_TRACE(InputMethodController) { | 1200 DEFINE_TRACE(InputMethodController) { |
| 1197 visitor->trace(m_frame); | 1201 visitor->trace(m_frame); |
| 1198 visitor->trace(m_compositionRange); | 1202 visitor->trace(m_compositionRange); |
| 1199 SynchronousMutationObserver::trace(visitor); | 1203 SynchronousMutationObserver::trace(visitor); |
| 1200 } | 1204 } |
| 1201 | 1205 |
| 1202 } // namespace blink | 1206 } // namespace blink |
| OLD | NEW |