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

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-25T17:29:10 Update use-events-crash.svg expectations 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
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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 template<typename PositionType> 650 template<typename PositionType>
651 void VisiblePosition::init(const PositionType& position, EAffinity affinity) 651 void VisiblePosition::init(const PositionType& position, EAffinity affinity)
652 { 652 {
653 m_affinity = affinity; 653 m_affinity = affinity;
654 654
655 m_deepPosition = canonicalPosition(position); 655 PositionType deepPosition = canonicalPosition(position);
656 m_deepPosition = toPositionInDOMTree(deepPosition);
656 657
657 if (m_affinity != UPSTREAM) 658 if (m_affinity != UPSTREAM)
658 return; 659 return;
659 660
660 if (isNull()) { 661 if (isNull()) {
661 m_affinity = DOWNSTREAM; 662 m_affinity = DOWNSTREAM;
662 return; 663 return;
663 } 664 }
664 665
665 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. 666 // 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))) 667 using PositionWithAffinityType = PositionWithAffinityTemplate<PositionType>;
668 if (!inSameLine(PositionWithAffinityType(deepPosition, DOWNSTREAM), Position WithAffinityType(deepPosition, UPSTREAM)))
667 return; 669 return;
668 m_affinity = DOWNSTREAM; 670 m_affinity = DOWNSTREAM;
669 } 671 }
670 672
671 UChar32 VisiblePosition::characterAfter() const 673 UChar32 VisiblePosition::characterAfter() const
672 { 674 {
673 // We canonicalize to the first of two equivalent candidates, but the second of the two candidates 675 // 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. 676 // is the one that will be inside the text node containing the character aft er this visible position.
675 Position pos = m_deepPosition.downstream(); 677 Position pos = m_deepPosition.downstream();
676 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) 678 if (!pos.containerNode() || !pos.containerNode()->isTextNode())
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 else 837 else
836 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 838 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
837 } 839 }
838 840
839 void showTree(const blink::VisiblePosition& vpos) 841 void showTree(const blink::VisiblePosition& vpos)
840 { 842 {
841 vpos.showTreeForThis(); 843 vpos.showTreeForThis();
842 } 844 }
843 845
844 #endif 846 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/StyledMarkupSerializer.cpp ('k') | Source/core/editing/VisiblePositionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698