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

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

Issue 1889053003: Fix InputConnection.deleteSurroundingText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Deal with multi-code-text, and add more tests. Created 4 years, 8 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 do { 449 do {
450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) 450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after)))
451 return; 451 return;
452 if (before == 0) 452 if (before == 0)
453 break; 453 break;
454 ++before; 454 ++before;
455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); 455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
456 TypingCommand::deleteSelection(*frame().document()); 456 TypingCommand::deleteSelection(*frame().document());
457 } 457 }
458 458
459 void InputMethodController::deleteSurroundingText(int before, int after)
460 {
461 if (!editor().canEdit())
462 return;
463 PlainTextRange selectionOffsets(getSelectionOffsets());
464 if (selectionOffsets.isNull())
465 return;
466
467 int selectionStart = static_cast<int>(selectionOffsets.start());
468 int selectionEnd = static_cast<int>(selectionOffsets.end());
469
470 // A common call of before=1 and after=0 will fail if the last character
471 // is multi-code-word UTF-16, including both multi-16bit code-points and
472 // Unicode combining character sequences of multiple single-16bit code-
473 // points (officially called "compositions"). Try more until success.
474 // It's similar to InputMethodController#extendSelectionAndDelete.
475 // http://crbug.com/355995
476 if (before > 0) {
477 int deleteLength, leftStart, leftEnd;
478 do {
479 deleteLength = std::min(selectionStart, before);
480 leftStart = selectionStart - deleteLength;
481 leftEnd = selectionStart;
482 if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd)))
483 return;
484 ++before;
485 } while (frame().selection().start() == frame().selection().end() && bef ore <= static_cast<int>(selectionOffsets.start()));
486 TypingCommand::deleteSelection(*frame().document());
487
488 selectionStart = leftStart;
489 selectionEnd = selectionEnd - deleteLength;
490 }
491
492 if (after > 0) {
Changwan Ryu 2016/04/21 01:07:06 shouldn't we apply the same logic to afterText? do
Changwan Ryu 2016/04/21 01:19:26 talked to yabinh@ offline. It's already covered by
yabinh 2016/04/21 01:24:16 We don't need that. Some multi-code-texts take 2
aelias_OOO_until_Jul13 2016/04/21 04:01:29 OK, but can we call a generic method to snap to th
aelias_OOO_until_Jul13 2016/04/22 08:18:29 I suggest looking in http://icu-project.org/apiref
493 int rightStart = selectionEnd;
494 int rightEnd = selectionEnd + after;
495 if (!setSelectionOffsets(PlainTextRange(rightStart, rightEnd)))
496 return;
497 TypingCommand::deleteSelection(*frame().document());
498 }
499
500 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
501 }
502
459 DEFINE_TRACE(InputMethodController) 503 DEFINE_TRACE(InputMethodController)
460 { 504 {
461 visitor->trace(m_frame); 505 visitor->trace(m_frame);
462 visitor->trace(m_compositionRange); 506 visitor->trace(m_compositionRange);
463 } 507 }
464 508
465 } // namespace blink 509 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698