Chromium Code Reviews| 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(int before, int after) | |
| 476 { | |
| 477 if (!editor().canEdit()) | |
| 478 return; | |
| 479 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
| 480 if (selectionOffsets.isNull()) | |
| 481 return; | |
| 482 | |
| 483 int selectionStart = static_cast<int>(selectionOffsets.start()); | |
| 484 int selectionEnd = static_cast<int>(selectionOffsets.end()); | |
| 485 | |
| 486 // Some multi-code-texts take 2 positions, like "\xF0\x9F\x8F\x86"(U+1F3C6 | |
| 487 // =="trophy"). We can select the whole multi-code-text successfully if we | |
| 488 // only select the left half of it, but we can't select it if we only select | |
| 489 // the right half of it. For the latter case, we need to select more. | |
| 490 if (before > 0) { | |
| 491 int deleteLength, leftStart, leftEnd; | |
| 492 int adjustedBefore = before; | |
| 493 do { | |
| 494 deleteLength = std::min(selectionStart, adjustedBefore); | |
| 495 leftStart = selectionStart - deleteLength; | |
| 496 leftEnd = selectionStart; | |
| 497 if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd))) | |
| 498 return; | |
| 499 ++adjustedBefore; | |
| 500 } while (frame().selection().start().computeOffsetInContainerNode() + be fore > frame().selection().end().computeOffsetInContainerNode() && before <= sta tic_cast<int>(selectionOffsets.start())); | |
|
Changwan Ryu
2016/04/22 02:16:09
1) while condition is too long, and the latter con
yabinh
2016/04/22 02:51:53
You are right. It'll be more simple.
| |
| 501 TypingCommand::deleteSelection(*frame().document()); | |
| 502 | |
| 503 selectionStart = leftStart; | |
| 504 selectionEnd = selectionEnd - deleteLength; | |
| 505 } | |
| 506 | |
| 507 if (after > 0) { | |
| 508 int rightStart = selectionEnd; | |
| 509 int rightEnd = selectionEnd + after; | |
| 510 if (!setSelectionOffsets(PlainTextRange(rightStart, rightEnd))) | |
| 511 return; | |
| 512 TypingCommand::deleteSelection(*frame().document()); | |
| 513 } | |
| 514 | |
| 515 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
| 516 } | |
| 517 | |
| 475 DEFINE_TRACE(InputMethodController) | 518 DEFINE_TRACE(InputMethodController) |
| 476 { | 519 { |
| 477 visitor->trace(m_frame); | 520 visitor->trace(m_frame); |
| 478 visitor->trace(m_compositionRange); | 521 visitor->trace(m_compositionRange); |
| 479 } | 522 } |
| 480 | 523 |
| 481 } // namespace blink | 524 } // namespace blink |
| OLD | NEW |