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

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

Issue 1328113005: Introduce composed tree version of characterAfter() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-07T18:55:16 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 | « Source/core/editing/VisibleUnits.h ('k') | Source/core/editing/VisibleUnitsTest.cpp » ('j') | 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, 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 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 2541
2542 // If this is not editable but |pos| has an editable root, skip to the end 2542 // If this is not editable but |pos| has an editable root, skip to the end
2543 if (!highestRoot && highestRootOfPos) 2543 if (!highestRoot && highestRootOfPos)
2544 return createVisiblePosition(Position(highestRootOfPos, PositionAnchorTy pe::AfterAnchor).parentAnchoredEquivalent()); 2544 return createVisiblePosition(Position(highestRootOfPos, PositionAnchorTy pe::AfterAnchor).parentAnchoredEquivalent());
2545 2545
2546 // That must mean that |pos| is not editable. Return the next position after 2546 // That must mean that |pos| is not editable. Return the next position after
2547 // |pos| that is in the same editable region as this position 2547 // |pos| that is in the same editable region as this position
2548 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot); 2548 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
2549 } 2549 }
2550 2550
2551 UChar32 characterAfter(const VisiblePosition& visiblePosition) 2551 template <typename Strategy>
2552 static UChar32 characterAfterAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition)
2552 { 2553 {
2553 // We canonicalize to the first of two equivalent candidates, but the second 2554 // We canonicalize to the first of two equivalent candidates, but the second
2554 // of the two candidates is the one that will be inside the text node 2555 // of the two candidates is the one that will be inside the text node
2555 // containing the character after this visible position. 2556 // containing the character after this visible position.
2556 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent()); 2557 const PositionAlgorithm<Strategy> pos = mostForwardCaretPosition(visiblePosi tion.deepEquivalent());
2557 if (!pos.isOffsetInAnchor()) 2558 if (!pos.isOffsetInAnchor())
2558 return 0; 2559 return 0;
2559 Node* containerNode = pos.computeContainerNode(); 2560 Node* containerNode = pos.computeContainerNode();
2560 if (!containerNode || !containerNode->isTextNode()) 2561 if (!containerNode || !containerNode->isTextNode())
2561 return 0; 2562 return 0;
2562 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode()); 2563 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode());
2563 Text* textNode = toText(containerNode); 2564 Text* textNode = toText(containerNode);
2564 unsigned length = textNode->length(); 2565 unsigned length = textNode->length();
2565 if (offset >= length) 2566 if (offset >= length)
2566 return 0; 2567 return 0;
2567 2568
2568 return textNode->data().characterStartingAt(offset); 2569 return textNode->data().characterStartingAt(offset);
2569 } 2570 }
2570 2571
2572 UChar32 characterAfter(const VisiblePosition& visiblePosition)
2573 {
2574 return characterAfterAlgorithm<EditingStrategy>(visiblePosition);
2575 }
2576
2577 UChar32 characterAfter(const VisiblePositionInComposedTree& visiblePosition)
2578 {
2579 return characterAfterAlgorithm<EditingInComposedTreeStrategy>(visiblePositio n);
2580 }
2581
2571 UChar32 characterBefore(const VisiblePosition& visiblePosition) 2582 UChar32 characterBefore(const VisiblePosition& visiblePosition)
2572 { 2583 {
2573 return characterAfter(previousPositionOf(visiblePosition)); 2584 return characterAfter(previousPositionOf(visiblePosition));
2574 } 2585 }
2575 2586
2576 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi tion) 2587 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi tion)
2577 { 2588 {
2578 const Position deepPosition = visiblePosition.deepEquivalent(); 2589 const Position deepPosition = visiblePosition.deepEquivalent();
2579 Position p = deepPosition; 2590 Position p = deepPosition;
2580 if (p.isNull()) 2591 if (p.isNull())
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale nt()); 2979 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale nt());
2969 case CanSkipOverEditingBoundary: 2980 case CanSkipOverEditingBoundary:
2970 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent ()); 2981 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent ());
2971 } 2982 }
2972 2983
2973 ASSERT_NOT_REACHED(); 2984 ASSERT_NOT_REACHED();
2974 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent() ); 2985 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent() );
2975 } 2986 }
2976 2987
2977 } // namespace blink 2988 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.h ('k') | Source/core/editing/VisibleUnitsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698