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/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/base/touch/selection_bound.h" | 9 #include "ui/base/touch/selection_bound.h" |
10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 struct UI_TOUCH_SELECTION_EXPORT Config { | 49 struct UI_TOUCH_SELECTION_EXPORT Config { |
50 Config(); | 50 Config(); |
51 ~Config(); | 51 ~Config(); |
52 | 52 |
53 // Maximum allowed time for handle tap detection. Defaults to 300 ms. | 53 // Maximum allowed time for handle tap detection. Defaults to 300 ms. |
54 base::TimeDelta max_tap_duration; | 54 base::TimeDelta max_tap_duration; |
55 | 55 |
56 // Defaults to 8 DIPs. | 56 // Defaults to 8 DIPs. |
57 float tap_slop; | 57 float tap_slop; |
58 | 58 |
| 59 // Controls whether adaptive orientation for selection handles is enabled. |
| 60 // Defaults to false. |
| 61 bool enable_adaptive_handle_orientation; |
| 62 |
59 // Controls whether drag selection after a longpress is enabled. | 63 // Controls whether drag selection after a longpress is enabled. |
60 // Defaults to false. | 64 // Defaults to false. |
61 bool enable_longpress_drag_selection; | 65 bool enable_longpress_drag_selection; |
62 | 66 |
63 // Controls whether an insertion handle is shown on a tap for an empty | 67 // Controls whether an insertion handle is shown on a tap for an empty |
64 // editable text. Defauls to false. | 68 // editable text. Defauls to false. |
65 bool show_on_tap_for_empty_editable; | 69 bool show_on_tap_for_empty_editable; |
66 }; | 70 }; |
67 | 71 |
68 TouchSelectionController(TouchSelectionControllerClient* client, | 72 TouchSelectionController(TouchSelectionControllerClient* client, |
69 const Config& config); | 73 const Config& config); |
70 ~TouchSelectionController() override; | 74 ~TouchSelectionController() override; |
71 | 75 |
72 // To be called when the selection bounds have changed. | 76 // To be called when the selection bounds have changed. |
73 // Note that such updates will trigger handle updates only if preceded | 77 // Note that such updates will trigger handle updates only if preceded |
74 // by an appropriate call to allow automatic showing. | 78 // by an appropriate call to allow automatic showing. |
75 void OnSelectionBoundsChanged(const SelectionBound& start, | 79 void OnSelectionBoundsChanged(const SelectionBound& start, |
76 const SelectionBound& end); | 80 const SelectionBound& end); |
77 | 81 |
| 82 // To be called when the viewport rect has been changed. This is used for |
| 83 // setting the state of the handles. |
| 84 void OnViewportChanged(const gfx::RectF viewport_rect); |
| 85 |
78 // Allows touch-dragging of the handle. | 86 // Allows touch-dragging of the handle. |
79 // Returns true iff the event was consumed, in which case the caller should | 87 // Returns true iff the event was consumed, in which case the caller should |
80 // cease further handling of the event. | 88 // cease further handling of the event. |
81 bool WillHandleTouchEvent(const MotionEvent& event); | 89 bool WillHandleTouchEvent(const MotionEvent& event); |
82 | 90 |
83 // To be called before forwarding a tap event. This allows automatically | 91 // To be called before forwarding a tap event. This allows automatically |
84 // showing the insertion handle from subsequent bounds changes. | 92 // showing the insertion handle from subsequent bounds changes. |
85 bool WillHandleTapEvent(const gfx::PointF& location); | 93 bool WillHandleTapEvent(const gfx::PointF& location); |
86 | 94 |
87 // To be called before forwarding a longpress event. This allows automatically | 95 // To be called before forwarding a longpress event. This allows automatically |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void OnDragBegin(const TouchSelectionDraggable& draggable, | 147 void OnDragBegin(const TouchSelectionDraggable& draggable, |
140 const gfx::PointF& drag_position) override; | 148 const gfx::PointF& drag_position) override; |
141 void OnDragUpdate(const TouchSelectionDraggable& draggable, | 149 void OnDragUpdate(const TouchSelectionDraggable& draggable, |
142 const gfx::PointF& drag_position) override; | 150 const gfx::PointF& drag_position) override; |
143 void OnDragEnd(const TouchSelectionDraggable& draggable) override; | 151 void OnDragEnd(const TouchSelectionDraggable& draggable) override; |
144 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; | 152 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; |
145 void OnHandleTapped(const TouchHandle& handle) override; | 153 void OnHandleTapped(const TouchHandle& handle) override; |
146 void SetNeedsAnimate() override; | 154 void SetNeedsAnimate() override; |
147 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; | 155 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; |
148 base::TimeDelta GetMaxTapDuration() const override; | 156 base::TimeDelta GetMaxTapDuration() const override; |
| 157 bool IsAdaptiveHandleOrientationEnabled() const override; |
149 | 158 |
150 // LongPressDragSelectorClient implementation. | 159 // LongPressDragSelectorClient implementation. |
151 void OnLongPressDragActiveStateChanged() override; | 160 void OnLongPressDragActiveStateChanged() override; |
152 gfx::PointF GetSelectionStart() const override; | 161 gfx::PointF GetSelectionStart() const override; |
153 gfx::PointF GetSelectionEnd() const override; | 162 gfx::PointF GetSelectionEnd() const override; |
154 | 163 |
155 void ShowInsertionHandleAutomatically(); | 164 void ShowInsertionHandleAutomatically(); |
156 void ShowSelectionHandlesAutomatically(); | 165 void ShowSelectionHandlesAutomatically(); |
157 bool WillHandleTapOrLongPress(const gfx::PointF& location); | 166 bool WillHandleTapOrLongPress(const gfx::PointF& location); |
158 | 167 |
159 void OnInsertionChanged(); | 168 void OnInsertionChanged(); |
160 void OnSelectionChanged(); | 169 void OnSelectionChanged(); |
161 | 170 |
162 // Returns true if insertion mode was newly (re)activated. | 171 // Returns true if insertion mode was newly (re)activated. |
163 bool ActivateInsertionIfNecessary(); | 172 bool ActivateInsertionIfNecessary(); |
164 void DeactivateInsertion(); | 173 void DeactivateInsertion(); |
165 // Returns true if selection mode was newly (re)activated. | 174 // Returns true if selection mode was newly (re)activated. |
166 bool ActivateSelectionIfNecessary(); | 175 bool ActivateSelectionIfNecessary(); |
167 void DeactivateSelection(); | 176 void DeactivateSelection(); |
168 void ForceNextUpdateIfInactive(); | 177 void ForceNextUpdateIfInactive(); |
| 178 void UpdateHandleLayoutIfNecessary(); |
169 | 179 |
170 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); | 180 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); |
171 void SetTemporarilyHiddenForLongPressDrag(bool hidden); | 181 void SetTemporarilyHiddenForLongPressDrag(bool hidden); |
172 void RefreshHandleVisibility(); | 182 void RefreshHandleVisibility(); |
173 | 183 |
174 gfx::Vector2dF GetStartLineOffset() const; | 184 gfx::Vector2dF GetStartLineOffset() const; |
175 gfx::Vector2dF GetEndLineOffset() const; | 185 gfx::Vector2dF GetEndLineOffset() const; |
176 bool GetStartVisible() const; | 186 bool GetStartVisible() const; |
177 bool GetEndVisible() const; | 187 bool GetEndVisible() const; |
178 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; | 188 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; |
(...skipping 30 matching lines...) Expand all Loading... |
209 | 219 |
210 // Whether to use the start bound (if false, the end bound) for computing the | 220 // Whether to use the start bound (if false, the end bound) for computing the |
211 // appropriate text line offset when performing a selection drag. This helps | 221 // appropriate text line offset when performing a selection drag. This helps |
212 // ensure that the initial selection induced by the drag doesn't "jump" | 222 // ensure that the initial selection induced by the drag doesn't "jump" |
213 // between lines. | 223 // between lines. |
214 bool anchor_drag_to_selection_start_; | 224 bool anchor_drag_to_selection_start_; |
215 | 225 |
216 // Longpress drag allows direct manipulation of longpress-initiated selection. | 226 // Longpress drag allows direct manipulation of longpress-initiated selection. |
217 LongPressDragSelector longpress_drag_selector_; | 227 LongPressDragSelector longpress_drag_selector_; |
218 | 228 |
| 229 gfx::RectF viewport_rect_; |
| 230 |
219 base::TimeTicks selection_start_time_; | 231 base::TimeTicks selection_start_time_; |
220 // Whether a selection handle was dragged during the current 'selection | 232 // Whether a selection handle was dragged during the current 'selection |
221 // session' - i.e. since the current selection has been activated. | 233 // session' - i.e. since the current selection has been activated. |
222 bool selection_handle_dragged_; | 234 bool selection_handle_dragged_; |
223 | 235 |
224 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | 236 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
225 }; | 237 }; |
226 | 238 |
227 } // namespace ui | 239 } // namespace ui |
228 | 240 |
229 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 241 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |