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

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: handle multi-code text with BackspaceStateMachine::previousPositionOf Created 4 years, 7 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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
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 != 0) {
Changwan Ryu 2016/04/26 05:36:30 before > 0u
487 before = std::min(selectionStart, before);
488
489 // Select the text to be deleted before selectionStart,
490 // and adjust the start of selection in case of multi-code text.
491 Position basePosition(frame().selection().start().anchorNode(), selectio nStart - before + 1);
492 Position adjustedPosition = previousPositionOf(basePosition, PositionMov eType::GraphemeCluster);
493 int adjustedStart = adjustedPosition.computeOffsetInContainerNode();
494
495 if (!setSelectionOffsets(PlainTextRange(adjustedStart, static_cast<int>( selectionStart))))
496 return;
497 TypingCommand::deleteSelection(*frame().document());
498
499 selectionEnd = selectionEnd - (selectionStart - adjustedStart);
500 selectionStart = adjustedStart;
501 }
502
503 if (after != 0) {
Changwan Ryu 2016/04/26 05:36:30 after > 0u Comment still missing: why do you need
504 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after))))
505 return;
506 TypingCommand::deleteSelection(*frame().document());
507 }
508
509 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
510 }
511
475 DEFINE_TRACE(InputMethodController) 512 DEFINE_TRACE(InputMethodController)
476 { 513 {
477 visitor->trace(m_frame); 514 visitor->trace(m_frame);
478 visitor->trace(m_compositionRange); 515 visitor->trace(m_compositionRange);
479 } 516 }
480 517
481 } // namespace blink 518 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698