OLD | NEW |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "wtf/text/CString.h" | 42 #include "wtf/text/CString.h" |
43 | 43 |
44 #ifndef NDEBUG | 44 #ifndef NDEBUG |
45 #include <stdio.h> | 45 #include <stdio.h> |
46 #endif | 46 #endif |
47 | 47 |
48 namespace blink { | 48 namespace blink { |
49 | 49 |
50 using namespace HTMLNames; | 50 using namespace HTMLNames; |
51 | 51 |
52 VisiblePosition::VisiblePosition(const Position &pos, TextAffinity affinity) | 52 VisiblePosition::VisiblePosition(const Position& position, TextAffinity affinity
) |
53 { | 53 { |
54 init(pos, affinity); | 54 // TODO(yosin) We should make |VisiblePosition| private and make this |
55 } | 55 // constructor to populate member variables by using |visiblePositionOf()|. |
56 | 56 *this = visiblePositionOf(position, affinity); |
57 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, TextAffinity
affinity) | |
58 { | |
59 init(pos, affinity); | |
60 } | 57 } |
61 | 58 |
62 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) | 59 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) |
| 60 : VisiblePosition(positionWithAffinity.position(), positionWithAffinity.affi
nity()) |
63 { | 61 { |
64 init(positionWithAffinity.position(), positionWithAffinity.affinity()); | 62 } |
| 63 |
| 64 VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
hAffinity& canonicalized) |
| 65 { |
| 66 VisiblePosition visiblePosition; |
| 67 visiblePosition.m_deepPosition = canonicalized.position(); |
| 68 visiblePosition.m_affinity = canonicalized.affinity(); |
| 69 return visiblePosition; |
65 } | 70 } |
66 | 71 |
67 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| | 72 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| |
68 // here to avoid forward declaration. | 73 // here to avoid forward declaration. |
69 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&, const
Position& anchor); | 74 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&, const
Position& anchor); |
70 | 75 |
71 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". | 76 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". |
72 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) | 77 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) |
73 { | 78 { |
74 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv
alent()), visiblePosition.affinity()); | 79 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv
alent()), visiblePosition.affinity()); |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 { | 660 { |
656 return canonicalPosition(position); | 661 return canonicalPosition(position); |
657 } | 662 } |
658 | 663 |
659 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) | 664 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) |
660 { | 665 { |
661 return canonicalPosition(position); | 666 return canonicalPosition(position); |
662 } | 667 } |
663 | 668 |
664 template<typename Strategy> | 669 template<typename Strategy> |
665 void VisiblePosition::init(const PositionAlgorithm<Strategy>& position, TextAffi
nity affinity) | 670 static PositionWithAffinityTemplate<Strategy> visiblePositionOfAlgorithm(const P
ositionAlgorithm<Strategy>& position, TextAffinity affinity) |
666 { | 671 { |
667 m_affinity = affinity; | 672 const PositionAlgorithm<Strategy> deepPosition = canonicalPosition(position)
; |
668 | 673 if (deepPosition.isNull()) |
669 PositionAlgorithm<Strategy> deepPosition = canonicalPosition(position); | 674 return PositionWithAffinityTemplate<Strategy>(); |
670 m_deepPosition = toPositionInDOMTree(deepPosition); | 675 if (affinity == TextAffinity::Downstream) |
671 | 676 return PositionWithAffinityTemplate<Strategy>(deepPosition); |
672 if (m_affinity != TextAffinity::Upstream) | |
673 return; | |
674 | |
675 if (isNull()) { | |
676 m_affinity = TextAffinity::Downstream; | |
677 return; | |
678 } | |
679 | 677 |
680 // When not at a line wrap, make sure to end up with | 678 // When not at a line wrap, make sure to end up with |
681 // |TextAffinity::Downstream| affinity. | 679 // |TextAffinity::Downstream| affinity. |
682 if (!inSameLine(PositionWithAffinityTemplate<Strategy>(deepPosition), Positi
onWithAffinityTemplate<Strategy>(deepPosition, TextAffinity::Upstream))) | 680 if (inSameLine(PositionWithAffinityTemplate<Strategy>(deepPosition), Positio
nWithAffinityTemplate<Strategy>(deepPosition, TextAffinity::Upstream))) |
683 return; | 681 return PositionWithAffinityTemplate<Strategy>(deepPosition); |
684 m_affinity = TextAffinity::Downstream; | 682 return PositionWithAffinityTemplate<Strategy>(deepPosition, TextAffinity::Up
stream); |
| 683 } |
| 684 |
| 685 VisiblePosition visiblePositionOf(const Position& position, TextAffinity affinit
y) |
| 686 { |
| 687 return VisiblePosition::createWithoutCanonicalization(visiblePositionOfAlgor
ithm<EditingStrategy>(position, affinity)); |
| 688 } |
| 689 |
| 690 VisiblePosition visiblePositionOf(const PositionInComposedTree& position, TextAf
finity affinity) |
| 691 { |
| 692 PositionInComposedTreeWithAffinity canonicalized = visiblePositionOfAlgorith
m<EditingInComposedTreeStrategy>(position, affinity); |
| 693 return VisiblePosition::createWithoutCanonicalization(PositionWithAffinity(t
oPositionInDOMTree(canonicalized.position()), canonicalized.affinity())); |
685 } | 694 } |
686 | 695 |
687 UChar32 characterAfter(const VisiblePosition& visiblePosition) | 696 UChar32 characterAfter(const VisiblePosition& visiblePosition) |
688 { | 697 { |
689 // We canonicalize to the first of two equivalent candidates, but the second | 698 // We canonicalize to the first of two equivalent candidates, but the second |
690 // of the two candidates is the one that will be inside the text node | 699 // of the two candidates is the one that will be inside the text node |
691 // containing the character after this visible position. | 700 // containing the character after this visible position. |
692 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 701 Position pos = mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
693 if (!pos.isOffsetInAnchor()) | 702 if (!pos.isOffsetInAnchor()) |
694 return 0; | 703 return 0; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 else | 797 else |
789 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 798 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
790 } | 799 } |
791 | 800 |
792 void showTree(const blink::VisiblePosition& vpos) | 801 void showTree(const blink::VisiblePosition& vpos) |
793 { | 802 { |
794 vpos.showTreeForThis(); | 803 vpos.showTreeForThis(); |
795 } | 804 } |
796 | 805 |
797 #endif | 806 #endif |
OLD | NEW |