| 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 const String& text = toText(node)->data(); | 550 const String& text = toText(node)->data(); |
| 550 if (text.is8Bit()) | 551 if (text.is8Bit()) |
| 551 return current - 1; // TODO(nona): Good to support CR x LF. | 552 return current - 1; // TODO(nona): Good to support CR x LF. |
| 552 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); | 553 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); |
| 553 if (!iterator) | 554 if (!iterator) |
| 554 return current - 1; | 555 return current - 1; |
| 555 const int result = iterator->preceding(current); | 556 const int result = iterator->preceding(current); |
| 556 return result == TextBreakDone ? current - 1 : result; | 557 return result == TextBreakDone ? current - 1 : result; |
| 557 } | 558 } |
| 558 | 559 |
| 559 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) | 560 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr
ent) |
| 560 { | 561 { |
| 561 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; | 562 DCHECK_GE(current, 0); |
| 563 if (current <= 1) |
| 564 return 0; |
| 565 if (!node->isTextNode()) |
| 566 return current - 1; |
| 567 |
| 568 const String& text = toText(node)->data(); |
| 569 CHECK(static_cast<unsigned>(current - 1) < text.length()); |
| 570 BackspaceStateMachine machine; |
| 571 for (int i = current - 1; i >= 0; --i) { |
| 572 if (machine.updateState(text[i])) |
| 573 break; |
| 574 } |
| 575 const int amount = machine.finalizeAndGetCodeUnitCountToBeDeleted(); |
| 576 DCHECK_GE(amount, 1); |
| 577 DCHECK_GE(current, amount); |
| 578 return current - amount; |
| 562 } | 579 } |
| 563 | 580 |
| 564 int uncheckedNextOffset(const Node* node, int current) | 581 int uncheckedNextOffset(const Node* node, int current) |
| 565 { | 582 { |
| 566 if (!node->isTextNode()) | 583 if (!node->isTextNode()) |
| 567 return current + 1; | 584 return current + 1; |
| 568 const String& text = toText(node)->data(); | 585 const String& text = toText(node)->data(); |
| 569 if (text.is8Bit()) | 586 if (text.is8Bit()) |
| 570 return current + 1; // TODO(nona): Good to support CR x LF. | 587 return current + 1; // TODO(nona): Good to support CR x LF. |
| 571 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); | 588 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te
xt.length()); |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1664 // instead of possibly at the end of the last node before the selection | 1681 // instead of possibly at the end of the last node before the selection |
| 1665 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1682 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1666 } | 1683 } |
| 1667 | 1684 |
| 1668 bool isTextSecurityNode(const Node* node) | 1685 bool isTextSecurityNode(const Node* node) |
| 1669 { | 1686 { |
| 1670 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; | 1687 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; |
| 1671 } | 1688 } |
| 1672 | 1689 |
| 1673 } // namespace blink | 1690 } // namespace blink |
| OLD | NEW |