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

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

Issue 1320233003: Move character{After,Before}() for VisiblePosition to VisibleUnits.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-01T11:25:07 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/VisiblePosition.h ('k') | Source/core/editing/VisibleUnits.h » ('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 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 { 583 {
584 return VisiblePosition::createWithoutCanonicalization(visiblePositionOfAlgor ithm<EditingStrategy>(position, affinity)); 584 return VisiblePosition::createWithoutCanonicalization(visiblePositionOfAlgor ithm<EditingStrategy>(position, affinity));
585 } 585 }
586 586
587 VisiblePosition visiblePositionOf(const PositionInComposedTree& position, TextAf finity affinity) 587 VisiblePosition visiblePositionOf(const PositionInComposedTree& position, TextAf finity affinity)
588 { 588 {
589 PositionInComposedTreeWithAffinity canonicalized = visiblePositionOfAlgorith m<EditingInComposedTreeStrategy>(position, affinity); 589 PositionInComposedTreeWithAffinity canonicalized = visiblePositionOfAlgorith m<EditingInComposedTreeStrategy>(position, affinity);
590 return VisiblePosition::createWithoutCanonicalization(PositionWithAffinity(t oPositionInDOMTree(canonicalized.position()), canonicalized.affinity())); 590 return VisiblePosition::createWithoutCanonicalization(PositionWithAffinity(t oPositionInDOMTree(canonicalized.position()), canonicalized.affinity()));
591 } 591 }
592 592
593 UChar32 characterAfter(const VisiblePosition& visiblePosition)
594 {
595 // We canonicalize to the first of two equivalent candidates, but the second
596 // of the two candidates is the one that will be inside the text node
597 // containing the character after this visible position.
598 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent());
599 if (!pos.isOffsetInAnchor())
600 return 0;
601 Node* containerNode = pos.computeContainerNode();
602 if (!containerNode || !containerNode->isTextNode())
603 return 0;
604 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode());
605 Text* textNode = toText(containerNode);
606 unsigned length = textNode->length();
607 if (offset >= length)
608 return 0;
609
610 return textNode->data().characterStartingAt(offset);
611 }
612
613 UChar32 characterBefore(const VisiblePosition& visiblePosition)
614 {
615 return characterAfter(previousPositionOf(visiblePosition));
616 }
617
618 IntRect absoluteCaretBoundsOf(const VisiblePosition& visiblePosition) 593 IntRect absoluteCaretBoundsOf(const VisiblePosition& visiblePosition)
619 { 594 {
620 LayoutObject* layoutObject; 595 LayoutObject* layoutObject;
621 LayoutRect localRect = localCaretRectOfPosition(visiblePosition.toPositionWi thAffinity(), layoutObject); 596 LayoutRect localRect = localCaretRectOfPosition(visiblePosition.toPositionWi thAffinity(), layoutObject);
622 if (localRect.isEmpty() || !layoutObject) 597 if (localRect.isEmpty() || !layoutObject)
623 return IntRect(); 598 return IntRect();
624 599
625 return layoutObject->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox(); 600 return layoutObject->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox();
626 } 601 }
627 602
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 else 662 else
688 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 663 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
689 } 664 }
690 665
691 void showTree(const blink::VisiblePosition& vpos) 666 void showTree(const blink::VisiblePosition& vpos)
692 { 667 {
693 vpos.showTreeForThis(); 668 vpos.showTreeForThis();
694 } 669 }
695 670
696 #endif 671 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisiblePosition.h ('k') | Source/core/editing/VisibleUnits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698