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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/touch_selection/touch_selection_controller.cc
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc
index 09f0e4b020bf7ba7398cbd727b405a0015ade221..80fa76fde4e8008e91c4f9e8d2a7a0a0721de3b0 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -68,7 +68,8 @@ TouchSelectionController::TouchSelectionController(
temporarily_hidden_(false),
anchor_drag_to_selection_start_(false),
longpress_drag_selector_(this),
- selection_handle_dragged_(false) {
+ selection_handle_dragged_(false),
+ consume_touch_sequence_(false) {
DCHECK(client_);
}
@@ -178,34 +179,16 @@ void TouchSelectionController::OnViewportChanged(
}
bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
- if (config_.enable_longpress_drag_selection &&
- longpress_drag_selector_.WillHandleTouchEvent(event)) {
- return true;
- }
-
- if (active_status_ == INSERTION_ACTIVE) {
- DCHECK(insertion_handle_);
- return insertion_handle_->WillHandleTouchEvent(event);
- }
-
- if (active_status_ == SELECTION_ACTIVE) {
- DCHECK(start_selection_handle_);
- DCHECK(end_selection_handle_);
- if (start_selection_handle_->IsActive())
- return start_selection_handle_->WillHandleTouchEvent(event);
-
- if (end_selection_handle_->IsActive())
- return end_selection_handle_->WillHandleTouchEvent(event);
-
- const gfx::PointF event_pos(event.GetX(), event.GetY());
- if ((event_pos - GetStartPosition()).LengthSquared() <=
- (event_pos - GetEndPosition()).LengthSquared()) {
- return start_selection_handle_->WillHandleTouchEvent(event);
- }
- return end_selection_handle_->WillHandleTouchEvent(event);
- }
-
- return false;
+ bool handled = WillHandleTouchEventImpl(event);
+ // If ACTION_DOWN is consumed, the rest of touch sequence should be consumed,
+ // too, regardless of value of |handled|.
+ // TODO(mohsen): This will consume touch events until the next ACTION_DOWN.
+ // Ideally we should consume until the final ACTION_UP/ACTION_CANCEL.
+ // But, apparently, we can't reliably determine the final ACTION_CANCEL in a
+ // multi-touch scenario. See https://crbug.com/653212.
+ if (event.GetAction() == MotionEvent::ACTION_DOWN)
+ consume_touch_sequence_ = handled;
+ return handled || consume_touch_sequence_;
}
bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location,
@@ -357,6 +340,38 @@ const gfx::PointF& TouchSelectionController::GetEndPosition() const {
return end_.edge_bottom();
}
+bool TouchSelectionController::WillHandleTouchEventImpl(
+ const MotionEvent& event) {
+ if (config_.enable_longpress_drag_selection &&
+ longpress_drag_selector_.WillHandleTouchEvent(event)) {
+ return true;
+ }
+
+ if (active_status_ == INSERTION_ACTIVE) {
+ DCHECK(insertion_handle_);
+ return insertion_handle_->WillHandleTouchEvent(event);
+ }
+
+ if (active_status_ == SELECTION_ACTIVE) {
+ DCHECK(start_selection_handle_);
+ DCHECK(end_selection_handle_);
+ if (start_selection_handle_->IsActive())
+ return start_selection_handle_->WillHandleTouchEvent(event);
+
+ if (end_selection_handle_->IsActive())
+ return end_selection_handle_->WillHandleTouchEvent(event);
+
+ const gfx::PointF event_pos(event.GetX(), event.GetY());
+ if ((event_pos - GetStartPosition()).LengthSquared() <=
+ (event_pos - GetEndPosition()).LengthSquared()) {
+ return start_selection_handle_->WillHandleTouchEvent(event);
+ }
+ return end_selection_handle_->WillHandleTouchEvent(event);
+ }
+
+ return false;
+}
+
void TouchSelectionController::OnDragBegin(
const TouchSelectionDraggable& draggable,
const gfx::PointF& drag_position) {
« 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