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

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: Factor out logic Created 5 years, 8 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; 44 virtual float GetTapSlop() const = 0;
47 }; 45 };
48 46
49 // Responsible for displaying a selection or insertion handle for text 47 // Responsible for displaying a selection or insertion handle for text
50 // interaction. 48 // interaction.
51 class UI_TOUCH_SELECTION_EXPORT TouchHandle { 49 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable {
52 public: 50 public:
53 // The drawable will be enabled but invisible until otherwise specified. 51 // The drawable will be enabled but invisible until otherwise specified.
54 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); 52 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation);
55 ~TouchHandle(); 53 ~TouchHandle() override;
56 54
57 // Sets whether the handle is active, allowing resource cleanup if necessary. 55 // Sets whether the handle is active, allowing resource cleanup if necessary.
58 // If false, active animations or touch drag sequences will be cancelled. 56 // If false, active animations or touch drag sequences will be cancelled.
59 // While disabled, manipulation is *explicitly not supported*, and may lead to 57 // While disabled, manipulation is *explicitly not supported*, and may lead to
60 // undesirable and/or unstable side-effects. The handle can be safely 58 // undesirable and/or unstable side-effects. The handle can be safely
61 // re-enabled to allow continued operation. 59 // re-enabled to allow continued operation.
62 void SetEnabled(bool enabled); 60 void SetEnabled(bool enabled);
63 61
64 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; 62 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
65 // Update the handle visibility, fading in/out according to |animation_style|. 63 // Update the handle visibility, fading in/out according to |animation_style|.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 100
103 scoped_ptr<TouchHandleDrawable> drawable_; 101 scoped_ptr<TouchHandleDrawable> drawable_;
104 102
105 TouchHandleClient* const client_; 103 TouchHandleClient* const client_;
106 104
107 gfx::PointF position_; 105 gfx::PointF position_;
108 TouchHandleOrientation orientation_; 106 TouchHandleOrientation orientation_;
109 TouchHandleOrientation deferred_orientation_; 107 TouchHandleOrientation deferred_orientation_;
110 108
111 gfx::PointF touch_down_position_; 109 gfx::PointF touch_down_position_;
112 gfx::Vector2dF touch_to_focus_offset_; 110 gfx::Vector2dF touch_drag_offset_;
113 base::TimeTicks touch_down_time_; 111 base::TimeTicks touch_down_time_;
114 112
115 // Note that when a fade animation is active, |is_visible_| and |position_| 113 // 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 114 // may not reflect the actual visibilty and position of the drawable. This
117 // discrepancy is resolved either upon fade completion or cancellation. 115 // discrepancy is resolved either upon fade completion or cancellation.
118 base::TimeTicks fade_end_time_; 116 base::TimeTicks fade_end_time_;
119 gfx::PointF fade_start_position_; 117 gfx::PointF fade_start_position_;
120 float alpha_; 118 float alpha_;
121 bool animate_deferred_fade_; 119 bool animate_deferred_fade_;
122 120
123 bool enabled_; 121 bool enabled_;
124 bool is_visible_; 122 bool is_visible_;
125 bool is_dragging_; 123 bool is_dragging_;
126 bool is_drag_within_tap_region_; 124 bool is_drag_within_tap_region_;
127 125
128 DISALLOW_COPY_AND_ASSIGN(TouchHandle); 126 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
129 }; 127 };
130 128
131 } // namespace ui 129 } // namespace ui
132 130
133 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ 131 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698