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 12 matching lines...) Expand all Loading... |
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 VisibleSelection_h | 26 #ifndef VisibleSelection_h |
27 #define VisibleSelection_h | 27 #define VisibleSelection_h |
28 | 28 |
29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
30 #include "core/editing/EditingStrategy.h" | 30 #include "core/editing/EditingStrategy.h" |
31 #include "core/editing/EphemeralRange.h" | 31 #include "core/editing/EphemeralRange.h" |
32 #include "core/editing/SelectionType.h" | 32 #include "core/editing/SelectionType.h" |
| 33 #include "core/editing/TextAffinity.h" |
33 #include "core/editing/TextGranularity.h" | 34 #include "core/editing/TextGranularity.h" |
34 #include "core/editing/VisiblePosition.h" | 35 #include "core/editing/VisiblePosition.h" |
35 #include "core/editing/VisibleUnits.h" | 36 #include "core/editing/VisibleUnits.h" |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 class LayoutPoint; | 40 class LayoutPoint; |
40 | 41 |
41 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. | 42 // TODO(yosin) We should use capitalized name instead of |SEL_DEFAULT_AFFINITY|. |
42 const EAffinity SEL_DEFAULT_AFFINITY = DOWNSTREAM; // NOLINT | 43 const TextAffinity SEL_DEFAULT_AFFINITY = TextAffinity::Downstream; // NOLINT |
43 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; | 44 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; |
44 | 45 |
45 class CORE_EXPORT VisibleSelection { | 46 class CORE_EXPORT VisibleSelection { |
46 DISALLOW_ALLOCATION(); | 47 DISALLOW_ALLOCATION(); |
47 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(VisibleSelection); | 48 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(VisibleSelection); |
48 public: | 49 public: |
49 class InDOMTree { | 50 class InDOMTree { |
50 public: | 51 public: |
51 using PositionType = Position; | 52 using PositionType = Position; |
52 using Strategy = EditingStrategy; | 53 using Strategy = EditingStrategy; |
(...skipping 18 matching lines...) Expand all Loading... |
71 static EphemeralRangeInComposedTree asRange(const VisibleSelection&); | 72 static EphemeralRangeInComposedTree asRange(const VisibleSelection&); |
72 static bool equalSelections(const VisibleSelection&, const VisibleSelect
ion&); | 73 static bool equalSelections(const VisibleSelection&, const VisibleSelect
ion&); |
73 static bool isRange(const VisibleSelection& selection) { return selectio
nType(selection) == RangeSelection; } | 74 static bool isRange(const VisibleSelection& selection) { return selectio
nType(selection) == RangeSelection; } |
74 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.baseInComposedTree(); } | 75 static PositionType selectionBase(const VisibleSelection& selection) { r
eturn selection.baseInComposedTree(); } |
75 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extentInComposedTree(); } | 76 static PositionType selectionExtent(const VisibleSelection& selection) {
return selection.extentInComposedTree(); } |
76 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.startInComposedTree(); } | 77 static PositionType selectionStart(const VisibleSelection& selection) {
return selection.startInComposedTree(); } |
77 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.endInComposedTree(); } | 78 static PositionType selectionEnd(const VisibleSelection& selection) { re
turn selection.endInComposedTree(); } |
78 static SelectionType selectionType(const VisibleSelection& selection) {
return selection.selectionTypeInComposedTree(); } | 79 static SelectionType selectionType(const VisibleSelection& selection) {
return selection.selectionTypeInComposedTree(); } |
79 static VisiblePosition selectionVisibleStart(const VisibleSelection& sel
ection) | 80 static VisiblePosition selectionVisibleStart(const VisibleSelection& sel
ection) |
80 { | 81 { |
81 return VisiblePosition(selectionStart(selection), isRange(selection)
? DOWNSTREAM : selection.affinity()); | 82 return VisiblePosition(selectionStart(selection), isRange(selection)
? TextAffinity::Downstream : selection.affinity()); |
82 } | 83 } |
83 static VisiblePosition selectionVisibleEnd(const VisibleSelection& selec
tion) | 84 static VisiblePosition selectionVisibleEnd(const VisibleSelection& selec
tion) |
84 { | 85 { |
85 return VisiblePosition(selectionEnd(selection), isRange(selection) ?
UPSTREAM : selection.affinity()); | 86 return VisiblePosition(selectionEnd(selection), isRange(selection) ?
TextAffinity::Upstream : selection.affinity()); |
86 } | 87 } |
87 static PositionType toPositionType(const Position& position) { return to
PositionInComposedTree(position); } | 88 static PositionType toPositionType(const Position& position) { return to
PositionInComposedTree(position); } |
88 }; | 89 }; |
89 | 90 |
90 VisibleSelection(); | 91 VisibleSelection(); |
91 | 92 |
92 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); | 93 VisibleSelection(const Position&, TextAffinity, bool isDirectional = false); |
93 VisibleSelection(const Position& base, const Position& extent, EAffinity = S
EL_DEFAULT_AFFINITY, bool isDirectional = false); | 94 VisibleSelection(const Position& base, const Position& extent, TextAffinity
= SEL_DEFAULT_AFFINITY, bool isDirectional = false); |
94 VisibleSelection(const PositionInComposedTree& base, const PositionInCompose
dTree& extent, EAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); | 95 VisibleSelection(const PositionInComposedTree& base, const PositionInCompose
dTree& extent, TextAffinity = SEL_DEFAULT_AFFINITY, bool isDirectional = false); |
95 | 96 |
96 explicit VisibleSelection(const EphemeralRange&, EAffinity = SEL_DEFAULT_AFF
INITY, bool isDirectional = false); | 97 explicit VisibleSelection(const EphemeralRange&, TextAffinity = SEL_DEFAULT_
AFFINITY, bool isDirectional = false); |
97 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo
ol isDirectional = false); | 98 explicit VisibleSelection(const Range*, TextAffinity = SEL_DEFAULT_AFFINITY,
bool isDirectional = false); |
98 | 99 |
99 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); | 100 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); |
100 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); | 101 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); |
101 | 102 |
102 VisibleSelection(const VisibleSelection&); | 103 VisibleSelection(const VisibleSelection&); |
103 VisibleSelection& operator=(const VisibleSelection&); | 104 VisibleSelection& operator=(const VisibleSelection&); |
104 | 105 |
105 static VisibleSelection selectionFromContentsOfNode(Node*); | 106 static VisibleSelection selectionFromContentsOfNode(Node*); |
106 | 107 |
107 SelectionType selectionType() const { return m_selectionType; } | 108 SelectionType selectionType() const { return m_selectionType; } |
108 SelectionType selectionTypeInComposedTree() const; | 109 SelectionType selectionTypeInComposedTree() const; |
109 | 110 |
110 void setAffinity(EAffinity affinity) { m_affinity = affinity; } | 111 void setAffinity(TextAffinity affinity) { m_affinity = affinity; } |
111 EAffinity affinity() const { return m_affinity; } | 112 TextAffinity affinity() const { return m_affinity; } |
112 | 113 |
113 void setBase(const Position&); | 114 void setBase(const Position&); |
114 void setBase(const PositionInComposedTree&); | 115 void setBase(const PositionInComposedTree&); |
115 void setBase(const VisiblePosition&); | 116 void setBase(const VisiblePosition&); |
116 void setExtent(const Position&); | 117 void setExtent(const Position&); |
117 void setExtent(const PositionInComposedTree&); | 118 void setExtent(const PositionInComposedTree&); |
118 void setExtent(const VisiblePosition&); | 119 void setExtent(const VisiblePosition&); |
119 | 120 |
120 Position base() const { return m_base; } | 121 Position base() const { return m_base; } |
121 Position extent() const { return m_extent; } | 122 Position extent() const { return m_extent; } |
122 Position start() const { return m_start; } | 123 Position start() const { return m_start; } |
123 Position end() const { return m_end; } | 124 Position end() const { return m_end; } |
124 PositionInComposedTree baseInComposedTree() const; | 125 PositionInComposedTree baseInComposedTree() const; |
125 PositionInComposedTree extentInComposedTree() const; | 126 PositionInComposedTree extentInComposedTree() const; |
126 PositionInComposedTree startInComposedTree() const; | 127 PositionInComposedTree startInComposedTree() const; |
127 PositionInComposedTree endInComposedTree() const; | 128 PositionInComposedTree endInComposedTree() const; |
128 | 129 |
129 VisiblePosition visibleStart() const { return VisiblePosition(m_start, isRan
ge() ? DOWNSTREAM : affinity()); } | 130 VisiblePosition visibleStart() const { return VisiblePosition(m_start, isRan
ge() ? TextAffinity::Downstream : affinity()); } |
130 VisiblePosition visibleEnd() const { return VisiblePosition(m_end, isRange()
? UPSTREAM : affinity()); } | 131 VisiblePosition visibleEnd() const { return VisiblePosition(m_end, isRange()
? TextAffinity::Upstream : affinity()); } |
131 VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange
() ? (isBaseFirst() ? UPSTREAM : DOWNSTREAM) : affinity()); } | 132 VisiblePosition visibleBase() const { return VisiblePosition(m_base, isRange
() ? (isBaseFirst() ? TextAffinity::Upstream : TextAffinity::Downstream) : affin
ity()); } |
132 VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isR
ange() ? (isBaseFirst() ? DOWNSTREAM : UPSTREAM) : affinity()); } | 133 VisiblePosition visibleExtent() const { return VisiblePosition(m_extent, isR
ange() ? (isBaseFirst() ? TextAffinity::Downstream : TextAffinity::Upstream) : a
ffinity()); } |
133 | 134 |
134 bool isNone() const { return selectionType() == NoSelection; } | 135 bool isNone() const { return selectionType() == NoSelection; } |
135 bool isCaret() const { return selectionType() == CaretSelection; } | 136 bool isCaret() const { return selectionType() == CaretSelection; } |
136 bool isRange() const { return selectionType() == RangeSelection; } | 137 bool isRange() const { return selectionType() == RangeSelection; } |
137 bool isCaretOrRange() const { return selectionType() != NoSelection; } | 138 bool isCaretOrRange() const { return selectionType() != NoSelection; } |
138 bool isNonOrphanedRange() const { return isRange() && !start().isOrphan() &&
!end().isOrphan(); } | 139 bool isNonOrphanedRange() const { return isRange() && !start().isOrphan() &&
!end().isOrphan(); } |
139 bool isNonOrphanedCaretOrRange() const { return isCaretOrRange() && !start()
.isOrphan() && !end().isOrphan(); } | 140 bool isNonOrphanedCaretOrRange() const { return isCaretOrRange() && !start()
.isOrphan() && !end().isOrphan(); } |
140 static SelectionType selectionType(const Position& start, const Position& en
d); | 141 static SelectionType selectionType(const Position& start, const Position& en
d); |
141 static SelectionType selectionType(const PositionInComposedTree& start, cons
t PositionInComposedTree& end); | 142 static SelectionType selectionType(const PositionInComposedTree& start, cons
t PositionInComposedTree& end); |
142 | 143 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // computed from the respective positions at validate(). To have selections | 236 // computed from the respective positions at validate(). To have selections |
236 // work on the composed tree more accurately, we need to compute the DOM | 237 // work on the composed tree more accurately, we need to compute the DOM |
237 // positions from the composed tree positions. To do this, we need to add | 238 // positions from the composed tree positions. To do this, we need to add |
238 // considable amount of fixes (including EditingUtilities.cpp, | 239 // considable amount of fixes (including EditingUtilities.cpp, |
239 // VisibleUnit.cpp, and VisiblePosition.cpp). We'll do that in the future. | 240 // VisibleUnit.cpp, and VisiblePosition.cpp). We'll do that in the future. |
240 PositionInComposedTree m_baseInComposedTree; | 241 PositionInComposedTree m_baseInComposedTree; |
241 PositionInComposedTree m_extentInComposedTree; | 242 PositionInComposedTree m_extentInComposedTree; |
242 PositionInComposedTree m_startInComposedTree; | 243 PositionInComposedTree m_startInComposedTree; |
243 PositionInComposedTree m_endInComposedTree; | 244 PositionInComposedTree m_endInComposedTree; |
244 | 245 |
245 EAffinity m_affinity; // the upstream/downstream affinity of the caret | 246 TextAffinity m_affinity; // the upstream/downstream affinity of the caret |
246 | 247 |
247 // Oilpan: this reference has a lifetime that is at least as long | 248 // Oilpan: this reference has a lifetime that is at least as long |
248 // as this object. | 249 // as this object. |
249 RawPtrWillBeMember<ChangeObserver> m_changeObserver; | 250 RawPtrWillBeMember<ChangeObserver> m_changeObserver; |
250 | 251 |
251 // these are cached, can be recalculated by validate() | 252 // these are cached, can be recalculated by validate() |
252 SelectionType m_selectionType; // None, Caret, Range | 253 SelectionType m_selectionType; // None, Caret, Range |
253 bool m_baseIsFirst : 1; // True if base is before the extent | 254 bool m_baseIsFirst : 1; // True if base is before the extent |
254 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. | 255 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. |
255 }; | 256 }; |
256 | 257 |
257 } // namespace blink | 258 } // namespace blink |
258 | 259 |
259 #ifndef NDEBUG | 260 #ifndef NDEBUG |
260 // Outside the WebCore namespace for ease of invocation from gdb. | 261 // Outside the WebCore namespace for ease of invocation from gdb. |
261 void showTree(const blink::VisibleSelection&); | 262 void showTree(const blink::VisibleSelection&); |
262 void showTree(const blink::VisibleSelection*); | 263 void showTree(const blink::VisibleSelection*); |
263 #endif | 264 #endif |
264 | 265 |
265 #endif // VisibleSelection_h | 266 #endif // VisibleSelection_h |
OLD | NEW |