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 13 matching lines...) Expand all Loading... | |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "core/editing/InputMethodController.h" | 27 #include "core/editing/InputMethodController.h" |
28 | 28 |
29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
31 #include "core/dom/Text.h" | 31 #include "core/dom/Text.h" |
32 #include "core/editing/EditingUtilities.h" | 32 #include "core/editing/EditingUtilities.h" |
33 #include "core/editing/Editor.h" | 33 #include "core/editing/Editor.h" |
34 #include "core/editing/commands/ReplaceSelectionCommand.h" | |
34 #include "core/editing/commands/TypingCommand.h" | 35 #include "core/editing/commands/TypingCommand.h" |
35 #include "core/editing/markers/DocumentMarkerController.h" | 36 #include "core/editing/markers/DocumentMarkerController.h" |
37 #include "core/editing/serializers/Serialization.h" | |
36 #include "core/events/CompositionEvent.h" | 38 #include "core/events/CompositionEvent.h" |
37 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
38 #include "core/html/HTMLTextAreaElement.h" | 40 #include "core/html/HTMLTextAreaElement.h" |
39 #include "core/input/EventHandler.h" | 41 #include "core/input/EventHandler.h" |
40 #include "core/layout/LayoutObject.h" | 42 #include "core/layout/LayoutObject.h" |
41 #include "core/layout/LayoutTheme.h" | 43 #include "core/layout/LayoutTheme.h" |
42 #include "core/page/ChromeClient.h" | 44 #include "core/page/ChromeClient.h" |
43 #include "wtf/Optional.h" | 45 #include "wtf/Optional.h" |
44 | 46 |
45 namespace blink { | 47 namespace blink { |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 return; | 463 return; |
462 if (before == 0) | 464 if (before == 0) |
463 break; | 465 break; |
464 ++before; | 466 ++before; |
465 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 467 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); |
466 // TODO(chongz): According to spec |data| should be "forward" or "backward". | 468 // TODO(chongz): According to spec |data| should be "forward" or "backward". |
467 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent); | 469 dispatchBeforeInputEditorCommand(frame().document()->focusedElement(), Input Event::InputType::DeleteContent); |
468 TypingCommand::deleteSelection(*frame().document()); | 470 TypingCommand::deleteSelection(*frame().document()); |
469 } | 471 } |
470 | 472 |
473 void InputMethodController::deleteSurroundingText(size_t before, size_t after) | |
474 { | |
475 if (!editor().canEdit()) | |
476 return; | |
477 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
478 if (selectionOffsets.isNull()) | |
479 return; | |
480 | |
481 size_t selectionStart = selectionOffsets.start(); | |
482 size_t selectionEnd = selectionOffsets.end(); | |
483 int replaceStart = static_cast<int>(selectionStart); | |
484 int replaceEnd = static_cast<int>(selectionEnd); | |
485 | |
486 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
487 if (!rootEditableElement) | |
488 return; | |
489 | |
490 if (before > 0u) { | |
491 // In case of exceeding the left boundary. | |
492 before = std::min(selectionStart, before); | |
Changwan Ryu
2016/05/02 05:58:28
This should be checked before the if statement. Wh
| |
493 | |
494 // Select the text to be deleted before selectionStart. | |
495 // For multi-code text, we can't select it successfully if we only | |
496 // select the right half of it. So we need to adjust the start of | |
497 // selection. | |
498 Position position(frame().selection().start().anchorNode(), selectionSta rt - before + 1); | |
499 Position adjustedPosition = previousPositionOf(position, PositionMoveTyp e::GraphemeCluster); | |
500 replaceStart = adjustedPosition.computeOffsetInContainerNode(); | |
501 } | |
502 | |
503 if (after > 0u) { | |
504 // In case of exceeding the right boundary. | |
505 PlainTextRange range(static_cast<int>(selectionEnd), static_cast<int>(se lectionEnd + after)); | |
506 if (range.isNull()) | |
507 return; | |
508 const EphemeralRange adjustedRange = range.createRange(*rootEditableElem ent); | |
509 if (adjustedRange.isNull()) | |
510 return; | |
511 | |
512 // Select the text to be deleted after selectionEnd. | |
513 // We also need to adjust the end of selection for multi-code text. | |
514 Position position(frame().selection().start().anchorNode(), adjustedRang e.endPosition().computeOffsetInContainerNode() - 1); | |
515 Position adjustedPosition = nextPositionOf(position, PositionMoveType::G raphemeCluster); | |
516 replaceEnd = adjustedPosition.computeOffsetInContainerNode(); | |
517 } | |
518 | |
519 String selectedText = frame().selection().selectedText(); | |
520 if (!setSelectionOffsets(PlainTextRange(replaceStart, replaceEnd))) | |
521 return; | |
522 const EphemeralRange selectionRange = selectionOffsets.createRange(*rootEdit ableElement); | |
523 if (selectionRange.isNull()) | |
524 return; | |
525 DocumentFragment* fragment = createFragmentFromText(selectionRange, selected Text); | |
526 ReplaceSelectionCommand::create(*frame().document(), fragment, ReplaceSelect ionCommand::SelectReplacement)->apply(); | |
Changwan Ryu
2016/05/02 05:58:28
You shouldn't try to replace the selection with ne
| |
527 } | |
528 | |
471 DEFINE_TRACE(InputMethodController) | 529 DEFINE_TRACE(InputMethodController) |
472 { | 530 { |
473 visitor->trace(m_frame); | 531 visitor->trace(m_frame); |
474 visitor->trace(m_compositionRange); | 532 visitor->trace(m_compositionRange); |
475 } | 533 } |
476 | 534 |
477 } // namespace blink | 535 } // namespace blink |
OLD | NEW |