Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) || consume_touch_sequence_; |
|
sadrul
2016/09/22 01:55:51
Reverse the order, so when |consume_touch_sequence
mohsen
2016/09/22 02:50:15
I actually want to call WillHandleTouchEventImpl()
sadrul
2016/09/22 03:10:33
Ah, I see. OK, in that case, either works. You cou
mohsen
2016/09/22 18:08:45
That would not work as the value of |consume_touch
| |
| 182 longpress_drag_selector_.WillHandleTouchEvent(event)) { | 183 switch (event.GetAction()) { |
| 183 return true; | 184 case MotionEvent::ACTION_DOWN: |
| 185 DCHECK(!consume_touch_sequence_); | |
| 186 // If ACTION_DOWN is consumed, the rest of the touch sequence should be | |
| 187 // consumed, too. | |
| 188 if (handled) | |
| 189 consume_touch_sequence_ = true; | |
| 190 break; | |
| 191 case MotionEvent::ACTION_UP: | |
| 192 case MotionEvent::ACTION_CANCEL: | |
| 193 consume_touch_sequence_ = false; | |
|
sadrul
2016/09/22 01:55:51
Should you check that this is the last pointer? (i
mohsen
2016/09/22 02:50:15
I was under the impression that ACTION_UP is retur
sadrul
2016/09/22 03:10:33
For UP, that does seem to be the case. Probably no
mohsen
2016/09/22 18:08:44
I could not conclude whether there is just one CAN
| |
| 194 break; | |
| 195 default: | |
| 196 break; | |
| 184 } | 197 } |
| 185 | 198 return handled; |
| 186 if (active_status_ == INSERTION_ACTIVE) { | |
| 187 DCHECK(insertion_handle_); | |
| 188 return insertion_handle_->WillHandleTouchEvent(event); | |
| 189 } | |
| 190 | |
| 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 } | 199 } |
| 210 | 200 |
| 211 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location, | 201 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location, |
| 212 int tap_count) { | 202 int tap_count) { |
| 213 if (WillHandleTapOrLongPress(location)) | 203 if (WillHandleTapOrLongPress(location)) |
| 214 return true; | 204 return true; |
| 215 | 205 |
| 216 if (tap_count > 1) { | 206 if (tap_count > 1) { |
| 217 response_pending_input_event_ = REPEATED_TAP; | 207 response_pending_input_event_ = REPEATED_TAP; |
| 218 ShowSelectionHandlesAutomatically(); | 208 ShowSelectionHandlesAutomatically(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 } | 340 } |
| 351 | 341 |
| 352 const gfx::PointF& TouchSelectionController::GetStartPosition() const { | 342 const gfx::PointF& TouchSelectionController::GetStartPosition() const { |
| 353 return start_.edge_bottom(); | 343 return start_.edge_bottom(); |
| 354 } | 344 } |
| 355 | 345 |
| 356 const gfx::PointF& TouchSelectionController::GetEndPosition() const { | 346 const gfx::PointF& TouchSelectionController::GetEndPosition() const { |
| 357 return end_.edge_bottom(); | 347 return end_.edge_bottom(); |
| 358 } | 348 } |
| 359 | 349 |
| 350 bool TouchSelectionController::WillHandleTouchEventImpl( | |
| 351 const MotionEvent& event) { | |
| 352 if (config_.enable_longpress_drag_selection && | |
| 353 longpress_drag_selector_.WillHandleTouchEvent(event)) { | |
| 354 return true; | |
| 355 } | |
| 356 | |
| 357 if (active_status_ == INSERTION_ACTIVE) { | |
| 358 DCHECK(insertion_handle_); | |
| 359 return insertion_handle_->WillHandleTouchEvent(event); | |
| 360 } | |
| 361 | |
| 362 if (active_status_ == SELECTION_ACTIVE) { | |
| 363 DCHECK(start_selection_handle_); | |
| 364 DCHECK(end_selection_handle_); | |
| 365 if (start_selection_handle_->IsActive()) | |
| 366 return start_selection_handle_->WillHandleTouchEvent(event); | |
| 367 | |
| 368 if (end_selection_handle_->IsActive()) | |
| 369 return end_selection_handle_->WillHandleTouchEvent(event); | |
| 370 | |
| 371 const gfx::PointF event_pos(event.GetX(), event.GetY()); | |
| 372 if ((event_pos - GetStartPosition()).LengthSquared() <= | |
| 373 (event_pos - GetEndPosition()).LengthSquared()) { | |
| 374 return start_selection_handle_->WillHandleTouchEvent(event); | |
| 375 } | |
| 376 return end_selection_handle_->WillHandleTouchEvent(event); | |
| 377 } | |
| 378 | |
| 379 return false; | |
| 380 } | |
| 381 | |
| 360 void TouchSelectionController::OnDragBegin( | 382 void TouchSelectionController::OnDragBegin( |
| 361 const TouchSelectionDraggable& draggable, | 383 const TouchSelectionDraggable& draggable, |
| 362 const gfx::PointF& drag_position) { | 384 const gfx::PointF& drag_position) { |
| 363 if (&draggable == insertion_handle_.get()) { | 385 if (&draggable == insertion_handle_.get()) { |
| 364 DCHECK_EQ(active_status_, INSERTION_ACTIVE); | 386 DCHECK_EQ(active_status_, INSERTION_ACTIVE); |
| 365 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED); | 387 client_->OnSelectionEvent(INSERTION_HANDLE_DRAG_STARTED); |
| 366 anchor_drag_to_selection_start_ = true; | 388 anchor_drag_to_selection_start_ = true; |
| 367 return; | 389 return; |
| 368 } | 390 } |
| 369 | 391 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 716 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 695 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 717 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 696 duration, | 718 duration, |
| 697 base::TimeDelta::FromMilliseconds(500), | 719 base::TimeDelta::FromMilliseconds(500), |
| 698 base::TimeDelta::FromSeconds(60), | 720 base::TimeDelta::FromSeconds(60), |
| 699 60); | 721 60); |
| 700 } | 722 } |
| 701 } | 723 } |
| 702 | 724 |
| 703 } // namespace ui | 725 } // namespace ui |
| OLD | NEW |