Chromium Code Reviews| 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", "CodePoint", "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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 // There are two reasons child might be 0: | 638 // There are two reasons child might be 0: |
| 626 // 1) The node is node like a text node that is not an element, and | 639 // 1) The node is node like a text node that is not an element, and |
| 627 // therefore has no children. Going backward one character at a | 640 // therefore has no children. Going backward one character at a |
| 628 // time is correct. | 641 // time is correct. |
| 629 // 2) The old offset was a bogus offset like (<br>, 1), and there is | 642 // 2) The old offset was a bogus offset like (<br>, 1), and there is |
| 630 // no child. Going from 1 to 0 is correct. | 643 // no child. Going from 1 to 0 is correct. |
| 631 switch (moveType) { | 644 switch (moveType) { |
| 632 case PositionMoveType::CodeUnit: | 645 case PositionMoveType::CodeUnit: |
| 633 return PositionTemplate<Strategy>(node, offset - 1); | 646 return PositionTemplate<Strategy>(node, offset - 1); |
| 634 case PositionMoveType::CodePoint: | 647 case PositionMoveType::CodePoint: |
| 635 // TODO(nona): Move to PositionMoveType::GraphemeBoundary case. | 648 NOTIMPLEMENTED() << moveType << " is not yet supported."; |
|
yosin_UTC9
2016/04/07 01:13:56
Let's see results of layout test. If nothing is fa
Seigo Nonaka
2016/04/08 05:47:45
Done.
| |
| 636 return PositionTemplate<Strategy>(node, previousGraphemeBoundaryOf(n ode, offset)); | 649 return PositionTemplate<Strategy>(node, offset - 1); |
| 637 case PositionMoveType::BackwardDeletion: | 650 case PositionMoveType::BackwardDeletion: |
| 638 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; | |
| 639 } | 656 } |
| 640 } | 657 } |
| 641 | 658 |
| 642 if (ContainerNode* parent = Strategy::parent(*node)) { | 659 if (ContainerNode* parent = Strategy::parent(*node)) { |
| 643 if (editingIgnoresContent(parent)) | 660 if (editingIgnoresContent(parent)) |
| 644 return PositionTemplate<Strategy>::beforeNode(parent); | 661 return PositionTemplate<Strategy>::beforeNode(parent); |
| 645 // TODO(yosin) We should use |Strategy::index(Node&)| instead of | 662 // TODO(yosin) We should use |Strategy::index(Node&)| instead of |
| 646 // |Node::nodeIndex()|. | 663 // |Node::nodeIndex()|. |
| 647 return PositionTemplate<Strategy>(parent, node->nodeIndex()); | 664 return PositionTemplate<Strategy>(parent, node->nodeIndex()); |
| 648 } | 665 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 675 | 692 |
| 676 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of | 693 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of |
| 677 // DOM tree version. | 694 // DOM tree version. |
| 678 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor Editing(node)) { | 695 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor Editing(node)) { |
| 679 // There are two reasons child might be 0: | 696 // There are two reasons child might be 0: |
| 680 // 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 |
| 681 // therefore has no children. Going forward one character at a time | 698 // therefore has no children. Going forward one character at a time |
| 682 // is correct. | 699 // is correct. |
| 683 // 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 |
| 684 // child. Going from 0 to 1 is correct. | 701 // child. Going from 0 to 1 is correct. |
| 685 // TODO(nona): Call nextGraphemeBoundaryOf if | 702 switch (moveType) { |
| 686 // moveType == PositionMoveType::GraphemeBoundary | 703 case PositionMoveType::CodeUnit: |
| 687 return PositionTemplate<Strategy>::editingPositionOf(node, (moveType == PositionMoveType::CodePoint) ? nextGraphemeBoundaryOf(node, offset) : offset + 1 ); | 704 return PositionTemplate<Strategy>::editingPositionOf(node, offset + 1); |
| 705 case PositionMoveType::CodePoint: | |
|
yosin_UTC9
2016/04/08 00:51:57
Since, nobody use |PositionMoveType::CodePoint|, c
Seigo Nonaka
2016/04/08 05:47:45
Done.
| |
| 706 NOTIMPLEMENTED() << moveType << " is not yet supported."; | |
| 707 return PositionTemplate<Strategy>::editingPositionOf(node, offset + 1); | |
| 708 case PositionMoveType::BackwardDeletion: | |
| 709 NOTREACHED() | |
| 710 << "BackwardDeletion is only available for prevPositionOf " | |
| 711 << "functions."; | |
| 712 return PositionTemplate<Strategy>::editingPositionOf(node, offset + 1); | |
| 713 case PositionMoveType::GraphemeCluster: | |
| 714 return PositionTemplate<Strategy>::editingPositionOf(node, nextGraph emeBoundaryOf(node, offset)); | |
| 715 default: | |
| 716 NOTREACHED() << "Unhandled moveType: " << moveType; | |
| 717 } | |
| 688 } | 718 } |
| 689 | 719 |
| 690 if (ContainerNode* parent = Strategy::parent(*node)) | 720 if (ContainerNode* parent = Strategy::parent(*node)) |
| 691 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i ndex(*node) + 1); | 721 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i ndex(*node) + 1); |
| 692 return position; | 722 return position; |
| 693 } | 723 } |
| 694 | 724 |
| 695 Position nextPositionOf(const Position& position, PositionMoveType moveType) | 725 Position nextPositionOf(const Position& position, PositionMoveType moveType) |
| 696 { | 726 { |
| 697 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); | 727 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1700 // instead of possibly at the end of the last node before the selection | 1730 // instead of possibly at the end of the last node before the selection |
| 1701 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1731 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1702 } | 1732 } |
| 1703 | 1733 |
| 1704 bool isTextSecurityNode(const Node* node) | 1734 bool isTextSecurityNode(const Node* node) |
| 1705 { | 1735 { |
| 1706 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; | 1736 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; |
| 1707 } | 1737 } |
| 1708 | 1738 |
| 1709 } // namespace blink | 1739 } // namespace blink |
| OLD | NEW |