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

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

Issue 1304353003: Use EditingStrategy as template parameter to lastEditablePositionBeforePositionInRootAlgorithm templ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-26T16:07:59 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698