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 "ui/base/touch/selection_bound.h" | 8 #include "ui/base/touch/selection_bound.h" |
9 #include "ui/gfx/geometry/point_f.h" | 9 #include "ui/gfx/geometry/point_f.h" |
10 #include "ui/gfx/geometry/rect_f.h" | 10 #include "ui/gfx/geometry/rect_f.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 virtual ~TouchSelectionControllerClient() {} | 23 virtual ~TouchSelectionControllerClient() {} |
24 | 24 |
25 virtual bool SupportsAnimation() const = 0; | 25 virtual bool SupportsAnimation() const = 0; |
26 virtual void SetNeedsAnimate() = 0; | 26 virtual void SetNeedsAnimate() = 0; |
27 virtual void MoveCaret(const gfx::PointF& position) = 0; | 27 virtual void MoveCaret(const gfx::PointF& position) = 0; |
28 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; | 28 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; |
29 virtual void SelectBetweenCoordinates(const gfx::PointF& base, | 29 virtual void SelectBetweenCoordinates(const gfx::PointF& base, |
30 const gfx::PointF& extent) = 0; | 30 const gfx::PointF& extent) = 0; |
31 virtual void OnSelectionEvent(SelectionEventType event) = 0; | 31 virtual void OnSelectionEvent(SelectionEventType event) = 0; |
32 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 32 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
| 33 virtual void OnScrollStarted() = 0; |
| 34 virtual void OnScrollCompleted() = 0; |
33 }; | 35 }; |
34 | 36 |
35 // Controller for manipulating text selection via touch input. | 37 // Controller for manipulating text selection via touch input. |
36 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController | 38 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController |
37 : public TouchHandleClient { | 39 : public TouchHandleClient { |
38 public: | 40 public: |
39 TouchSelectionController(TouchSelectionControllerClient* client, | 41 TouchSelectionController(TouchSelectionControllerClient* client, |
40 base::TimeDelta tap_timeout, | 42 base::TimeDelta tap_timeout, |
41 float tap_slop, | 43 float tap_slop, |
42 bool show_on_tap_for_empty_editable); | 44 bool show_on_tap_for_empty_editable); |
43 ~TouchSelectionController() override; | 45 ~TouchSelectionController() override; |
44 | 46 |
45 // To be called when the selection bounds have changed. | 47 // To be called when the selection bounds info has been updated. |
46 // Note that such updates will trigger handle updates only if preceded | 48 // Note that such updates will trigger handle updates only if preceded |
47 // by an appropriate call to allow automatic showing. | 49 // by an appropriate call to allow automatic showing. |
48 void OnSelectionBoundsChanged(const SelectionBound& start, | 50 // Return value specifies if anything has been updated or not. |
| 51 bool OnSelectionBoundsUpdated(const SelectionBound& start, |
49 const SelectionBound& end); | 52 const SelectionBound& end); |
50 | 53 |
51 // Allows touch-dragging of the handle. | 54 // Allows touch-dragging of the handle. |
52 // Returns true iff the event was consumed, in which case the caller should | 55 // Returns true iff the event was consumed, in which case the caller should |
53 // cease further handling of the event. | 56 // cease further handling of the event. |
54 bool WillHandleTouchEvent(const MotionEvent& event); | 57 bool WillHandleTouchEvent(const MotionEvent& event); |
55 | 58 |
56 // To be called before forwarding a tap event. This allows automatically | 59 // To be called before forwarding a tap event. This allows automatically |
57 // showing the insertion handle from subsequent bounds changes. | 60 // showing the insertion handle from subsequent bounds changes. |
58 void OnTapEvent(); | 61 void OnTapEvent(); |
(...skipping 12 matching lines...) Expand all Loading... |
71 | 74 |
72 // Override the handle visibility according to |hidden|. | 75 // Override the handle visibility according to |hidden|. |
73 void SetTemporarilyHidden(bool hidden); | 76 void SetTemporarilyHidden(bool hidden); |
74 | 77 |
75 // To be called when the editability of the focused region changes. | 78 // To be called when the editability of the focused region changes. |
76 void OnSelectionEditable(bool editable); | 79 void OnSelectionEditable(bool editable); |
77 | 80 |
78 // To be called when the contents of the focused region changes. | 81 // To be called when the contents of the focused region changes. |
79 void OnSelectionEmpty(bool empty); | 82 void OnSelectionEmpty(bool empty); |
80 | 83 |
| 84 // To be called when native view moves around. |
| 85 void OnNativeViewMoved(); |
| 86 |
81 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 87 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
82 // Returns true if an animation is active and requires further ticking. | 88 // Returns true if an animation is active and requires further ticking. |
83 bool Animate(base::TimeTicks animate_time); | 89 bool Animate(base::TimeTicks animate_time); |
84 | 90 |
85 // Returns the rect between the two active selection bounds. If just one of | 91 // Returns the rect between the two active selection bounds. If just one of |
86 // the bounds is visible, the rect is simply the (one-dimensional) rect of | 92 // the bounds is visible, the rect is simply the (one-dimensional) rect of |
87 // that bound. If no selection is active, an empty rect will be returned. | 93 // that bound. If no selection is active, an empty rect will be returned. |
88 gfx::RectF GetRectBetweenBounds() const; | 94 gfx::RectF GetRectBetweenBounds() const; |
89 | 95 |
90 // Returns the visible rect of specified touch handle. For an active insertion | 96 // Returns the visible rect of specified touch handle. For an active insertion |
91 // these values will be identical. | 97 // these values will be identical. |
92 gfx::RectF GetStartHandleRect() const; | 98 gfx::RectF GetStartHandleRect() const; |
93 gfx::RectF GetEndHandleRect() const; | 99 gfx::RectF GetEndHandleRect() const; |
94 | 100 |
95 // Returns the focal point of the start and end bounds, as defined by | 101 // Returns the focal point of the start and end bounds, as defined by |
96 // their bottom coordinate. | 102 // their bottom coordinate. |
97 const gfx::PointF& GetStartPosition() const; | 103 const gfx::PointF& GetStartPosition() const; |
98 const gfx::PointF& GetEndPosition() const; | 104 const gfx::PointF& GetEndPosition() const; |
99 | 105 |
| 106 const SelectionBound& start() const { return start_; } |
| 107 const SelectionBound& end() const { return end_; } |
| 108 |
| 109 bool is_insertion_active() const { return is_insertion_active_; } |
| 110 bool is_selection_active() const { return is_selection_active_; } |
| 111 |
100 private: | 112 private: |
101 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; | 113 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; |
102 | 114 |
103 // TouchHandleClient implementation. | 115 // TouchHandleClient implementation. |
104 void OnHandleDragBegin(const TouchHandle& handle) override; | 116 void OnHandleDragBegin(const TouchHandle& handle) override; |
105 void OnHandleDragUpdate(const TouchHandle& handle, | 117 void OnHandleDragUpdate(const TouchHandle& handle, |
106 const gfx::PointF& new_position) override; | 118 const gfx::PointF& new_position) override; |
107 void OnHandleDragEnd(const TouchHandle& handle) override; | 119 void OnHandleDragEnd(const TouchHandle& handle) override; |
108 void OnHandleTapped(const TouchHandle& handle) override; | 120 void OnHandleTapped(const TouchHandle& handle) override; |
109 void SetNeedsAnimate() override; | 121 void SetNeedsAnimate() override; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // Whether a selection handle was dragged during the current 'selection | 176 // Whether a selection handle was dragged during the current 'selection |
165 // session' - i.e. since the current selection has been activated. | 177 // session' - i.e. since the current selection has been activated. |
166 bool selection_handle_dragged_; | 178 bool selection_handle_dragged_; |
167 | 179 |
168 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | 180 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
169 }; | 181 }; |
170 | 182 |
171 } // namespace ui | 183 } // namespace ui |
172 | 184 |
173 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 185 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |