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 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 continue; | 936 continue; |
937 if (ancestor->hasTagName(tagName)) | 937 if (ancestor->hasTagName(tagName)) |
938 return ancestor; | 938 return ancestor; |
939 if (ancestor == root) | 939 if (ancestor == root) |
940 return 0; | 940 return 0; |
941 } | 941 } |
942 | 942 |
943 return 0; | 943 return 0; |
944 } | 944 } |
945 | 945 |
946 Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*),
EditingBoundaryCrossingRule rule) | 946 template <typename Strategy> |
| 947 static Node* enclosingNodeOfTypeAlgorithm(const PositionAlgorithm<Strategy>& p,
bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule rule) |
947 { | 948 { |
948 // FIXME: support CanSkipCrossEditingBoundary | 949 // TODO(yosin) support CanSkipCrossEditingBoundary |
949 ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary
); | 950 ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary
); |
950 if (p.isNull()) | 951 if (p.isNull()) |
951 return 0; | 952 return nullptr; |
952 | 953 |
953 ContainerNode* root = rule == CannotCrossEditingBoundary ? highestEditableRo
ot(p) : 0; | 954 ContainerNode* const root = rule == CannotCrossEditingBoundary ? highestEdit
ableRoot(p) : nullptr; |
954 for (Node* n = p.anchorNode(); n; n = n->parentNode()) { | 955 for (Node* n = p.anchorNode(); n; n = Strategy::parent(*n)) { |
955 // Don't return a non-editable node if the input position was editable,
since | 956 // Don't return a non-editable node if the input position was editable,
since |
956 // the callers from editing will no doubt want to perform editing inside
the returned node. | 957 // the callers from editing will no doubt want to perform editing inside
the returned node. |
957 if (root && !n->hasEditableStyle()) | 958 if (root && !n->hasEditableStyle()) |
958 continue; | 959 continue; |
959 if (nodeIsOfType(n)) | 960 if (nodeIsOfType(n)) |
960 return n; | 961 return n; |
961 if (n == root) | 962 if (n == root) |
962 return 0; | 963 return nullptr; |
963 } | 964 } |
964 | 965 |
965 return 0; | 966 return nullptr; |
| 967 } |
| 968 |
| 969 Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*),
EditingBoundaryCrossingRule rule) |
| 970 { |
| 971 return enclosingNodeOfTypeAlgorithm<EditingStrategy>(p, nodeIsOfType, rule); |
| 972 } |
| 973 |
| 974 Node* enclosingNodeOfType(const PositionInComposedTree& p, bool (*nodeIsOfType)(
const Node*), EditingBoundaryCrossingRule rule) |
| 975 { |
| 976 return enclosingNodeOfTypeAlgorithm<EditingInComposedTreeStrategy>(p, nodeIs
OfType, rule); |
966 } | 977 } |
967 | 978 |
968 Node* highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const N
ode*), EditingBoundaryCrossingRule rule, Node* stayWithin) | 979 Node* highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const N
ode*), EditingBoundaryCrossingRule rule, Node* stayWithin) |
969 { | 980 { |
970 Node* highest = nullptr; | 981 Node* highest = nullptr; |
971 ContainerNode* root = rule == CannotCrossEditingBoundary ? highestEditableRo
ot(p) : nullptr; | 982 ContainerNode* root = rule == CannotCrossEditingBoundary ? highestEditableRo
ot(p) : nullptr; |
972 for (Node* n = p.computeContainerNode(); n && n != stayWithin; n = n->parent
Node()) { | 983 for (Node* n = p.computeContainerNode(); n && n != stayWithin; n = n->parent
Node()) { |
973 if (root && !n->hasEditableStyle()) | 984 if (root && !n->hasEditableStyle()) |
974 continue; | 985 continue; |
975 if (nodeIsOfType(n)) | 986 if (nodeIsOfType(n)) |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 // if the selection starts just before a paragraph break, skip over it | 1577 // if the selection starts just before a paragraph break, skip over it |
1567 if (isEndOfParagraph(visiblePosition)) | 1578 if (isEndOfParagraph(visiblePosition)) |
1568 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent())
; | 1579 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent())
; |
1569 | 1580 |
1570 // otherwise, make sure to be at the start of the first selected node, | 1581 // otherwise, make sure to be at the start of the first selected node, |
1571 // instead of possibly at the end of the last node before the selection | 1582 // instead of possibly at the end of the last node before the selection |
1572 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1583 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
1573 } | 1584 } |
1574 | 1585 |
1575 } // namespace blink | 1586 } // namespace blink |
OLD | NEW |