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

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

Issue 2355403002: Consume entire touch sequence in touch selection controller (Closed)
Patch Set: Added a TODO comment Created 4 years, 2 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 #include "ui/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 start_orientation_(TouchHandleOrientation::UNDEFINED), 61 start_orientation_(TouchHandleOrientation::UNDEFINED),
62 end_orientation_(TouchHandleOrientation::UNDEFINED), 62 end_orientation_(TouchHandleOrientation::UNDEFINED),
63 active_status_(INACTIVE), 63 active_status_(INACTIVE),
64 activate_insertion_automatically_(false), 64 activate_insertion_automatically_(false),
65 activate_selection_automatically_(false), 65 activate_selection_automatically_(false),
66 selection_empty_(false), 66 selection_empty_(false),
67 selection_editable_(false), 67 selection_editable_(false),
68 temporarily_hidden_(false), 68 temporarily_hidden_(false),
69 anchor_drag_to_selection_start_(false), 69 anchor_drag_to_selection_start_(false),
70 longpress_drag_selector_(this), 70 longpress_drag_selector_(this),
71 selection_handle_dragged_(false) { 71 selection_handle_dragged_(false),
72 consume_touch_sequence_(false) {
72 DCHECK(client_); 73 DCHECK(client_);
73 } 74 }
74 75
75 TouchSelectionController::~TouchSelectionController() { 76 TouchSelectionController::~TouchSelectionController() {
76 } 77 }
77 78
78 void TouchSelectionController::OnSelectionBoundsChanged( 79 void TouchSelectionController::OnSelectionBoundsChanged(
79 const gfx::SelectionBound& start, 80 const gfx::SelectionBound& start,
80 const gfx::SelectionBound& end) { 81 const gfx::SelectionBound& end) {
81 if (!force_next_update_ && start == start_ && end_ == end) 82 if (!force_next_update_ && start == start_ && end_ == end)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DCHECK(end_selection_handle_); 172 DCHECK(end_selection_handle_);
172 start_selection_handle_->SetViewportRect(viewport_rect); 173 start_selection_handle_->SetViewportRect(viewport_rect);
173 end_selection_handle_->SetViewportRect(viewport_rect); 174 end_selection_handle_->SetViewportRect(viewport_rect);
174 } 175 }
175 176
176 // Update handle layout after setting the new Viewport size. 177 // Update handle layout after setting the new Viewport size.
177 UpdateHandleLayoutIfNecessary(); 178 UpdateHandleLayoutIfNecessary();
178 } 179 }
179 180
180 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { 181 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
181 if (config_.enable_longpress_drag_selection && 182 bool handled = WillHandleTouchEventImpl(event);
182 longpress_drag_selector_.WillHandleTouchEvent(event)) { 183 // If ACTION_DOWN is consumed, the rest of touch sequence should be consumed,
183 return true; 184 // too, regardless of value of |handled|.
184 } 185 // TODO(mohsen): This will consume touch events until the next ACTION_DOWN.
185 186 // Ideally we should consume until the final ACTION_UP/ACTION_CANCEL.
186 if (active_status_ == INSERTION_ACTIVE) { 187 // But, apparently, we can't reliably determine the final ACTION_CANCEL in a
187 DCHECK(insertion_handle_); 188 // multi-touch scenario. See https://crbug.com/653212.
188 return insertion_handle_->WillHandleTouchEvent(event); 189 if (event.GetAction() == MotionEvent::ACTION_DOWN)
189 } 190 consume_touch_sequence_ = handled;
190 191 return handled || consume_touch_sequence_;
191 if (active_status_ == SELECTION_ACTIVE) {
192 DCHECK(start_selection_handle_);
193 DCHECK(end_selection_handle_);
194 if (start_selection_handle_->IsActive())
195 return start_selection_handle_->WillHandleTouchEvent(event);
196
197 if (end_selection_handle_->IsActive())
198 return end_selection_handle_->WillHandleTouchEvent(event);
199
200 const gfx::PointF event_pos(event.GetX(), event.GetY());
201 if ((event_pos - GetStartPosition()).LengthSquared() <=
202 (event_pos - GetEndPosition()).LengthSquared()) {
203 return start_selection_handle_->WillHandleTouchEvent(event);
204 }
205 return end_selection_handle_->WillHandleTouchEvent(event);
206 }
207
208 return false;
209 } 192 }
210 193
211 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location, 194 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location,
212 int tap_count) { 195 int tap_count) {
213 if (WillHandleTapOrLongPress(location)) 196 if (WillHandleTapOrLongPress(location))
214 return true; 197 return true;
215 198
216 if (tap_count > 1) { 199 if (tap_count > 1) {
217 response_pending_input_event_ = REPEATED_TAP; 200 response_pending_input_event_ = REPEATED_TAP;
218 ShowSelectionHandlesAutomatically(); 201 ShowSelectionHandlesAutomatically();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 333 }
351 334
352 const gfx::PointF& TouchSelectionController::GetStartPosition() const { 335 const gfx::PointF& TouchSelectionController::GetStartPosition() const {
353 return start_.edge_bottom(); 336 return start_.edge_bottom();
354 } 337 }
355 338
356 const gfx::PointF& TouchSelectionController::GetEndPosition() const { 339 const gfx::PointF& TouchSelectionController::GetEndPosition() const {
357 return end_.edge_bottom(); 340 return end_.edge_bottom();
358 } 341 }
359 342
343 bool TouchSelectionController::WillHandleTouchEventImpl(
344 const MotionEvent& event) {
345 if (config_.enable_longpress_drag_selection &&
346 longpress_drag_selector_.WillHandleTouchEvent(event)) {
347 return true;
348 }
349
350 if (active_status_ == INSERTION_ACTIVE) {
351 DCHECK(insertion_handle_);
352 return insertion_handle_->WillHandleTouchEvent(event);
353 }
354
355 if (active_status_ == SELECTION_ACTIVE) {
356 DCHECK(start_selection_handle_);
357 DCHECK(end_selection_handle_);
358 if (start_selection_handle_->IsActive())
359 return start_selection_handle_->WillHandleTouchEvent(event);
360
361 if (end_selection_handle_->IsActive())
362 return end_selection_handle_->WillHandleTouchEvent(event);
363
364 const gfx::PointF event_pos(event.GetX(), event.GetY());
365 if ((event_pos - GetStartPosition()).LengthSquared() <=
366 (event_pos - GetEndPosition()).LengthSquared()) {
367 return start_selection_handle_->WillHandleTouchEvent(event);
368 }
369 return end_selection_handle_->WillHandleTouchEvent(event);
370 }
371
372 return false;
373 }
374
360 void TouchSelectionController::OnDragBegin( 375 void TouchSelectionController::OnDragBegin(
361 const TouchSelectionDraggable& draggable, 376 const TouchSelectionDraggable& draggable,
362 const gfx::PointF& drag_position) { 377 const gfx::PointF& drag_position) {
363 if (&draggable == insertion_handle_.get()) { 378 if (&draggable == insertion_handle_.get()) {
364 DCHECK_EQ(active_status_, INSERTION_ACTIVE); 379 DCHECK_EQ(active_status_, INSERTION_ACTIVE);
365 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED); 380 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED);
366 anchor_drag_to_selection_start_ = true; 381 anchor_drag_to_selection_start_ = true;
367 return; 382 return;
368 } 383 }
369 384
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 709 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
695 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 710 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
696 duration, 711 duration,
697 base::TimeDelta::FromMilliseconds(500), 712 base::TimeDelta::FromMilliseconds(500),
698 base::TimeDelta::FromSeconds(60), 713 base::TimeDelta::FromSeconds(60),
699 60); 714 60);
700 } 715 }
701 } 716 }
702 717
703 } // namespace ui 718 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698