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

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

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 7 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/ui_touch_selection_export.h" 16 #include "ui/touch_selection/ui_touch_selection_export.h"
17 17
18 namespace ui { 18 namespace ui {
19 19
20 class TouchHandle; 20 class TouchHandle;
21 21
22 // Interface through which |TouchHandle| delegates rendering-specific duties. 22 // Interface through which |TouchHandle| delegates rendering-specific duties.
23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { 23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable {
24 public: 24 public:
25 virtual ~TouchHandleDrawable() {} 25 virtual ~TouchHandleDrawable() {}
26 virtual void SetEnabled(bool enabled) = 0; 26 virtual void SetEnabled(bool enabled) = 0;
27 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; 27 virtual void SetLayout(const gfx::PointF& position,
28 ui::TouchHandleOrientation orientation,
29 bool mirror_vertical,
30 bool mirror_horizontal) = 0;
28 virtual void SetAlpha(float alpha) = 0; 31 virtual void SetAlpha(float alpha) = 0;
29 virtual void SetFocus(const gfx::PointF& position) = 0;
30 virtual gfx::RectF GetVisibleBounds() const = 0; 32 virtual gfx::RectF GetVisibleBounds() const = 0;
31 }; 33 };
32 34
33 // Interface through which |TouchHandle| communicates handle manipulation and 35 // Interface through which |TouchHandle| communicates handle manipulation and
34 // requests concrete drawable instances. 36 // requests concrete drawable instances.
35 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { 37 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient {
36 public: 38 public:
37 virtual ~TouchHandleClient() {} 39 virtual ~TouchHandleClient() {}
38 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0; 40 virtual void OnHandleDragBegin(const TouchHandle& handle) = 0;
39 virtual void OnHandleDragUpdate(const TouchHandle& handle, 41 virtual void OnHandleDragUpdate(const TouchHandle& handle,
(...skipping 19 matching lines...) Expand all
59 // While disabled, manipulation is *explicitly not supported*, and may lead to 61 // While disabled, manipulation is *explicitly not supported*, and may lead to
60 // undesirable and/or unstable side-effects. The handle can be safely 62 // undesirable and/or unstable side-effects. The handle can be safely
61 // re-enabled to allow continued operation. 63 // re-enabled to allow continued operation.
62 void SetEnabled(bool enabled); 64 void SetEnabled(bool enabled);
63 65
64 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; 66 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
65 // Update the handle visibility, fading in/out according to |animation_style|. 67 // Update the handle visibility, fading in/out according to |animation_style|.
66 // If an animation is in-progress, it will be overriden appropriately. 68 // If an animation is in-progress, it will be overriden appropriately.
67 void SetVisible(bool visible, AnimationStyle animation_style); 69 void SetVisible(bool visible, AnimationStyle animation_style);
68 70
69 // Update the handle placement to |position|. 71 // Update the focus points for the handles. The Handle will be positioned
72 // either |top| or |bottom| based on the mirror parameters.
70 // Note: If a fade out animation is active or the handle is invisible, the 73 // 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. 74 // handle position will not be updated until the handle regains visibility.
72 void SetPosition(const gfx::PointF& position); 75 void SetFocus(const gfx::PointF& top, const gfx::PointF& bottom);
mfomitchev 2015/05/13 22:19:14 We always call both SetFocus and SetViewportRect,
jdduke (slow) 2015/05/14 15:20:10 Hmm, but we would only do the layout twice if the
AviD 2015/05/19 16:26:28 SetSelectionParams() ?
AviD 2015/05/21 09:23:14 I have changed this to update the viewport rect on
76
77 // Update the Viewport rect, based on which the handle decide its inversion
78 void SetViewportRect(const gfx::RectF viewport_rect);
73 79
74 // Update the handle visuals to |orientation|. 80 // Update the handle visuals to |orientation|.
75 // Note: If the handle is being dragged, the orientation change will be 81 // Note: If the handle is being dragged, the orientation change will be
76 // deferred until the drag has ceased. 82 // deferred until the drag has ceased.
77 void SetOrientation(TouchHandleOrientation orientation); 83 void SetOrientation(TouchHandleOrientation orientation);
78 84
79 // Allows touch-dragging of the handle. Returns true if the event was 85 // Allows touch-dragging of the handle. Returns true if the event was
80 // consumed, in which case the caller should cease further handling. 86 // consumed, in which case the caller should cease further handling.
81 bool WillHandleTouchEvent(const MotionEvent& event); 87 bool WillHandleTouchEvent(const MotionEvent& event);
82 88
83 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. 89 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
84 // Returns true if an animation is active and requires further ticking. 90 // Returns true if an animation is active and requires further ticking.
85 bool Animate(base::TimeTicks frame_time); 91 bool Animate(base::TimeTicks frame_time);
86 92
87 bool is_dragging() const { return is_dragging_; } 93 bool is_dragging() const { return is_dragging_; }
88 const gfx::PointF& position() const { return position_; } 94 const gfx::PointF& position() const { return focus_bottom_; }
mfomitchev 2015/05/13 22:19:14 rename to focus_bottom()?
AviD 2015/05/19 16:26:28 Done.
89 TouchHandleOrientation orientation() const { return orientation_; } 95 TouchHandleOrientation orientation() const { return orientation_; }
90 96
91 private: 97 private:
98 void UpdateLayout();
92 void BeginDrag(); 99 void BeginDrag();
93 void EndDrag(); 100 void EndDrag();
94 void BeginFade(); 101 void BeginFade();
95 void EndFade(); 102 void EndFade();
96 void SetAlpha(float alpha); 103 void SetAlpha(float alpha);
97 104
98 scoped_ptr<TouchHandleDrawable> drawable_; 105 scoped_ptr<TouchHandleDrawable> drawable_;
99 106
100 TouchHandleClient* const client_; 107 TouchHandleClient* const client_;
101 108
102 gfx::PointF position_; 109 gfx::PointF focus_bottom_;
110 gfx::PointF focus_top_;
111 gfx::RectF viewport_rect_;
103 TouchHandleOrientation orientation_; 112 TouchHandleOrientation orientation_;
104 TouchHandleOrientation deferred_orientation_; 113 TouchHandleOrientation deferred_orientation_;
105 114
106 gfx::PointF touch_down_position_; 115 gfx::PointF touch_down_position_;
107 gfx::Vector2dF touch_to_focus_offset_; 116 gfx::Vector2dF touch_to_focus_offset_;
108 base::TimeTicks touch_down_time_; 117 base::TimeTicks touch_down_time_;
109 118
110 // Note that when a fade animation is active, |is_visible_| and |position_| 119 // Note that when a fade animation is active, |is_visible_| and |position_|
111 // may not reflect the actual visibilty and position of the drawable. This 120 // may not reflect the actual visibilty and position of the drawable. This
112 // discrepancy is resolved either upon fade completion or cancellation. 121 // discrepancy is resolved either upon fade completion or cancellation.
113 base::TimeTicks fade_end_time_; 122 base::TimeTicks fade_end_time_;
114 gfx::PointF fade_start_position_; 123 gfx::PointF fade_start_position_;
115 float alpha_; 124 float alpha_;
116 bool animate_deferred_fade_; 125 bool animate_deferred_fade_;
117 126
118 bool enabled_; 127 bool enabled_;
119 bool is_visible_; 128 bool is_visible_;
120 bool is_dragging_; 129 bool is_dragging_;
121 bool is_drag_within_tap_region_; 130 bool is_drag_within_tap_region_;
122 131
132 // Mirror variables determine if the handles should be inverted or not.
133 bool mirror_vertical_;
134 bool mirror_horizontal_;
135
123 DISALLOW_COPY_AND_ASSIGN(TouchHandle); 136 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
124 }; 137 };
125 138
126 } // namespace ui 139 } // namespace ui
127 140
128 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ 141 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698