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

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: Change some comments. Created 4 years, 6 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 if (before == 0) 541 if (before == 0)
542 break; 542 break;
543 ++before; 543 ++before;
544 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); 544 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start()));
545 // TODO(chongz): New spec might want to change InputType. 545 // TODO(chongz): New spec might want to change InputType.
546 // https://github.com/w3c/editing/issues/125#issuecomment-213041256 546 // https://github.com/w3c/editing/issues/125#issuecomment-213041256
547 dispatchBeforeInputEditorCommand(m_frame->document()->focusedElement(), Inpu tEvent::InputType::DeleteContent, emptyString(), new RangeVector(1, m_frame->sel ection().firstRange())); 547 dispatchBeforeInputEditorCommand(m_frame->document()->focusedElement(), Inpu tEvent::InputType::DeleteContent, emptyString(), new RangeVector(1, m_frame->sel ection().firstRange()));
548 TypingCommand::deleteSelection(*frame().document()); 548 TypingCommand::deleteSelection(*frame().document());
549 } 549 }
550 550
551 // TODO(yabinh): We should reduce the number of selectionchange events.
552 void InputMethodController::deleteSurroundingText(size_t before, size_t after)
553 {
554 if (!editor().canEdit())
555 return;
556 PlainTextRange selectionOffsets(getSelectionOffsets());
557 if (selectionOffsets.isNull())
558 return;
559
560 size_t selectionStart = selectionOffsets.start();
561 size_t selectionEnd = selectionOffsets.end();
562
563 if (before > 0u && selectionStart > 0u) {
564 // In case of exceeding the left boundary.
565 before = std::min(selectionStart, before);
566
567 // Select the text to be deleted before selectionStart.
568 // For multi-code text, we can't select it successfully if we only
569 // select the right half of it. So we need to adjust the start of
570 // selection.
571 Position position(frame().selection().start().anchorNode(), selectionSta rt - before + 1);
Changwan Ryu 2016/07/05 15:47:36 On a second look, I'm concerned about this line. I
yabinh 2016/07/06 02:15:02 I think we've already had that case in DeleteSurro
Changwan Ryu 2016/07/06 04:20:19 Hmm... I was more worried about the case where bef
572 Position adjustedPosition = previousPositionOf(position, PositionMoveTyp e::GraphemeCluster);
573 int adjustedStart = adjustedPosition.computeOffsetInContainerNode();
574
575 if (!setSelectionOffsets(PlainTextRange(adjustedStart, static_cast<int>( selectionStart))))
576 return;
577 TypingCommand::deleteSelection(*frame().document());
578
579 selectionEnd = selectionEnd - (selectionStart - adjustedStart);
580 selectionStart = adjustedStart;
581 }
582
583 if (after > 0u) {
584 // Adjust the deleted range in case of exceeding the right boundary.
585 PlainTextRange range(static_cast<int>(selectionEnd), static_cast<int>(se lectionEnd + after));
586 if (range.isNull())
587 return;
588 Element* rootEditableElement = frame().selection().rootEditableElement() ;
589 if (!rootEditableElement)
590 return;
591 const EphemeralRange adjustedRange = range.createRange(*rootEditableElem ent);
592 if (adjustedRange.isNull())
593 return;
594
595 // Select the text to be deleted after selectionEnd.
596 // We also need to adjust the end of selection for multi-code text.
597 Position position(frame().selection().start().anchorNode(), adjustedRang e.endPosition().computeOffsetInContainerNode() - 1);
598 Position adjustedPosition = nextPositionOf(position, PositionMoveType::G raphemeCluster);
599 int adjustedEnd = adjustedPosition.computeOffsetInContainerNode();
600
601 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), adjustedEnd)))
602 return;
603 TypingCommand::deleteSelection(*frame().document());
604 }
605
606 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
607 }
608
551 DEFINE_TRACE(InputMethodController) 609 DEFINE_TRACE(InputMethodController)
552 { 610 {
553 visitor->trace(m_frame); 611 visitor->trace(m_frame);
554 visitor->trace(m_compositionRange); 612 visitor->trace(m_compositionRange);
555 } 613 }
556 614
557 } // namespace blink 615 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698