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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller.h

Issue 759433002: Reland: Move TouchSelectionController from content to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Excluded ui/touch_selection from Windows GN build Created 6 years 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
(Empty)
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.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_
7
8 #include "cc/output/viewport_selection_bound.h"
9 #include "content/browser/renderer_host/input/selection_event_type.h"
10 #include "content/browser/renderer_host/input/touch_handle.h"
11 #include "content/common/content_export.h"
12 #include "ui/gfx/geometry/point_f.h"
13 #include "ui/gfx/geometry/rect_f.h"
14
15 namespace blink {
16 class WebInputEvent;
17 }
18
19 namespace ui {
20 class MotionEvent;
21 }
22
23 namespace content {
24
25 // Interface through which |TouchSelectionController| issues selection-related
26 // commands, notifications and requests.
27 class CONTENT_EXPORT TouchSelectionControllerClient {
28 public:
29 virtual ~TouchSelectionControllerClient() {}
30
31 virtual bool SupportsAnimation() const = 0;
32 virtual void SetNeedsAnimate() = 0;
33 virtual void MoveCaret(const gfx::PointF& position) = 0;
34 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0;
35 virtual void SelectBetweenCoordinates(const gfx::PointF& base,
36 const gfx::PointF& extent) = 0;
37 virtual void OnSelectionEvent(SelectionEventType event,
38 const gfx::PointF& position) = 0;
39 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0;
40 };
41
42 // Controller for manipulating text selection via touch input.
43 class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient {
44 public:
45 TouchSelectionController(TouchSelectionControllerClient* client,
46 base::TimeDelta tap_timeout,
47 float tap_slop);
48 ~TouchSelectionController() override;
49
50 // To be called when the selection bounds have changed.
51 // Note that such updates will trigger handle updates only if preceded
52 // by an appropriate call to allow automatic showing.
53 void OnSelectionBoundsChanged(const cc::ViewportSelectionBound& start,
54 const cc::ViewportSelectionBound& end);
55
56 // Allows touch-dragging of the handle.
57 // Returns true iff the event was consumed, in which case the caller should
58 // cease further handling of the event.
59 bool WillHandleTouchEvent(const ui::MotionEvent& event);
60
61 // To be called before forwarding a tap event. This allows automatically
62 // showing the insertion handle from subsequent bounds changes.
63 void OnTapEvent();
64
65 // To be called before forwarding a longpress event. This allows automatically
66 // showing the selection or insertion handles from subsequent bounds changes.
67 void OnLongPressEvent();
68
69 // Allow showing the selection handles from the most recent selection bounds
70 // update (if valid), or a future valid bounds update.
71 void AllowShowingFromCurrentSelection();
72
73 // Hide the handles and suppress bounds updates until the next explicit
74 // showing allowance.
75 void HideAndDisallowShowingAutomatically();
76
77 // Override the handle visibility according to |hidden|.
78 void SetTemporarilyHidden(bool hidden);
79
80 // To be called when the editability of the focused region changes.
81 void OnSelectionEditable(bool editable);
82
83 // To be called when the contents of the focused region changes.
84 void OnSelectionEmpty(bool empty);
85
86 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|.
87 // Returns true if an animation is active and requires further ticking.
88 bool Animate(base::TimeTicks animate_time);
89
90 private:
91 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE };
92
93 // TouchHandleClient implementation.
94 void OnHandleDragBegin(const TouchHandle& handle) override;
95 void OnHandleDragUpdate(const TouchHandle& handle,
96 const gfx::PointF& new_position) override;
97 void OnHandleDragEnd(const TouchHandle& handle) override;
98 void OnHandleTapped(const TouchHandle& handle) override;
99 void SetNeedsAnimate() override;
100 scoped_ptr<TouchHandleDrawable> CreateDrawable() override;
101 base::TimeDelta GetTapTimeout() const override;
102 float GetTapSlop() const override;
103
104 void ShowInsertionHandleAutomatically();
105 void ShowSelectionHandlesAutomatically();
106
107 void OnInsertionChanged();
108 void OnSelectionChanged();
109
110 void ActivateInsertion();
111 void DeactivateInsertion();
112 void ActivateSelection();
113 void DeactivateSelection();
114 void ResetCachedValuesIfInactive();
115
116 const gfx::PointF& GetStartPosition() const;
117 const gfx::PointF& GetEndPosition() const;
118 gfx::Vector2dF GetStartLineOffset() const;
119 gfx::Vector2dF GetEndLineOffset() const;
120 bool GetStartVisible() const;
121 bool GetEndVisible() const;
122 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const;
123
124 TouchSelectionControllerClient* const client_;
125 const base::TimeDelta tap_timeout_;
126 const float tap_slop_;
127
128 InputEventType response_pending_input_event_;
129
130 cc::ViewportSelectionBound start_;
131 cc::ViewportSelectionBound end_;
132 TouchHandleOrientation start_orientation_;
133 TouchHandleOrientation end_orientation_;
134
135 scoped_ptr<TouchHandle> insertion_handle_;
136 bool is_insertion_active_;
137 bool activate_insertion_automatically_;
138
139 scoped_ptr<TouchHandle> start_selection_handle_;
140 scoped_ptr<TouchHandle> end_selection_handle_;
141 bool is_selection_active_;
142 bool activate_selection_automatically_;
143
144 bool selection_empty_;
145 bool selection_editable_;
146
147 bool temporarily_hidden_;
148
149 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController);
150 };
151
152 } // namespace content
153
154 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698