Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: Source/core/editing/EditingUtilities.cpp

Issue 1316063002: Introduce firstEditablePositionAfterPositionInRoot() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-26T17:01:44 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return previousVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position) ; 447 return previousVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position) ;
448 } 448 }
449 449
450 PositionInComposedTree previousVisuallyDistinctCandidate(const PositionInCompose dTree& position) 450 PositionInComposedTree previousVisuallyDistinctCandidate(const PositionInCompose dTree& position)
451 { 451 {
452 return previousVisuallyDistinctCandidateAlgorithm<EditingInComposedTreeStrat egy>(position); 452 return previousVisuallyDistinctCandidateAlgorithm<EditingInComposedTreeStrat egy>(position);
453 } 453 }
454 454
455 VisiblePosition firstEditableVisiblePositionAfterPositionInRoot(const Position& position, ContainerNode* highestRoot) 455 VisiblePosition firstEditableVisiblePositionAfterPositionInRoot(const Position& position, ContainerNode* highestRoot)
456 { 456 {
457 return VisiblePosition(firstEditablePositionAfterPositionInRoot(position, hi ghestRoot));
458 }
459
460 template <typename Strategy>
461 PositionAlgorithm<Strategy> firstEditablePositionAfterPositionInRootAlgorithm(co nst PositionAlgorithm<Strategy>& position, Node* highestRoot)
462 {
457 // position falls before highestRoot. 463 // position falls before highestRoot.
458 if (comparePositions(position, firstPositionInNode(highestRoot)) == -1 && hi ghestRoot->hasEditableStyle()) 464 if (position.compareTo(PositionAlgorithm<Strategy>::firstPositionInNode(high estRoot)) == -1 && highestRoot->hasEditableStyle())
459 return VisiblePosition(firstPositionInNode(highestRoot)); 465 return PositionAlgorithm<Strategy>::firstPositionInNode(highestRoot);
460 466
461 Position editablePosition = position; 467 PositionAlgorithm<Strategy> editablePosition = position;
462 468
463 if (position.anchorNode()->treeScope() != highestRoot->treeScope()) { 469 if (position.anchorNode()->treeScope() != highestRoot->treeScope()) {
464 Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(edit ablePosition.anchorNode()); 470 Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(edit ablePosition.anchorNode());
465 if (!shadowAncestor) 471 if (!shadowAncestor)
466 return VisiblePosition(); 472 return PositionAlgorithm<Strategy>();
467 473
468 editablePosition = positionAfterNode(shadowAncestor); 474 editablePosition = PositionAlgorithm<Strategy>::afterNode(shadowAncestor );
469 } 475 }
470 476
471 while (editablePosition.anchorNode() && !isEditablePosition(editablePosition ) && editablePosition.anchorNode()->isDescendantOf(highestRoot)) 477 while (editablePosition.anchorNode() && !isEditablePosition(editablePosition ) && editablePosition.anchorNode()->isDescendantOf(highestRoot))
472 editablePosition = isAtomicNode(editablePosition.anchorNode()) ? positio nInParentAfterNode(*editablePosition.anchorNode()) : nextVisuallyDistinctCandida te(editablePosition); 478 editablePosition = isAtomicNode(editablePosition.anchorNode()) ? Positio nAlgorithm<Strategy>::inParentAfterNode(*editablePosition.anchorNode()) : nextVi suallyDistinctCandidate(editablePosition);
473 479
474 if (editablePosition.anchorNode() && editablePosition.anchorNode() != highes tRoot && !editablePosition.anchorNode()->isDescendantOf(highestRoot)) 480 if (editablePosition.anchorNode() && editablePosition.anchorNode() != highes tRoot && !editablePosition.anchorNode()->isDescendantOf(highestRoot))
475 return VisiblePosition(); 481 return PositionAlgorithm<Strategy>();
476 482
477 return VisiblePosition(editablePosition); 483 return editablePosition;
484 }
485
486 Position firstEditablePositionAfterPositionInRoot(const Position& position, Node * highestRoot)
487 {
488 return firstEditablePositionAfterPositionInRootAlgorithm<EditingStrategy>(po sition, highestRoot);
489 }
490
491 PositionInComposedTree firstEditablePositionAfterPositionInRoot(const PositionIn ComposedTree& position, Node* highestRoot)
492 {
493 return firstEditablePositionAfterPositionInRootAlgorithm<EditingInComposedTr eeStrategy>(position, highestRoot);
478 } 494 }
479 495
480 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position& position, ContainerNode* highestRoot) 496 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position& position, ContainerNode* highestRoot)
481 { 497 {
482 return VisiblePosition(lastEditablePositionBeforePositionInRoot(position, hi ghestRoot)); 498 return VisiblePosition(lastEditablePositionBeforePositionInRoot(position, hi ghestRoot));
483 } 499 }
484 500
485 template <typename PositionType> 501 template <typename PositionType>
486 PositionType lastEditablePositionBeforePositionInRootAlgorithm(const PositionTyp e& position, Node* highestRoot) 502 PositionType lastEditablePositionBeforePositionInRootAlgorithm(const PositionTyp e& position, Node* highestRoot)
487 { 503 {
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 // if the selection starts just before a paragraph break, skip over it 1593 // if the selection starts just before a paragraph break, skip over it
1578 if (isEndOfParagraph(visiblePosition)) 1594 if (isEndOfParagraph(visiblePosition))
1579 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent()) ; 1595 return mostForwardCaretPosition(visiblePosition.next().deepEquivalent()) ;
1580 1596
1581 // otherwise, make sure to be at the start of the first selected node, 1597 // 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 1598 // instead of possibly at the end of the last node before the selection
1583 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1599 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1584 } 1600 }
1585 1601
1586 } // namespace blink 1602 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698