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

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

Issue 1201403002: Make VisiblePosition constructor to canonicalize a position in composed tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-25T13:30:25 Rebase Created 5 years, 6 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 | Source/core/editing/VisiblePositionTest.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 * 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace blink { 47 namespace blink {
48 48
49 using namespace HTMLNames; 49 using namespace HTMLNames;
50 50
51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity) 51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity)
52 { 52 {
53 init(pos, affinity); 53 init(pos, affinity);
54 } 54 }
55 55
56 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, EAffinity af finity) 56 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, EAffinity af finity)
57 : VisiblePosition(toPositionInDOMTree(pos), affinity)
58 { 57 {
58 init(pos, affinity);
59 } 59 }
60 60
61 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit y) 61 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit y)
62 { 62 {
63 init(positionWithAffinity.position(), positionWithAffinity.affinity()); 63 init(positionWithAffinity.position(), positionWithAffinity.affinity());
64 } 64 }
65 65
66 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const 66 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const
67 { 67 {
68 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini ty); 68 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini ty);
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 Position canonicalPositionOf(const Position& position) 640 Position canonicalPositionOf(const Position& position)
641 { 641 {
642 return canonicalPosition(position); 642 return canonicalPosition(position);
643 } 643 }
644 644
645 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio n) 645 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio n)
646 { 646 {
647 return canonicalPosition(position); 647 return canonicalPosition(position);
648 } 648 }
649 649
650 static Position toPositionInDOMTree(const Position& position)
tkent 2015/06/25 05:52:26 How about moving this to Position.h?
651 {
652 return position;
653 }
654
650 template<typename PositionType> 655 template<typename PositionType>
651 void VisiblePosition::init(const PositionType& position, EAffinity affinity) 656 void VisiblePosition::init(const PositionType& position, EAffinity affinity)
652 { 657 {
653 m_affinity = affinity; 658 m_affinity = affinity;
654 659
655 m_deepPosition = canonicalPosition(position); 660 PositionType deepPosition = canonicalPosition(position);
661 m_deepPosition = toPositionInDOMTree(deepPosition);
656 662
657 if (m_affinity != UPSTREAM) 663 if (m_affinity != UPSTREAM)
658 return; 664 return;
659 665
660 if (isNull()) { 666 if (isNull()) {
661 m_affinity = DOWNSTREAM; 667 m_affinity = DOWNSTREAM;
662 return; 668 return;
663 } 669 }
664 670
665 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. 671 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity.
666 if (!inSameLine(PositionWithAffinity(m_deepPosition, DOWNSTREAM), PositionWi thAffinity(m_deepPosition, UPSTREAM))) 672 using PositionWithAffinityType = PositionWithAffinityTemplate<PositionType>;
673 if (!inSameLine(PositionWithAffinityType(deepPosition, DOWNSTREAM), Position WithAffinityType(deepPosition, UPSTREAM)))
667 return; 674 return;
668 m_affinity = DOWNSTREAM; 675 m_affinity = DOWNSTREAM;
669 } 676 }
670 677
671 UChar32 VisiblePosition::characterAfter() const 678 UChar32 VisiblePosition::characterAfter() const
672 { 679 {
673 // We canonicalize to the first of two equivalent candidates, but the second of the two candidates 680 // We canonicalize to the first of two equivalent candidates, but the second of the two candidates
674 // is the one that will be inside the text node containing the character aft er this visible position. 681 // is the one that will be inside the text node containing the character aft er this visible position.
675 Position pos = m_deepPosition.downstream(); 682 Position pos = m_deepPosition.downstream();
676 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) 683 if (!pos.containerNode() || !pos.containerNode()->isTextNode())
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 else 842 else
836 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 843 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
837 } 844 }
838 845
839 void showTree(const blink::VisiblePosition& vpos) 846 void showTree(const blink::VisiblePosition& vpos)
840 { 847 {
841 vpos.showTreeForThis(); 848 vpos.showTreeForThis();
842 } 849 }
843 850
844 #endif 851 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/VisiblePositionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698