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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 do { | 449 do { |
| 450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) | 450 if (!setSelectionOffsets(PlainTextRange(std::max(static_cast<int>(select ionOffsets.start()) - before, 0), selectionOffsets.end() + after))) |
| 451 return; | 451 return; |
| 452 if (before == 0) | 452 if (before == 0) |
| 453 break; | 453 break; |
| 454 ++before; | 454 ++before; |
| 455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); | 455 } while (frame().selection().start() == frame().selection().end() && before <= static_cast<int>(selectionOffsets.start())); |
| 456 TypingCommand::deleteSelection(*frame().document()); | 456 TypingCommand::deleteSelection(*frame().document()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void InputMethodController::deleteSurroundingText(int before, int after) | |
| 460 { | |
| 461 if (!editor().canEdit()) | |
| 462 return; | |
| 463 PlainTextRange selectionOffsets(getSelectionOffsets()); | |
| 464 if (selectionOffsets.isNull()) | |
| 465 return; | |
| 466 | |
| 467 int selectionStart = static_cast<int>(selectionOffsets.start()); | |
|
aelias_OOO_until_Jul13
2016/04/21 04:01:29
Why static_cast, is there a warning/error if you j
yabinh
2016/04/22 01:26:48
Since we use "std::min(selectionStart, before)", a
| |
| 468 int selectionEnd = static_cast<int>(selectionOffsets.end()); | |
| 469 | |
| 470 // Some multi-code-texts take 2 positions, like "\xF0\x9F\x8F\x86"(U+1F3C6 = = | |
| 471 // "trophy"). We can select the whole multi-code-text successfully if we onl y | |
| 472 // select the left half of it, but sometimes we can't select it successfully if we | |
| 473 // only select the right half of it, so we need to select more. That's why w e need | |
| 474 // to apply a while-loop to the beforeText and don't need to apply it to the afterText. | |
| 475 if (before > 0) { | |
| 476 int deleteLength, leftStart, leftEnd; | |
| 477 do { | |
| 478 deleteLength = std::min(selectionStart, before); | |
| 479 leftStart = selectionStart - deleteLength; | |
| 480 leftEnd = selectionStart; | |
| 481 if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd))) | |
| 482 return; | |
| 483 ++before; | |
| 484 } while (frame().selection().start() == frame().selection().end() && bef ore <= static_cast<int>(selectionOffsets.start())); | |
| 485 TypingCommand::deleteSelection(*frame().document()); | |
| 486 | |
| 487 selectionStart = leftStart; | |
| 488 selectionEnd = selectionEnd - deleteLength; | |
| 489 } | |
| 490 | |
| 491 if (after > 0) { | |
| 492 int rightStart = selectionEnd; | |
| 493 int rightEnd = selectionEnd + after; | |
| 494 if (!setSelectionOffsets(PlainTextRange(rightStart, rightEnd))) | |
| 495 return; | |
| 496 TypingCommand::deleteSelection(*frame().document()); | |
| 497 } | |
| 498 | |
| 499 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); | |
| 500 } | |
| 501 | |
| 459 DEFINE_TRACE(InputMethodController) | 502 DEFINE_TRACE(InputMethodController) |
| 460 { | 503 { |
| 461 visitor->trace(m_frame); | 504 visitor->trace(m_frame); |
| 462 visitor->trace(m_compositionRange); | 505 visitor->trace(m_compositionRange); |
| 463 } | 506 } |
| 464 | 507 |
| 465 } // namespace blink | 508 } // namespace blink |
| OLD | NEW |