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

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

Issue 1299873002: ALL-IN-ONE Introduce enum class TextAffinity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-19T18:08:52 Created 5 years, 4 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/TextAffinity.h ('k') | Source/core/editing/VisiblePosition.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, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
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 12 matching lines...) Expand all
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef VisiblePosition_h 26 #ifndef VisiblePosition_h
27 #define VisiblePosition_h 27 #define VisiblePosition_h
28 28
29 #include "core/CoreExport.h" 29 #include "core/CoreExport.h"
30 #include "core/editing/EditingBoundary.h" 30 #include "core/editing/EditingBoundary.h"
31 #include "core/editing/EphemeralRange.h" 31 #include "core/editing/EphemeralRange.h"
32 #include "core/editing/PositionWithAffinity.h" 32 #include "core/editing/PositionWithAffinity.h"
33 #include "core/editing/TextAffinity.h"
33 #include "platform/heap/Handle.h" 34 #include "platform/heap/Handle.h"
34 #include "platform/text/TextDirection.h" 35 #include "platform/text/TextDirection.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 // VisiblePosition default affinity is downstream because 39 // VisiblePosition default affinity is downstream because
39 // the callers do not really care (they just want the 40 // the callers do not really care (they just want the
40 // deep position without regard to line position), and this 41 // deep position without regard to line position), and this
41 // is cheaper than UPSTREAM 42 // is cheaper than UPSTREAM
42 #define VP_DEFAULT_AFFINITY DOWNSTREAM 43 #define VP_DEFAULT_AFFINITY TextAffinity::Downstream
43 44
44 // Callers who do not know where on the line the position is, 45 // Callers who do not know where on the line the position is,
45 // but would like UPSTREAM if at a line break or DOWNSTREAM 46 // but would like UPSTREAM if at a line break or DOWNSTREAM
46 // otherwise, need a clear way to specify that. The 47 // otherwise, need a clear way to specify that. The
47 // constructors auto-correct UPSTREAM to DOWNSTREAM if the 48 // constructors auto-correct UPSTREAM to DOWNSTREAM if the
48 // position is not at a line break. 49 // position is not at a line break.
49 #define VP_UPSTREAM_IF_POSSIBLE UPSTREAM 50 #define VP_UPSTREAM_IF_POSSIBLE TextAffinity::Upstream
50 51
51 class InlineBox; 52 class InlineBox;
52 class Range; 53 class Range;
53 54
54 // |VisiblePosition| is an immutable object representing "canonical position" 55 // |VisiblePosition| is an immutable object representing "canonical position"
55 // with affinity. 56 // with affinity.
56 // 57 //
57 // "canonical position" is roughly equivalent to a position where we can place 58 // "canonical position" is roughly equivalent to a position where we can place
58 // caret, see |canonicalPosition()| for actual definition. 59 // caret, see |canonicalPosition()| for actual definition.
59 // 60 //
60 // "affinity" represents a place of caret at wrapped line. UPSTREAM affinity 61 // "affinity" represents a place of caret at wrapped line. UPSTREAM affinity
61 // means caret is placed at end of line. DOWNSTREAM affinity means caret is 62 // means caret is placed at end of line. DOWNSTREAM affinity means caret is
62 // placed at start of line. 63 // placed at start of line.
63 // 64 //
64 // Example of affinity: 65 // Example of affinity:
65 // abc^def where "^" represent |Position| 66 // abc^def where "^" represent |Position|
66 // When above text line wrapped after "abc" 67 // When above text line wrapped after "abc"
67 // abc| UPSTREAM |VisiblePosition| 68 // abc| UPSTREAM |VisiblePosition|
68 // |def DOWNSTREAM |VisiblePosition| 69 // |def DOWNSTREAM |VisiblePosition|
69 // 70 //
70 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, 71 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line,
71 // otherwise it will be converted to DOWNSTREAM. 72 // otherwise it will be converted to DOWNSTREAM.
72 class CORE_EXPORT VisiblePosition final { 73 class CORE_EXPORT VisiblePosition final {
73 DISALLOW_ALLOCATION(); 74 DISALLOW_ALLOCATION();
74 public: 75 public:
75 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { } 76 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { }
76 explicit VisiblePosition(const Position&, EAffinity = VP_DEFAULT_AFFINITY); 77 explicit VisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY );
77 explicit VisiblePosition(const PositionInComposedTree&, EAffinity = VP_DEFAU LT_AFFINITY); 78 explicit VisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DE FAULT_AFFINITY);
78 explicit VisiblePosition(const PositionWithAffinity&); 79 explicit VisiblePosition(const PositionWithAffinity&);
79 80
80 // Intentionally delete |operator==()| and |operator!=()| for reducing 81 // Intentionally delete |operator==()| and |operator!=()| for reducing
81 // compilation error message. 82 // compilation error message.
82 // TODO(yosin) We'll have |equals()| when we have use cases of checking 83 // TODO(yosin) We'll have |equals()| when we have use cases of checking
83 // equality of both position and affinity. 84 // equality of both position and affinity.
84 bool operator==(const VisiblePosition&) const = delete; 85 bool operator==(const VisiblePosition&) const = delete;
85 bool operator!=(const VisiblePosition&) const = delete; 86 bool operator!=(const VisiblePosition&) const = delete;
86 87
87 bool isNull() const { return m_deepPosition.isNull(); } 88 bool isNull() const { return m_deepPosition.isNull(); }
88 bool isNotNull() const { return m_deepPosition.isNotNull(); } 89 bool isNotNull() const { return m_deepPosition.isNotNull(); }
89 bool isOrphan() const { return m_deepPosition.isOrphan(); } 90 bool isOrphan() const { return m_deepPosition.isOrphan(); }
90 91
91 Position deepEquivalent() const { return m_deepPosition; } 92 Position deepEquivalent() const { return m_deepPosition; }
92 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn choredEquivalent(); } 93 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn choredEquivalent(); }
93 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff inity(m_deepPosition, m_affinity); } 94 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff inity(m_deepPosition, m_affinity); }
94 EAffinity affinity() const { ASSERT(m_affinity == UPSTREAM || m_affinity == DOWNSTREAM); return m_affinity; } 95 TextAffinity affinity() const { return m_affinity; }
95 96
96 // next() and previous() will increment/decrement by a character cluster. 97 // next() and previous() will increment/decrement by a character cluster.
97 VisiblePosition next(EditingBoundaryCrossingRule = CanCrossEditingBoundary) const; 98 VisiblePosition next(EditingBoundaryCrossingRule = CanCrossEditingBoundary) const;
98 VisiblePosition previous(EditingBoundaryCrossingRule = CanCrossEditingBounda ry) const; 99 VisiblePosition previous(EditingBoundaryCrossingRule = CanCrossEditingBounda ry) const;
99 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&) const ; 100 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&) const ;
100 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&) const; 101 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&) const;
101 VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition&) const; 102 VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition&) const;
102 VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&) const; 103 VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&) const;
103 104
104 VisiblePosition left() const; 105 VisiblePosition left() const;
(...skipping 16 matching lines...) Expand all
121 DECLARE_TRACE(); 122 DECLARE_TRACE();
122 123
123 #ifndef NDEBUG 124 #ifndef NDEBUG
124 void debugPosition(const char* msg = "") const; 125 void debugPosition(const char* msg = "") const;
125 void formatForDebugger(char* buffer, unsigned length) const; 126 void formatForDebugger(char* buffer, unsigned length) const;
126 void showTreeForThis() const; 127 void showTreeForThis() const;
127 #endif 128 #endif
128 129
129 private: 130 private:
130 template<typename Strategy> 131 template<typename Strategy>
131 void init(const PositionAlgorithm<Strategy>&, EAffinity); 132 void init(const PositionAlgorithm<Strategy>&, TextAffinity);
132 133
133 Position leftVisuallyDistinctCandidate() const; 134 Position leftVisuallyDistinctCandidate() const;
134 Position rightVisuallyDistinctCandidate() const; 135 Position rightVisuallyDistinctCandidate() const;
135 136
136 Position m_deepPosition; 137 Position m_deepPosition;
137 EAffinity m_affinity; 138 TextAffinity m_affinity;
138 }; 139 };
139 140
140 // TODO(yosin) We should move |computeInlineBoxPosition()| to "VisibleUnits.h" 141 // TODO(yosin) We should move |computeInlineBoxPosition()| to "VisibleUnits.h"
141 // with |Position| version. 142 // with |Position| version.
142 inline InlineBoxPosition computeInlineBoxPosition(const VisiblePosition& positio n) 143 inline InlineBoxPosition computeInlineBoxPosition(const VisiblePosition& positio n)
143 { 144 {
144 return position.deepEquivalent().computeInlineBoxPosition(position.affinity( )); 145 return position.deepEquivalent().computeInlineBoxPosition(position.affinity( ));
145 } 146 }
146 147
147 EphemeralRange makeRange(const VisiblePosition&, const VisiblePosition&); 148 EphemeralRange makeRange(const VisiblePosition&, const VisiblePosition&);
148 149
149 CORE_EXPORT Position canonicalPositionOf(const Position&); 150 CORE_EXPORT Position canonicalPositionOf(const Position&);
150 CORE_EXPORT PositionInComposedTree canonicalPositionOf(const PositionInComposedT ree&); 151 CORE_EXPORT PositionInComposedTree canonicalPositionOf(const PositionInComposedT ree&);
151 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity &, const Position& anchor); 152 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity &, const Position& anchor);
152 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor); 153 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor);
153 154
154 } // namespace blink 155 } // namespace blink
155 156
156 #ifndef NDEBUG 157 #ifndef NDEBUG
157 // Outside the WebCore namespace for ease of invocation from gdb. 158 // Outside the WebCore namespace for ease of invocation from gdb.
158 void showTree(const blink::VisiblePosition*); 159 void showTree(const blink::VisiblePosition*);
159 void showTree(const blink::VisiblePosition&); 160 void showTree(const blink::VisiblePosition&);
160 #endif 161 #endif
161 162
162 #endif // VisiblePosition_h 163 #endif // VisiblePosition_h
OLDNEW
« no previous file with comments | « Source/core/editing/TextAffinity.h ('k') | Source/core/editing/VisiblePosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698