| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "core/editing/EditingStrategy.h" | 35 #include "core/editing/EditingStrategy.h" |
| 36 #include "core/editing/Editor.h" | 36 #include "core/editing/Editor.h" |
| 37 #include "core/editing/PlainTextRange.h" | 37 #include "core/editing/PlainTextRange.h" |
| 38 #include "core/editing/PositionIterator.h" | 38 #include "core/editing/PositionIterator.h" |
| 39 #include "core/editing/VisiblePosition.h" | 39 #include "core/editing/VisiblePosition.h" |
| 40 #include "core/editing/VisibleSelection.h" | 40 #include "core/editing/VisibleSelection.h" |
| 41 #include "core/editing/VisibleUnits.h" | 41 #include "core/editing/VisibleUnits.h" |
| 42 #include "core/editing/iterators/TextIterator.h" | 42 #include "core/editing/iterators/TextIterator.h" |
| 43 #include "core/editing/serializers/HTMLInterchange.h" | 43 #include "core/editing/serializers/HTMLInterchange.h" |
| 44 #include "core/editing/state_machines/BackspaceStateMachine.h" | 44 #include "core/editing/state_machines/BackspaceStateMachine.h" |
| 45 #include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h" |
| 46 #include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h" |
| 45 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
| 46 #include "core/frame/UseCounter.h" | 48 #include "core/frame/UseCounter.h" |
| 47 #include "core/html/HTMLBRElement.h" | 49 #include "core/html/HTMLBRElement.h" |
| 48 #include "core/html/HTMLDivElement.h" | 50 #include "core/html/HTMLDivElement.h" |
| 49 #include "core/html/HTMLLIElement.h" | 51 #include "core/html/HTMLLIElement.h" |
| 50 #include "core/html/HTMLParagraphElement.h" | 52 #include "core/html/HTMLParagraphElement.h" |
| 51 #include "core/html/HTMLSpanElement.h" | 53 #include "core/html/HTMLSpanElement.h" |
| 52 #include "core/html/HTMLTableCellElement.h" | 54 #include "core/html/HTMLTableCellElement.h" |
| 53 #include "core/html/HTMLUListElement.h" | 55 #include "core/html/HTMLUListElement.h" |
| 54 #include "core/layout/LayoutObject.h" | 56 #include "core/layout/LayoutObject.h" |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 int findNextBoundaryOffset(const String& str, int current) | 550 int findNextBoundaryOffset(const String& str, int current) |
| 549 { | 551 { |
| 550 StateMachine machine; | 552 StateMachine machine; |
| 551 TextSegmentationMachineState state = TextSegmentationMachineState::Invalid; | 553 TextSegmentationMachineState state = TextSegmentationMachineState::Invalid; |
| 552 | 554 |
| 553 for (int i = current - 1; i >= 0; --i) { | 555 for (int i = current - 1; i >= 0; --i) { |
| 554 state = machine.feedPrecedingCodeUnit(str[i]); | 556 state = machine.feedPrecedingCodeUnit(str[i]); |
| 555 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) | 557 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) |
| 556 break; | 558 break; |
| 557 } | 559 } |
| 558 if (state == TextSegmentationMachineState::NeedMoreCodeUnit) | 560 if (current == 0 || state == TextSegmentationMachineState::NeedMoreCodeUnit) |
| 559 state = machine.tellEndOfPrecedingText(); | 561 state = machine.tellEndOfPrecedingText(); |
| 560 if (state == TextSegmentationMachineState::Finished) | 562 if (state == TextSegmentationMachineState::Finished) |
| 561 return current + machine.finalizeAndGetBoundaryOffset(); | 563 return current + machine.finalizeAndGetBoundaryOffset(); |
| 562 const int length = str.length(); | 564 const int length = str.length(); |
| 563 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state); | 565 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state); |
| 564 for (int i = current; i < length; ++i) { | 566 for (int i = current; i < length; ++i) { |
| 565 state = machine.feedFollowingCodeUnit(str[i]); | 567 state = machine.feedFollowingCodeUnit(str[i]); |
| 566 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) | 568 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) |
| 567 break; | 569 break; |
| 568 } | 570 } |
| 569 return current + machine.finalizeAndGetBoundaryOffset(); | 571 return current + machine.finalizeAndGetBoundaryOffset(); |
| 570 } | 572 } |
| 571 | 573 |
| 572 int previousGraphemeBoundaryOf(const Node* node, int current) | 574 int previousGraphemeBoundaryOf(const Node* node, int current) |
| 573 { | 575 { |
| 574 if (!node->isTextNode()) | 576 // TODO(yosin): Need to support grapheme crossing |Node| boundary. |
| 577 DCHECK_GE(current, 0); |
| 578 if (current <= 1 || !node->isTextNode()) |
| 575 return current - 1; | 579 return current - 1; |
| 576 const String& text = toText(node)->data(); | 580 const String& text = toText(node)->data(); |
| 577 if (text.is8Bit()) | 581 // TODO(yosin): Replace with DCHECK for out-of-range request. |
| 578 return current - 1; // TODO(nona): Good to support CR x LF. | 582 if (static_cast<unsigned>(current) > text.length()) |
| 579 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); | |
| 580 if (!iterator) | |
| 581 return current - 1; | 583 return current - 1; |
| 582 const int result = iterator->preceding(current); | 584 return findNextBoundaryOffset<BackwardGraphemeBoundaryStateMachine>(text, cu
rrent); |
| 583 return result == TextBreakDone ? current - 1 : result; | |
| 584 } | 585 } |
| 585 | 586 |
| 586 static int previousBackwardDeletionOffsetOf(const Node* node, int current) | 587 static int previousBackwardDeletionOffsetOf(const Node* node, int current) |
| 587 { | 588 { |
| 588 DCHECK_GE(current, 0); | 589 DCHECK_GE(current, 0); |
| 589 if (current <= 1) | 590 if (current <= 1) |
| 590 return 0; | 591 return 0; |
| 591 if (!node->isTextNode()) | 592 if (!node->isTextNode()) |
| 592 return current - 1; | 593 return current - 1; |
| 593 | 594 |
| 594 const String& text = toText(node)->data(); | 595 const String& text = toText(node)->data(); |
| 595 DCHECK_LT(static_cast<unsigned>(current - 1), text.length()); | 596 DCHECK_LT(static_cast<unsigned>(current - 1), text.length()); |
| 596 return findNextBoundaryOffset<BackspaceStateMachine>(text, current); | 597 return findNextBoundaryOffset<BackspaceStateMachine>(text, current); |
| 597 } | 598 } |
| 598 | 599 |
| 599 int nextGraphemeBoundaryOf(const Node* node, int current) | 600 int nextGraphemeBoundaryOf(const Node* node, int current) |
| 600 { | 601 { |
| 602 // TODO(yosin): Need to support grapheme crossing |Node| boundary. |
| 601 if (!node->isTextNode()) | 603 if (!node->isTextNode()) |
| 602 return current + 1; | 604 return current + 1; |
| 603 const String& text = toText(node)->data(); | 605 const String& text = toText(node)->data(); |
| 604 if (text.is8Bit()) | 606 const int length = text.length(); |
| 605 return current + 1; // TODO(nona): Good to support CR x LF. | 607 DCHECK_LE(current, length); |
| 606 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); | 608 if (current >= length - 1) |
| 607 if (!iterator) | |
| 608 return current + 1; | 609 return current + 1; |
| 609 const int result = iterator->following(current); | 610 return findNextBoundaryOffset<ForwardGraphemeBoundaryStateMachine>(text, cur
rent); |
| 610 return result == TextBreakDone ? current + 1 : result; | |
| 611 } | 611 } |
| 612 | 612 |
| 613 template <typename Strategy> | 613 template <typename Strategy> |
| 614 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St
rategy>& position, PositionMoveType moveType) | 614 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St
rategy>& position, PositionMoveType moveType) |
| 615 { | 615 { |
| 616 Node* const node = position.anchorNode(); | 616 Node* const node = position.anchorNode(); |
| 617 if (!node) | 617 if (!node) |
| 618 return position; | 618 return position; |
| 619 | 619 |
| 620 const int offset = position.computeEditingOffset(); | 620 const int offset = position.computeEditingOffset(); |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 // instead of possibly at the end of the last node before the selection | 1703 // instead of possibly at the end of the last node before the selection |
| 1704 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1704 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 bool isTextSecurityNode(const Node* node) | 1707 bool isTextSecurityNode(const Node* node) |
| 1708 { | 1708 { |
| 1709 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; | 1709 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; |
| 1710 } | 1710 } |
| 1711 | 1711 |
| 1712 } // namespace blink | 1712 } // namespace blink |
| OLD | NEW |