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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 if (before == 0) | 553 if (before == 0) |
554 break; | 554 break; |
555 ++before; | 555 ++before; |
556 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 556 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); |
557 // TODO(chongz): New spec might want to change InputType. | 557 // TODO(chongz): New spec might want to change InputType. |
558 // https://github.com/w3c/editing/issues/125#issuecomment-213041256 | 558 // https://github.com/w3c/editing/issues/125#issuecomment-213041256 |
559 dispatchBeforeInputEditorCommand(m_frame->document()->focusedElement(), Inpu tEvent::InputType::DeleteContent, emptyString(), new RangeVector(1, m_frame->sel ection().firstRange())); | 559 dispatchBeforeInputEditorCommand(m_frame->document()->focusedElement(), Inpu tEvent::InputType::DeleteContent, emptyString(), new RangeVector(1, m_frame->sel ection().firstRange())); |
560 TypingCommand::deleteSelection(*frame().document()); | 560 TypingCommand::deleteSelection(*frame().document()); |
561 } | 561 } |
562 | 562 |
563 // TODO(yabinh): We should reduce the number of selectionchange events. | |
564 void InputMethodController::deleteSurroundingText(size_t before, size_t after) | |
565 { | |
566 if (!editor().canEdit()) | |
567 return; | |
568 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
569 if (selectionOffsets.isNull()) | |
570 return; | |
571 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
572 if (!rootEditableElement) | |
573 return; | |
574 | |
575 size_t selectionStart = selectionOffsets.start(); | |
576 size_t selectionEnd = selectionOffsets.end(); | |
577 | |
578 if (before > 0u && selectionStart > 0u) { | |
579 // In case of exceeding the left boundary. | |
580 int start = std::max(static_cast<int>(selectionStart) - static_cast<int> (before), 0); | |
581 | |
582 // Select the text to be deleted before selectionStart. | |
583 // For multi-code text, we can't select it successfully if we only | |
yosin_UTC9
2016/10/04 09:59:54
What do you mean "multi-code text"? Do you mean a
yabinh
2016/10/11 03:16:57
Yes. I'll add some comment in the next patch.
| |
584 // select the right half of it. So we need to adjust the start of | |
585 // selection. | |
586 const EphemeralRange range = PlainTextRange(0, start).createRange(*rootE ditableElement); | |
yosin_UTC9
2016/10/04 09:59:54
s/const EphemeralRange/const EphemeralRange&/
yabinh
2016/10/11 03:16:57
Done.
| |
587 if (range.isNull()) | |
588 return; | |
589 Position position = range.endPosition(); | |
590 Position adjustedPosition = previousPositionOf(nextPositionOf(position, PositionMoveType::GraphemeCluster), PositionMoveType::GraphemeCluster); | |
591 int diff = adjustedPosition.computeOffsetInContainerNode() - position.co mputeOffsetInContainerNode(); | |
Changwan Ryu
2016/07/20 08:37:42
what should happen if adjustedPosition and positio
yabinh
2016/07/20 11:49:16
There is no such case. I'll add assertion here.
| |
592 start = start + diff; | |
593 | |
594 if (!setSelectionOffsets(PlainTextRange(start, static_cast<int>(selectio nStart)))) | |
595 return; | |
596 TypingCommand::deleteSelection(*frame().document()); | |
597 | |
598 selectionEnd = selectionEnd - (selectionStart - start); | |
599 selectionStart = start; | |
600 } | |
601 | |
602 if (after > 0u) { | |
603 // Adjust the deleted range in case of exceeding the right boundary. | |
604 PlainTextRange range(0, static_cast<int>(selectionEnd + after)); | |
605 if (range.isNull()) | |
606 return; | |
607 const EphemeralRange validRange = range.createRange(*rootEditableElement ); | |
608 if (validRange.isNull()) | |
609 return; | |
610 int end = PlainTextRange::create(*rootEditableElement, validRange).end() ; | |
611 | |
612 // We also need to adjust the end of selection for multi-code text. | |
613 Position position = validRange.endPosition(); | |
yosin_UTC9
2016/10/04 09:59:54
nit: s/Position/const Position&/
yabinh
2016/10/11 03:16:57
Done.
| |
614 Position adjustedPosition = nextPositionOf(previousPositionOf(position, PositionMoveType::GraphemeCluster), PositionMoveType::GraphemeCluster); | |
yosin_UTC9
2016/10/04 09:59:54
nit: s/Position/const Position&/
yabinh
2016/10/11 03:16:57
Done.
| |
615 int diff = adjustedPosition.computeOffsetInContainerNode() - position.co mputeOffsetInContainerNode(); | |
Changwan Ryu
2016/07/20 08:37:42
same comment applies here
yosin_UTC9
2016/10/04 09:59:54
We should handle in case of position.computeContai
yabinh
2016/10/11 03:16:57
It seems that we couldn't find such a case. As we
| |
616 end = end + diff; | |
617 | |
618 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), end))) | |
619 return; | |
620 TypingCommand::deleteSelection(*frame().document()); | |
621 } | |
622 | |
623 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
624 } | |
625 | |
563 DEFINE_TRACE(InputMethodController) | 626 DEFINE_TRACE(InputMethodController) |
564 { | 627 { |
565 visitor->trace(m_frame); | 628 visitor->trace(m_frame); |
566 visitor->trace(m_compositionRange); | 629 visitor->trace(m_compositionRange); |
567 } | 630 } |
568 | 631 |
569 } // namespace blink | 632 } // namespace blink |
OLD | NEW |