| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "core/editing/EditingUtilities.h" | 26 #include "core/editing/EditingUtilities.h" |
| 27 | 27 |
| 28 #include "core/HTMLElementFactory.h" | 28 #include "core/HTMLElementFactory.h" |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/ElementTraversal.h" | 31 #include "core/dom/ElementTraversal.h" |
| 32 #include "core/dom/Range.h" | 32 #include "core/dom/Range.h" |
| 33 #include "core/dom/Text.h" | 33 #include "core/dom/Text.h" |
| 34 #include "core/dom/shadow/ShadowRoot.h" | 34 #include "core/dom/shadow/ShadowRoot.h" |
| 35 #include "core/editing/BackspaceStateMachine.h" |
| 35 #include "core/editing/EditingStrategy.h" | 36 #include "core/editing/EditingStrategy.h" |
| 36 #include "core/editing/Editor.h" | 37 #include "core/editing/Editor.h" |
| 37 #include "core/editing/PlainTextRange.h" | 38 #include "core/editing/PlainTextRange.h" |
| 38 #include "core/editing/PositionIterator.h" | 39 #include "core/editing/PositionIterator.h" |
| 39 #include "core/editing/VisiblePosition.h" | 40 #include "core/editing/VisiblePosition.h" |
| 40 #include "core/editing/VisibleSelection.h" | 41 #include "core/editing/VisibleSelection.h" |
| 41 #include "core/editing/VisibleUnits.h" | 42 #include "core/editing/VisibleUnits.h" |
| 42 #include "core/editing/iterators/TextIterator.h" | 43 #include "core/editing/iterators/TextIterator.h" |
| 43 #include "core/editing/serializers/HTMLInterchange.h" | 44 #include "core/editing/serializers/HTMLInterchange.h" |
| 44 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat
Tree& position, Node& highestRoot) | 541 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat
Tree& position, Node& highestRoot) |
| 541 { | 542 { |
| 542 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt
rategy>(position, highestRoot); | 543 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt
rategy>(position, highestRoot); |
| 543 } | 544 } |
| 544 | 545 |
| 545 int uncheckedPreviousOffset(const Node* n, int current) | 546 int uncheckedPreviousOffset(const Node* n, int current) |
| 546 { | 547 { |
| 547 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; | 548 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; |
| 548 } | 549 } |
| 549 | 550 |
| 550 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) | 551 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr
ent) |
| 551 { | 552 { |
| 552 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; | 553 if (current <= 1) |
| 554 return 0; |
| 555 if (!node->isTextNode()) |
| 556 return current - 1; |
| 557 |
| 558 const String& text = toText(node)->data(); |
| 559 CHECK(static_cast<unsigned>(current - 1) < text.length()); |
| 560 BackspaceStateMachine machine; |
| 561 for (int i = current - 1; i >= 0; --i) { |
| 562 if (machine.updateState(text[i])) |
| 563 break; |
| 564 } |
| 565 return current - machine.finalizeAndGetCodeUnitCountToBeDeleted(); |
| 553 } | 566 } |
| 554 | 567 |
| 555 int uncheckedNextOffset(const Node* n, int current) | 568 int uncheckedNextOffset(const Node* n, int current) |
| 556 { | 569 { |
| 557 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current
+ 1; | 570 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current
+ 1; |
| 558 } | 571 } |
| 559 | 572 |
| 560 template <typename Strategy> | 573 template <typename Strategy> |
| 561 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St
rategy>& position, PositionMoveType moveType) | 574 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St
rategy>& position, PositionMoveType moveType) |
| 562 { | 575 { |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 // instead of possibly at the end of the last node before the selection | 1659 // instead of possibly at the end of the last node before the selection |
| 1647 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1660 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1648 } | 1661 } |
| 1649 | 1662 |
| 1650 bool isTextSecurityNode(const Node* node) | 1663 bool isTextSecurityNode(const Node* node) |
| 1651 { | 1664 { |
| 1652 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; | 1665 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; |
| 1653 } | 1666 } |
| 1654 | 1667 |
| 1655 } // namespace blink | 1668 } // namespace blink |
| OLD | NEW |