| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Position canonicalPositionOf(const Position& position) | 159 Position canonicalPositionOf(const Position& position) |
| 160 { | 160 { |
| 161 return canonicalPosition(position); | 161 return canonicalPosition(position); |
| 162 } | 162 } |
| 163 | 163 |
| 164 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) | 164 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) |
| 165 { | 165 { |
| 166 return canonicalPosition(position); | 166 return canonicalPosition(position); |
| 167 } | 167 } |
| 168 | 168 |
| 169 template <typename Strategy> |
| 170 static PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBeforeAlgo
rithm(const PositionWithAffinityTemplate<Strategy>& pos, const PositionAlgorithm
<Strategy>& anchor) |
| 171 { |
| 172 if (pos.isNull()) |
| 173 return pos; |
| 174 |
| 175 ContainerNode* highestRoot = highestEditableRoot(anchor); |
| 176 |
| 177 // Return empty position if |pos| is not somewhere inside the editable |
| 178 // region containing this position |
| 179 if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot)
) |
| 180 return PositionWithAffinityTemplate<Strategy>(); |
| 181 |
| 182 // Return |pos| itself if the two are from the very same editable region, or |
| 183 // both are non-editable |
| 184 // TODO(yosin) In the non-editable case, just because the new position is |
| 185 // non-editable doesn't mean movement to it is allowed. |
| 186 // |VisibleSelection::adjustForEditableContent()| has this problem too. |
| 187 if (highestEditableRoot(pos.position()) == highestRoot) |
| 188 return pos; |
| 189 |
| 190 // Return empty position if this position is non-editable, but |pos| is |
| 191 // editable. |
| 192 // TODO(yosin) Move to the previous non-editable region. |
| 193 if (!highestRoot) |
| 194 return PositionWithAffinityTemplate<Strategy>(); |
| 195 |
| 196 // Return the last position before |pos| that is in the same editable region |
| 197 // as this position |
| 198 return lastEditablePositionBeforePositionInRoot(pos.position(), highestRoot)
; |
| 199 } |
| 200 |
| 201 static PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithA
ffinity& pos, const Position& anchor) |
| 202 { |
| 203 return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor); |
| 204 } |
| 205 |
| 206 static PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const
PositionInComposedTreeWithAffinity& pos, const PositionInComposedTree& anchor) |
| 207 { |
| 208 return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor); |
| 209 } |
| 210 |
| 211 static VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition& pos
, const Position& anchor) |
| 212 { |
| 213 return createVisiblePosition(honorEditingBoundaryAtOrBeforeOf(pos.toPosition
WithAffinity(), anchor)); |
| 214 } |
| 215 |
| 216 static VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition& pos,
const Position& anchor) |
| 217 { |
| 218 if (pos.isNull()) |
| 219 return pos; |
| 220 |
| 221 ContainerNode* highestRoot = highestEditableRoot(anchor); |
| 222 |
| 223 // Return empty position if |pos| is not somewhere inside the editable |
| 224 // region // containing this position |
| 225 if (highestRoot && !pos.deepEquivalent().anchorNode()->isDescendantOf(highes
tRoot)) |
| 226 return VisiblePosition(); |
| 227 |
| 228 // Return |pos| itself if the two are from the very same editable region, or |
| 229 // both are non-editable |
| 230 // TODO(yosin) In the non-editable case, just because the new position is |
| 231 // non-editable doesn't mean movement to it is allowed. |
| 232 // |VisibleSelection::adjustForEditableContent()| has this problem too. |
| 233 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot) |
| 234 return pos; |
| 235 |
| 236 // Return empty position if this position is non-editable, but |pos| is |
| 237 // editable |
| 238 // TODO(yosin) Move to the next non-editable region. |
| 239 if (!highestRoot) |
| 240 return VisiblePosition(); |
| 241 |
| 242 // Return the next position after |pos| that is in the same editable region |
| 243 // as this position |
| 244 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); |
| 245 } |
| 246 |
| 169 static Node* previousLeafWithSameEditability(Node* node, EditableType editableTy
pe) | 247 static Node* previousLeafWithSameEditability(Node* node, EditableType editableTy
pe) |
| 170 { | 248 { |
| 171 bool editable = node->hasEditableStyle(editableType); | 249 bool editable = node->hasEditableStyle(editableType); |
| 172 node = previousAtomicLeafNode(*node); | 250 node = previousAtomicLeafNode(*node); |
| 173 while (node) { | 251 while (node) { |
| 174 if (editable == node->hasEditableStyle(editableType)) | 252 if (editable == node->hasEditableStyle(editableType)) |
| 175 return node; | 253 return node; |
| 176 node = previousAtomicLeafNode(*node); | 254 node = previousAtomicLeafNode(*node); |
| 177 } | 255 } |
| 178 return 0; | 256 return 0; |
| (...skipping 2711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale
nt()); | 2968 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale
nt()); |
| 2891 case CanSkipOverEditingBoundary: | 2969 case CanSkipOverEditingBoundary: |
| 2892 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); | 2970 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); |
| 2893 } | 2971 } |
| 2894 | 2972 |
| 2895 ASSERT_NOT_REACHED(); | 2973 ASSERT_NOT_REACHED(); |
| 2896 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent()
); | 2974 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent()
); |
| 2897 } | 2975 } |
| 2898 | 2976 |
| 2899 } // namespace blink | 2977 } // namespace blink |
| OLD | NEW |