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