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); |
mohsen
2016/11/22 23:23:54
nit: Now that this function is not returning bool,
| |
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, |
mohsen
2016/11/22 23:23:54
nit: Now that this function is not returning bool,
| |
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 bool WillHandleTouchEventImpl(const MotionEvent& event); | 137 bool WillHandleTouchEventImpl(const MotionEvent& event); |
154 | 138 |
155 // TouchHandleClient implementation. | 139 // TouchHandleClient implementation. |
156 void OnDragBegin(const TouchSelectionDraggable& draggable, | 140 void OnDragBegin(const TouchSelectionDraggable& draggable, |
157 const gfx::PointF& drag_position) override; | 141 const gfx::PointF& drag_position) override; |
158 void OnDragUpdate(const TouchSelectionDraggable& draggable, | 142 void OnDragUpdate(const TouchSelectionDraggable& draggable, |
159 const gfx::PointF& drag_position) override; | 143 const gfx::PointF& drag_position) override; |
160 void OnDragEnd(const TouchSelectionDraggable& draggable) override; | 144 void OnDragEnd(const TouchSelectionDraggable& draggable) override; |
161 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; | 145 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; |
162 void OnHandleTapped(const TouchHandle& handle) override; | 146 void OnHandleTapped(const TouchHandle& handle) override; |
163 void SetNeedsAnimate() override; | 147 void SetNeedsAnimate() override; |
164 std::unique_ptr<TouchHandleDrawable> CreateDrawable() override; | 148 std::unique_ptr<TouchHandleDrawable> CreateDrawable() override; |
165 base::TimeDelta GetMaxTapDuration() const override; | 149 base::TimeDelta GetMaxTapDuration() const override; |
166 bool IsAdaptiveHandleOrientationEnabled() const override; | 150 bool IsAdaptiveHandleOrientationEnabled() const override; |
167 | 151 |
168 // LongPressDragSelectorClient implementation. | 152 // LongPressDragSelectorClient implementation. |
169 void OnLongPressDragActiveStateChanged() override; | 153 void OnLongPressDragActiveStateChanged() override; |
170 gfx::PointF GetSelectionStart() const override; | 154 gfx::PointF GetSelectionStart() const override; |
171 gfx::PointF GetSelectionEnd() const override; | 155 gfx::PointF GetSelectionEnd() const override; |
172 | 156 |
173 void ShowInsertionHandleAutomatically(); | |
174 void ShowSelectionHandlesAutomatically(); | |
175 bool WillHandleTapOrLongPress(const gfx::PointF& location); | |
176 | |
177 void OnInsertionChanged(); | 157 void OnInsertionChanged(); |
178 void OnSelectionChanged(); | 158 void OnSelectionChanged(); |
179 | 159 |
180 // Returns true if insertion mode was newly (re)activated. | 160 // Returns true if insertion mode was newly (re)activated. |
181 bool ActivateInsertionIfNecessary(); | 161 bool ActivateInsertionIfNecessary(); |
182 void DeactivateInsertion(); | 162 void DeactivateInsertion(); |
183 // Returns true if selection mode was newly (re)activated. | 163 // Returns true if selection mode was newly (re)activated. |
184 bool ActivateSelectionIfNecessary(); | 164 bool ActivateSelectionIfNecessary(); |
185 void DeactivateSelection(); | 165 void DeactivateSelection(); |
186 void ForceNextUpdateIfInactive(); | |
187 void UpdateHandleLayoutIfNecessary(); | 166 void UpdateHandleLayoutIfNecessary(); |
188 | 167 |
189 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); | 168 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); |
190 void SetTemporarilyHiddenForLongPressDrag(bool hidden); | 169 void SetTemporarilyHiddenForLongPressDrag(bool hidden); |
191 void RefreshHandleVisibility(); | 170 void RefreshHandleVisibility(); |
192 | 171 |
193 gfx::Vector2dF GetStartLineOffset() const; | 172 gfx::Vector2dF GetStartLineOffset() const; |
194 gfx::Vector2dF GetEndLineOffset() const; | 173 gfx::Vector2dF GetEndLineOffset() const; |
195 bool GetStartVisible() const; | 174 bool GetStartVisible() const; |
196 bool GetEndVisible() const; | 175 bool GetEndVisible() const; |
197 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; | 176 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; |
198 | 177 |
199 void LogSelectionEnd(); | 178 void LogSelectionEnd(); |
200 | 179 |
201 TouchSelectionControllerClient* const client_; | 180 TouchSelectionControllerClient* const client_; |
202 const Config config_; | 181 const Config config_; |
203 | 182 |
204 // Whether to force an update on the next selection event even if the | 183 // TODO(amaralp): This is not necessary. Remove it. |
205 // cached selection matches the new selection. | |
206 bool force_next_update_; | |
207 | |
208 InputEventType response_pending_input_event_; | 184 InputEventType response_pending_input_event_; |
209 | 185 |
210 gfx::SelectionBound start_; | 186 gfx::SelectionBound start_; |
211 gfx::SelectionBound end_; | 187 gfx::SelectionBound end_; |
212 TouchHandleOrientation start_orientation_; | 188 TouchHandleOrientation start_orientation_; |
213 TouchHandleOrientation end_orientation_; | 189 TouchHandleOrientation end_orientation_; |
214 | 190 |
215 ActiveStatus active_status_; | 191 ActiveStatus active_status_; |
216 | 192 |
217 std::unique_ptr<TouchHandle> insertion_handle_; | 193 std::unique_ptr<TouchHandle> insertion_handle_; |
218 bool activate_insertion_automatically_; | |
219 | 194 |
220 std::unique_ptr<TouchHandle> start_selection_handle_; | 195 std::unique_ptr<TouchHandle> start_selection_handle_; |
221 std::unique_ptr<TouchHandle> end_selection_handle_; | 196 std::unique_ptr<TouchHandle> end_selection_handle_; |
222 bool activate_selection_automatically_; | |
223 | |
224 bool selection_empty_; | |
225 bool selection_editable_; | |
226 | 197 |
227 bool temporarily_hidden_; | 198 bool temporarily_hidden_; |
228 | 199 |
229 // Whether to use the start bound (if false, the end bound) for computing the | 200 // Whether to use the start bound (if false, the end bound) for computing the |
230 // appropriate text line offset when performing a selection drag. This helps | 201 // appropriate text line offset when performing a selection drag. This helps |
231 // ensure that the initial selection induced by the drag doesn't "jump" | 202 // ensure that the initial selection induced by the drag doesn't "jump" |
232 // between lines. | 203 // between lines. |
233 bool anchor_drag_to_selection_start_; | 204 bool anchor_drag_to_selection_start_; |
234 | 205 |
235 // Longpress drag allows direct manipulation of longpress-initiated selection. | 206 // Longpress drag allows direct manipulation of longpress-initiated selection. |
236 LongPressDragSelector longpress_drag_selector_; | 207 LongPressDragSelector longpress_drag_selector_; |
237 | 208 |
238 gfx::RectF viewport_rect_; | 209 gfx::RectF viewport_rect_; |
239 | 210 |
240 base::TimeTicks selection_start_time_; | 211 base::TimeTicks selection_start_time_; |
241 // Whether a selection handle was dragged during the current 'selection | 212 // Whether a selection handle was dragged during the current 'selection |
242 // session' - i.e. since the current selection has been activated. | 213 // session' - i.e. since the current selection has been activated. |
243 bool selection_handle_dragged_; | 214 bool selection_handle_dragged_; |
244 | 215 |
245 // Determines whether the entire touch sequence should be consumed or not. | 216 // Determines whether the entire touch sequence should be consumed or not. |
246 bool consume_touch_sequence_; | 217 bool consume_touch_sequence_; |
247 | 218 |
219 bool show_touch_handles_; | |
220 | |
248 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | 221 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
249 }; | 222 }; |
250 | 223 |
251 } // namespace ui | 224 } // namespace ui |
252 | 225 |
253 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 226 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |