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

Side by Side Diff: ui/touch_selection/touch_handle.h

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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
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 UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ 5 #ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
6 #define UI_TOUCH_SELECTION_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 "ui/events/gesture_detection/motion_event.h" 11 #include "ui/events/gesture_detection/motion_event.h"
12 #include "ui/gfx/geometry/point_f.h" 12 #include "ui/gfx/geometry/point_f.h"
13 #include "ui/gfx/geometry/rect_f.h" 13 #include "ui/gfx/geometry/rect_f.h"
14 #include "ui/gfx/geometry/vector2d_f.h" 14 #include "ui/gfx/geometry/vector2d_f.h"
15 #include "ui/touch_selection/touch_handle_orientation.h" 15 #include "ui/touch_selection/touch_handle_orientation.h"
16 #include "ui/touch_selection/touch_selection_draggable.h"
16 #include "ui/touch_selection/ui_touch_selection_export.h" 17 #include "ui/touch_selection/ui_touch_selection_export.h"
17 18
18 namespace ui { 19 namespace ui {
19 20
20 class TouchHandle; 21 class TouchHandle;
21 22
22 // Interface through which |TouchHandle| delegates rendering-specific duties. 23 // Interface through which |TouchHandle| delegates rendering-specific duties.
23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { 24 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable {
24 public: 25 public:
25 virtual ~TouchHandleDrawable() {} 26 virtual ~TouchHandleDrawable() {}
26 virtual void SetEnabled(bool enabled) = 0; 27 virtual void SetEnabled(bool enabled) = 0;
27 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; 28 virtual void SetOrientation(TouchHandleOrientation orientation) = 0;
28 virtual void SetAlpha(float alpha) = 0; 29 virtual void SetAlpha(float alpha) = 0;
29 virtual void SetFocus(const gfx::PointF& position) = 0; 30 virtual void SetFocus(const gfx::PointF& position) = 0;
30 virtual gfx::RectF GetVisibleBounds() const = 0; 31 virtual gfx::RectF GetVisibleBounds() const = 0;
31 }; 32 };
32 33
33 // Interface through which |TouchHandle| communicates handle manipulation and 34 // Interface through which |TouchHandle| communicates handle manipulation and
34 // requests concrete drawable instances. 35 // requests concrete drawable instances.
35 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { 36 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient
37 : public TouchSelectionDraggableClient {
36 public: 38 public:
37 virtual ~TouchHandleClient() {} 39 ~TouchHandleClient() override {}
38 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0;
39 virtual void OnHandleDragUpdate(const TouchHandle& handle,
40 const gfx::PointF& new_position) = 0;
41 virtual void OnHandleDragEnd(const TouchHandle& handle) = 0;
42 virtual void OnHandleTapped(const TouchHandle& handle) = 0; 40 virtual void OnHandleTapped(const TouchHandle& handle) = 0;
43 virtual void SetNeedsAnimate() = 0; 41 virtual void SetNeedsAnimate() = 0;
44 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; 42 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
45 virtual base::TimeDelta GetTapTimeout() const = 0; 43 virtual base::TimeDelta GetTapTimeout() const = 0;
46 virtual float GetTapSlop() const = 0;
47 }; 44 };
48 45
49 // Responsible for displaying a selection or insertion handle for text 46 // Responsible for displaying a selection or insertion handle for text
50 // interaction. 47 // interaction.
51 class UI_TOUCH_SELECTION_EXPORT TouchHandle { 48 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable {
52 public: 49 public:
53 // The drawable will be enabled but invisible until otherwise specified. 50 // The drawable will be enabled but invisible until otherwise specified.
54 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); 51 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation);
55 ~TouchHandle(); 52 ~TouchHandle() override;
53
54 // TouchSelectionDraggable implementation.
55 bool WillHandleTouchEvent(const MotionEvent& event) override;
56 bool IsActive() const override;
56 57
57 // Sets whether the handle is active, allowing resource cleanup if necessary. 58 // Sets whether the handle is active, allowing resource cleanup if necessary.
58 // If false, active animations or touch drag sequences will be cancelled. 59 // If false, active animations or touch drag sequences will be cancelled.
59 // While disabled, manipulation is *explicitly not supported*, and may lead to 60 // While disabled, manipulation is *explicitly not supported*, and may lead to
60 // undesirable and/or unstable side-effects. The handle can be safely 61 // undesirable and/or unstable side-effects. The handle can be safely
61 // re-enabled to allow continued operation. 62 // re-enabled to allow continued operation.
62 void SetEnabled(bool enabled); 63 void SetEnabled(bool enabled);
63 64
64 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; 65 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
65 // Update the handle visibility, fading in/out according to |animation_style|. 66 // Update the handle visibility, fading in/out according to |animation_style|.
66 // If an animation is in-progress, it will be overriden appropriately. 67 // If an animation is in-progress, it will be overriden appropriately.
67 void SetVisible(bool visible, AnimationStyle animation_style); 68 void SetVisible(bool visible, AnimationStyle animation_style);
68 69
69 // Update the handle placement to |position|. 70 // Update the handle placement to |position|.
70 // Note: If a fade out animation is active or the handle is invisible, the 71 // Note: If a fade out animation is active or the handle is invisible, the
71 // handle position will not be updated until the handle regains visibility. 72 // handle position will not be updated until the handle regains visibility.
72 void SetPosition(const gfx::PointF& position); 73 void SetPosition(const gfx::PointF& position);
73 74
74 // Update the handle visuals to |orientation|. 75 // Update the handle visuals to |orientation|.
75 // Note: If the handle is being dragged, the orientation change will be 76 // Note: If the handle is being dragged, the orientation change will be
76 // deferred until the drag has ceased. 77 // deferred until the drag has ceased.
77 void SetOrientation(TouchHandleOrientation orientation); 78 void SetOrientation(TouchHandleOrientation orientation);
78 79
79 // Allows touch-dragging of the handle. Returns true if the event was
80 // consumed, in which case the caller should cease further handling.
81 bool WillHandleTouchEvent(const MotionEvent& event);
82
83 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. 80 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
84 // Returns true if an animation is active and requires further ticking. 81 // Returns true if an animation is active and requires further ticking.
85 bool Animate(base::TimeTicks frame_time); 82 bool Animate(base::TimeTicks frame_time);
86 83
87 // Get the visible bounds of the handle, based on the current position and 84 // Get the visible bounds of the handle, based on the current position and
88 // the drawable's size/orientation. If the handle is invisible or disabled, 85 // the drawable's size/orientation. If the handle is invisible or disabled,
89 // the bounds will be empty. 86 // the bounds will be empty.
90 gfx::RectF GetVisibleBounds() const; 87 gfx::RectF GetVisibleBounds() const;
91 88
92 bool is_dragging() const { return is_dragging_; }
93 const gfx::PointF& position() const { return position_; } 89 const gfx::PointF& position() const { return position_; }
94 TouchHandleOrientation orientation() const { return orientation_; } 90 TouchHandleOrientation orientation() const { return orientation_; }
95 91
96 private: 92 private:
97 void BeginDrag(); 93 void BeginDrag();
98 void EndDrag(); 94 void EndDrag();
99 void BeginFade(); 95 void BeginFade();
100 void EndFade(); 96 void EndFade();
101 void SetAlpha(float alpha); 97 void SetAlpha(float alpha);
102 98
103 scoped_ptr<TouchHandleDrawable> drawable_; 99 scoped_ptr<TouchHandleDrawable> drawable_;
104 100
105 TouchHandleClient* const client_; 101 TouchHandleClient* const client_;
106 102
107 gfx::PointF position_; 103 gfx::PointF position_;
108 TouchHandleOrientation orientation_; 104 TouchHandleOrientation orientation_;
109 TouchHandleOrientation deferred_orientation_; 105 TouchHandleOrientation deferred_orientation_;
110 106
111 gfx::PointF touch_down_position_; 107 gfx::PointF touch_down_position_;
112 gfx::Vector2dF touch_to_focus_offset_; 108 gfx::Vector2dF touch_drag_offset_;
113 base::TimeTicks touch_down_time_; 109 base::TimeTicks touch_down_time_;
114 110
115 // Note that when a fade animation is active, |is_visible_| and |position_| 111 // 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 112 // may not reflect the actual visibilty and position of the drawable. This
117 // discrepancy is resolved either upon fade completion or cancellation. 113 // discrepancy is resolved either upon fade completion or cancellation.
118 base::TimeTicks fade_end_time_; 114 base::TimeTicks fade_end_time_;
119 gfx::PointF fade_start_position_; 115 gfx::PointF fade_start_position_;
120 float alpha_; 116 float alpha_;
121 bool animate_deferred_fade_; 117 bool animate_deferred_fade_;
122 118
123 bool enabled_; 119 bool enabled_;
124 bool is_visible_; 120 bool is_visible_;
125 bool is_dragging_; 121 bool is_dragging_;
126 bool is_drag_within_tap_region_; 122 bool is_drag_within_tap_region_;
127 123
128 DISALLOW_COPY_AND_ASSIGN(TouchHandle); 124 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
129 }; 125 };
130 126
131 } // namespace ui 127 } // namespace ui
132 128
133 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ 129 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
OLDNEW
« no previous file with comments | « ui/touch_selection/longpress_drag_selector_unittest.cc ('k') | ui/touch_selection/touch_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698