Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_handle.h
blobc78a5b952a72e8c4f84300b316858424e02c110e
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_
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/rect_f.h"
15 #include "ui/gfx/geometry/vector2d_f.h"
17 namespace content {
19 class TouchHandle;
21 enum TouchHandleOrientation {
22 TOUCH_HANDLE_LEFT,
23 TOUCH_HANDLE_CENTER,
24 TOUCH_HANDLE_RIGHT,
25 TOUCH_HANDLE_ORIENTATION_UNDEFINED,
28 // Interface through which |TouchHandle| delegates rendering-specific duties.
29 class CONTENT_EXPORT TouchHandleDrawable {
30 public:
31 virtual ~TouchHandleDrawable() {}
32 virtual void SetEnabled(bool enabled) = 0;
33 virtual void SetOrientation(TouchHandleOrientation orientation) = 0;
34 virtual void SetAlpha(float alpha) = 0;
35 virtual void SetFocus(const gfx::PointF& position) = 0;
36 virtual void SetVisible(bool visible) = 0;
37 virtual bool IntersectsWith(const gfx::RectF& rect) const = 0;
40 // Interface through which |TouchHandle| communicates handle manipulation and
41 // requests concrete drawable instances.
42 class CONTENT_EXPORT TouchHandleClient {
43 public:
44 virtual ~TouchHandleClient() {}
45 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0;
46 virtual void OnHandleDragUpdate(const TouchHandle& handle,
47 const gfx::PointF& new_position) = 0;
48 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0;
49 virtual void OnHandleTapped(const TouchHandle& handle) = 0;
50 virtual void SetNeedsAnimate() = 0;
51 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
54 // Responsible for displaying a selection or insertion handle for text
55 // interaction.
56 class CONTENT_EXPORT TouchHandle {
57 public:
58 // The drawable will be enabled but invisible until otherwise specified.
59 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation);
60 ~TouchHandle();
62 // Sets whether the handle is active, allowing resource cleanup if necessary.
63 // If false, active animations or touch drag sequences will be cancelled.
64 // While disabled, manipulation is *explicitly not supported*, and may lead to
65 // undesirable and/or unstable side-effects. The handle can be safely
66 // re-enabled to allow continued operation.
67 void SetEnabled(bool enabled);
69 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
70 // Update the handle visibility, fading in/out according to |animation_style|.
71 // If an animation is in-progress, it will be overriden appropriately.
72 void SetVisible(bool visible, AnimationStyle animation_style);
74 // Update the handle placement to |position|.
75 // Note: If a fade out animation is active or the handle is invisible, the
76 // handle position will not be updated until the handle regains visibility.
77 void SetPosition(const gfx::PointF& position);
79 // Update the handle visuals to |orientation|.
80 // Note: If the handle is being dragged, the orientation change will be
81 // deferred until the drag has ceased.
82 void SetOrientation(TouchHandleOrientation orientation);
84 // Allows touch-dragging of the handle. Returns true if the event was
85 // consumed, in which case the caller should cease further handling.
86 bool WillHandleTouchEvent(const ui::MotionEvent& event);
88 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
89 // Returns true if an animation is active and requires further ticking.
90 bool Animate(base::TimeTicks frame_time);
92 bool is_dragging() const { return is_dragging_; }
93 const gfx::PointF& position() const { return position_; }
94 TouchHandleOrientation orientation() const { return orientation_; }
96 private:
97 void BeginDrag();
98 void EndDrag();
99 void BeginFade();
100 void EndFade();
101 void SetAlpha(float alpha);
103 scoped_ptr<TouchHandleDrawable> drawable_;
105 TouchHandleClient* const client_;
107 gfx::PointF position_;
108 TouchHandleOrientation orientation_;
109 TouchHandleOrientation deferred_orientation_;
111 gfx::PointF touch_down_position_;
112 gfx::Vector2dF touch_to_focus_offset_;
113 base::TimeTicks touch_down_time_;
115 // Note that when a fade animation is active, |is_visible_| and |position_|
116 // may not reflect the actual visibilty and position of the drawable. This
117 // discrepancy is resolved either upon fade completion or cancellation.
118 base::TimeTicks fade_end_time_;
119 gfx::PointF fade_start_position_;
120 float alpha_;
121 bool animate_deferred_fade_;
123 bool enabled_;
124 bool is_visible_;
125 bool is_dragging_;
127 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
130 } // namespace content
132 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_