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

Side by Side Diff: ui/touch_selection/touch_selection_controller_aura.cc

Issue 698253004: Reland: Implement Aura side of unified touch text selection for contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed overrides in TouchHandleDrawableAura Created 5 years, 11 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
(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 #include "ui/touch_selection/touch_selection_controller_aura.h"
6
7 #include "ui/aura/client/cursor_client.h"
8 #include "ui/aura/env.h"
9 #include "ui/aura/window.h"
10 #include "ui/events/event.h"
11 #include "ui/events/gesture_detection/gesture_configuration.h"
12 #include "ui/events/gestures/motion_event_aura.h"
13 #include "ui/touch_selection/touch_handle_drawable_aura.h"
14
15
16 namespace ui {
17
18 TouchSelectionControllerAura::TouchSelectionControllerAura(
19 TouchSelectionControllerAuraClient* client)
20 : client_(client),
21 motion_event_(new MotionEventAura),
22 scroll_in_progress_(false),
23 overscroll_in_progress_(false),
24 handle_drag_in_progress_(false) {
25 int tap_timeout_ms =
26 GestureConfiguration::GetInstance()->show_press_delay_in_ms();
27 int touch_slop =
28 GestureConfiguration::GetInstance()->max_touch_move_in_pixels_for_click();
29 controller_.reset(new TouchSelectionController(
30 this,
31 base::TimeDelta::FromMilliseconds(tap_timeout_ms),
32 touch_slop,
33 true));
jdduke (slow) 2015/01/28 16:35:32 The side-effetcs of |true| are a little unclear un
mohsen 2015/02/22 23:23:09 Done.
34 }
35
36 TouchSelectionControllerAura::~TouchSelectionControllerAura() {
37 }
38
39 void TouchSelectionControllerAura::OnSelectionEditable(bool editable) {
40 controller_->OnSelectionEditable(editable);
41 UpdateQuickMenu();
42 }
43
44 void TouchSelectionControllerAura::OnSelectionEmpty(bool empty) {
45 controller_->OnSelectionEmpty(empty);
46 UpdateQuickMenu();
47 }
48
49
50 void TouchSelectionControllerAura::OnSelectionBoundsUpdated(
51 const SelectionBound& start,
52 const SelectionBound& end) {
53 if (controller_->start() == start && controller_->end() == end)
jdduke (slow) 2015/01/28 16:35:32 Don't love this early exit, one alternative would
mohsen 2015/02/22 23:23:09 Done.
54 return;
55
56 controller_->OnSelectionBoundsUpdated(start, end);
57 UpdateQuickMenu();
58 }
59
60 void TouchSelectionControllerAura::HandleGestureEvent(GestureEvent* event) {
61 switch (event->type()) {
62 case ET_GESTURE_LONG_PRESS:
63 controller_->OnLongPressEvent();
64 break;
65 case ET_GESTURE_TAP:
66 if (!controller_->is_insertion_active() &&
67 !controller_->is_selection_active() &&
68 RectBetweenSelectionBounds(
69 controller_->start(),
70 controller_->end()).Contains(event->x(), event->y())) {
71 // TODO: also check for editability
72 controller_->TryActivateSelection();
73 event->SetHandled();
74 } else {
75 controller_->OnTapEvent();
76 }
77 break;
78 case ET_GESTURE_SCROLL_BEGIN:
79 scroll_in_progress_ = true;
80 UpdateQuickMenu();
81 break;
82 case ET_GESTURE_SCROLL_END:
83 scroll_in_progress_ = false;
84 UpdateQuickMenu();
85 break;
86 default:
87 break;
88 }
89 }
90
91 void TouchSelectionControllerAura::HandleTouchEvent(TouchEvent* event) {
92 const int index = motion_event_->FindPointerIndexOfId(event->touch_id());
93 const bool pointer_id_is_active = index != -1;
94
95 if (event->type() != ET_TOUCH_PRESSED && !pointer_id_is_active)
96 return;
97
98 if (event->type() == ET_TOUCH_PRESSED && pointer_id_is_active)
99 motion_event_.reset(new MotionEventAura);
100
101 motion_event_->OnTouch(*event);
102 if (controller_->WillHandleTouchEvent(*motion_event_))
103 event->SetHandled();
104 motion_event_->CleanupRemovedTouchPoints(*event);
105 }
106
107 void TouchSelectionControllerAura::HideAndDisallowShowingAutomatically() {
108 controller_->HideAndDisallowShowingAutomatically();
109 UpdateQuickMenu();
110 }
111
112 void TouchSelectionControllerAura::OnWindowMoved() {
113 UpdateQuickMenu();
114 }
115
116 void TouchSelectionControllerAura::OnOverscrollStarted() {
117 overscroll_in_progress_ = true;
118 UpdateQuickMenu();
119 }
120
121 void TouchSelectionControllerAura::OnOverscrollCompleted() {
122 overscroll_in_progress_ = false;
123 UpdateQuickMenu();
124 }
125
126 void TouchSelectionControllerAura::OnFlingCompleted() {
127 scroll_in_progress_ = false;
128 UpdateQuickMenu();
129 }
130
131 gfx::Rect TouchSelectionControllerAura::GetAnchorRect() const {
132 // TODO: Crop to view bounds
133 const SelectionBound& start = controller_->start();
134 const SelectionBound& end = controller_->end();
135
136 if (start.visible() && end.visible())
137 return RectBetweenSelectionBounds(start, end);
138 if (start.visible())
139 return gfx::BoundingRect(start.edge_top_rounded(),
140 start.edge_bottom_rounded());
141 return gfx::BoundingRect(end.edge_top_rounded(), end.edge_bottom_rounded());
142 }
143
144 void TouchSelectionControllerAura::ShowQuickMenu() {
145 DCHECK(controller_->is_insertion_active() ||
146 controller_->is_selection_active());
147
148 if (!controller_->start().visible() && !controller_->end().visible())
149 return;
150
151 if (TouchSelectionMenuRunner::GetInstance()) {
152 TouchSelectionMenuRunner::GetInstance()->RunMenu(
153 this,
154 client_->ConvertRectToScreen(GetAnchorRect()),
155 TouchHandleDrawableAura::GetMaxHandleImageSize(),
156 client_->GetParentWindow()->GetToplevelWindow());
157 }
158 }
159
160 void TouchSelectionControllerAura::UpdateQuickMenu() {
161 // Hide quick menu if there is any.
162 if (TouchSelectionMenuRunner::GetInstance() &&
163 TouchSelectionMenuRunner::GetInstance()->IsRunning()) {
164 TouchSelectionMenuRunner::GetInstance()->CloseMenu();
165 } else {
166 quick_menu_timer_.Stop();
167 }
168
169 // Start timer to show quick menu if necessary.
170 if (!controller_->is_insertion_active() &&
171 !controller_->is_selection_active())
172 return;
173
174 if (!IsQuickMenuAllowed())
175 return;
176
177 if (immediate_quick_menu_for_testing_) {
178 ShowQuickMenu();
179 } else {
180 quick_menu_timer_.Start(
181 FROM_HERE,
182 base::TimeDelta::FromMilliseconds(100),
183 this,
184 &TouchSelectionControllerAura::ShowQuickMenu);
185 }
186 }
187
188 bool TouchSelectionControllerAura::IsQuickMenuAllowed() const {
189 return !scroll_in_progress_ && !overscroll_in_progress_ &&
190 !handle_drag_in_progress_;
191 }
192
193 bool TouchSelectionControllerAura::SupportsAnimation() const {
194 return false;
195 }
196
197 void TouchSelectionControllerAura::SetNeedsAnimate() {
198 NOTREACHED();
199 }
200
201 void TouchSelectionControllerAura::MoveCaret(const gfx::PointF& position) {
202 client_->MoveCaret(position);
203 }
204
205 void TouchSelectionControllerAura::MoveRangeSelectionExtent(
206 const gfx::PointF& extent) {
207 client_->MoveRangeSelectionExtent(extent);
208 }
209
210 void TouchSelectionControllerAura::SelectBetweenCoordinates(
211 const gfx::PointF& base,
212 const gfx::PointF& extent) {
213 client_->SelectBetweenCoordinates(base, extent);
214 }
215
216 void TouchSelectionControllerAura::OnSelectionEvent(
217 SelectionEventType event,
218 const gfx::PointF& position) {
219 switch (event) {
220 case SELECTION_SHOWN:
221 UpdateQuickMenu();
222 aura::Env::GetInstance()->RemovePreTargetHandler(this);
223 aura::Env::GetInstance()->AddPreTargetHandler(this);
224 break;
225 case SELECTION_CLEARED:
226 aura::Env::GetInstance()->RemovePreTargetHandler(this);
227 UpdateQuickMenu();
228 break;
229 case SELECTION_DRAG_STARTED:
230 handle_drag_in_progress_ = true;
231 UpdateQuickMenu();
232 break;
233 case SELECTION_DRAG_STOPPED:
234 handle_drag_in_progress_ = false;
235 UpdateQuickMenu();
236 break;
237 case INSERTION_SHOWN:
238 UpdateQuickMenu();
239 aura::Env::GetInstance()->RemovePreTargetHandler(this);
240 aura::Env::GetInstance()->AddPreTargetHandler(this);
241 break;
242 case INSERTION_MOVED:
243 break;
244 case INSERTION_TAPPED:
245 //UpdateQuickMenu();
246 break;
247 case INSERTION_CLEARED:
248 aura::Env::GetInstance()->RemovePreTargetHandler(this);
249 UpdateQuickMenu();
250 break;
251 case INSERTION_DRAG_STARTED:
252 handle_drag_in_progress_ = true;
253 UpdateQuickMenu();
254 break;
255 case INSERTION_DRAG_STOPPED:
256 handle_drag_in_progress_ = false;
257 UpdateQuickMenu();
258 break;
259 };
260 }
261
262 scoped_ptr<TouchHandleDrawable> TouchSelectionControllerAura::CreateDrawable() {
263 return scoped_ptr<TouchHandleDrawable>(
264 new TouchHandleDrawableAura(client_->GetParentWindow()));
265 }
266
267 bool TouchSelectionControllerAura::IsCommandIdEnabled(int command_id) const {
268 return client_->IsCommandIdEnabled(command_id);
269 }
270
271 void TouchSelectionControllerAura::ExecuteCommand(int command_id,
272 int event_flags) {
273 HideAndDisallowShowingAutomatically();
274 client_->ExecuteCommand(command_id, event_flags);
275 }
276
277 void TouchSelectionControllerAura::OpenContextMenu() {
278 HideAndDisallowShowingAutomatically();
279 gfx::Rect anchor_rect = GetAnchorRect();
280 client_->OpenContextMenu(gfx::Point(anchor_rect.CenterPoint().x(),
281 anchor_rect.y()));
282 }
283
284 void TouchSelectionControllerAura::OnKeyEvent(KeyEvent* event) {
285 LOG(ERROR) << "KeyEvent: " << event->name();
286
287 DCHECK(controller_->is_insertion_active() ||
288 controller_->is_selection_active());
289
290 HideAndDisallowShowingAutomatically();
291 }
292
293 void TouchSelectionControllerAura::OnMouseEvent(MouseEvent* event) {
294 LOG(ERROR) << "MouseEvent: " << event->name();
295
296 DCHECK(controller_->is_insertion_active() ||
297 controller_->is_selection_active());
298
299 aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(
300 client_->GetParentWindow()->GetRootWindow());
301 if (!cursor_client || cursor_client->IsMouseEventsEnabled())
302 HideAndDisallowShowingAutomatically();
303 }
304
305 void TouchSelectionControllerAura::OnScrollEvent(ScrollEvent* event) {
306 LOG(ERROR) << "ScrollEvent: " << event->name();
307
308 DCHECK(controller_->is_insertion_active() ||
309 controller_->is_selection_active());
310
311 HideAndDisallowShowingAutomatically();
312 }
313
314 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698