OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 5 #ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
6 #define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 6 #define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 // To be called when the viewport rect has been changed. This is used for | 79 // To be called when the viewport rect has been changed. This is used for |
80 // setting the state of the handles. | 80 // setting the state of the handles. |
81 void OnViewportChanged(const gfx::RectF viewport_rect); | 81 void OnViewportChanged(const gfx::RectF viewport_rect); |
82 | 82 |
83 // Allows touch-dragging of the handle. | 83 // Allows touch-dragging of the handle. |
84 // Returns true iff the event was consumed, in which case the caller should | 84 // Returns true iff the event was consumed, in which case the caller should |
85 // cease further handling of the event. | 85 // cease further handling of the event. |
86 bool WillHandleTouchEvent(const MotionEvent& event); | 86 bool WillHandleTouchEvent(const MotionEvent& event); |
87 | 87 |
88 // To be called before forwarding a tap event. This allows automatically | 88 // To be called before forwarding a tap event. |
89 // showing the insertion handle from subsequent bounds changes. | |
90 // |tap_count| is tap index in a repeated sequence, i.e., 1 for the first | 89 // |tap_count| is tap index in a repeated sequence, i.e., 1 for the first |
91 // tap, 2 for the second tap, etc... | 90 // tap, 2 for the second tap, etc... |
92 bool WillHandleTapEvent(const gfx::PointF& location, int tap_count); | 91 void WillHandleTapEvent(const gfx::PointF& location, int tap_count); |
93 | 92 |
94 // To be called before forwarding a longpress event. This allows automatically | 93 // To be called before forwarding a longpress event. |
95 // showing the selection or insertion handles from subsequent bounds changes. | 94 void WillHandleLongPressEvent(base::TimeTicks event_time, |
96 bool WillHandleLongPressEvent(base::TimeTicks event_time, | |
97 const gfx::PointF& location); | 95 const gfx::PointF& location); |
98 | 96 |
99 // To be called before forwarding a gesture scroll begin event to prevent | 97 // To be called before forwarding a gesture scroll begin event to prevent |
100 // long-press drag. | 98 // long-press drag. |
101 void OnScrollBeginEvent(); | 99 void OnScrollBeginEvent(); |
102 | 100 |
103 // Allow showing the selection handles from the most recent selection bounds | |
104 // update (if valid), or a future valid bounds update. | |
105 void AllowShowingFromCurrentSelection(); | |
106 | |
107 // Hide the handles and suppress bounds updates until the next explicit | 101 // Hide the handles and suppress bounds updates until the next explicit |
108 // showing allowance. | 102 // showing allowance. |
109 void HideAndDisallowShowingAutomatically(); | 103 void HideAndDisallowShowingAutomatically(); |
110 | 104 |
111 // Override the handle visibility according to |hidden|. | 105 // Override the handle visibility according to |hidden|. |
112 void SetTemporarilyHidden(bool hidden); | 106 void SetTemporarilyHidden(bool hidden); |
113 | 107 |
114 // To be called when the editability of the focused region changes. | |
115 void OnSelectionEditable(bool editable); | |
116 | |
117 // To be called when the contents of the focused region changes. | |
118 void OnSelectionEmpty(bool empty); | |
119 | |
120 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 108 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
121 // Returns true if an animation is active and requires further ticking. | 109 // Returns true if an animation is active and requires further ticking. |
122 bool Animate(base::TimeTicks animate_time); | 110 bool Animate(base::TimeTicks animate_time); |
123 | 111 |
124 // Returns the rect between the two active selection bounds. If just one of | 112 // Returns the rect between the two active selection bounds. If just one of |
125 // the bounds is visible, the rect is simply the (one-dimensional) rect of | 113 // the bounds is visible, the rect is simply the (one-dimensional) rect of |
126 // that bound. If no selection is active, an empty rect will be returned. | 114 // that bound. If no selection is active, an empty rect will be returned. |
127 gfx::RectF GetRectBetweenBounds() const; | 115 gfx::RectF GetRectBetweenBounds() const; |
128 | 116 |
129 // Returns the visible rect of specified touch handle. For an active insertion | 117 // Returns the visible rect of specified touch handle. For an active insertion |
130 // these values will be identical. | 118 // these values will be identical. |
131 gfx::RectF GetStartHandleRect() const; | 119 gfx::RectF GetStartHandleRect() const; |
132 gfx::RectF GetEndHandleRect() const; | 120 gfx::RectF GetEndHandleRect() const; |
133 | 121 |
134 // Returns the focal point of the start and end bounds, as defined by | 122 // Returns the focal point of the start and end bounds, as defined by |
135 // their bottom coordinate. | 123 // their bottom coordinate. |
136 const gfx::PointF& GetStartPosition() const; | 124 const gfx::PointF& GetStartPosition() const; |
137 const gfx::PointF& GetEndPosition() const; | 125 const gfx::PointF& GetEndPosition() const; |
138 | 126 |
139 const gfx::SelectionBound& start() const { return start_; } | 127 const gfx::SelectionBound& start() const { return start_; } |
140 const gfx::SelectionBound& end() const { return end_; } | 128 const gfx::SelectionBound& end() const { return end_; } |
141 | 129 |
142 ActiveStatus active_status() const { return active_status_; } | 130 ActiveStatus active_status() const { return active_status_; } |
143 | 131 |
144 bool insertion_active_or_requested() const { | |
145 return activate_insertion_automatically_; | |
146 } | |
147 | |
148 private: | 132 private: |
149 friend class TouchSelectionControllerTestApi; | 133 friend class TouchSelectionControllerTestApi; |
150 | 134 |
151 enum InputEventType { TAP, REPEATED_TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; | 135 enum InputEventType { TAP, REPEATED_TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; |
152 | 136 |
153 // TouchHandleClient implementation. | 137 // TouchHandleClient implementation. |
154 void OnDragBegin(const TouchSelectionDraggable& draggable, | 138 void OnDragBegin(const TouchSelectionDraggable& draggable, |
155 const gfx::PointF& drag_position) override; | 139 const gfx::PointF& drag_position) override; |
156 void OnDragUpdate(const TouchSelectionDraggable& draggable, | 140 void OnDragUpdate(const TouchSelectionDraggable& draggable, |
157 const gfx::PointF& drag_position) override; | 141 const gfx::PointF& drag_position) override; |
158 void OnDragEnd(const TouchSelectionDraggable& draggable) override; | 142 void OnDragEnd(const TouchSelectionDraggable& draggable) override; |
159 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; | 143 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; |
160 void OnHandleTapped(const TouchHandle& handle) override; | 144 void OnHandleTapped(const TouchHandle& handle) override; |
161 void SetNeedsAnimate() override; | 145 void SetNeedsAnimate() override; |
162 std::unique_ptr<TouchHandleDrawable> CreateDrawable() override; | 146 std::unique_ptr<TouchHandleDrawable> CreateDrawable() override; |
163 base::TimeDelta GetMaxTapDuration() const override; | 147 base::TimeDelta GetMaxTapDuration() const override; |
164 bool IsAdaptiveHandleOrientationEnabled() const override; | 148 bool IsAdaptiveHandleOrientationEnabled() const override; |
165 | 149 |
166 // LongPressDragSelectorClient implementation. | 150 // LongPressDragSelectorClient implementation. |
167 void OnLongPressDragActiveStateChanged() override; | 151 void OnLongPressDragActiveStateChanged() override; |
168 gfx::PointF GetSelectionStart() const override; | 152 gfx::PointF GetSelectionStart() const override; |
169 gfx::PointF GetSelectionEnd() const override; | 153 gfx::PointF GetSelectionEnd() const override; |
170 | 154 |
171 void ShowInsertionHandleAutomatically(); | |
172 void ShowSelectionHandlesAutomatically(); | |
173 bool WillHandleTapOrLongPress(const gfx::PointF& location); | |
174 | |
175 void OnInsertionChanged(); | 155 void OnInsertionChanged(); |
176 void OnSelectionChanged(); | 156 void OnSelectionChanged(); |
177 | 157 |
178 // Returns true if insertion mode was newly (re)activated. | 158 // Returns true if insertion mode was newly (re)activated. |
179 bool ActivateInsertionIfNecessary(); | 159 bool ActivateInsertionIfNecessary(); |
180 void DeactivateInsertion(); | 160 void DeactivateInsertion(); |
181 // Returns true if selection mode was newly (re)activated. | 161 // Returns true if selection mode was newly (re)activated. |
182 bool ActivateSelectionIfNecessary(); | 162 bool ActivateSelectionIfNecessary(); |
183 void DeactivateSelection(); | 163 void DeactivateSelection(); |
184 void ForceNextUpdateIfInactive(); | |
185 void UpdateHandleLayoutIfNecessary(); | 164 void UpdateHandleLayoutIfNecessary(); |
186 | 165 |
187 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); | 166 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); |
188 void SetTemporarilyHiddenForLongPressDrag(bool hidden); | 167 void SetTemporarilyHiddenForLongPressDrag(bool hidden); |
189 void RefreshHandleVisibility(); | 168 void RefreshHandleVisibility(); |
190 | 169 |
191 gfx::Vector2dF GetStartLineOffset() const; | 170 gfx::Vector2dF GetStartLineOffset() const; |
192 gfx::Vector2dF GetEndLineOffset() const; | 171 gfx::Vector2dF GetEndLineOffset() const; |
193 bool GetStartVisible() const; | 172 bool GetStartVisible() const; |
194 bool GetEndVisible() const; | 173 bool GetEndVisible() const; |
195 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; | 174 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; |
196 | 175 |
197 void LogSelectionEnd(); | 176 void LogSelectionEnd(); |
198 | 177 |
199 TouchSelectionControllerClient* const client_; | 178 TouchSelectionControllerClient* const client_; |
200 const Config config_; | 179 const Config config_; |
201 | 180 |
202 // Whether to force an update on the next selection event even if the | |
203 // cached selection matches the new selection. | |
204 bool force_next_update_; | |
205 | |
206 InputEventType response_pending_input_event_; | 181 InputEventType response_pending_input_event_; |
207 | 182 |
208 gfx::SelectionBound start_; | 183 gfx::SelectionBound start_; |
209 gfx::SelectionBound end_; | 184 gfx::SelectionBound end_; |
210 TouchHandleOrientation start_orientation_; | 185 TouchHandleOrientation start_orientation_; |
211 TouchHandleOrientation end_orientation_; | 186 TouchHandleOrientation end_orientation_; |
212 | 187 |
213 ActiveStatus active_status_; | 188 ActiveStatus active_status_; |
214 | 189 |
215 std::unique_ptr<TouchHandle> insertion_handle_; | 190 std::unique_ptr<TouchHandle> insertion_handle_; |
216 bool activate_insertion_automatically_; | |
217 | 191 |
218 std::unique_ptr<TouchHandle> start_selection_handle_; | 192 std::unique_ptr<TouchHandle> start_selection_handle_; |
219 std::unique_ptr<TouchHandle> end_selection_handle_; | 193 std::unique_ptr<TouchHandle> end_selection_handle_; |
220 bool activate_selection_automatically_; | |
221 | |
222 bool selection_empty_; | |
223 bool selection_editable_; | |
224 | 194 |
225 bool temporarily_hidden_; | 195 bool temporarily_hidden_; |
226 | 196 |
227 // Whether to use the start bound (if false, the end bound) for computing the | 197 // Whether to use the start bound (if false, the end bound) for computing the |
228 // appropriate text line offset when performing a selection drag. This helps | 198 // appropriate text line offset when performing a selection drag. This helps |
229 // ensure that the initial selection induced by the drag doesn't "jump" | 199 // ensure that the initial selection induced by the drag doesn't "jump" |
230 // between lines. | 200 // between lines. |
231 bool anchor_drag_to_selection_start_; | 201 bool anchor_drag_to_selection_start_; |
232 | 202 |
233 // Longpress drag allows direct manipulation of longpress-initiated selection. | 203 // Longpress drag allows direct manipulation of longpress-initiated selection. |
234 LongPressDragSelector longpress_drag_selector_; | 204 LongPressDragSelector longpress_drag_selector_; |
235 | 205 |
236 gfx::RectF viewport_rect_; | 206 gfx::RectF viewport_rect_; |
237 | 207 |
238 base::TimeTicks selection_start_time_; | 208 base::TimeTicks selection_start_time_; |
239 // Whether a selection handle was dragged during the current 'selection | 209 // Whether a selection handle was dragged during the current 'selection |
240 // session' - i.e. since the current selection has been activated. | 210 // session' - i.e. since the current selection has been activated. |
241 bool selection_handle_dragged_; | 211 bool selection_handle_dragged_; |
242 | 212 |
243 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | 213 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
244 }; | 214 }; |
245 | 215 |
246 } // namespace ui | 216 } // namespace ui |
247 | 217 |
248 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 218 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |