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 "ui/base/touch/selection_bound.h" | 9 #include "ui/base/touch/selection_bound.h" |
9 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
10 #include "ui/gfx/geometry/rect_f.h" | 11 #include "ui/gfx/geometry/rect_f.h" |
12 #include "ui/gfx/geometry/vector2d_f.h" | |
13 #include "ui/touch_selection/longpress_drag_selector.h" | |
11 #include "ui/touch_selection/selection_event_type.h" | 14 #include "ui/touch_selection/selection_event_type.h" |
12 #include "ui/touch_selection/touch_handle.h" | 15 #include "ui/touch_selection/touch_handle.h" |
13 #include "ui/touch_selection/touch_handle_orientation.h" | 16 #include "ui/touch_selection/touch_handle_orientation.h" |
14 #include "ui/touch_selection/ui_touch_selection_export.h" | 17 #include "ui/touch_selection/ui_touch_selection_export.h" |
15 | 18 |
16 namespace ui { | 19 namespace ui { |
17 class MotionEvent; | 20 class MotionEvent; |
18 | 21 |
19 // Interface through which |TouchSelectionController| issues selection-related | 22 // Interface through which |TouchSelectionController| issues selection-related |
20 // commands, notifications and requests. | 23 // commands, notifications and requests. |
21 class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient { | 24 class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient { |
22 public: | 25 public: |
23 virtual ~TouchSelectionControllerClient() {} | 26 virtual ~TouchSelectionControllerClient() {} |
24 | 27 |
25 virtual bool SupportsAnimation() const = 0; | 28 virtual bool SupportsAnimation() const = 0; |
26 virtual void SetNeedsAnimate() = 0; | 29 virtual void SetNeedsAnimate() = 0; |
27 virtual void MoveCaret(const gfx::PointF& position) = 0; | 30 virtual void MoveCaret(const gfx::PointF& position) = 0; |
28 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; | 31 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; |
29 virtual void SelectBetweenCoordinates(const gfx::PointF& base, | 32 virtual void SelectBetweenCoordinates(const gfx::PointF& base, |
30 const gfx::PointF& extent) = 0; | 33 const gfx::PointF& extent) = 0; |
31 virtual void OnSelectionEvent(SelectionEventType event) = 0; | 34 virtual void OnSelectionEvent(SelectionEventType event) = 0; |
32 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 35 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
33 }; | 36 }; |
34 | 37 |
35 // Controller for manipulating text selection via touch input. | 38 // Controller for manipulating text selection via touch input. |
36 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController | 39 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController |
37 : public TouchHandleClient { | 40 : public TouchHandleClient, |
41 public LongPressDragSelectorClient { | |
38 public: | 42 public: |
39 enum ActiveStatus { | 43 enum ActiveStatus { |
40 INACTIVE, | 44 INACTIVE, |
41 INSERTION_ACTIVE, | 45 INSERTION_ACTIVE, |
42 SELECTION_ACTIVE, | 46 SELECTION_ACTIVE, |
43 }; | 47 }; |
44 | 48 |
45 TouchSelectionController(TouchSelectionControllerClient* client, | 49 TouchSelectionController(TouchSelectionControllerClient* client, |
46 base::TimeDelta tap_timeout, | 50 base::TimeDelta tap_timeout, |
47 float tap_slop, | 51 float tap_slop, |
(...skipping 10 matching lines...) Expand all Loading... | |
58 // Returns true iff the event was consumed, in which case the caller should | 62 // Returns true iff the event was consumed, in which case the caller should |
59 // cease further handling of the event. | 63 // cease further handling of the event. |
60 bool WillHandleTouchEvent(const MotionEvent& event); | 64 bool WillHandleTouchEvent(const MotionEvent& event); |
61 | 65 |
62 // To be called before forwarding a tap event. This allows automatically | 66 // To be called before forwarding a tap event. This allows automatically |
63 // showing the insertion handle from subsequent bounds changes. | 67 // showing the insertion handle from subsequent bounds changes. |
64 void OnTapEvent(); | 68 void OnTapEvent(); |
65 | 69 |
66 // To be called before forwarding a longpress event. This allows automatically | 70 // To be called before forwarding a longpress event. This allows automatically |
67 // showing the selection or insertion handles from subsequent bounds changes. | 71 // showing the selection or insertion handles from subsequent bounds changes. |
68 void OnLongPressEvent(); | 72 void OnLongPressEvent(base::TimeTicks event_time, |
73 const gfx::PointF& location); | |
69 | 74 |
70 // Allow showing the selection handles from the most recent selection bounds | 75 // Allow showing the selection handles from the most recent selection bounds |
71 // update (if valid), or a future valid bounds update. | 76 // update (if valid), or a future valid bounds update. |
72 void AllowShowingFromCurrentSelection(); | 77 void AllowShowingFromCurrentSelection(); |
73 | 78 |
74 // Hide the handles and suppress bounds updates until the next explicit | 79 // Hide the handles and suppress bounds updates until the next explicit |
75 // showing allowance. | 80 // showing allowance. |
76 void HideAndDisallowShowingAutomatically(); | 81 void HideAndDisallowShowingAutomatically(); |
77 | 82 |
78 // Override the handle visibility according to |hidden|. | 83 // Override the handle visibility according to |hidden|. |
(...skipping 17 matching lines...) Expand all Loading... | |
96 // Returns the visible rect of specified touch handle. For an active insertion | 101 // Returns the visible rect of specified touch handle. For an active insertion |
97 // these values will be identical. | 102 // these values will be identical. |
98 gfx::RectF GetStartHandleRect() const; | 103 gfx::RectF GetStartHandleRect() const; |
99 gfx::RectF GetEndHandleRect() const; | 104 gfx::RectF GetEndHandleRect() const; |
100 | 105 |
101 // Returns the focal point of the start and end bounds, as defined by | 106 // Returns the focal point of the start and end bounds, as defined by |
102 // their bottom coordinate. | 107 // their bottom coordinate. |
103 const gfx::PointF& GetStartPosition() const; | 108 const gfx::PointF& GetStartPosition() const; |
104 const gfx::PointF& GetEndPosition() const; | 109 const gfx::PointF& GetEndPosition() const; |
105 | 110 |
111 // Whether the specified touch handle is visible, both as indicated by the | |
112 // renderer and for any temporary visibility overrides. | |
113 bool GetStartVisibleForTesting() const; | |
mfomitchev
2015/05/13 20:52:25
How about creating TouchSelectionControllerTestApi
jdduke (slow)
2015/05/14 18:29:26
Sure.
| |
114 bool GetEndVisibleForTesting() const; | |
115 | |
106 const SelectionBound& start() const { return start_; } | 116 const SelectionBound& start() const { return start_; } |
107 const SelectionBound& end() const { return end_; } | 117 const SelectionBound& end() const { return end_; } |
108 | 118 |
109 ActiveStatus active_status() const { return active_status_; } | 119 ActiveStatus active_status() const { return active_status_; } |
110 | 120 |
111 private: | 121 private: |
112 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; | 122 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; |
113 | 123 |
114 // TouchHandleClient implementation. | 124 // TouchHandleClient implementation. |
115 void OnHandleDragBegin(const TouchHandle& handle) override; | 125 void OnDragBegin(const TouchSelectionDraggable& draggable, |
116 void OnHandleDragUpdate(const TouchHandle& handle, | 126 const gfx::PointF& drag_position) override; |
117 const gfx::PointF& new_position) override; | 127 void OnDragUpdate(const TouchSelectionDraggable& draggable, |
118 void OnHandleDragEnd(const TouchHandle& handle) override; | 128 const gfx::PointF& drag_position) override; |
129 void OnDragEnd(const TouchSelectionDraggable& draggable) override; | |
130 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override; | |
119 void OnHandleTapped(const TouchHandle& handle) override; | 131 void OnHandleTapped(const TouchHandle& handle) override; |
120 void SetNeedsAnimate() override; | 132 void SetNeedsAnimate() override; |
121 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; | 133 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; |
122 base::TimeDelta GetTapTimeout() const override; | 134 base::TimeDelta GetTapTimeout() const override; |
123 float GetTapSlop() const override; | 135 |
136 // LongPressDragSelectorClient implementation. | |
137 void OnLongPressDragActiveStateChanged() override; | |
138 gfx::PointF GetSelectionStart() const override; | |
139 gfx::PointF GetSelectionEnd() const override; | |
124 | 140 |
125 void ShowInsertionHandleAutomatically(); | 141 void ShowInsertionHandleAutomatically(); |
126 void ShowSelectionHandlesAutomatically(); | 142 void ShowSelectionHandlesAutomatically(); |
127 | 143 |
128 void OnInsertionChanged(); | 144 void OnInsertionChanged(); |
129 void OnSelectionChanged(); | 145 void OnSelectionChanged(); |
130 | 146 |
131 void ActivateInsertion(); | 147 void ActivateInsertion(); |
132 void DeactivateInsertion(); | 148 void DeactivateInsertion(); |
133 void ActivateSelection(); | 149 void ActivateSelection(); |
134 void DeactivateSelection(); | 150 void DeactivateSelection(); |
135 void ForceNextUpdateIfInactive(); | 151 void ForceNextUpdateIfInactive(); |
136 | 152 |
153 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event); | |
154 void SetTemporarilyHiddenForLongPressDrag(bool hidden); | |
155 void RefreshHandleVisibility(); | |
156 | |
137 gfx::Vector2dF GetStartLineOffset() const; | 157 gfx::Vector2dF GetStartLineOffset() const; |
138 gfx::Vector2dF GetEndLineOffset() const; | 158 gfx::Vector2dF GetEndLineOffset() const; |
139 bool GetStartVisible() const; | 159 bool GetStartVisible() const; |
140 bool GetEndVisible() const; | 160 bool GetEndVisible() const; |
141 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; | 161 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; |
142 | 162 |
143 void LogSelectionEnd(); | 163 void LogSelectionEnd(); |
144 | 164 |
145 TouchSelectionControllerClient* const client_; | 165 TouchSelectionControllerClient* const client_; |
146 const base::TimeDelta tap_timeout_; | 166 const base::TimeDelta tap_timeout_; |
147 const float tap_slop_; | 167 const double tap_slop_squared_; |
148 | 168 |
149 // Whether to force an update on the next selection event even if the | 169 // Whether to force an update on the next selection event even if the |
150 // cached selection matches the new selection. | 170 // cached selection matches the new selection. |
151 bool force_next_update_; | 171 bool force_next_update_; |
152 | 172 |
153 // Controls whether an insertion handle is shown on a tap for an empty | 173 // Controls whether an insertion handle is shown on a tap for an empty |
154 // editable text. | 174 // editable text. |
155 bool show_on_tap_for_empty_editable_; | 175 bool show_on_tap_for_empty_editable_; |
156 | 176 |
157 InputEventType response_pending_input_event_; | 177 InputEventType response_pending_input_event_; |
(...skipping 10 matching lines...) Expand all Loading... | |
168 | 188 |
169 scoped_ptr<TouchHandle> start_selection_handle_; | 189 scoped_ptr<TouchHandle> start_selection_handle_; |
170 scoped_ptr<TouchHandle> end_selection_handle_; | 190 scoped_ptr<TouchHandle> end_selection_handle_; |
171 bool activate_selection_automatically_; | 191 bool activate_selection_automatically_; |
172 | 192 |
173 bool selection_empty_; | 193 bool selection_empty_; |
174 bool selection_editable_; | 194 bool selection_editable_; |
175 | 195 |
176 bool temporarily_hidden_; | 196 bool temporarily_hidden_; |
177 | 197 |
198 // Offset from the start of a drag sequence to a reasonable position on the | |
199 // corresponding line of text. This helps ensure that the initial selection | |
200 // induced by the drag doesn't "jump" between lines. | |
201 gfx::Vector2dF drag_line_offset_; | |
202 | |
203 // Longpress drag allows direct manipulation of longpress-initiated selection. | |
204 LongPressDragSelector longpress_drag_selector_; | |
205 | |
178 base::TimeTicks selection_start_time_; | 206 base::TimeTicks selection_start_time_; |
179 // Whether a selection handle was dragged during the current 'selection | 207 // Whether a selection handle was dragged during the current 'selection |
180 // session' - i.e. since the current selection has been activated. | 208 // session' - i.e. since the current selection has been activated. |
181 bool selection_handle_dragged_; | 209 bool selection_handle_dragged_; |
182 | 210 |
183 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | 211 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
184 }; | 212 }; |
185 | 213 |
186 } // namespace ui | 214 } // namespace ui |
187 | 215 |
188 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 216 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |