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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 } while (frame().selection().start() == frame().selection().end() && | 861 } while (frame().selection().start() == frame().selection().end() && |
862 before <= static_cast<int>(selectionOffsets.start())); | 862 before <= static_cast<int>(selectionOffsets.start())); |
863 // TODO(chongz): Find a way to distinguish Forward and Backward. | 863 // TODO(chongz): Find a way to distinguish Forward and Backward. |
864 dispatchBeforeInputEditorCommand( | 864 dispatchBeforeInputEditorCommand( |
865 m_frame->document()->focusedElement(), | 865 m_frame->document()->focusedElement(), |
866 InputEvent::InputType::DeleteContentBackward, | 866 InputEvent::InputType::DeleteContentBackward, |
867 new RangeVector(1, m_frame->selection().firstRange())); | 867 new RangeVector(1, m_frame->selection().firstRange())); |
868 TypingCommand::deleteSelection(*frame().document()); | 868 TypingCommand::deleteSelection(*frame().document()); |
869 } | 869 } |
870 | 870 |
871 // TODO(yabinh): We should reduce the number of selectionchange events. | |
872 void InputMethodController::deleteSurroundingText(int before, int after) { | |
873 if (!editor().canEdit()) | |
874 return; | |
875 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
yosin_UTC9
2016/10/13 03:40:10
s/PlainTextRange/const PlainTextRange/
yabinh
2016/10/13 05:08:23
Done.
| |
876 if (selectionOffsets.isNull()) | |
877 return; | |
878 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
yosin_UTC9
2016/10/13 03:40:10
s/Element*/Element* const/
yabinh
2016/10/13 05:08:23
Done.
| |
879 if (!rootEditableElement) | |
880 return; | |
881 int selectionStart = static_cast<int>(selectionOffsets.start()); | |
882 int selectionEnd = static_cast<int>(selectionOffsets.end()); | |
883 | |
884 // Select the text to be deleted before selectionStart. | |
885 if (before > 0 && selectionStart > 0) { | |
886 // In case of exceeding the left boundary. | |
887 const int start = std::max(selectionStart - before, 0); | |
888 | |
889 const EphemeralRange& range = | |
890 PlainTextRange(0, start).createRange(*rootEditableElement); | |
891 if (range.isNull()) | |
892 return; | |
893 const Position& position = range.endPosition(); | |
894 | |
895 // Adjust the start of selection for multi-code text(a grapheme cluster | |
896 // contains more than one code point). TODO(yabinh): Adjustment should be | |
897 // based on code point instead of grapheme cluster. | |
898 const size_t diff = computeDistanceToLeftGraphemeBoundary(position); | |
899 const int adjustedStart = start - static_cast<int>(diff); | |
900 | |
901 if (!setSelectionOffsets(PlainTextRange(adjustedStart, selectionStart))) | |
902 return; | |
903 TypingCommand::deleteSelection(*frame().document()); | |
904 | |
905 selectionEnd = selectionEnd - (selectionStart - adjustedStart); | |
906 selectionStart = adjustedStart; | |
907 } | |
908 | |
909 // Select the text to be deleted after selectionEnd. | |
910 if (after > 0) { | |
911 // Adjust the deleted range in case of exceeding the right boundary. | |
912 PlainTextRange range(0, selectionEnd + after); | |
yosin_UTC9
2016/10/13 03:40:10
s/PlainTextRange/const PlainTextRange/
yabinh
2016/10/13 05:08:23
Done.
| |
913 if (range.isNull()) | |
914 return; | |
915 const EphemeralRange& validRange = range.createRange(*rootEditableElement); | |
916 if (validRange.isNull()) | |
917 return; | |
918 const int end = | |
919 PlainTextRange::create(*rootEditableElement, validRange).end(); | |
920 const Position& position = validRange.endPosition(); | |
921 | |
922 // Adjust the end of selection for multi-code text. TODO(yabinh): Adjustment | |
923 // should be based on code point instead of grapheme cluster. | |
924 const size_t diff = computeDistanceToRightGraphemeBoundary(position); | |
925 const int adjustedEnd = end + static_cast<int>(diff); | |
926 | |
yosin_UTC9
2016/10/13 03:40:10
nit: Remove an extra blank line
yabinh
2016/10/13 05:08:23
Done.
| |
927 if (!setSelectionOffsets(PlainTextRange(selectionEnd, adjustedEnd))) | |
928 return; | |
929 TypingCommand::deleteSelection(*frame().document()); | |
930 } | |
931 | |
932 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
933 } | |
934 | |
871 DEFINE_TRACE(InputMethodController) { | 935 DEFINE_TRACE(InputMethodController) { |
872 visitor->trace(m_frame); | 936 visitor->trace(m_frame); |
873 visitor->trace(m_compositionRange); | 937 visitor->trace(m_compositionRange); |
874 } | 938 } |
875 | 939 |
876 } // namespace blink | 940 } // namespace blink |
OLD | NEW |