 Chromium Code Reviews
 Chromium Code Reviews Issue 1889053003:
  Fix InputConnection.deleteSurroundingText()  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1889053003:
  Fix InputConnection.deleteSurroundingText()  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 return; | 465 return; | 
| 466 if (before == 0) | 466 if (before == 0) | 
| 467 break; | 467 break; | 
| 468 ++before; | 468 ++before; | 
| 469 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 469 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 
| 470 // TODO(chongz): According to spec |data| should be "forward" or "backward". | 470 // TODO(chongz): According to spec |data| should be "forward" or "backward". | 
| 471 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent); | 471 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent); | 
| 472 TypingCommand::deleteSelection(*frame().document()); | 472 TypingCommand::deleteSelection(*frame().document()); | 
| 473 } | 473 } | 
| 474 | 474 | 
| 475 void InputMethodController::deleteSurroundingText(size_t before, size_t after) | |
| 
yosin_UTC9
2016/04/26 08:18:54
Can you guarantee |before| is at end of grapheme a
 | |
| 476 { | |
| 477 if (!editor().canEdit()) | |
| 478 return; | |
| 479 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
| 480 if (selectionOffsets.isNull()) | |
| 481 return; | |
| 482 | |
| 483 size_t selectionStart = selectionOffsets.start(); | |
| 484 size_t selectionEnd = selectionOffsets.end(); | |
| 485 | |
| 486 if (before > 0u) { | |
| 487 before = std::min(selectionStart, before); | |
| 
aelias_OOO_until_Jul13
2016/04/26 07:29:32
What is this line for?  I don't understand it.
 
yabinh
2016/04/26 08:05:15
It's for boundary checking. In case that "before"
 
yosin_UTC9
2016/04/27 08:21:16
When |selectionStart|=0 and |before|=2, |before| g
 | |
| 488 | |
| 489 // Select the text to be deleted before selectionStart. | |
| 490 // For multi-code text, we can select it successfully if we only select | |
| 491 // the left half of it, but we can't select it if we only select the | |
| 492 // right half of it. For the latter case, we need to adjust the start | |
| 493 // of selection. | |
| 494 Position basePosition(frame().selection().start().anchorNode(), selectio nStart - before + 1); | |
| 
aelias_OOO_until_Jul13
2016/04/26 07:29:32
Why + 1?
 
yabinh
2016/04/26 08:05:16
Because previousPositionOf(basePosition, PositionM
 | |
| 495 Position adjustedPosition = previousPositionOf(basePosition, PositionMov eType::GraphemeCluster); | |
| 496 int adjustedStart = adjustedPosition.computeOffsetInContainerNode(); | |
| 497 | |
| 498 if (!setSelectionOffsets(PlainTextRange(adjustedStart, static_cast<int>( selectionStart)))) | |
| 499 return; | |
| 500 TypingCommand::deleteSelection(*frame().document()); | |
| 
aelias_OOO_until_Jul13
2016/04/26 07:29:32
Hmm, I still don't like the two deletion calls too
 
yabinh
2016/04/26 08:05:16
I've verified that this patch doesn't trigger any
 
yosin_UTC9
2016/04/26 08:18:54
Better way is using Range::delteContent(). It disp
 
yosin_UTC9
2016/04/26 09:12:29
How did you check these events? Did you check with
 | |
| 501 | |
| 502 selectionEnd = selectionEnd - (selectionStart - adjustedStart); | |
| 503 selectionStart = adjustedStart; | |
| 504 } | |
| 505 | |
| 506 if (after > 0u) { | |
| 507 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after)))) | |
| 
yosin_UTC9
2016/04/26 09:12:29
We may want to |selectionEnd + after| is at end of
 | |
| 508 return; | |
| 509 TypingCommand::deleteSelection(*frame().document()); | |
| 510 } | |
| 511 | |
| 512 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
| 513 } | |
| 514 | |
| 475 DEFINE_TRACE(InputMethodController) | 515 DEFINE_TRACE(InputMethodController) | 
| 476 { | 516 { | 
| 477 visitor->trace(m_frame); | 517 visitor->trace(m_frame); | 
| 478 visitor->trace(m_compositionRange); | 518 visitor->trace(m_compositionRange); | 
| 479 } | 519 } | 
| 480 | 520 | 
| 481 } // namespace blink | 521 } // namespace blink | 
| OLD | NEW |