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 CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ | 5 #ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_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 "content/common/content_export.h" | |
12 #include "ui/events/gesture_detection/motion_event.h" | 11 #include "ui/events/gesture_detection/motion_event.h" |
13 #include "ui/gfx/geometry/point_f.h" | 12 #include "ui/gfx/geometry/point_f.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 13 #include "ui/gfx/geometry/rect_f.h" |
15 #include "ui/gfx/geometry/vector2d_f.h" | 14 #include "ui/gfx/geometry/vector2d_f.h" |
| 15 #include "ui/touch_selection/ui_touch_selection_export.h" |
16 | 16 |
17 namespace content { | 17 namespace ui { |
18 | 18 |
19 class TouchHandle; | 19 class TouchHandle; |
20 | 20 |
21 enum TouchHandleOrientation { | 21 enum TouchHandleOrientation { |
22 TOUCH_HANDLE_LEFT, | 22 TOUCH_HANDLE_LEFT, |
23 TOUCH_HANDLE_CENTER, | 23 TOUCH_HANDLE_CENTER, |
24 TOUCH_HANDLE_RIGHT, | 24 TOUCH_HANDLE_RIGHT, |
25 TOUCH_HANDLE_ORIENTATION_UNDEFINED, | 25 TOUCH_HANDLE_ORIENTATION_UNDEFINED, |
26 }; | 26 }; |
27 | 27 |
28 // Interface through which |TouchHandle| delegates rendering-specific duties. | 28 // Interface through which |TouchHandle| delegates rendering-specific duties. |
29 class CONTENT_EXPORT TouchHandleDrawable { | 29 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { |
30 public: | 30 public: |
31 virtual ~TouchHandleDrawable() {} | 31 virtual ~TouchHandleDrawable() {} |
32 virtual void SetEnabled(bool enabled) = 0; | 32 virtual void SetEnabled(bool enabled) = 0; |
33 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; | 33 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; |
34 virtual void SetAlpha(float alpha) = 0; | 34 virtual void SetAlpha(float alpha) = 0; |
35 virtual void SetFocus(const gfx::PointF& position) = 0; | 35 virtual void SetFocus(const gfx::PointF& position) = 0; |
36 virtual bool IntersectsWith(const gfx::RectF& rect) const = 0; | 36 virtual bool IntersectsWith(const gfx::RectF& rect) const = 0; |
37 }; | 37 }; |
38 | 38 |
39 // Interface through which |TouchHandle| communicates handle manipulation and | 39 // Interface through which |TouchHandle| communicates handle manipulation and |
40 // requests concrete drawable instances. | 40 // requests concrete drawable instances. |
41 class CONTENT_EXPORT TouchHandleClient { | 41 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { |
42 public: | 42 public: |
43 virtual ~TouchHandleClient() {} | 43 virtual ~TouchHandleClient() {} |
44 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0; | 44 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0; |
45 virtual void OnHandleDragUpdate(const TouchHandle& handle, | 45 virtual void OnHandleDragUpdate(const TouchHandle& handle, |
46 const gfx::PointF& new_position) = 0; | 46 const gfx::PointF& new_position) = 0; |
47 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0; | 47 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0; |
48 virtual void OnHandleTapped(const TouchHandle& handle) = 0; | 48 virtual void OnHandleTapped(const TouchHandle& handle) = 0; |
49 virtual void SetNeedsAnimate() = 0; | 49 virtual void SetNeedsAnimate() = 0; |
50 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 50 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
51 virtual base::TimeDelta GetTapTimeout() const = 0; | 51 virtual base::TimeDelta GetTapTimeout() const = 0; |
52 virtual float GetTapSlop() const = 0; | 52 virtual float GetTapSlop() const = 0; |
53 }; | 53 }; |
54 | 54 |
55 // Responsible for displaying a selection or insertion handle for text | 55 // Responsible for displaying a selection or insertion handle for text |
56 // interaction. | 56 // interaction. |
57 class CONTENT_EXPORT TouchHandle { | 57 class UI_TOUCH_SELECTION_EXPORT TouchHandle { |
58 public: | 58 public: |
59 // The drawable will be enabled but invisible until otherwise specified. | 59 // The drawable will be enabled but invisible until otherwise specified. |
60 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); | 60 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); |
61 ~TouchHandle(); | 61 ~TouchHandle(); |
62 | 62 |
63 // Sets whether the handle is active, allowing resource cleanup if necessary. | 63 // Sets whether the handle is active, allowing resource cleanup if necessary. |
64 // If false, active animations or touch drag sequences will be cancelled. | 64 // If false, active animations or touch drag sequences will be cancelled. |
65 // While disabled, manipulation is *explicitly not supported*, and may lead to | 65 // While disabled, manipulation is *explicitly not supported*, and may lead to |
66 // undesirable and/or unstable side-effects. The handle can be safely | 66 // undesirable and/or unstable side-effects. The handle can be safely |
67 // re-enabled to allow continued operation. | 67 // re-enabled to allow continued operation. |
68 void SetEnabled(bool enabled); | 68 void SetEnabled(bool enabled); |
69 | 69 |
70 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; | 70 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; |
71 // Update the handle visibility, fading in/out according to |animation_style|. | 71 // Update the handle visibility, fading in/out according to |animation_style|. |
72 // If an animation is in-progress, it will be overriden appropriately. | 72 // If an animation is in-progress, it will be overriden appropriately. |
73 void SetVisible(bool visible, AnimationStyle animation_style); | 73 void SetVisible(bool visible, AnimationStyle animation_style); |
74 | 74 |
75 // Update the handle placement to |position|. | 75 // Update the handle placement to |position|. |
76 // Note: If a fade out animation is active or the handle is invisible, the | 76 // Note: If a fade out animation is active or the handle is invisible, the |
77 // handle position will not be updated until the handle regains visibility. | 77 // handle position will not be updated until the handle regains visibility. |
78 void SetPosition(const gfx::PointF& position); | 78 void SetPosition(const gfx::PointF& position); |
79 | 79 |
80 // Update the handle visuals to |orientation|. | 80 // Update the handle visuals to |orientation|. |
81 // Note: If the handle is being dragged, the orientation change will be | 81 // Note: If the handle is being dragged, the orientation change will be |
82 // deferred until the drag has ceased. | 82 // deferred until the drag has ceased. |
83 void SetOrientation(TouchHandleOrientation orientation); | 83 void SetOrientation(TouchHandleOrientation orientation); |
84 | 84 |
85 // Allows touch-dragging of the handle. Returns true if the event was | 85 // Allows touch-dragging of the handle. Returns true if the event was |
86 // consumed, in which case the caller should cease further handling. | 86 // consumed, in which case the caller should cease further handling. |
87 bool WillHandleTouchEvent(const ui::MotionEvent& event); | 87 bool WillHandleTouchEvent(const MotionEvent& event); |
88 | 88 |
89 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 89 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
90 // Returns true if an animation is active and requires further ticking. | 90 // Returns true if an animation is active and requires further ticking. |
91 bool Animate(base::TimeTicks frame_time); | 91 bool Animate(base::TimeTicks frame_time); |
92 | 92 |
93 bool is_dragging() const { return is_dragging_; } | 93 bool is_dragging() const { return is_dragging_; } |
94 const gfx::PointF& position() const { return position_; } | 94 const gfx::PointF& position() const { return position_; } |
95 TouchHandleOrientation orientation() const { return orientation_; } | 95 TouchHandleOrientation orientation() const { return orientation_; } |
96 | 96 |
97 private: | 97 private: |
(...skipping 24 matching lines...) Expand all Loading... |
122 bool animate_deferred_fade_; | 122 bool animate_deferred_fade_; |
123 | 123 |
124 bool enabled_; | 124 bool enabled_; |
125 bool is_visible_; | 125 bool is_visible_; |
126 bool is_dragging_; | 126 bool is_dragging_; |
127 bool is_drag_within_tap_region_; | 127 bool is_drag_within_tap_region_; |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(TouchHandle); | 129 DISALLOW_COPY_AND_ASSIGN(TouchHandle); |
130 }; | 130 }; |
131 | 131 |
132 } // namespace content | 132 } // namespace ui |
133 | 133 |
134 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ | 134 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
OLD | NEW |