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

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2579253002: [EditCommandSource] Pass source to |CompositEditCommand| and |TypingCommand| (3/3) (Closed)
Patch Set: Created 4 years 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
142 const bool isIncrementalInsertion = needsIncrementalInsertion(frame, text); 142 const bool isIncrementalInsertion = needsIncrementalInsertion(frame, text);
143 143
144 switch (compositionType) { 144 switch (compositionType) {
145 case TypingCommand::TextCompositionType::TextCompositionUpdate: 145 case TypingCommand::TextCompositionType::TextCompositionUpdate:
146 case TypingCommand::TextCompositionType::TextCompositionConfirm: 146 case TypingCommand::TextCompositionType::TextCompositionConfirm:
147 TypingCommand::insertText(*frame.document(), text, options, 147 TypingCommand::insertText(
148 compositionType, isIncrementalInsertion); 148 *frame.document(), EditCommandSource::kMenuOrKeyBinding, text,
149 options, compositionType, isIncrementalInsertion);
149 break; 150 break;
150 case TypingCommand::TextCompositionType::TextCompositionCancel: 151 case TypingCommand::TextCompositionType::TextCompositionCancel:
151 // TODO(chongz): Use TypingCommand::insertText after TextEvent was 152 // TODO(chongz): Use TypingCommand::insertText after TextEvent was
152 // removed. (Removed from spec since 2012) 153 // removed. (Removed from spec since 2012)
153 // See TextEvent.idl. 154 // See TextEvent.idl.
154 frame.eventHandler().handleTextInputEvent(text, 0, 155 frame.eventHandler().handleTextInputEvent(text, 0,
155 TextEventInputComposition); 156 TextEventInputComposition);
156 break; 157 break;
157 default: 158 default:
158 NOTREACHED(); 159 NOTREACHED();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 if (frame().selection().isNone()) 294 if (frame().selection().isNone())
294 return false; 295 return false;
295 296
296 if (!isAvailable()) 297 if (!isAvailable())
297 return false; 298 return false;
298 299
299 // If text is empty, then delete the old composition here. If text is 300 // If text is empty, then delete the old composition here. If text is
300 // non-empty, InsertTextCommand::input will delete the old composition with 301 // non-empty, InsertTextCommand::input will delete the old composition with
301 // an optimized replace operation. 302 // an optimized replace operation.
302 if (text.isEmpty()) 303 if (text.isEmpty()) {
303 TypingCommand::deleteSelection(document(), 0); 304 TypingCommand::deleteSelection(document(),
305 EditCommandSource::kMenuOrKeyBinding, 0);
306 }
304 307
305 clear(); 308 clear();
306 309
307 insertTextDuringCompositionWithEvents( 310 insertTextDuringCompositionWithEvents(
308 frame(), text, 0, 311 frame(), text, 0,
309 TypingCommand::TextCompositionType::TextCompositionConfirm); 312 TypingCommand::TextCompositionType::TextCompositionConfirm);
310 // Event handler might destroy document. 313 // Event handler might destroy document.
311 if (!isAvailable()) 314 if (!isAvailable())
312 return false; 315 return false;
313 316
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // composition node, i.e. !hasComposition() && test.isEmpty(). 495 // composition node, i.e. !hasComposition() && test.isEmpty().
493 if (text.isEmpty()) { 496 if (text.isEmpty()) {
494 if (hasComposition()) { 497 if (hasComposition()) {
495 Editor::RevealSelectionScope revealSelectionScope(&editor()); 498 Editor::RevealSelectionScope revealSelectionScope(&editor());
496 replaceComposition(emptyString()); 499 replaceComposition(emptyString());
497 } else { 500 } else {
498 // It's weird to call |setComposition()| with empty text outside 501 // It's weird to call |setComposition()| with empty text outside
499 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so 502 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so
500 // we simply delete selection without sending extra events. 503 // we simply delete selection without sending extra events.
501 TypingCommand::deleteSelection(document(), 504 TypingCommand::deleteSelection(document(),
505 EditCommandSource::kMenuOrKeyBinding,
502 TypingCommand::PreventSpellChecking); 506 TypingCommand::PreventSpellChecking);
503 } 507 }
504 508
505 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 509 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
506 // needs to be audited. see http://crbug.com/590369 for more details. 510 // needs to be audited. see http://crbug.com/590369 for more details.
507 document().updateStyleAndLayoutIgnorePendingStylesheets(); 511 document().updateStyleAndLayoutIgnorePendingStylesheets();
508 512
509 setEditableSelectionOffsets(selectedRange); 513 setEditableSelectionOffsets(selectedRange);
510 514
511 // No DOM update after 'compositionend'. 515 // No DOM update after 'compositionend'.
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 return; 773 return;
770 if (before == 0) 774 if (before == 0)
771 break; 775 break;
772 ++before; 776 ++before;
773 } while (frame().selection().start() == frame().selection().end() && 777 } while (frame().selection().start() == frame().selection().end() &&
774 before <= static_cast<int>(selectionOffsets.start())); 778 before <= static_cast<int>(selectionOffsets.start()));
775 // TODO(chongz): Find a way to distinguish Forward and Backward. 779 // TODO(chongz): Find a way to distinguish Forward and Backward.
776 dispatchBeforeInputEditorCommand( 780 dispatchBeforeInputEditorCommand(
777 document().focusedElement(), InputEvent::InputType::DeleteContentBackward, 781 document().focusedElement(), InputEvent::InputType::DeleteContentBackward,
778 new RangeVector(1, m_frame->selection().firstRange())); 782 new RangeVector(1, m_frame->selection().firstRange()));
779 TypingCommand::deleteSelection(document()); 783 TypingCommand::deleteSelection(document(),
784 EditCommandSource::kMenuOrKeyBinding);
780 } 785 }
781 786
782 // TODO(yabinh): We should reduce the number of selectionchange events. 787 // TODO(yabinh): We should reduce the number of selectionchange events.
783 void InputMethodController::deleteSurroundingText(int before, int after) { 788 void InputMethodController::deleteSurroundingText(int before, int after) {
784 if (!editor().canEdit()) 789 if (!editor().canEdit())
785 return; 790 return;
786 const PlainTextRange selectionOffsets(getSelectionOffsets()); 791 const PlainTextRange selectionOffsets(getSelectionOffsets());
787 if (selectionOffsets.isNull()) 792 if (selectionOffsets.isNull())
788 return; 793 return;
789 Element* const rootEditableElement = 794 Element* const rootEditableElement =
(...skipping 14 matching lines...) Expand all
804 return; 809 return;
805 const Position& position = range.endPosition(); 810 const Position& position = range.endPosition();
806 811
807 // Adjust the start of selection for multi-code text(a grapheme cluster 812 // Adjust the start of selection for multi-code text(a grapheme cluster
808 // contains more than one code point). TODO(yabinh): Adjustment should be 813 // contains more than one code point). TODO(yabinh): Adjustment should be
809 // based on code point instead of grapheme cluster. 814 // based on code point instead of grapheme cluster.
810 const size_t diff = computeDistanceToLeftGraphemeBoundary(position); 815 const size_t diff = computeDistanceToLeftGraphemeBoundary(position);
811 const int adjustedStart = start - static_cast<int>(diff); 816 const int adjustedStart = start - static_cast<int>(diff);
812 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart))) 817 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart)))
813 return; 818 return;
814 TypingCommand::deleteSelection(document()); 819 TypingCommand::deleteSelection(document(),
820 EditCommandSource::kMenuOrKeyBinding);
815 821
816 selectionEnd = selectionEnd - (selectionStart - adjustedStart); 822 selectionEnd = selectionEnd - (selectionStart - adjustedStart);
817 selectionStart = adjustedStart; 823 selectionStart = adjustedStart;
818 } 824 }
819 825
820 // Select the text to be deleted after selectionEnd. 826 // Select the text to be deleted after selectionEnd.
821 if (after > 0) { 827 if (after > 0) {
822 // Adjust the deleted range in case of exceeding the right boundary. 828 // Adjust the deleted range in case of exceeding the right boundary.
823 const PlainTextRange range(0, selectionEnd + after); 829 const PlainTextRange range(0, selectionEnd + after);
824 if (range.isNull()) 830 if (range.isNull())
825 return; 831 return;
826 const EphemeralRange& validRange = range.createRange(*rootEditableElement); 832 const EphemeralRange& validRange = range.createRange(*rootEditableElement);
827 if (validRange.isNull()) 833 if (validRange.isNull())
828 return; 834 return;
829 const int end = 835 const int end =
830 PlainTextRange::create(*rootEditableElement, validRange).end(); 836 PlainTextRange::create(*rootEditableElement, validRange).end();
831 const Position& position = validRange.endPosition(); 837 const Position& position = validRange.endPosition();
832 838
833 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment 839 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment
834 // should be based on code point instead of grapheme cluster. 840 // should be based on code point instead of grapheme cluster.
835 const size_t diff = computeDistanceToRightGraphemeBoundary(position); 841 const size_t diff = computeDistanceToRightGraphemeBoundary(position);
836 const int adjustedEnd = end + static_cast<int>(diff); 842 const int adjustedEnd = end + static_cast<int>(diff);
837 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd))) 843 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd)))
838 return; 844 return;
839 TypingCommand::deleteSelection(document()); 845 TypingCommand::deleteSelection(document(),
846 EditCommandSource::kMenuOrKeyBinding);
840 } 847 }
841 848
842 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); 849 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
843 } 850 }
844 851
845 WebTextInputInfo InputMethodController::textInputInfo() const { 852 WebTextInputInfo InputMethodController::textInputInfo() const {
846 WebTextInputInfo info; 853 WebTextInputInfo info;
847 if (!isAvailable()) 854 if (!isAvailable())
848 return info; 855 return info;
849 856
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 frame().chromeClient().resetInputMethod(); 1063 frame().chromeClient().resetInputMethod();
1057 } 1064 }
1058 1065
1059 DEFINE_TRACE(InputMethodController) { 1066 DEFINE_TRACE(InputMethodController) {
1060 visitor->trace(m_frame); 1067 visitor->trace(m_frame);
1061 visitor->trace(m_compositionRange); 1068 visitor->trace(m_compositionRange);
1062 SynchronousMutationObserver::trace(visitor); 1069 SynchronousMutationObserver::trace(visitor);
1063 } 1070 }
1064 1071
1065 } // namespace blink 1072 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698