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_HANDLE_H_ | 5 #ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
6 #define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ | 6 #define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "ui/events/gesture_detection/motion_event.h" | 11 #include "ui/events/gesture_detection/motion_event.h" |
12 #include "ui/gfx/geometry/point_f.h" | 12 #include "ui/gfx/geometry/point_f.h" |
13 #include "ui/gfx/geometry/rect_f.h" | 13 #include "ui/gfx/geometry/rect_f.h" |
14 #include "ui/gfx/geometry/vector2d_f.h" | 14 #include "ui/gfx/geometry/vector2d_f.h" |
15 #include "ui/touch_selection/touch_handle_orientation.h" | 15 #include "ui/touch_selection/touch_handle_orientation.h" |
16 #include "ui/touch_selection/touch_selection_draggable.h" | 16 #include "ui/touch_selection/touch_selection_draggable.h" |
17 #include "ui/touch_selection/ui_touch_selection_export.h" | 17 #include "ui/touch_selection/ui_touch_selection_export.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 class TouchHandle; | 21 class TouchHandle; |
22 | 22 |
23 // Interface through which |TouchHandle| delegates rendering-specific duties. | 23 // Interface through which |TouchHandle| delegates rendering-specific duties. |
24 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { | 24 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { |
25 public: | 25 public: |
26 virtual ~TouchHandleDrawable() {} | 26 virtual ~TouchHandleDrawable() {} |
27 | |
28 // Sets whether the handle is active, allowing resource cleanup if necessary. | |
27 virtual void SetEnabled(bool enabled) = 0; | 29 virtual void SetEnabled(bool enabled) = 0; |
28 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; | 30 |
31 // Update the handle visuals to |orientation|. | |
32 // |mirror_vertical| and |mirror_horizontal| are used to invert the drawables | |
33 // if required for Adaptive Handle Orientation. | |
34 virtual void SetOrientation(ui::TouchHandleOrientation orientation, | |
35 bool mirror_vertical, | |
36 bool mirror_horizontal) = 0; | |
37 | |
38 // Sets the Origin position of the touch handle. | |
39 // |origin| takes care of positioning the handle drawable based on the | |
mfomitchev
2015/08/10 13:23:46
I think if you say that it's based on handle's vis
AviD
2015/08/10 14:16:10
Done.
| |
40 // horizontal transparent padding and the orientation. | |
41 virtual void SetOrigin(const gfx::PointF& origin) = 0; | |
42 | |
43 // Sets the transparency |alpha| for the handle drawable. | |
29 virtual void SetAlpha(float alpha) = 0; | 44 virtual void SetAlpha(float alpha) = 0; |
30 virtual void SetFocus(const gfx::PointF& position) = 0; | 45 |
46 // Returns the visible bounds of the handle drawable. | |
47 // The bounds includes the transparent horizontal padding, which is | |
mfomitchev
2015/08/10 13:23:45
Nit: I'd drop the "which is" part - IMO generally
AviD
2015/08/10 14:16:10
Done.
| |
48 // present in case of Android handle drawables. | |
31 virtual gfx::RectF GetVisibleBounds() const = 0; | 49 virtual gfx::RectF GetVisibleBounds() const = 0; |
50 | |
51 // Returns the Transparent horizontal if present in the handle drawable. | |
mfomitchev
2015/08/10 13:23:45
"padding" missing
AviD
2015/08/10 14:16:10
Done.
| |
52 // The transparent padding is present in case of Android handle drawables. | |
mfomitchev
2015/08/10 13:23:46
I'd drop the second sentence.
AviD
2015/08/10 14:16:10
Done.
| |
53 virtual const float GetDrawableHorizontalPadding() const = 0; | |
32 }; | 54 }; |
33 | 55 |
34 // Interface through which |TouchHandle| communicates handle manipulation and | 56 // Interface through which |TouchHandle| communicates handle manipulation and |
35 // requests concrete drawable instances. | 57 // requests concrete drawable instances. |
36 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient | 58 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient |
37 : public TouchSelectionDraggableClient { | 59 : public TouchSelectionDraggableClient { |
38 public: | 60 public: |
39 ~TouchHandleClient() override {} | 61 ~TouchHandleClient() override {} |
40 virtual void OnHandleTapped(const TouchHandle& handle) = 0; | 62 virtual void OnHandleTapped(const TouchHandle& handle) = 0; |
41 virtual void SetNeedsAnimate() = 0; | 63 virtual void SetNeedsAnimate() = 0; |
42 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 64 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
43 virtual base::TimeDelta GetTapTimeout() const = 0; | 65 virtual base::TimeDelta GetTapTimeout() const = 0; |
66 virtual bool IsEnabledAdaptiveHandleOrientation() const = 0; | |
44 }; | 67 }; |
45 | 68 |
46 // Responsible for displaying a selection or insertion handle for text | 69 // Responsible for displaying a selection or insertion handle for text |
47 // interaction. | 70 // interaction. |
48 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable { | 71 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable { |
49 public: | 72 public: |
50 // The drawable will be enabled but invisible until otherwise specified. | 73 // The drawable will be enabled but invisible until otherwise specified. |
51 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); | 74 TouchHandle(TouchHandleClient* client, |
75 TouchHandleOrientation orientation, | |
76 const gfx::RectF viewport_rect); | |
52 ~TouchHandle() override; | 77 ~TouchHandle() override; |
53 | 78 |
54 // TouchSelectionDraggable implementation. | 79 // TouchSelectionDraggable implementation. |
55 bool WillHandleTouchEvent(const MotionEvent& event) override; | 80 bool WillHandleTouchEvent(const MotionEvent& event) override; |
56 bool IsActive() const override; | 81 bool IsActive() const override; |
57 | 82 |
58 // Sets whether the handle is active, allowing resource cleanup if necessary. | 83 // Sets whether the handle is active, allowing resource cleanup if necessary. |
59 // If false, active animations or touch drag sequences will be cancelled. | 84 // If false, active animations or touch drag sequences will be cancelled. |
60 // While disabled, manipulation is *explicitly not supported*, and may lead to | 85 // While disabled, manipulation is *explicitly not supported*, and may lead to |
61 // undesirable and/or unstable side-effects. The handle can be safely | 86 // undesirable and/or unstable side-effects. The handle can be safely |
62 // re-enabled to allow continued operation. | 87 // re-enabled to allow continued operation. |
63 void SetEnabled(bool enabled); | 88 void SetEnabled(bool enabled); |
64 | 89 |
65 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; | 90 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; |
66 // Update the handle visibility, fading in/out according to |animation_style|. | 91 // Update the handle visibility, fading in/out according to |animation_style|. |
67 // If an animation is in-progress, it will be overriden appropriately. | 92 // If an animation is in-progress, it will be overriden appropriately. |
68 void SetVisible(bool visible, AnimationStyle animation_style); | 93 void SetVisible(bool visible, AnimationStyle animation_style); |
69 | 94 |
70 // Update the handle placement to |position|. | 95 // Update the focus points for the handles. The Handle will be positioned |
96 // either |top| or |bottom| based on the mirror parameters. | |
71 // Note: If a fade out animation is active or the handle is invisible, the | 97 // Note: If a fade out animation is active or the handle is invisible, the |
72 // handle position will not be updated until the handle regains visibility. | 98 // handle position will not be updated until the handle regains visibility. |
73 void SetPosition(const gfx::PointF& position); | 99 void SetFocus(const gfx::PointF& top, const gfx::PointF& bottom); |
100 | |
101 // Update the Viewport rect, based on which the handle decide its inversion | |
102 void SetViewportRect(const gfx::RectF viewport_rect); | |
74 | 103 |
75 // Update the handle visuals to |orientation|. | 104 // Update the handle visuals to |orientation|. |
76 // Note: If the handle is being dragged, the orientation change will be | 105 // Note: If the handle is being dragged, the orientation change will be |
77 // deferred until the drag has ceased. | 106 // deferred until the drag has ceased. |
78 void SetOrientation(TouchHandleOrientation orientation); | 107 void SetOrientation(TouchHandleOrientation orientation); |
79 | 108 |
80 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 109 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
81 // Returns true if an animation is active and requires further ticking. | 110 // Returns true if an animation is active and requires further ticking. |
82 bool Animate(base::TimeTicks frame_time); | 111 bool Animate(base::TimeTicks frame_time); |
83 | 112 |
84 // Get the visible bounds of the handle, based on the current position and | 113 // Get the visible bounds of the handle, based on the current position and |
85 // the drawable's size/orientation. If the handle is invisible or disabled, | 114 // the drawable's size/orientation. If the handle is invisible or disabled, |
86 // the bounds will be empty. | 115 // the bounds will be empty. |
87 gfx::RectF GetVisibleBounds() const; | 116 gfx::RectF GetVisibleBounds() const; |
88 | 117 |
89 const gfx::PointF& position() const { return position_; } | 118 // Updates the Handle layout if the is_handle_layout_update_required_ flag is |
119 // set. Will be called once per frame update, avoids multiple updates for | |
120 // for the same frame update due to more than one parameter updates. | |
121 void UpdateHandleLayout(); | |
122 | |
123 const gfx::PointF& focus_bottom() const { return focus_bottom_; } | |
90 TouchHandleOrientation orientation() const { return orientation_; } | 124 TouchHandleOrientation orientation() const { return orientation_; } |
91 | 125 |
92 private: | 126 private: |
127 gfx::PointF GetHandleOrigin() const; | |
93 void BeginDrag(); | 128 void BeginDrag(); |
94 void EndDrag(); | 129 void EndDrag(); |
95 void BeginFade(); | 130 void BeginFade(); |
96 void EndFade(); | 131 void EndFade(); |
97 void SetAlpha(float alpha); | 132 void SetAlpha(float alpha); |
133 void SetUpdateLayoutRequired() { is_handle_layout_update_required_ = true; } | |
98 | 134 |
99 scoped_ptr<TouchHandleDrawable> drawable_; | 135 scoped_ptr<TouchHandleDrawable> drawable_; |
100 | 136 |
101 TouchHandleClient* const client_; | 137 TouchHandleClient* const client_; |
102 | 138 |
103 gfx::PointF position_; | 139 gfx::PointF focus_bottom_; |
140 gfx::PointF focus_top_; | |
141 gfx::RectF viewport_rect_; | |
104 TouchHandleOrientation orientation_; | 142 TouchHandleOrientation orientation_; |
105 TouchHandleOrientation deferred_orientation_; | 143 TouchHandleOrientation deferred_orientation_; |
106 | 144 |
107 gfx::PointF touch_down_position_; | 145 gfx::PointF touch_down_position_; |
108 gfx::Vector2dF touch_drag_offset_; | 146 gfx::Vector2dF touch_drag_offset_; |
109 base::TimeTicks touch_down_time_; | 147 base::TimeTicks touch_down_time_; |
110 | 148 |
111 // Note that when a fade animation is active, |is_visible_| and |position_| | 149 // Note that when a fade animation is active, |is_visible_| and |position_| |
112 // may not reflect the actual visibilty and position of the drawable. This | 150 // may not reflect the actual visibilty and position of the drawable. This |
113 // discrepancy is resolved either upon fade completion or cancellation. | 151 // discrepancy is resolved either upon fade completion or cancellation. |
114 base::TimeTicks fade_end_time_; | 152 base::TimeTicks fade_end_time_; |
115 gfx::PointF fade_start_position_; | 153 gfx::PointF fade_start_position_; |
116 float alpha_; | 154 float alpha_; |
117 bool animate_deferred_fade_; | 155 bool animate_deferred_fade_; |
118 | 156 |
119 bool enabled_; | 157 bool enabled_; |
120 bool is_visible_; | 158 bool is_visible_; |
121 bool is_dragging_; | 159 bool is_dragging_; |
122 bool is_drag_within_tap_region_; | 160 bool is_drag_within_tap_region_; |
161 bool is_handle_layout_update_required_; | |
162 | |
163 // Mirror variables determine if the handles should be inverted or not. | |
164 bool mirror_vertical_; | |
165 bool mirror_horizontal_; | |
166 float handle_horizontal_padding_; | |
123 | 167 |
124 DISALLOW_COPY_AND_ASSIGN(TouchHandle); | 168 DISALLOW_COPY_AND_ASSIGN(TouchHandle); |
125 }; | 169 }; |
126 | 170 |
127 } // namespace ui | 171 } // namespace ui |
128 | 172 |
129 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ | 173 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
OLD | NEW |