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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 339 |
340 Element* rootEditableElement = frame().selection().rootEditableElement(); | 340 Element* rootEditableElement = frame().selection().rootEditableElement(); |
341 if (!rootEditableElement) | 341 if (!rootEditableElement) |
342 return; | 342 return; |
343 | 343 |
344 // In case of exceeding the right boundary. | 344 // In case of exceeding the right boundary. |
345 // If both |value1| and |value2| exceed right boundary, | 345 // If both |value1| and |value2| exceed right boundary, |
346 // PlainTextRange(value1, value2)::createRange() will return a default | 346 // PlainTextRange(value1, value2)::createRange() will return a default |
347 // value, which is [0,0]. In order to get the correct Position in that case, | 347 // value, which is [0,0]. In order to get the correct Position in that case, |
348 // we should make sure |value1| is within range at least. | 348 // we should make sure |value1| is within range at least. |
349 const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*roo tEditableElement); | 349 const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*roo tEditableElement); |
Changwan Ryu
2016/05/24 08:35:50
There is a bit of duplicacy between setComposition
| |
350 const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEdi tableElement); | 350 const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEdi tableElement); |
351 | 351 |
352 // TODO(yabinh): There should be a better way to create |startPosition| and | 352 // TODO(yabinh): There should be a better way to create |startPosition| and |
353 // |endPosition|. But for now, since we can't get |anchorNode| and |offset|, | 353 // |endPosition|. But for now, since we can't get |anchorNode| and |offset|, |
354 // we can't create the 2 Position objects directly. So we use | 354 // we can't create the 2 Position objects directly. So we use |
355 // PlainTextRange::createRange as a workaround. | 355 // PlainTextRange::createRange as a workaround. |
356 const Position& startPosition = startRange.endPosition(); | 356 const Position& startPosition = startRange.endPosition(); |
357 const Position& endPosition = endRange.endPosition(); | 357 const Position& endPosition = endRange.endPosition(); |
358 Range* selectedRange = Range::create(rootEditableElement->document(), startP osition, endPosition); | 358 Range* selectedRange = Range::create(rootEditableElement->document(), startP osition, endPosition); |
359 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); | 359 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele ctionDirectionalMode::NonDirectional, FrameSelection::CloseTyping); | 450 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele ctionDirectionalMode::NonDirectional, FrameSelection::CloseTyping); |
451 } | 451 } |
452 | 452 |
453 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se lectionOffsets) | 453 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se lectionOffsets) |
454 { | 454 { |
455 if (!editor().canEdit()) | 455 if (!editor().canEdit()) |
456 return false; | 456 return false; |
457 return setSelectionOffsets(selectionOffsets); | 457 return setSelectionOffsets(selectionOffsets); |
458 } | 458 } |
459 | 459 |
460 bool InputMethodController::setEditableSelectionOffsetsWithBoundaryCheck(int sta rt, int end) | |
461 { | |
462 if (!editor().canEdit()) | |
463 return false; | |
464 | |
465 // In case of exceeding left boundary. | |
466 start = std::max(start, 0); | |
467 end = std::max(end, 0); | |
Changwan Ryu
2016/05/24 08:35:50
s/0/start/ ?
| |
468 | |
469 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
470 if (!rootEditableElement) | |
471 return false; | |
472 | |
473 // In case of exceeding the right boundary. | |
474 // If both |value1| and |value2| exceed right boundary, | |
475 // PlainTextRange(value1, value2)::createRange() will return a default | |
476 // value, which is [0,0]. In order to get the correct Position in that case, | |
477 // we should make sure |value1| is within range at least. | |
478 const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*roo tEditableElement); | |
479 if (startRange.isNull()) | |
480 return false; | |
481 const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEdi tableElement); | |
482 if (endRange.isNull()) | |
483 return false; | |
484 | |
485 const Position& startPosition = startRange.endPosition(); | |
486 const Position& endPosition = endRange.endPosition(); | |
487 const EphemeralRange& range = EphemeralRange(startPosition, endPosition); | |
488 if (range.isNull()) | |
489 return false; | |
490 | |
491 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele ctionDirectionalMode::NonDirectional, FrameSelection::CloseTyping); | |
492 } | |
493 | |
460 void InputMethodController::extendSelectionAndDelete(int before, int after) | 494 void InputMethodController::extendSelectionAndDelete(int before, int after) |
461 { | 495 { |
462 if (!editor().canEdit()) | 496 if (!editor().canEdit()) |
463 return; | 497 return; |
464 PlainTextRange selectionOffsets(getSelectionOffsets()); | 498 PlainTextRange selectionOffsets(getSelectionOffsets()); |
465 if (selectionOffsets.isNull()) | 499 if (selectionOffsets.isNull()) |
466 return; | 500 return; |
467 | 501 |
468 // A common call of before=1 and after=0 will fail if the last character | 502 // A common call of before=1 and after=0 will fail if the last character |
469 // is multi-code-word UTF-16, including both multi-16bit code-points and | 503 // is multi-code-word UTF-16, including both multi-16bit code-points and |
(...skipping 19 matching lines...) Expand all Loading... | |
489 TypingCommand::deleteSelection(*frame().document()); | 523 TypingCommand::deleteSelection(*frame().document()); |
490 } | 524 } |
491 | 525 |
492 DEFINE_TRACE(InputMethodController) | 526 DEFINE_TRACE(InputMethodController) |
493 { | 527 { |
494 visitor->trace(m_frame); | 528 visitor->trace(m_frame); |
495 visitor->trace(m_compositionRange); | 529 visitor->trace(m_compositionRange); |
496 } | 530 } |
497 | 531 |
498 } // namespace blink | 532 } // namespace blink |
OLD | NEW |