Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: ui/touch_selection/touch_selection_controller.h

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool WillHandleTapEvent(const gfx::PointF& location); 68 bool WillHandleTapEvent(const gfx::PointF& location);
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 bool WillHandleLongPressEvent(const gfx::PointF& location); 72 bool WillHandleLongPressEvent(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 23 matching lines...) Expand all
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
106 const SelectionBound& start() const { return start_; } 111 const SelectionBound& start() const { return start_; }
107 const SelectionBound& end() const { return end_; } 112 const SelectionBound& end() const { return end_; }
108 113
109 ActiveStatus active_status() const { return active_status_; } 114 ActiveStatus active_status() const { return active_status_; }
110 115
111 private: 116 private:
117 friend class TouchSelectionControllerTestApi;
118
112 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; 119 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE };
113 120
114 // TouchHandleClient implementation. 121 // TouchHandleClient implementation.
115 void OnHandleDragBegin(const TouchHandle& handle) override; 122 void OnDragBegin(const TouchSelectionDraggable& draggable,
116 void OnHandleDragUpdate(const TouchHandle& handle, 123 const gfx::PointF& drag_position) override;
117 const gfx::PointF& new_position) override; 124 void OnDragUpdate(const TouchSelectionDraggable& draggable,
118 void OnHandleDragEnd(const TouchHandle& handle) override; 125 const gfx::PointF& drag_position) override;
126 void OnDragEnd(const TouchSelectionDraggable& draggable) override;
127 bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override;
119 void OnHandleTapped(const TouchHandle& handle) override; 128 void OnHandleTapped(const TouchHandle& handle) override;
120 void SetNeedsAnimate() override; 129 void SetNeedsAnimate() override;
121 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; 130 scoped_ptr<TouchHandleDrawable> CreateDrawable() override;
122 base::TimeDelta GetTapTimeout() const override; 131 base::TimeDelta GetTapTimeout() const override;
123 float GetTapSlop() const override; 132
133 // LongPressDragSelectorClient implementation.
134 void OnLongPressDragActiveStateChanged() override;
135 gfx::PointF GetSelectionStart() const override;
136 gfx::PointF GetSelectionEnd() const override;
124 137
125 void ShowInsertionHandleAutomatically(); 138 void ShowInsertionHandleAutomatically();
126 void ShowSelectionHandlesAutomatically(); 139 void ShowSelectionHandlesAutomatically();
127 bool WillHandleTapOrLongPress(const gfx::PointF& location); 140 bool WillHandleTapOrLongPress(const gfx::PointF& location);
128 141
129 void OnInsertionChanged(); 142 void OnInsertionChanged();
130 void OnSelectionChanged(); 143 void OnSelectionChanged();
131 144
132 void ActivateInsertion(); 145 void ActivateInsertion();
133 void DeactivateInsertion(); 146 void DeactivateInsertion();
134 void ActivateSelection(); 147 void ActivateSelection();
135 void DeactivateSelection(); 148 void DeactivateSelection();
136 void ForceNextUpdateIfInactive(); 149 void ForceNextUpdateIfInactive();
137 150
151 bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event);
152 void SetTemporarilyHiddenForLongPressDrag(bool hidden);
153 void RefreshHandleVisibility();
154
138 gfx::Vector2dF GetStartLineOffset() const; 155 gfx::Vector2dF GetStartLineOffset() const;
139 gfx::Vector2dF GetEndLineOffset() const; 156 gfx::Vector2dF GetEndLineOffset() const;
140 bool GetStartVisible() const; 157 bool GetStartVisible() const;
141 bool GetEndVisible() const; 158 bool GetEndVisible() const;
142 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; 159 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const;
143 160
144 void LogSelectionEnd(); 161 void LogSelectionEnd();
145 162
146 TouchSelectionControllerClient* const client_; 163 TouchSelectionControllerClient* const client_;
147 const base::TimeDelta tap_timeout_; 164 const base::TimeDelta tap_timeout_;
148 const float tap_slop_; 165 const double tap_slop_squared_;
149 166
150 // Whether to force an update on the next selection event even if the 167 // Whether to force an update on the next selection event even if the
151 // cached selection matches the new selection. 168 // cached selection matches the new selection.
152 bool force_next_update_; 169 bool force_next_update_;
153 170
154 // Controls whether an insertion handle is shown on a tap for an empty 171 // Controls whether an insertion handle is shown on a tap for an empty
155 // editable text. 172 // editable text.
156 bool show_on_tap_for_empty_editable_; 173 bool show_on_tap_for_empty_editable_;
157 174
158 InputEventType response_pending_input_event_; 175 InputEventType response_pending_input_event_;
(...skipping 10 matching lines...) Expand all
169 186
170 scoped_ptr<TouchHandle> start_selection_handle_; 187 scoped_ptr<TouchHandle> start_selection_handle_;
171 scoped_ptr<TouchHandle> end_selection_handle_; 188 scoped_ptr<TouchHandle> end_selection_handle_;
172 bool activate_selection_automatically_; 189 bool activate_selection_automatically_;
173 190
174 bool selection_empty_; 191 bool selection_empty_;
175 bool selection_editable_; 192 bool selection_editable_;
176 193
177 bool temporarily_hidden_; 194 bool temporarily_hidden_;
178 195
196 // Offset from the start of a drag sequence to a reasonable position on the
197 // corresponding line of text. This helps ensure that the initial selection
198 // induced by the drag doesn't "jump" between lines.
199 gfx::Vector2dF drag_line_offset_;
200
201 // Longpress drag allows direct manipulation of longpress-initiated selection.
202 LongPressDragSelector longpress_drag_selector_;
203
179 base::TimeTicks selection_start_time_; 204 base::TimeTicks selection_start_time_;
180 // Whether a selection handle was dragged during the current 'selection 205 // Whether a selection handle was dragged during the current 'selection
181 // session' - i.e. since the current selection has been activated. 206 // session' - i.e. since the current selection has been activated.
182 bool selection_handle_dragged_; 207 bool selection_handle_dragged_;
183 208
184 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); 209 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController);
185 }; 210 };
186 211
187 } // namespace ui 212 } // namespace ui
188 213
189 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ 214 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698