OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // When above text line wrapped after "abc" | 66 // When above text line wrapped after "abc" |
67 // abc| UPSTREAM |VisiblePosition| | 67 // abc| UPSTREAM |VisiblePosition| |
68 // |def DOWNSTREAM |VisiblePosition| | 68 // |def DOWNSTREAM |VisiblePosition| |
69 // | 69 // |
70 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, | 70 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, |
71 // otherwise it will be converted to DOWNSTREAM. | 71 // otherwise it will be converted to DOWNSTREAM. |
72 class CORE_EXPORT VisiblePosition final { | 72 class CORE_EXPORT VisiblePosition final { |
73 DISALLOW_ALLOCATION(); | 73 DISALLOW_ALLOCATION(); |
74 public: | 74 public: |
75 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { } | 75 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { } |
| 76 |
| 77 // TODO(yosin) We should use |visiblePositionOf()| instead of constructor, |
| 78 // and make constructors to have private accessibility, since constructors |
| 79 // aren't simple, e.g. they update layout tree. |
76 explicit VisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY
); | 80 explicit VisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY
); |
77 explicit VisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DE
FAULT_AFFINITY); | |
78 explicit VisiblePosition(const PositionWithAffinity&); | 81 explicit VisiblePosition(const PositionWithAffinity&); |
79 | 82 |
| 83 // Node: Other than |visiblePositionOf()|, we should not use |
| 84 // |createWithoutCanonicalization()|. |
| 85 static VisiblePosition createWithoutCanonicalization(const PositionWithAffin
ity& canonicalized); |
| 86 |
80 // Intentionally delete |operator==()| and |operator!=()| for reducing | 87 // Intentionally delete |operator==()| and |operator!=()| for reducing |
81 // compilation error message. | 88 // compilation error message. |
82 // TODO(yosin) We'll have |equals()| when we have use cases of checking | 89 // TODO(yosin) We'll have |equals()| when we have use cases of checking |
83 // equality of both position and affinity. | 90 // equality of both position and affinity. |
84 bool operator==(const VisiblePosition&) const = delete; | 91 bool operator==(const VisiblePosition&) const = delete; |
85 bool operator!=(const VisiblePosition&) const = delete; | 92 bool operator!=(const VisiblePosition&) const = delete; |
86 | 93 |
87 bool isNull() const { return m_deepPosition.isNull(); } | 94 bool isNull() const { return m_deepPosition.isNull(); } |
88 bool isNotNull() const { return m_deepPosition.isNotNull(); } | 95 bool isNotNull() const { return m_deepPosition.isNotNull(); } |
89 bool isOrphan() const { return m_deepPosition.isOrphan(); } | 96 bool isOrphan() const { return m_deepPosition.isOrphan(); } |
90 | 97 |
91 Position deepEquivalent() const { return m_deepPosition; } | 98 Position deepEquivalent() const { return m_deepPosition; } |
92 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn
choredEquivalent(); } | 99 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn
choredEquivalent(); } |
93 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff
inity(m_deepPosition, m_affinity); } | 100 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff
inity(m_deepPosition, m_affinity); } |
94 TextAffinity affinity() const { return m_affinity; } | 101 TextAffinity affinity() const { return m_affinity; } |
95 | 102 |
96 // TODO(yosin) This does not handle [table, 0] correctly. | 103 // TODO(yosin) This does not handle [table, 0] correctly. |
97 Element* rootEditableElement() const { return m_deepPosition.isNotNull() ? m
_deepPosition.anchorNode()->rootEditableElement() : 0; } | 104 Element* rootEditableElement() const { return m_deepPosition.isNotNull() ? m
_deepPosition.anchorNode()->rootEditableElement() : 0; } |
98 | 105 |
99 DECLARE_TRACE(); | 106 DECLARE_TRACE(); |
100 | 107 |
101 #ifndef NDEBUG | 108 #ifndef NDEBUG |
102 void debugPosition(const char* msg = "") const; | 109 void debugPosition(const char* msg = "") const; |
103 void formatForDebugger(char* buffer, unsigned length) const; | 110 void formatForDebugger(char* buffer, unsigned length) const; |
104 void showTreeForThis() const; | 111 void showTreeForThis() const; |
105 #endif | 112 #endif |
106 | 113 |
107 private: | 114 private: |
108 template<typename Strategy> | 115 // TODO(yosin) We should use |PositionWithAffinity| to make |
109 void init(const PositionAlgorithm<Strategy>&, TextAffinity); | 116 // |toPositionWithAffinity()| simpler. |
110 | |
111 Position m_deepPosition; | 117 Position m_deepPosition; |
112 TextAffinity m_affinity; | 118 TextAffinity m_affinity; |
113 }; | 119 }; |
114 | 120 |
115 // TODO(yosin) We should move |absoluteCaretBoundsOf()| to "VisibleUnits.cpp". | 121 // TODO(yosin) We should move |absoluteCaretBoundsOf()| to "VisibleUnits.cpp". |
116 // Bounds of (possibly transformed) caret in absolute coords | 122 // Bounds of (possibly transformed) caret in absolute coords |
117 CORE_EXPORT IntRect absoluteCaretBoundsOf(const VisiblePosition&); | 123 CORE_EXPORT IntRect absoluteCaretBoundsOf(const VisiblePosition&); |
118 | 124 |
119 // Abs x/y position of the caret ignoring transforms. | 125 // Abs x/y position of the caret ignoring transforms. |
120 // TODO(yosin) navigation with transforms should be smarter. | 126 // TODO(yosin) navigation with transforms should be smarter. |
121 // TODO(yosin) We should move a glboal funciton | 127 // TODO(yosin) We should move a glboal funciton |
122 // |lineDirectionPointForBlockDirectionNavigationOf()| to "FrameSelection.h" | 128 // |lineDirectionPointForBlockDirectionNavigationOf()| to "FrameSelection.h" |
123 // as static function. | 129 // as static function. |
124 int lineDirectionPointForBlockDirectionNavigationOf(const VisiblePosition&); | 130 int lineDirectionPointForBlockDirectionNavigationOf(const VisiblePosition&); |
125 | 131 |
126 // TODO(yosin) We should move |leftPositionOf()| and |rightPositionOf()| to | 132 // TODO(yosin) We should move |leftPositionOf()| and |rightPositionOf()| to |
127 // "VisibleUnits.cpp". | 133 // "VisibleUnits.cpp". |
128 VisiblePosition leftPositionOf(const VisiblePosition&); | 134 VisiblePosition leftPositionOf(const VisiblePosition&); |
129 VisiblePosition rightPositionOf(const VisiblePosition&); | 135 VisiblePosition rightPositionOf(const VisiblePosition&); |
130 | 136 |
131 CORE_EXPORT Position canonicalPositionOf(const Position&); | 137 CORE_EXPORT Position canonicalPositionOf(const Position&); |
132 CORE_EXPORT PositionInComposedTree canonicalPositionOf(const PositionInComposedT
ree&); | 138 CORE_EXPORT PositionInComposedTree canonicalPositionOf(const PositionInComposedT
ree&); |
| 139 |
133 // TODO(yosin) We should move |characterAfter()| and |characterBefore()| to | 140 // TODO(yosin) We should move |characterAfter()| and |characterBefore()| to |
134 // "VisibleUnits.cpp" | 141 // "VisibleUnits.cpp" |
135 UChar32 characterAfter(const VisiblePosition&); | 142 UChar32 characterAfter(const VisiblePosition&); |
136 UChar32 characterBefore(const VisiblePosition&); | 143 UChar32 characterBefore(const VisiblePosition&); |
137 | 144 |
138 // TODO(yosin) We should move |honorEditingBoundaryAtOr{Before,After} to | 145 // TODO(yosin) We should move |honorEditingBoundaryAtOr{Before,After} to |
139 // "VisibleUnits.cpp" as static function. | 146 // "VisibleUnits.cpp" as static function. |
140 // next() and previous() will increment/decrement by a character cluster. | 147 // next() and previous() will increment/decrement by a character cluster. |
141 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&, const Pos
ition& anchor); | 148 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&, const Pos
ition& anchor); |
142 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
&, const Position& anchor); | 149 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
&, const Position& anchor); |
143 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi
onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor); | 150 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi
onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor); |
144 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&, const Posi
tion& anchor); | 151 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&, const Posi
tion& anchor); |
145 | 152 |
146 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". | 153 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". |
147 VisiblePosition nextPositionOf(const VisiblePosition&, EditingBoundaryCrossingRu
le = CanCrossEditingBoundary); | 154 VisiblePosition nextPositionOf(const VisiblePosition&, EditingBoundaryCrossingRu
le = CanCrossEditingBoundary); |
148 // TODO(yosin) We should move |previousPositionOf()| to "VisibleUnits.cpp" | 155 // TODO(yosin) We should move |previousPositionOf()| to "VisibleUnits.cpp" |
149 VisiblePosition previousPositionOf(const VisiblePosition&, EditingBoundaryCrossi
ngRule = CanCrossEditingBoundary); | 156 VisiblePosition previousPositionOf(const VisiblePosition&, EditingBoundaryCrossi
ngRule = CanCrossEditingBoundary); |
150 | 157 |
| 158 CORE_EXPORT VisiblePosition visiblePositionOf(const Position&, TextAffinity = VP
_DEFAULT_AFFINITY); |
| 159 CORE_EXPORT VisiblePosition visiblePositionOf(const PositionInComposedTree&, Tex
tAffinity = VP_DEFAULT_AFFINITY); |
| 160 |
151 } // namespace blink | 161 } // namespace blink |
152 | 162 |
153 #ifndef NDEBUG | 163 #ifndef NDEBUG |
154 // Outside the WebCore namespace for ease of invocation from gdb. | 164 // Outside the WebCore namespace for ease of invocation from gdb. |
155 void showTree(const blink::VisiblePosition*); | 165 void showTree(const blink::VisiblePosition*); |
156 void showTree(const blink::VisiblePosition&); | 166 void showTree(const blink::VisiblePosition&); |
157 #endif | 167 #endif |
158 | 168 |
159 #endif // VisiblePosition_h | 169 #endif // VisiblePosition_h |
OLD | NEW |