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 | 32 |
33 namespace WebCore { | 33 namespace WebCore { |
34 | 34 |
35 class LayoutPoint; | 35 class LayoutPoint; |
36 class Position; | 36 class Position; |
37 | 37 |
38 const EAffinity SEL_DEFAULT_AFFINITY = DOWNSTREAM; | 38 const EAffinity SEL_DEFAULT_AFFINITY = DOWNSTREAM; |
39 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; | 39 enum SelectionDirection { DirectionForward, DirectionBackward, DirectionRight, D
irectionLeft }; |
40 | 40 |
41 class VisibleSelection { | 41 class VisibleSelection { |
| 42 DISALLOW_ALLOCATION(); |
42 public: | 43 public: |
43 VisibleSelection(); | 44 VisibleSelection(); |
44 | 45 |
45 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); | 46 VisibleSelection(const Position&, EAffinity, bool isDirectional = false); |
46 VisibleSelection(const Position&, const Position&, EAffinity = SEL_DEFAULT_A
FFINITY, bool isDirectional = false); | 47 VisibleSelection(const Position&, const Position&, EAffinity = SEL_DEFAULT_A
FFINITY, bool isDirectional = false); |
47 | 48 |
48 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo
ol isDirectional = false); | 49 explicit VisibleSelection(const Range*, EAffinity = SEL_DEFAULT_AFFINITY, bo
ol isDirectional = false); |
49 | 50 |
50 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); | 51 explicit VisibleSelection(const VisiblePosition&, bool isDirectional = false
); |
51 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); | 52 VisibleSelection(const VisiblePosition&, const VisiblePosition&, bool isDire
ctional = false); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 Node* nonBoundaryShadowTreeRootNode() const; | 110 Node* nonBoundaryShadowTreeRootNode() const; |
110 | 111 |
111 VisiblePosition visiblePositionRespectingEditingBoundary(const LayoutPoint&
localPoint, Node* targetNode) const; | 112 VisiblePosition visiblePositionRespectingEditingBoundary(const LayoutPoint&
localPoint, Node* targetNode) const; |
112 | 113 |
113 void setWithoutValidation(const Position&, const Position&); | 114 void setWithoutValidation(const Position&, const Position&); |
114 | 115 |
115 // Listener of VisibleSelection modification. didChangeVisibleSelection() wi
ll be invoked when base, extent, start | 116 // Listener of VisibleSelection modification. didChangeVisibleSelection() wi
ll be invoked when base, extent, start |
116 // or end is moved to a different position. | 117 // or end is moved to a different position. |
117 // | 118 // |
118 // Objects implementing |ChangeObserver| interface must outlive the VisibleS
election object. | 119 // Objects implementing |ChangeObserver| interface must outlive the VisibleS
election object. |
119 class ChangeObserver { | 120 class ChangeObserver : public WillBeGarbageCollectedMixin { |
120 WTF_MAKE_NONCOPYABLE(ChangeObserver); | 121 WTF_MAKE_NONCOPYABLE(ChangeObserver); |
121 public: | 122 public: |
122 ChangeObserver(); | 123 ChangeObserver(); |
123 virtual ~ChangeObserver(); | 124 virtual ~ChangeObserver(); |
124 virtual void didChangeVisibleSelection() = 0; | 125 virtual void didChangeVisibleSelection() = 0; |
| 126 virtual void trace(Visitor*) { } |
125 }; | 127 }; |
126 | 128 |
127 void setChangeObserver(ChangeObserver&); | 129 void setChangeObserver(ChangeObserver&); |
128 void clearChangeObserver(); | 130 void clearChangeObserver(); |
129 void didChange(); // Fire the change observer, if any. | 131 void didChange(); // Fire the change observer, if any. |
130 | 132 |
| 133 void trace(Visitor*); |
| 134 |
131 #ifndef NDEBUG | 135 #ifndef NDEBUG |
132 void debugPosition() const; | 136 void debugPosition() const; |
133 void formatForDebugger(char* buffer, unsigned length) const; | 137 void formatForDebugger(char* buffer, unsigned length) const; |
134 void showTreeForThis() const; | 138 void showTreeForThis() const; |
135 #endif | 139 #endif |
136 | 140 |
137 private: | 141 private: |
138 void validate(TextGranularity = CharacterGranularity); | 142 void validate(TextGranularity = CharacterGranularity); |
139 | 143 |
140 // Support methods for validate() | 144 // Support methods for validate() |
141 void setBaseAndExtentToDeepEquivalents(); | 145 void setBaseAndExtentToDeepEquivalents(); |
142 void setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity); | 146 void setStartAndEndFromBaseAndExtentRespectingGranularity(TextGranularity); |
143 void adjustSelectionToAvoidCrossingShadowBoundaries(); | 147 void adjustSelectionToAvoidCrossingShadowBoundaries(); |
144 void adjustSelectionToAvoidCrossingEditingBoundaries(); | 148 void adjustSelectionToAvoidCrossingEditingBoundaries(); |
145 void updateSelectionType(); | 149 void updateSelectionType(); |
146 | 150 |
147 // We need to store these as Positions because VisibleSelection is | 151 // We need to store these as Positions because VisibleSelection is |
148 // used to store values in editing commands for use when | 152 // used to store values in editing commands for use when |
149 // undoing the command. We need to be able to create a selection that, while
currently | 153 // undoing the command. We need to be able to create a selection that, while
currently |
150 // invalid, will be valid once the changes are undone. | 154 // invalid, will be valid once the changes are undone. |
151 | 155 |
152 Position m_base; // Where the first click happened | 156 Position m_base; // Where the first click happened |
153 Position m_extent; // Where the end click happened | 157 Position m_extent; // Where the end click happened |
154 Position m_start; // Leftmost position when expanded to respect granularity | 158 Position m_start; // Leftmost position when expanded to respect granularity |
155 Position m_end; // Rightmost position when expanded to respect granularit
y | 159 Position m_end; // Rightmost position when expanded to respect granularit
y |
156 | 160 |
157 EAffinity m_affinity; // the upstream/downstream affinity of the c
aret | 161 EAffinity m_affinity; // the upstream/downstream affinity of the c
aret |
158 | 162 |
159 ChangeObserver* m_changeObserver; | 163 // Oilpan: this reference has a lifetime that is at least as long |
| 164 // as this object. |
| 165 RawPtrWillBeMember<ChangeObserver> m_changeObserver; |
160 | 166 |
161 // these are cached, can be recalculated by validate() | 167 // these are cached, can be recalculated by validate() |
162 SelectionType m_selectionType; // None, Caret, Range | 168 SelectionType m_selectionType; // None, Caret, Range |
163 bool m_baseIsFirst : 1; // True if base is before the extent | 169 bool m_baseIsFirst : 1; // True if base is before the extent |
164 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. | 170 bool m_isDirectional : 1; // Non-directional ignores m_baseIsFirst and selec
tion always extends on shift + arrow key. |
165 }; | 171 }; |
166 | 172 |
167 inline bool operator==(const VisibleSelection& a, const VisibleSelection& b) | 173 inline bool operator==(const VisibleSelection& a, const VisibleSelection& b) |
168 { | 174 { |
169 return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.aff
inity() && a.isBaseFirst() == b.isBaseFirst() | 175 return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.aff
inity() && a.isBaseFirst() == b.isBaseFirst() |
170 && a.isDirectional() == b.isDirectional(); | 176 && a.isDirectional() == b.isDirectional(); |
171 } | 177 } |
172 | 178 |
173 inline bool operator!=(const VisibleSelection& a, const VisibleSelection& b) | 179 inline bool operator!=(const VisibleSelection& a, const VisibleSelection& b) |
174 { | 180 { |
175 return !(a == b); | 181 return !(a == b); |
176 } | 182 } |
177 | 183 |
178 } // namespace WebCore | 184 } // namespace WebCore |
179 | 185 |
180 #ifndef NDEBUG | 186 #ifndef NDEBUG |
181 // Outside the WebCore namespace for ease of invocation from gdb. | 187 // Outside the WebCore namespace for ease of invocation from gdb. |
182 void showTree(const WebCore::VisibleSelection&); | 188 void showTree(const WebCore::VisibleSelection&); |
183 void showTree(const WebCore::VisibleSelection*); | 189 void showTree(const WebCore::VisibleSelection*); |
184 #endif | 190 #endif |
185 | 191 |
186 #endif // VisibleSelection_h | 192 #endif // VisibleSelection_h |
OLD | NEW |