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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { | |
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 size_t adjustedStart = selectionStart + 1 - before; | |
492 const LChar* text = frame().document()->activeElement()->innerText().cha racters8(); | |
493 U8_SET_CP_START(text, 0, adjustedStart); | |
Changwan Ryu
2016/04/25 10:21:08
This is incorrect if the given text is UTF16 strin
| |
494 --adjustedStart; | |
495 | |
496 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(adjustedStart), static_cast<int>(selectionStart)))) | |
497 return; | |
498 TypingCommand::deleteSelection(*frame().document()); | |
499 | |
500 selectionEnd = selectionEnd - (selectionStart - adjustedStart); | |
501 selectionStart = adjustedStart; | |
502 } | |
503 | |
504 if (after != 0) { | |
505 if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after)))) | |
506 return; | |
507 TypingCommand::deleteSelection(*frame().document()); | |
508 } | |
509 | |
510 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
511 } | |
512 | |
475 DEFINE_TRACE(InputMethodController) | 513 DEFINE_TRACE(InputMethodController) |
476 { | 514 { |
477 visitor->trace(m_frame); | 515 visitor->trace(m_frame); |
478 visitor->trace(m_compositionRange); | 516 visitor->trace(m_compositionRange); |
479 } | 517 } |
480 | 518 |
481 } // namespace blink | 519 } // namespace blink |
OLD | NEW |