| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 return VisiblePosition(); | 475 return VisiblePosition(); |
| 476 | 476 |
| 477 return VisiblePosition(editablePosition); | 477 return VisiblePosition(editablePosition); |
| 478 } | 478 } |
| 479 | 479 |
| 480 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position&
position, ContainerNode* highestRoot) | 480 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position&
position, ContainerNode* highestRoot) |
| 481 { | 481 { |
| 482 return VisiblePosition(lastEditablePositionBeforePositionInRoot(position, hi
ghestRoot)); | 482 return VisiblePosition(lastEditablePositionBeforePositionInRoot(position, hi
ghestRoot)); |
| 483 } | 483 } |
| 484 | 484 |
| 485 template <typename PositionType> | 485 template <typename Strategy> |
| 486 PositionType lastEditablePositionBeforePositionInRootAlgorithm(const PositionTyp
e& position, Node* highestRoot) | 486 PositionAlgorithm<Strategy> lastEditablePositionBeforePositionInRootAlgorithm(co
nst PositionAlgorithm<Strategy>& position, Node* highestRoot) |
| 487 { | 487 { |
| 488 // When position falls after highestRoot, the result is easy to compute. | 488 // When position falls after highestRoot, the result is easy to compute. |
| 489 if (position.compareTo(PositionType::lastPositionInNode(highestRoot)) == 1) | 489 if (position.compareTo(PositionAlgorithm<Strategy>::lastPositionInNode(highe
stRoot)) == 1) |
| 490 return PositionType::lastPositionInNode(highestRoot); | 490 return PositionAlgorithm<Strategy>::lastPositionInNode(highestRoot); |
| 491 | 491 |
| 492 PositionType editablePosition = position; | 492 PositionAlgorithm<Strategy> editablePosition = position; |
| 493 | 493 |
| 494 if (position.anchorNode()->treeScope() != highestRoot->treeScope()) { | 494 if (position.anchorNode()->treeScope() != highestRoot->treeScope()) { |
| 495 Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(edit
ablePosition.anchorNode()); | 495 Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(edit
ablePosition.anchorNode()); |
| 496 if (!shadowAncestor) | 496 if (!shadowAncestor) |
| 497 return PositionType(); | 497 return PositionAlgorithm<Strategy>(); |
| 498 | 498 |
| 499 editablePosition = PositionType::firstPositionInOrBeforeNode(shadowAnces
tor); | 499 editablePosition = PositionAlgorithm<Strategy>::firstPositionInOrBeforeN
ode(shadowAncestor); |
| 500 } | 500 } |
| 501 | 501 |
| 502 while (editablePosition.anchorNode() && !isEditablePosition(editablePosition
) && editablePosition.anchorNode()->isDescendantOf(highestRoot)) | 502 while (editablePosition.anchorNode() && !isEditablePosition(editablePosition
) && editablePosition.anchorNode()->isDescendantOf(highestRoot)) |
| 503 editablePosition = isAtomicNode(editablePosition.anchorNode()) ? Positio
nType::inParentBeforeNode(*editablePosition.anchorNode()) : previousVisuallyDist
inctCandidate(editablePosition); | 503 editablePosition = isAtomicNode(editablePosition.anchorNode()) ? Positio
nAlgorithm<Strategy>::inParentBeforeNode(*editablePosition.anchorNode()) : previ
ousVisuallyDistinctCandidate(editablePosition); |
| 504 | 504 |
| 505 if (editablePosition.anchorNode() && editablePosition.anchorNode() != highes
tRoot && !editablePosition.anchorNode()->isDescendantOf(highestRoot)) | 505 if (editablePosition.anchorNode() && editablePosition.anchorNode() != highes
tRoot && !editablePosition.anchorNode()->isDescendantOf(highestRoot)) |
| 506 return PositionType(); | 506 return PositionAlgorithm<Strategy>(); |
| 507 return editablePosition; | 507 return editablePosition; |
| 508 } | 508 } |
| 509 | 509 |
| 510 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node
* highestRoot) | 510 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node
* highestRoot) |
| 511 { | 511 { |
| 512 return lastEditablePositionBeforePositionInRootAlgorithm<Position>(position,
highestRoot); | 512 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po
sition, highestRoot); |
| 513 } | 513 } |
| 514 | 514 |
| 515 PositionInComposedTree lastEditablePositionBeforePositionInRoot(const PositionIn
ComposedTree& position, Node* highestRoot) | 515 PositionInComposedTree lastEditablePositionBeforePositionInRoot(const PositionIn
ComposedTree& position, Node* highestRoot) |
| 516 { | 516 { |
| 517 return lastEditablePositionBeforePositionInRootAlgorithm<PositionInComposedT
ree>(position, highestRoot); | 517 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInComposedTr
eeStrategy>(position, highestRoot); |
| 518 } | 518 } |
| 519 | 519 |
| 520 int uncheckedPreviousOffset(const Node* n, int current) | 520 int uncheckedPreviousOffset(const Node* n, int current) |
| 521 { | 521 { |
| 522 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; | 522 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; |
| 523 } | 523 } |
| 524 | 524 |
| 525 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) | 525 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) |
| 526 { | 526 { |
| 527 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; | 527 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 // 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 |
| 1578 if (isEndOfParagraph(visiblePosition)) | 1578 if (isEndOfParagraph(visiblePosition)) |
| 1579 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent())
; | 1579 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent())
; |
| 1580 | 1580 |
| 1581 // 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, |
| 1582 // 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 |
| 1583 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1583 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 } // namespace blink | 1586 } // namespace blink |
| OLD | NEW |