OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
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 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) | 2951 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) |
2952 { | 2952 { |
2953 return nextPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); | 2953 return nextPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); |
2954 } | 2954 } |
2955 | 2955 |
2956 VisiblePositionInComposedTree nextPositionOf(const VisiblePositionInComposedTree
& visiblePosition, EditingBoundaryCrossingRule rule) | 2956 VisiblePositionInComposedTree nextPositionOf(const VisiblePositionInComposedTree
& visiblePosition, EditingBoundaryCrossingRule rule) |
2957 { | 2957 { |
2958 return nextPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePositio
n, rule); | 2958 return nextPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePositio
n, rule); |
2959 } | 2959 } |
2960 | 2960 |
2961 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition& pos,
const Position& anchor) | 2961 template <typename Strategy> |
| 2962 static VisiblePositionTemplate<Strategy> skipToStartOfEditingBoundary(const Visi
blePositionTemplate<Strategy>& pos, const PositionAlgorithm<Strategy>& anchor) |
2962 { | 2963 { |
2963 if (pos.isNull()) | 2964 if (pos.isNull()) |
2964 return pos; | 2965 return pos; |
2965 | 2966 |
2966 ContainerNode* highestRoot = highestEditableRoot(anchor); | 2967 ContainerNode* highestRoot = highestEditableRoot(anchor); |
2967 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | 2968 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); |
2968 | 2969 |
2969 // Return |pos| itself if the two are from the very same editable region, or | 2970 // Return |pos| itself if the two are from the very same editable region, or |
2970 // both are non-editable. | 2971 // both are non-editable. |
2971 if (highestRootOfPos == highestRoot) | 2972 if (highestRootOfPos == highestRoot) |
2972 return pos; | 2973 return pos; |
2973 | 2974 |
2974 // If this is not editable but |pos| has an editable root, skip to the start | 2975 // If this is not editable but |pos| has an editable root, skip to the start |
2975 if (!highestRoot && highestRootOfPos) | 2976 if (!highestRoot && highestRootOfPos) |
2976 return createVisiblePosition(previousVisuallyDistinctCandidate(Position(
highestRootOfPos, PositionAnchorType::BeforeAnchor).parentAnchoredEquivalent()))
; | 2977 return createVisiblePosition(previousVisuallyDistinctCandidate(PositionA
lgorithm<Strategy>(highestRootOfPos, PositionAnchorType::BeforeAnchor).parentAnc
horedEquivalent())); |
2977 | 2978 |
2978 // That must mean that |pos| is not editable. Return the last position | 2979 // That must mean that |pos| is not editable. Return the last position |
2979 // before |pos| that is in the same editable region as this position | 2980 // before |pos| that is in the same editable region as this position |
2980 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); | 2981 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); |
2981 } | 2982 } |
2982 | 2983 |
2983 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) | 2984 template <typename Strategy> |
| 2985 static VisiblePositionTemplate<Strategy> previousPositionOfAlgorithm(const Visib
lePositionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule rule) |
2984 { | 2986 { |
2985 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival
ent()); | 2987 const PositionAlgorithm<Strategy> pos = previousVisuallyDistinctCandidate(vi
siblePosition.deepEquivalent()); |
2986 | 2988 |
2987 // return null visible position if there is no previous visible position | 2989 // return null visible position if there is no previous visible position |
2988 if (pos.atStartOfTree()) | 2990 if (pos.atStartOfTree()) |
2989 return VisiblePosition(); | 2991 return VisiblePositionTemplate<Strategy>(); |
2990 | 2992 |
2991 VisiblePosition prev = createVisiblePosition(pos); | 2993 const VisiblePositionTemplate<Strategy> prev = createVisiblePosition(pos); |
2992 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); | 2994 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); |
2993 | 2995 |
2994 #if ENABLE(ASSERT) | 2996 #if ENABLE(ASSERT) |
2995 // we should always be able to make the affinity |TextAffinity::Downstream|, | 2997 // we should always be able to make the affinity |TextAffinity::Downstream|, |
2996 // because going previous from an |TextAffinity::Upstream| position can | 2998 // because going previous from an |TextAffinity::Upstream| position can |
2997 // never yield another |TextAffinity::Upstream position| (unless line wrap | 2999 // never yield another |TextAffinity::Upstream position| (unless line wrap |
2998 // length is 0!). | 3000 // length is 0!). |
2999 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { | 3001 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { |
3000 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); | 3002 ASSERT(inSameLine(PositionWithAffinityTemplate<Strategy>(prev.deepEquiva
lent()), PositionWithAffinityTemplate<Strategy>(prev.deepEquivalent(), TextAffin
ity::Upstream))); |
3001 } | 3003 } |
3002 #endif | 3004 #endif |
3003 | 3005 |
3004 switch (rule) { | 3006 switch (rule) { |
3005 case CanCrossEditingBoundary: | 3007 case CanCrossEditingBoundary: |
3006 return prev; | 3008 return prev; |
3007 case CannotCrossEditingBoundary: | 3009 case CannotCrossEditingBoundary: |
3008 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale
nt()); | 3010 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale
nt()); |
3009 case CanSkipOverEditingBoundary: | 3011 case CanSkipOverEditingBoundary: |
3010 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); | 3012 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); |
3011 } | 3013 } |
3012 | 3014 |
3013 ASSERT_NOT_REACHED(); | 3015 ASSERT_NOT_REACHED(); |
3014 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent()
); | 3016 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent()
); |
3015 } | 3017 } |
3016 | 3018 |
| 3019 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) |
| 3020 { |
| 3021 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); |
| 3022 } |
| 3023 |
| 3024 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed
Tree& visiblePosition, EditingBoundaryCrossingRule rule) |
| 3025 { |
| 3026 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos
ition, rule); |
| 3027 } |
| 3028 |
3017 } // namespace blink | 3029 } // namespace blink |
OLD | NEW |