OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "ui/events/gesture_detection/motion_event.h" |
| 13 #include "ui/gfx/geometry/point_f.h" |
| 14 #include "ui/gfx/geometry/vector2d_f.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class TouchHandle; |
| 19 |
| 20 enum TouchHandleOrientation { |
| 21 TOUCH_HANDLE_LEFT, |
| 22 TOUCH_HANDLE_CENTER, |
| 23 TOUCH_HANDLE_RIGHT, |
| 24 TOUCH_HANDLE_ORIENTATION_UNDEFINED, |
| 25 }; |
| 26 |
| 27 // Interface through which |TouchHandle| delegates rendering-specific duties. |
| 28 class CONTENT_EXPORT TouchHandleDrawable { |
| 29 public: |
| 30 virtual ~TouchHandleDrawable() {} |
| 31 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; |
| 32 virtual void SetAlpha(float alpha) = 0; |
| 33 virtual void SetFocus(const gfx::PointF& position) = 0; |
| 34 virtual void SetVisible(bool visible) = 0; |
| 35 virtual bool ContainsPoint(const gfx::PointF& point) const = 0; |
| 36 }; |
| 37 |
| 38 // Interface through which |TouchHandle| communicates handle manipulation and |
| 39 // requests concrete drawable instances. |
| 40 class CONTENT_EXPORT TouchHandleClient { |
| 41 public: |
| 42 virtual ~TouchHandleClient() {} |
| 43 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0; |
| 44 virtual void OnHandleDragUpdate(const TouchHandle& handle, |
| 45 const gfx::PointF& new_position) = 0; |
| 46 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0; |
| 47 virtual void OnHandleTapped(const TouchHandle& handle) = 0; |
| 48 virtual void SetNeedsAnimate() = 0; |
| 49 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
| 50 }; |
| 51 |
| 52 // Responsible for displaying a selection or insertion handle for text |
| 53 // interaction. |
| 54 class CONTENT_EXPORT TouchHandle { |
| 55 public: |
| 56 // The created drawable will remain invisible until otherwise specified. |
| 57 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); |
| 58 ~TouchHandle(); |
| 59 |
| 60 enum AnimationStyle { |
| 61 ANIMATION_NONE, |
| 62 ANIMATION_SMOOTH |
| 63 }; |
| 64 // Update the handle visibility, fading in/out according to |animation_style|. |
| 65 // If an animation is in-progress, it will be overriden appropriately. |
| 66 void SetVisible(bool visible, AnimationStyle animation_style); |
| 67 |
| 68 // Update the handle placement to |position|. |
| 69 // Note: If a handle fade animation is active, the visual handle position will |
| 70 // not be updated. |
| 71 void SetPosition(const gfx::PointF& position); |
| 72 |
| 73 // Update the handle visuals to |orientation|. |
| 74 // Note: If the handle is being dragged, the orientation change will be |
| 75 // deferred until the drag has ceased. |
| 76 void SetOrientation(TouchHandleOrientation orientation); |
| 77 |
| 78 // Hide the handles and cancel any active animations. |
| 79 void Hide(); |
| 80 |
| 81 // Allows touch-dragging of the handle. Returns true if the event was |
| 82 // consumed, in which case the caller should cease further handling. |
| 83 bool WillHandleTouchEvent(const ui::MotionEvent& event); |
| 84 |
| 85 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
| 86 // Returns true if an animation is active and requires further ticking. |
| 87 bool Animate(base::TimeTicks frame_time); |
| 88 |
| 89 bool is_dragging() const { return is_dragging_; } |
| 90 const gfx::PointF& position() const { return position_; } |
| 91 TouchHandleOrientation orientation() const { return orientation_; } |
| 92 |
| 93 private: |
| 94 void BeginDrag(); |
| 95 void EndDrag(); |
| 96 void ScheduleFade(); |
| 97 void CancelFade(); |
| 98 void SetAlpha(float alpha); |
| 99 |
| 100 scoped_ptr<TouchHandleDrawable> drawable_; |
| 101 |
| 102 TouchHandleClient* const client_; |
| 103 |
| 104 gfx::PointF position_; |
| 105 TouchHandleOrientation orientation_; |
| 106 TouchHandleOrientation deferred_orientation_; |
| 107 |
| 108 gfx::PointF touch_down_position_; |
| 109 gfx::Vector2dF touch_to_focus_offset_; |
| 110 base::TimeTicks touch_down_time_; |
| 111 |
| 112 // Note that when a fade animation is active, |is_visible_| and |position_| |
| 113 // may not reflect the actual visibilty and position of the drawable. This |
| 114 // discrepancy is resolved either upon fade completion or cancellation. |
| 115 base::TimeTicks fade_end_time_; |
| 116 gfx::PointF fade_start_position_; |
| 117 float alpha_; |
| 118 |
| 119 bool is_visible_; |
| 120 bool is_dragging_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(TouchHandle); |
| 123 }; |
| 124 |
| 125 } // namespace content |
| 126 |
| 127 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ |
OLD | NEW |