| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "core/layout/LayoutTableCell.h" | 57 #include "core/layout/LayoutTableCell.h" |
| 58 #include "wtf/Assertions.h" | 58 #include "wtf/Assertions.h" |
| 59 #include "wtf/StdLibExtras.h" | 59 #include "wtf/StdLibExtras.h" |
| 60 #include "wtf/text/StringBuilder.h" | 60 #include "wtf/text/StringBuilder.h" |
| 61 #include "wtf/text/Unicode.h" | 61 #include "wtf/text/Unicode.h" |
| 62 | 62 |
| 63 namespace blink { | 63 namespace blink { |
| 64 | 64 |
| 65 using namespace HTMLNames; | 65 using namespace HTMLNames; |
| 66 | 66 |
| 67 namespace { |
| 68 std::ostream& operator<<(std::ostream& os, PositionMoveType type) |
| 69 { |
| 70 static const char* const texts[] = { |
| 71 "CodeUnit", "BackwardDeletion", "GraphemeCluster" |
| 72 }; |
| 73 const auto& it = std::begin(texts) + static_cast<size_t>(type); |
| 74 DCHECK_GE(it, std::begin(texts)) << "Unknown PositionMoveType value"; |
| 75 DCHECK_LT(it, std::end(texts)) << "Unknown PositionMoveType value"; |
| 76 return os << *it; |
| 77 } |
| 78 } // namespace |
| 79 |
| 67 // Atomic means that the node has no children, or has children which are ignored
for the | 80 // Atomic means that the node has no children, or has children which are ignored
for the |
| 68 // purposes of editing. | 81 // purposes of editing. |
| 69 bool isAtomicNode(const Node *node) | 82 bool isAtomicNode(const Node *node) |
| 70 { | 83 { |
| 71 return node && (!node->hasChildren() || editingIgnoresContent(node)); | 84 return node && (!node->hasChildren() || editingIgnoresContent(node)); |
| 72 } | 85 } |
| 73 | 86 |
| 74 template <typename Traversal> | 87 template <typename Traversal> |
| 75 static int comparePositions(Node* containerA, int offsetA, Node* containerB, int
offsetB, bool* disconnected) | 88 static int comparePositions(Node* containerA, int offsetA, Node* containerB, int
offsetB, bool* disconnected) |
| 76 { | 89 { |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 | 640 |
| 628 // There are two reasons child might be 0: | 641 // There are two reasons child might be 0: |
| 629 // 1) The node is node like a text node that is not an element, and | 642 // 1) The node is node like a text node that is not an element, and |
| 630 // therefore has no children. Going backward one character at a | 643 // therefore has no children. Going backward one character at a |
| 631 // time is correct. | 644 // time is correct. |
| 632 // 2) The old offset was a bogus offset like (<br>, 1), and there is | 645 // 2) The old offset was a bogus offset like (<br>, 1), and there is |
| 633 // no child. Going from 1 to 0 is correct. | 646 // no child. Going from 1 to 0 is correct. |
| 634 switch (moveType) { | 647 switch (moveType) { |
| 635 case PositionMoveType::CodeUnit: | 648 case PositionMoveType::CodeUnit: |
| 636 return PositionTemplate<Strategy>(node, offset - 1); | 649 return PositionTemplate<Strategy>(node, offset - 1); |
| 637 case PositionMoveType::CodePoint: | |
| 638 // TODO(nona): Move to PositionMoveType::GraphemeBoundary case. | |
| 639 return PositionTemplate<Strategy>(node, previousGraphemeBoundaryOf(n
ode, offset)); | |
| 640 case PositionMoveType::BackwardDeletion: | 650 case PositionMoveType::BackwardDeletion: |
| 641 return PositionTemplate<Strategy>(node, previousBackwardDeletionOffs
etOf(node, offset)); | 651 return PositionTemplate<Strategy>(node, previousBackwardDeletionOffs
etOf(node, offset)); |
| 652 case PositionMoveType::GraphemeCluster: |
| 653 return PositionTemplate<Strategy>(node, previousGraphemeBoundaryOf(n
ode, offset)); |
| 654 default: |
| 655 NOTREACHED() << "Unhandled moveType: " << moveType; |
| 642 } | 656 } |
| 643 } | 657 } |
| 644 | 658 |
| 645 if (ContainerNode* parent = Strategy::parent(*node)) { | 659 if (ContainerNode* parent = Strategy::parent(*node)) { |
| 646 if (editingIgnoresContent(parent)) | 660 if (editingIgnoresContent(parent)) |
| 647 return PositionTemplate<Strategy>::beforeNode(parent); | 661 return PositionTemplate<Strategy>::beforeNode(parent); |
| 648 // TODO(yosin) We should use |Strategy::index(Node&)| instead of | 662 // TODO(yosin) We should use |Strategy::index(Node&)| instead of |
| 649 // |Node::nodeIndex()|. | 663 // |Node::nodeIndex()|. |
| 650 return PositionTemplate<Strategy>(parent, node->nodeIndex()); | 664 return PositionTemplate<Strategy>(parent, node->nodeIndex()); |
| 651 } | 665 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 678 | 692 |
| 679 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of | 693 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of |
| 680 // DOM tree version. | 694 // DOM tree version. |
| 681 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor
Editing(node)) { | 695 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor
Editing(node)) { |
| 682 // There are two reasons child might be 0: | 696 // There are two reasons child might be 0: |
| 683 // 1) The node is node like a text node that is not an element, and | 697 // 1) The node is node like a text node that is not an element, and |
| 684 // therefore has no children. Going forward one character at a time | 698 // therefore has no children. Going forward one character at a time |
| 685 // is correct. | 699 // is correct. |
| 686 // 2) The new offset is a bogus offset like (<br>, 1), and there is no | 700 // 2) The new offset is a bogus offset like (<br>, 1), and there is no |
| 687 // child. Going from 0 to 1 is correct. | 701 // child. Going from 0 to 1 is correct. |
| 688 // TODO(nona): Call nextGraphemeBoundaryOf if | 702 switch (moveType) { |
| 689 // moveType == PositionMoveType::GraphemeBoundary | 703 case PositionMoveType::CodeUnit: |
| 690 return PositionTemplate<Strategy>::editingPositionOf(node, (moveType ==
PositionMoveType::CodePoint) ? nextGraphemeBoundaryOf(node, offset) : offset + 1
); | 704 return PositionTemplate<Strategy>::editingPositionOf(node, offset +
1); |
| 705 case PositionMoveType::BackwardDeletion: |
| 706 NOTREACHED() |
| 707 << "BackwardDeletion is only available for prevPositionOf " |
| 708 << "functions."; |
| 709 return PositionTemplate<Strategy>::editingPositionOf(node, offset +
1); |
| 710 case PositionMoveType::GraphemeCluster: |
| 711 return PositionTemplate<Strategy>::editingPositionOf(node, nextGraph
emeBoundaryOf(node, offset)); |
| 712 default: |
| 713 NOTREACHED() << "Unhandled moveType: " << moveType; |
| 714 } |
| 691 } | 715 } |
| 692 | 716 |
| 693 if (ContainerNode* parent = Strategy::parent(*node)) | 717 if (ContainerNode* parent = Strategy::parent(*node)) |
| 694 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i
ndex(*node) + 1); | 718 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i
ndex(*node) + 1); |
| 695 return position; | 719 return position; |
| 696 } | 720 } |
| 697 | 721 |
| 698 Position nextPositionOf(const Position& position, PositionMoveType moveType) | 722 Position nextPositionOf(const Position& position, PositionMoveType moveType) |
| 699 { | 723 { |
| 700 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); | 724 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); |
| (...skipping 1002 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 | 1727 // instead of possibly at the end of the last node before the selection |
| 1704 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1728 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1705 } | 1729 } |
| 1706 | 1730 |
| 1707 bool isTextSecurityNode(const Node* node) | 1731 bool isTextSecurityNode(const Node* node) |
| 1708 { | 1732 { |
| 1709 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; | 1733 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; |
| 1710 } | 1734 } |
| 1711 | 1735 |
| 1712 } // namespace blink | 1736 } // namespace blink |
| OLD | NEW |