Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: content/browser/renderer_host/input/touch_handle.h

Issue 335943002: [Android] Composited selection handle rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_native_handles_final
Patch Set: Fix animation tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 SetEnabled(bool enabled) = 0;
32 virtual void SetOrientation(TouchHandleOrientation orientation) = 0;
33 virtual void SetAlpha(float alpha) = 0;
34 virtual void SetFocus(const gfx::PointF& position) = 0;
35 virtual void SetVisible(bool visible) = 0;
36 virtual bool ContainsPoint(const gfx::PointF& point) const = 0;
37 };
38
39 // Interface through which |TouchHandle| communicates handle manipulation and
40 // requests concrete drawable instances.
41 class CONTENT_EXPORT TouchHandleClient {
42 public:
43 virtual ~TouchHandleClient() {}
44 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0;
45 virtual void OnHandleDragUpdate(const TouchHandle& handle,
46 const gfx::PointF& new_position) = 0;
47 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0;
48 virtual void OnHandleTapped(const TouchHandle& handle) = 0;
49 virtual void SetNeedsAnimate() = 0;
50 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
51 };
52
53 // Responsible for displaying a selection or insertion handle for text
54 // interaction.
55 class CONTENT_EXPORT TouchHandle {
56 public:
57 // The drawable will be enabled but invisible until otherwise specified.
58 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation);
59 ~TouchHandle();
60
61 // Sets whether the handle is active, allowing resource cleanup if necessary.
62 // If false, active animations or touch drag sequences will be cancelled.
63 // While disabled, manipulation is *explicitly not supported*, and may lead to
64 // undesirable and/or unstable side-effects. The handle can be safely
65 // re-enabled to allow continued operation.
66 void SetEnabled(bool enabled);
67
68 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
69 // Update the handle visibility, fading in/out according to |animation_style|.
70 // If an animation is in-progress, it will be overriden appropriately.
71 void SetVisible(bool visible, AnimationStyle animation_style);
72
73 // Update the handle placement to |position|.
74 // Note: If a fade out animation is active or the handle is invisible, the
75 // handle position will not be updated until the handle regains visibility.
76 void SetPosition(const gfx::PointF& position);
77
78 // Update the handle visuals to |orientation|.
79 // Note: If the handle is being dragged, the orientation change will be
80 // deferred until the drag has ceased.
81 void SetOrientation(TouchHandleOrientation orientation);
82
83 // Allows touch-dragging of the handle. Returns true if the event was
84 // consumed, in which case the caller should cease further handling.
85 bool WillHandleTouchEvent(const ui::MotionEvent& event);
86
87 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
88 // Returns true if an animation is active and requires further ticking.
89 bool Animate(base::TimeTicks frame_time);
90
91 bool is_dragging() const { return is_dragging_; }
92 const gfx::PointF& position() const { return position_; }
93 TouchHandleOrientation orientation() const { return orientation_; }
94
95 private:
96 void BeginDrag();
97 void EndDrag();
98 void BeginFade();
99 void EndFade();
100 void SetAlpha(float alpha);
101
102 scoped_ptr<TouchHandleDrawable> drawable_;
103
104 TouchHandleClient* const client_;
105
106 gfx::PointF position_;
107 TouchHandleOrientation orientation_;
108 TouchHandleOrientation deferred_orientation_;
109
110 gfx::PointF touch_down_position_;
111 gfx::Vector2dF touch_to_focus_offset_;
112 base::TimeTicks touch_down_time_;
113
114 // Note that when a fade animation is active, |is_visible_| and |position_|
115 // may not reflect the actual visibilty and position of the drawable. This
116 // discrepancy is resolved either upon fade completion or cancellation.
117 base::TimeTicks fade_end_time_;
118 gfx::PointF fade_start_position_;
119 float alpha_;
120 bool animate_deferred_fade_;
121
122 bool enabled_;
123 bool is_visible_;
124 bool is_dragging_;
125
126 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
127 };
128
129 } // namespace content
130
131 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_HANDLE_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/selection_event_type_list.h ('k') | content/browser/renderer_host/input/touch_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698