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

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

Issue 2636043002: Revert of [EditCommandSource] Pass source to |CompositEditCommand| and |TypingCommand| (3/3) (Closed)
Patch Set: Remove command source in ApplyStyleCommandTest.cpp Created 3 years, 11 months 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( 147 TypingCommand::insertText(*frame.document(), text, options,
148 *frame.document(), EditCommandSource::kMenuOrKeyBinding, text, 148 compositionType, isIncrementalInsertion);
149 options, compositionType, isIncrementalInsertion);
150 break; 149 break;
151 case TypingCommand::TextCompositionType::TextCompositionCancel: 150 case TypingCommand::TextCompositionType::TextCompositionCancel:
152 // TODO(chongz): Use TypingCommand::insertText after TextEvent was 151 // TODO(chongz): Use TypingCommand::insertText after TextEvent was
153 // removed. (Removed from spec since 2012) 152 // removed. (Removed from spec since 2012)
154 // See TextEvent.idl. 153 // See TextEvent.idl.
155 frame.eventHandler().handleTextInputEvent(text, 0, 154 frame.eventHandler().handleTextInputEvent(text, 0,
156 TextEventInputComposition); 155 TextEventInputComposition);
157 break; 156 break;
158 default: 157 default:
159 NOTREACHED(); 158 NOTREACHED();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 298
300 if (frame().selection().isNone()) 299 if (frame().selection().isNone())
301 return false; 300 return false;
302 301
303 if (!isAvailable()) 302 if (!isAvailable())
304 return false; 303 return false;
305 304
306 // If text is empty, then delete the old composition here. If text is 305 // If text is empty, then delete the old composition here. If text is
307 // non-empty, InsertTextCommand::input will delete the old composition with 306 // non-empty, InsertTextCommand::input will delete the old composition with
308 // an optimized replace operation. 307 // an optimized replace operation.
309 if (text.isEmpty()) { 308 if (text.isEmpty())
310 TypingCommand::deleteSelection(document(), 309 TypingCommand::deleteSelection(document(), 0);
311 EditCommandSource::kMenuOrKeyBinding, 0);
312 }
313 310
314 clear(); 311 clear();
315 312
316 insertTextDuringCompositionWithEvents( 313 insertTextDuringCompositionWithEvents(
317 frame(), text, 0, 314 frame(), text, 0,
318 TypingCommand::TextCompositionType::TextCompositionConfirm); 315 TypingCommand::TextCompositionType::TextCompositionConfirm);
319 // Event handler might destroy document. 316 // Event handler might destroy document.
320 if (!isAvailable()) 317 if (!isAvailable())
321 return false; 318 return false;
322 319
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // composition node, i.e. !hasComposition() && test.isEmpty(). 528 // composition node, i.e. !hasComposition() && test.isEmpty().
532 if (text.isEmpty()) { 529 if (text.isEmpty()) {
533 if (hasComposition()) { 530 if (hasComposition()) {
534 Editor::RevealSelectionScope revealSelectionScope(&editor()); 531 Editor::RevealSelectionScope revealSelectionScope(&editor());
535 replaceComposition(emptyString()); 532 replaceComposition(emptyString());
536 } else { 533 } else {
537 // It's weird to call |setComposition()| with empty text outside 534 // It's weird to call |setComposition()| with empty text outside
538 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so 535 // composition, however some IME (e.g. Japanese IBus-Anthy) did this, so
539 // we simply delete selection without sending extra events. 536 // we simply delete selection without sending extra events.
540 TypingCommand::deleteSelection(document(), 537 TypingCommand::deleteSelection(document(),
541 EditCommandSource::kMenuOrKeyBinding,
542 TypingCommand::PreventSpellChecking); 538 TypingCommand::PreventSpellChecking);
543 } 539 }
544 540
545 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 541 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
546 // needs to be audited. see http://crbug.com/590369 for more details. 542 // needs to be audited. see http://crbug.com/590369 for more details.
547 document().updateStyleAndLayoutIgnorePendingStylesheets(); 543 document().updateStyleAndLayoutIgnorePendingStylesheets();
548 544
549 setEditableSelectionOffsets(selectedRange); 545 setEditableSelectionOffsets(selectedRange);
550 546
551 // No DOM update after 'compositionend'. 547 // No DOM update after 'compositionend'.
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 return; 786 return;
791 if (before == 0) 787 if (before == 0)
792 break; 788 break;
793 ++before; 789 ++before;
794 } while (frame().selection().start() == frame().selection().end() && 790 } while (frame().selection().start() == frame().selection().end() &&
795 before <= static_cast<int>(selectionOffsets.start())); 791 before <= static_cast<int>(selectionOffsets.start()));
796 // TODO(chongz): Find a way to distinguish Forward and Backward. 792 // TODO(chongz): Find a way to distinguish Forward and Backward.
797 dispatchBeforeInputEditorCommand( 793 dispatchBeforeInputEditorCommand(
798 document().focusedElement(), InputEvent::InputType::DeleteContentBackward, 794 document().focusedElement(), InputEvent::InputType::DeleteContentBackward,
799 new RangeVector(1, m_frame->selection().firstRange())); 795 new RangeVector(1, m_frame->selection().firstRange()));
800 TypingCommand::deleteSelection(document(), 796 TypingCommand::deleteSelection(document());
801 EditCommandSource::kMenuOrKeyBinding);
802 } 797 }
803 798
804 // TODO(yabinh): We should reduce the number of selectionchange events. 799 // TODO(yabinh): We should reduce the number of selectionchange events.
805 void InputMethodController::deleteSurroundingText(int before, int after) { 800 void InputMethodController::deleteSurroundingText(int before, int after) {
806 if (!editor().canEdit()) 801 if (!editor().canEdit())
807 return; 802 return;
808 const PlainTextRange selectionOffsets(getSelectionOffsets()); 803 const PlainTextRange selectionOffsets(getSelectionOffsets());
809 if (selectionOffsets.isNull()) 804 if (selectionOffsets.isNull())
810 return; 805 return;
811 Element* const rootEditableElement = 806 Element* const rootEditableElement =
(...skipping 14 matching lines...) Expand all
826 return; 821 return;
827 const Position& position = range.endPosition(); 822 const Position& position = range.endPosition();
828 823
829 // Adjust the start of selection for multi-code text(a grapheme cluster 824 // Adjust the start of selection for multi-code text(a grapheme cluster
830 // contains more than one code point). TODO(yabinh): Adjustment should be 825 // contains more than one code point). TODO(yabinh): Adjustment should be
831 // based on code point instead of grapheme cluster. 826 // based on code point instead of grapheme cluster.
832 const size_t diff = computeDistanceToLeftGraphemeBoundary(position); 827 const size_t diff = computeDistanceToLeftGraphemeBoundary(position);
833 const int adjustedStart = start - static_cast<int>(diff); 828 const int adjustedStart = start - static_cast<int>(diff);
834 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart))) 829 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart)))
835 return; 830 return;
836 TypingCommand::deleteSelection(document(), 831 TypingCommand::deleteSelection(document());
837 EditCommandSource::kMenuOrKeyBinding);
838 832
839 selectionEnd = selectionEnd - (selectionStart - adjustedStart); 833 selectionEnd = selectionEnd - (selectionStart - adjustedStart);
840 selectionStart = adjustedStart; 834 selectionStart = adjustedStart;
841 } 835 }
842 836
843 // Select the text to be deleted after selectionEnd. 837 // Select the text to be deleted after selectionEnd.
844 if (after > 0) { 838 if (after > 0) {
845 // Adjust the deleted range in case of exceeding the right boundary. 839 // Adjust the deleted range in case of exceeding the right boundary.
846 const PlainTextRange range(0, selectionEnd + after); 840 const PlainTextRange range(0, selectionEnd + after);
847 if (range.isNull()) 841 if (range.isNull())
848 return; 842 return;
849 const EphemeralRange& validRange = range.createRange(*rootEditableElement); 843 const EphemeralRange& validRange = range.createRange(*rootEditableElement);
850 if (validRange.isNull()) 844 if (validRange.isNull())
851 return; 845 return;
852 const int end = 846 const int end =
853 PlainTextRange::create(*rootEditableElement, validRange).end(); 847 PlainTextRange::create(*rootEditableElement, validRange).end();
854 const Position& position = validRange.endPosition(); 848 const Position& position = validRange.endPosition();
855 849
856 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment 850 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment
857 // should be based on code point instead of grapheme cluster. 851 // should be based on code point instead of grapheme cluster.
858 const size_t diff = computeDistanceToRightGraphemeBoundary(position); 852 const size_t diff = computeDistanceToRightGraphemeBoundary(position);
859 const int adjustedEnd = end + static_cast<int>(diff); 853 const int adjustedEnd = end + static_cast<int>(diff);
860 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd))) 854 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd)))
861 return; 855 return;
862 TypingCommand::deleteSelection(document(), 856 TypingCommand::deleteSelection(document());
863 EditCommandSource::kMenuOrKeyBinding);
864 } 857 }
865 858
866 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); 859 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
867 } 860 }
868 861
869 WebTextInputInfo InputMethodController::textInputInfo() const { 862 WebTextInputInfo InputMethodController::textInputInfo() const {
870 WebTextInputInfo info; 863 WebTextInputInfo info;
871 if (!isAvailable()) 864 if (!isAvailable())
872 return info; 865 return info;
873 866
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 frame().chromeClient().resetInputMethod(); 1073 frame().chromeClient().resetInputMethod();
1081 } 1074 }
1082 1075
1083 DEFINE_TRACE(InputMethodController) { 1076 DEFINE_TRACE(InputMethodController) {
1084 visitor->trace(m_frame); 1077 visitor->trace(m_frame);
1085 visitor->trace(m_compositionRange); 1078 visitor->trace(m_compositionRange);
1086 SynchronousMutationObserver::trace(visitor); 1079 SynchronousMutationObserver::trace(visitor);
1087 } 1080 }
1088 1081
1089 } // namespace blink 1082 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698