Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / touch_selection / touch_selection_controller.h
blobabc75b59ce7f588b603d2148bcba957cfc304eec
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_SELECTION_CONTROLLER_H_
6 #define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_
8 #include "ui/base/touch/selection_bound.h"
9 #include "ui/gfx/geometry/point_f.h"
10 #include "ui/gfx/geometry/rect_f.h"
11 #include "ui/touch_selection/selection_event_type.h"
12 #include "ui/touch_selection/touch_handle.h"
13 #include "ui/touch_selection/touch_handle_orientation.h"
14 #include "ui/touch_selection/ui_touch_selection_export.h"
16 namespace ui {
17 class MotionEvent;
19 // Interface through which |TouchSelectionController| issues selection-related
20 // commands, notifications and requests.
21 class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient {
22 public:
23 virtual ~TouchSelectionControllerClient() {}
25 virtual bool SupportsAnimation() const = 0;
26 virtual void SetNeedsAnimate() = 0;
27 virtual void MoveCaret(const gfx::PointF& position) = 0;
28 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0;
29 virtual void SelectBetweenCoordinates(const gfx::PointF& base,
30 const gfx::PointF& extent) = 0;
31 virtual void OnSelectionEvent(SelectionEventType event,
32 const gfx::PointF& position) = 0;
33 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
36 // Controller for manipulating text selection via touch input.
37 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
38 : public TouchHandleClient {
39 public:
40 TouchSelectionController(TouchSelectionControllerClient* client,
41 base::TimeDelta tap_timeout,
42 float tap_slop,
43 bool show_on_tap_for_empty_editable);
44 ~TouchSelectionController() override;
46 // To be called when the selection bounds have changed.
47 // Note that such updates will trigger handle updates only if preceded
48 // by an appropriate call to allow automatic showing.
49 void OnSelectionBoundsChanged(const SelectionBound& start,
50 const SelectionBound& end);
52 // Allows touch-dragging of the handle.
53 // Returns true iff the event was consumed, in which case the caller should
54 // cease further handling of the event.
55 bool WillHandleTouchEvent(const MotionEvent& event);
57 // To be called before forwarding a tap event. This allows automatically
58 // showing the insertion handle from subsequent bounds changes.
59 void OnTapEvent();
61 // To be called before forwarding a longpress event. This allows automatically
62 // showing the selection or insertion handles from subsequent bounds changes.
63 void OnLongPressEvent();
65 // Allow showing the selection handles from the most recent selection bounds
66 // update (if valid), or a future valid bounds update.
67 void AllowShowingFromCurrentSelection();
69 // Hide the handles and suppress bounds updates until the next explicit
70 // showing allowance.
71 void HideAndDisallowShowingAutomatically();
73 // Override the handle visibility according to |hidden|.
74 void SetTemporarilyHidden(bool hidden);
76 // To be called when the editability of the focused region changes.
77 void OnSelectionEditable(bool editable);
79 // To be called when the contents of the focused region changes.
80 void OnSelectionEmpty(bool empty);
82 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
83 // Returns true if an animation is active and requires further ticking.
84 bool Animate(base::TimeTicks animate_time);
86 private:
87 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE };
89 // TouchHandleClient implementation.
90 void OnHandleDragBegin(const TouchHandle& handle) override;
91 void OnHandleDragUpdate(const TouchHandle& handle,
92 const gfx::PointF& new_position) override;
93 void OnHandleDragEnd(const TouchHandle& handle) override;
94 void OnHandleTapped(const TouchHandle& handle) override;
95 void SetNeedsAnimate() override;
96 scoped_ptr<TouchHandleDrawable> CreateDrawable() override;
97 base::TimeDelta GetTapTimeout() const override;
98 float GetTapSlop() const override;
100 void ShowInsertionHandleAutomatically();
101 void ShowSelectionHandlesAutomatically();
103 void OnInsertionChanged();
104 void OnSelectionChanged();
106 void ActivateInsertion();
107 void DeactivateInsertion();
108 void ActivateSelection();
109 void DeactivateSelection();
110 void ResetCachedValuesIfInactive();
112 const gfx::PointF& GetStartPosition() const;
113 const gfx::PointF& GetEndPosition() const;
114 gfx::Vector2dF GetStartLineOffset() const;
115 gfx::Vector2dF GetEndLineOffset() const;
116 bool GetStartVisible() const;
117 bool GetEndVisible() const;
118 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const;
120 void LogSelectionEnd();
122 TouchSelectionControllerClient* const client_;
123 const base::TimeDelta tap_timeout_;
124 const float tap_slop_;
126 // Controls whether an insertion handle is shown on a tap for an empty
127 // editable text.
128 bool show_on_tap_for_empty_editable_;
130 InputEventType response_pending_input_event_;
132 SelectionBound start_;
133 SelectionBound end_;
134 TouchHandleOrientation start_orientation_;
135 TouchHandleOrientation end_orientation_;
137 scoped_ptr<TouchHandle> insertion_handle_;
138 bool is_insertion_active_;
139 bool activate_insertion_automatically_;
141 scoped_ptr<TouchHandle> start_selection_handle_;
142 scoped_ptr<TouchHandle> end_selection_handle_;
143 bool is_selection_active_;
144 bool activate_selection_automatically_;
146 bool selection_empty_;
147 bool selection_editable_;
149 bool temporarily_hidden_;
151 base::TimeTicks selection_start_time_;
152 // Whether a selection handle was dragged during the current 'selection
153 // session' - i.e. since the current selection has been activated.
154 bool selection_handle_dragged_;
156 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController);
159 } // namespace ui
161 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_