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

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

Issue 2370663002: Remove logic to reset input method more than needed (Closed)
Patch Set: fix test, fix IMC 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 frame().selection().setSelection( 241 frame().selection().setSelection(
242 SelectionInDOMTree::Builder().setBaseAndExtent(range).build(), 0); 242 SelectionInDOMTree::Builder().setBaseAndExtent(range).build(), 0);
243 } 243 }
244 244
245 bool InputMethodController::finishComposingText( 245 bool InputMethodController::finishComposingText(
246 ConfirmCompositionBehavior confirmBehavior) { 246 ConfirmCompositionBehavior confirmBehavior) {
247 if (!hasComposition()) 247 if (!hasComposition())
248 return false; 248 return false;
249 249
250 if (confirmBehavior == KeepSelection) { 250 if (confirmBehavior == KeepSelection) {
251 // Do not dismiss handles if we are not moving selection.
252 int selectionOptions = frame().selection().isHandleVisible()
253 ? FrameSelection::HandleVisible
254 : 0;
Changwan Ryu 2017/01/19 09:13:39 yosin@, could you take another look at this part?
yosin_UTC9 2017/01/19 09:29:51 This is yet another case |FrameSeleciton.isHandleV
Changwan Ryu 2017/01/19 11:42:59 Thanks for the pointer. I considered fixing FrameS
251 PlainTextRange oldOffsets = getSelectionOffsets(); 255 PlainTextRange oldOffsets = getSelectionOffsets();
252 Editor::RevealSelectionScope revealSelectionScope(&editor()); 256 Editor::RevealSelectionScope revealSelectionScope(&editor());
253 257
254 const String& composing = composingText(); 258 const String& composing = composingText();
255 const bool result = replaceComposition(composing); 259 const bool result = replaceComposition(composing);
256 260
257 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 261 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
258 // needs to be audited. see http://crbug.com/590369 for more details. 262 // needs to be audited. see http://crbug.com/590369 for more details.
259 document().updateStyleAndLayoutIgnorePendingStylesheets(); 263 document().updateStyleAndLayoutIgnorePendingStylesheets();
260 264
261 setSelectionOffsets(oldOffsets); 265 setSelectionOffsets(oldOffsets, selectionOptions);
262 266
263 // No DOM update after 'compositionend'. 267 // No DOM update after 'compositionend'.
264 dispatchCompositionEndEvent(frame(), composing); 268 dispatchCompositionEndEvent(frame(), composing);
265 269
266 return result; 270 return result;
267 } 271 }
268 272
269 return replaceCompositionAndMoveCaret(composingText(), 0, 273 return replaceCompositionAndMoveCaret(composingText(), 0,
270 Vector<CompositionUnderline>()); 274 Vector<CompositionUnderline>());
271 } 275 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return; 438 return;
435 439
436 // An open typing command that disagrees about current selection would cause 440 // An open typing command that disagrees about current selection would cause
437 // issues with typing later on. 441 // issues with typing later on.
438 TypingCommand::closeTyping(m_frame); 442 TypingCommand::closeTyping(m_frame);
439 443
440 // No DOM update after 'compositionend'. 444 // No DOM update after 'compositionend'.
441 dispatchCompositionEndEvent(frame(), emptyString()); 445 dispatchCompositionEndEvent(frame(), emptyString());
442 } 446 }
443 447
444 void InputMethodController::cancelCompositionIfSelectionIsInvalid() {
445 if (!hasComposition() || editor().preventRevealSelection())
446 return;
447
448 // Check if selection start and selection end are valid.
449 FrameSelection& selection = frame().selection();
450 if (!selection.isNone() && !m_compositionRange->collapsed()) {
451 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0 &&
452 selection.end().compareTo(m_compositionRange->endPosition()) <= 0)
453 return;
454 }
455
456 cancelComposition();
457 frame().chromeClient().didCancelCompositionOnSelectionChange();
458 }
459
460 // If current position is at grapheme boundary, return 0; otherwise, return the 448 // If current position is at grapheme boundary, return 0; otherwise, return the
461 // distance to its nearest left grapheme boundary. 449 // distance to its nearest left grapheme boundary.
462 static size_t computeDistanceToLeftGraphemeBoundary(const Position& position) { 450 static size_t computeDistanceToLeftGraphemeBoundary(const Position& position) {
463 const Position& adjustedPosition = previousPositionOf( 451 const Position& adjustedPosition = previousPositionOf(
464 nextPositionOf(position, PositionMoveType::GraphemeCluster), 452 nextPositionOf(position, PositionMoveType::GraphemeCluster),
465 PositionMoveType::GraphemeCluster); 453 PositionMoveType::GraphemeCluster);
466 DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode()); 454 DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode());
467 DCHECK_GE(position.computeOffsetInContainerNode(), 455 DCHECK_GE(position.computeOffsetInContainerNode(),
468 adjustedPosition.computeOffsetInContainerNode()); 456 adjustedPosition.computeOffsetInContainerNode());
469 return static_cast<size_t>(position.computeOffsetInContainerNode() - 457 return static_cast<size_t>(position.computeOffsetInContainerNode() -
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 frame().chromeClient().resetInputMethod(); 1061 frame().chromeClient().resetInputMethod();
1074 } 1062 }
1075 1063
1076 DEFINE_TRACE(InputMethodController) { 1064 DEFINE_TRACE(InputMethodController) {
1077 visitor->trace(m_frame); 1065 visitor->trace(m_frame);
1078 visitor->trace(m_compositionRange); 1066 visitor->trace(m_compositionRange);
1079 SynchronousMutationObserver::trace(visitor); 1067 SynchronousMutationObserver::trace(visitor);
1080 } 1068 }
1081 1069
1082 } // namespace blink 1070 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.h ('k') | third_party/WebKit/Source/core/page/ChromeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698