Chromium Code Reviews| 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 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); | |
| 57 ~TouchHandle(); | |
| 58 | |
| 59 void SetVisible(bool visible); | |
| 60 void SetVisibleAnimated(bool visible); | |
| 61 void SetPosition(const gfx::PointF& position); | |
| 62 void SetOrientation(TouchHandleOrientation orientation); | |
| 63 void Hide(); | |
| 64 | |
| 65 bool WillHandleTouchEvent(const ui::MotionEvent& event); | |
| 66 bool Animate(base::TimeTicks frame_time); | |
| 67 | |
| 68 bool is_dragging() const { return is_dragging_; } | |
| 69 const gfx::PointF& position() const { return position_; } | |
| 70 TouchHandleOrientation orientation() const { return orientation_; } | |
| 71 | |
| 72 private: | |
| 73 void BeginDrag(); | |
| 74 void EndDrag(); | |
| 75 void ScheduleFade(); | |
| 76 void CancelFade(); | |
| 77 void SetAlpha(float alpha); | |
| 78 | |
| 79 scoped_ptr<TouchHandleDrawable> drawable_; | |
| 80 | |
| 81 TouchHandleClient* const client_; | |
| 82 | |
| 83 gfx::PointF position_; | |
| 84 TouchHandleOrientation orientation_; | |
| 85 TouchHandleOrientation deferred_orientation_; | |
|
cjhopman
2014/07/07 22:13:41
A comment somewhere that orientation changes while
jdduke (slow)
2014/07/08 00:54:44
Good call, added some basic documentation to each
| |
| 86 | |
| 87 gfx::PointF down_position_; | |
| 88 gfx::Vector2dF touch_to_focus_offset_; | |
| 89 | |
| 90 base::TimeTicks touch_timer_; | |
|
cjhopman
2014/07/07 22:13:41
Maybe make a note about what things might get out
jdduke (slow)
2014/07/08 00:54:44
Done.
| |
| 91 float alpha_; | |
| 92 base::TimeTicks fade_end_time_; | |
| 93 gfx::PointF fade_start_position_; | |
| 94 | |
| 95 bool is_visible_; | |
| 96 bool is_dragging_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(TouchHandle); | |
| 99 }; | |
| 100 | |
| 101 } // namespace content | |
| 102 | |
| 103 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_ | |
| OLD | NEW |