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()); |
| 468 int selectionEnd = static_cast<int>(selectionOffsets.end()); |
| 469 |
| 470 if (before > 0) { |
| 471 int deleteLength = std::min(selectionStart, before); |
| 472 int leftStart = selectionStart - deleteLength; |
| 473 int leftEnd = selectionStart; |
| 474 if (!setSelectionOffsets(PlainTextRange(leftStart, leftEnd))) |
| 475 return; |
| 476 TypingCommand::deleteSelection(*frame().document()); |
| 477 |
| 478 selectionStart = leftStart; |
| 479 selectionEnd = selectionEnd - deleteLength; |
| 480 } |
| 481 |
| 482 if (after > 0) { |
| 483 int rightStart = selectionEnd; |
| 484 int rightEnd = selectionEnd + after; |
| 485 if (!setSelectionOffsets(PlainTextRange(rightStart, rightEnd))) |
| 486 return; |
| 487 TypingCommand::deleteSelection(*frame().document()); |
| 488 } |
| 489 |
| 490 setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd)); |
| 491 } |
| 492 |
459 DEFINE_TRACE(InputMethodController) | 493 DEFINE_TRACE(InputMethodController) |
460 { | 494 { |
461 visitor->trace(m_frame); | 495 visitor->trace(m_frame); |
462 visitor->trace(m_compositionRange); | 496 visitor->trace(m_compositionRange); |
463 } | 497 } |
464 | 498 |
465 } // namespace blink | 499 } // namespace blink |
OLD | NEW |