Remove unused parameter.
[chromium-blink-merge.git] / ui / touch_selection / touch_handle.h
blob12c66d09983626db3c3f9b4a356aa80a2a9d9178
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 UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
6 #define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "ui/events/gesture_detection/motion_event.h"
12 #include "ui/gfx/geometry/point_f.h"
13 #include "ui/gfx/geometry/rect_f.h"
14 #include "ui/gfx/geometry/vector2d_f.h"
15 #include "ui/touch_selection/touch_handle_orientation.h"
16 #include "ui/touch_selection/ui_touch_selection_export.h"
18 namespace ui {
20 class TouchHandle;
22 // Interface through which |TouchHandle| delegates rendering-specific duties.
23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable {
24 public:
25 virtual ~TouchHandleDrawable() {}
26 virtual void SetEnabled(bool enabled) = 0;
27 virtual void SetOrientation(TouchHandleOrientation orientation) = 0;
28 virtual void SetAlpha(float alpha) = 0;
29 virtual void SetFocus(const gfx::PointF& position) = 0;
30 virtual gfx::RectF GetVisibleBounds() const = 0;
33 // Interface through which |TouchHandle| communicates handle manipulation and
34 // requests concrete drawable instances.
35 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient {
36 public:
37 virtual ~TouchHandleClient() {}
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;
43 virtual void SetNeedsAnimate() = 0;
44 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
45 virtual base::TimeDelta GetTapTimeout() const = 0;
46 virtual float GetTapSlop() const = 0;
49 // Responsible for displaying a selection or insertion handle for text
50 // interaction.
51 class UI_TOUCH_SELECTION_EXPORT TouchHandle {
52 public:
53 // The drawable will be enabled but invisible until otherwise specified.
54 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation);
55 ~TouchHandle();
57 // Sets whether the handle is active, allowing resource cleanup if necessary.
58 // If false, active animations or touch drag sequences will be cancelled.
59 // While disabled, manipulation is *explicitly not supported*, and may lead to
60 // undesirable and/or unstable side-effects. The handle can be safely
61 // re-enabled to allow continued operation.
62 void SetEnabled(bool enabled);
64 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
65 // Update the handle visibility, fading in/out according to |animation_style|.
66 // If an animation is in-progress, it will be overriden appropriately.
67 void SetVisible(bool visible, AnimationStyle animation_style);
69 // Update the handle placement to |position|.
70 // 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 void SetPosition(const gfx::PointF& position);
74 // Update the handle visuals to |orientation|.
75 // Note: If the handle is being dragged, the orientation change will be
76 // deferred until the drag has ceased.
77 void SetOrientation(TouchHandleOrientation orientation);
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);
83 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
84 // Returns true if an animation is active and requires further ticking.
85 bool Animate(base::TimeTicks frame_time);
87 bool is_dragging() const { return is_dragging_; }
88 const gfx::PointF& position() const { return position_; }
89 TouchHandleOrientation orientation() const { return orientation_; }
91 private:
92 void BeginDrag();
93 void EndDrag();
94 void BeginFade();
95 void EndFade();
96 void SetAlpha(float alpha);
98 scoped_ptr<TouchHandleDrawable> drawable_;
100 TouchHandleClient* const client_;
102 gfx::PointF position_;
103 TouchHandleOrientation orientation_;
104 TouchHandleOrientation deferred_orientation_;
106 gfx::PointF touch_down_position_;
107 gfx::Vector2dF touch_to_focus_offset_;
108 base::TimeTicks touch_down_time_;
110 // 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
112 // discrepancy is resolved either upon fade completion or cancellation.
113 base::TimeTicks fade_end_time_;
114 gfx::PointF fade_start_position_;
115 float alpha_;
116 bool animate_deferred_fade_;
118 bool enabled_;
119 bool is_visible_;
120 bool is_dragging_;
121 bool is_drag_within_tap_region_;
123 DISALLOW_COPY_AND_ASSIGN(TouchHandle);
126 } // namespace ui
128 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_