OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004 Apple Computer, 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 21 matching lines...) Expand all Loading... |
32 #include "core/editing/SelectionType.h" | 32 #include "core/editing/SelectionType.h" |
33 #include "core/editing/TextAffinity.h" | 33 #include "core/editing/TextAffinity.h" |
34 #include "core/editing/TextGranularity.h" | 34 #include "core/editing/TextGranularity.h" |
35 #include "core/editing/VisiblePosition.h" | 35 #include "core/editing/VisiblePosition.h" |
36 #include "core/editing/VisibleUnits.h" | 36 #include "core/editing/VisibleUnits.h" |
37 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class LayoutPoint; | 41 class LayoutPoint; |
| 42 class SelectionAdjuster; |
42 | 43 |
43 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. | 44 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. |
44 const TextAffinity SEL_DEFAULT_AFFINITY = TextAffinity::Downstream; // NOLINT | 45 const TextAffinity SEL_DEFAULT_AFFINITY = TextAffinity::Downstream; // NOLINT |
45 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; | 46 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; |
46 | 47 |
47 // Listener of |VisibleSelection| modification. |didChangeVisibleSelection()| | 48 // Listener of |VisibleSelection| modification. |didChangeVisibleSelection()| |
48 // will be invoked when base, extent, start or end is moved to a different | 49 // will be invoked when base, extent, start or end is moved to a different |
49 // position. | 50 // position. |
50 // | 51 // |
51 // Objects implementing |VisibleSelectionChangeObserver| interface must outlive | 52 // Objects implementing |VisibleSelectionChangeObserver| interface must outlive |
(...skipping 15 matching lines...) Expand all Loading... |
67 VisibleSelectionTemplate(); | 68 VisibleSelectionTemplate(); |
68 VisibleSelectionTemplate(const PositionTemplate<Strategy>&, TextAffinity, bo
ol isDirectional = false); | 69 VisibleSelectionTemplate(const PositionTemplate<Strategy>&, TextAffinity, bo
ol isDirectional = false); |
69 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, TextAffinity = SEL_DEFAULT_AFFINITY, bool isDirec
tional = false); | 70 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, TextAffinity = SEL_DEFAULT_AFFINITY, bool isDirec
tional = false); |
70 explicit VisibleSelectionTemplate(const EphemeralRangeTemplate<Strategy>&, T
extAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); | 71 explicit VisibleSelectionTemplate(const EphemeralRangeTemplate<Strategy>&, T
extAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); |
71 | 72 |
72 explicit VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&,
bool isDirectional = false); | 73 explicit VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&,
bool isDirectional = false); |
73 VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&, const Vis
iblePositionTemplate<Strategy>&, bool isDirectional = false); | 74 VisibleSelectionTemplate(const VisiblePositionTemplate<Strategy>&, const Vis
iblePositionTemplate<Strategy>&, bool isDirectional = false); |
74 | 75 |
75 explicit VisibleSelectionTemplate(const PositionWithAffinityTemplate<Strateg
y>&, bool isDirectional = false); | 76 explicit VisibleSelectionTemplate(const PositionWithAffinityTemplate<Strateg
y>&, bool isDirectional = false); |
76 | 77 |
77 static VisibleSelectionTemplate<Strategy> createWithoutValidation(const Posi
tionTemplate<Strategy>& base, const PositionTemplate<Strategy>& extent, const Po
sitionTemplate<Strategy>& start, const PositionTemplate<Strategy>& end, TextAffi
nity, bool isDirectional); | |
78 | |
79 VisibleSelectionTemplate(const VisibleSelectionTemplate&); | 78 VisibleSelectionTemplate(const VisibleSelectionTemplate&); |
80 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); | 79 VisibleSelectionTemplate& operator=(const VisibleSelectionTemplate&); |
81 | 80 |
82 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); | 81 static VisibleSelectionTemplate selectionFromContentsOfNode(Node*); |
83 | 82 |
84 SelectionType selectionType() const { return m_selectionType; } | 83 SelectionType selectionType() const { return m_selectionType; } |
85 | 84 |
86 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } | 85 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } |
87 TextAffinity affinity() const { return m_affinity; } | 86 TextAffinity affinity() const { return m_affinity; } |
88 | 87 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 #ifndef NDEBUG | 157 #ifndef NDEBUG |
159 void debugPosition(const char* message) const; | 158 void debugPosition(const char* message) const; |
160 void formatForDebugger(char* buffer, unsigned length) const; | 159 void formatForDebugger(char* buffer, unsigned length) const; |
161 void showTreeForThis() const; | 160 void showTreeForThis() const; |
162 #endif | 161 #endif |
163 | 162 |
164 void setStartRespectingGranularity(TextGranularity, EWordSide = RightWordIfO
nBoundary); | 163 void setStartRespectingGranularity(TextGranularity, EWordSide = RightWordIfO
nBoundary); |
165 void setEndRespectingGranularity(TextGranularity, EWordSide = RightWordIfOnB
oundary); | 164 void setEndRespectingGranularity(TextGranularity, EWordSide = RightWordIfOnB
oundary); |
166 | 165 |
167 private: | 166 private: |
168 VisibleSelectionTemplate(const PositionTemplate<Strategy>& base, const Posit
ionTemplate<Strategy>& extent, const PositionTemplate<Strategy>& start, const Po
sitionTemplate<Strategy>& end, TextAffinity, bool isDirectional); | 167 friend class SelectionAdjuster; |
169 | 168 |
170 void validate(TextGranularity = CharacterGranularity); | 169 void validate(TextGranularity = CharacterGranularity); |
171 | 170 |
172 // Support methods for validate() | 171 // Support methods for validate() |
173 void setBaseAndExtentToDeepEquivalents(); | 172 void setBaseAndExtentToDeepEquivalents(); |
174 void adjustSelectionToAvoidCrossingShadowBoundaries(); | 173 void adjustSelectionToAvoidCrossingShadowBoundaries(); |
175 void adjustSelectionToAvoidCrossingEditingBoundaries(); | 174 void adjustSelectionToAvoidCrossingEditingBoundaries(); |
176 void updateSelectionType(); | 175 void updateSelectionType(); |
177 | 176 |
178 // We need to store these as Positions because VisibleSelection is | 177 // We need to store these as Positions because VisibleSelection is |
(...skipping 21 matching lines...) Expand all Loading... |
200 bool m_baseIsFirst : 1; // True if base is before the extent | 199 bool m_baseIsFirst : 1; // True if base is before the extent |
201 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. | 200 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. |
202 }; | 201 }; |
203 | 202 |
204 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngStrategy>; | 203 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngStrategy>; |
205 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngInComposedTreeStrategy>; | 204 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisibleSelectionTemplate<Editi
ngInComposedTreeStrategy>; |
206 | 205 |
207 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; | 206 using VisibleSelection = VisibleSelectionTemplate<EditingStrategy>; |
208 using VisibleSelectionInComposedTree = VisibleSelectionTemplate<EditingInCompose
dTreeStrategy>; | 207 using VisibleSelectionInComposedTree = VisibleSelectionTemplate<EditingInCompose
dTreeStrategy>; |
209 | 208 |
| 209 // TODO(yosin): We should move |SelectionAdjuster| to its own file. |
| 210 class SelectionAdjuster final { |
| 211 STATIC_ONLY(SelectionAdjuster); |
| 212 public: |
| 213 static void adjustSelectionInComposedTree(VisibleSelectionInComposedTree*, c
onst VisibleSelection&); |
| 214 static void adjustSelectionInDOMTree(VisibleSelection*, const VisibleSelecti
onInComposedTree&); |
| 215 static void adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelection*
); |
| 216 static void adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSelectionI
nComposedTree*); |
| 217 }; |
| 218 |
210 // TODO(yosin): We should use |operator==()| instead of | 219 // TODO(yosin): We should use |operator==()| instead of |
211 // |equalSelectionsInDOMTree()|. | 220 // |equalSelectionsInDOMTree()|. |
212 bool equalSelectionsInDOMTree(const VisibleSelection&, const VisibleSelection&); | 221 bool equalSelectionsInDOMTree(const VisibleSelection&, const VisibleSelection&); |
213 | 222 |
214 // We don't yet support multi-range selections, so we only ever have one range | 223 // We don't yet support multi-range selections, so we only ever have one range |
215 // to return. | 224 // to return. |
216 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); | 225 CORE_EXPORT EphemeralRange firstEphemeralRangeOf(const VisibleSelection&); |
217 | 226 |
218 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. | 227 // TODO(sof): move more firstRangeOf() uses to be over EphemeralRange instead. |
219 CORE_EXPORT PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection&); | 228 CORE_EXPORT PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection&); |
220 | 229 |
221 } // namespace blink | 230 } // namespace blink |
222 | 231 |
223 #ifndef NDEBUG | 232 #ifndef NDEBUG |
224 // Outside the WebCore namespace for ease of invocation from gdb. | 233 // Outside the WebCore namespace for ease of invocation from gdb. |
225 void showTree(const blink::VisibleSelection&); | 234 void showTree(const blink::VisibleSelection&); |
226 void showTree(const blink::VisibleSelection*); | 235 void showTree(const blink::VisibleSelection*); |
227 void showTree(const blink::VisibleSelectionInComposedTree&); | 236 void showTree(const blink::VisibleSelectionInComposedTree&); |
228 void showTree(const blink::VisibleSelectionInComposedTree*); | 237 void showTree(const blink::VisibleSelectionInComposedTree*); |
229 #endif | 238 #endif |
230 | 239 |
231 #endif // VisibleSelection_h | 240 #endif // VisibleSelection_h |
OLD | NEW |