| 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 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), | 52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), |
| 53 start_orientation_(TouchHandleOrientation::UNDEFINED), | 53 start_orientation_(TouchHandleOrientation::UNDEFINED), |
| 54 end_orientation_(TouchHandleOrientation::UNDEFINED), | 54 end_orientation_(TouchHandleOrientation::UNDEFINED), |
| 55 is_insertion_active_(false), | 55 is_insertion_active_(false), |
| 56 activate_insertion_automatically_(false), | 56 activate_insertion_automatically_(false), |
| 57 is_selection_active_(false), | 57 is_selection_active_(false), |
| 58 activate_selection_automatically_(false), | 58 activate_selection_automatically_(false), |
| 59 selection_empty_(false), | 59 selection_empty_(false), |
| 60 selection_editable_(false), | 60 selection_editable_(false), |
| 61 temporarily_hidden_(false), | 61 temporarily_hidden_(false), |
| 62 viewport_size_changed_(false), |
| 62 selection_handle_dragged_(false) { | 63 selection_handle_dragged_(false) { |
| 63 DCHECK(client_); | 64 DCHECK(client_); |
| 64 } | 65 } |
| 65 | 66 |
| 66 TouchSelectionController::~TouchSelectionController() { | 67 TouchSelectionController::~TouchSelectionController() { |
| 67 } | 68 } |
| 68 | 69 |
| 70 void TouchSelectionController::OnViewportChanged( |
| 71 const gfx::RectF viewport_rect) { |
| 72 if (viewport_rect_ == viewport_rect) |
| 73 return; |
| 74 viewport_size_changed_ = true; |
| 75 viewport_rect_ = viewport_rect; |
| 76 } |
| 77 |
| 69 void TouchSelectionController::OnSelectionBoundsChanged( | 78 void TouchSelectionController::OnSelectionBoundsChanged( |
| 70 const SelectionBound& start, | 79 const SelectionBound& start, |
| 71 const SelectionBound& end) { | 80 const SelectionBound& end) { |
| 72 if (start == start_ && end_ == end) | 81 if (start == start_ && end_ == end && !viewport_size_changed_) |
| 73 return; | 82 return; |
| 74 | 83 |
| 75 start_ = start; | 84 start_ = start; |
| 76 end_ = end; | 85 end_ = end; |
| 77 start_orientation_ = ToTouchHandleOrientation(start_.type()); | 86 start_orientation_ = ToTouchHandleOrientation(start_.type()); |
| 78 end_orientation_ = ToTouchHandleOrientation(end_.type()); | 87 end_orientation_ = ToTouchHandleOrientation(end_.type()); |
| 88 viewport_size_changed_ = false; |
| 79 | 89 |
| 80 if (!activate_selection_automatically_ && | 90 if (!activate_selection_automatically_ && |
| 81 !activate_insertion_automatically_) { | 91 !activate_insertion_automatically_) { |
| 82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); | 92 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); |
| 83 return; | 93 return; |
| 84 } | 94 } |
| 85 | 95 |
| 86 // Ensure that |response_pending_input_event_| is cleared after the method | 96 // Ensure that |response_pending_input_event_| is cleared after the method |
| 87 // completes, while also making its current value available for the duration | 97 // completes, while also making its current value available for the duration |
| 88 // of the call. | 98 // of the call. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 334 |
| 325 const bool was_active = is_insertion_active_; | 335 const bool was_active = is_insertion_active_; |
| 326 const gfx::PointF position = GetStartPosition(); | 336 const gfx::PointF position = GetStartPosition(); |
| 327 if (!is_insertion_active_) | 337 if (!is_insertion_active_) |
| 328 ActivateInsertion(); | 338 ActivateInsertion(); |
| 329 else | 339 else |
| 330 client_->OnSelectionEvent(INSERTION_MOVED, position); | 340 client_->OnSelectionEvent(INSERTION_MOVED, position); |
| 331 | 341 |
| 332 insertion_handle_->SetVisible(GetStartVisible(), | 342 insertion_handle_->SetVisible(GetStartVisible(), |
| 333 GetAnimationStyle(was_active)); | 343 GetAnimationStyle(was_active)); |
| 334 insertion_handle_->SetPosition(position); | 344 insertion_handle_->UpdatePosition(); |
| 335 } | 345 } |
| 336 | 346 |
| 337 void TouchSelectionController::OnSelectionChanged() { | 347 void TouchSelectionController::OnSelectionChanged() { |
| 338 DeactivateInsertion(); | 348 DeactivateInsertion(); |
| 339 | 349 |
| 340 if (!activate_selection_automatically_) | 350 if (!activate_selection_automatically_) |
| 341 return; | 351 return; |
| 342 | 352 |
| 343 const bool was_active = is_selection_active_; | 353 const bool was_active = is_selection_active_; |
| 344 ActivateSelection(); | 354 ActivateSelection(); |
| 345 | 355 |
| 346 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); | 356 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); |
| 347 start_selection_handle_->SetVisible(GetStartVisible(), animation); | 357 start_selection_handle_->SetVisible(GetStartVisible(), animation); |
| 348 end_selection_handle_->SetVisible(GetEndVisible(), animation); | 358 end_selection_handle_->SetVisible(GetEndVisible(), animation); |
| 349 | 359 |
| 350 start_selection_handle_->SetPosition(GetStartPosition()); | 360 start_selection_handle_->UpdatePosition(); |
| 351 end_selection_handle_->SetPosition(GetEndPosition()); | 361 end_selection_handle_->UpdatePosition(); |
| 352 } | 362 } |
| 353 | 363 |
| 354 void TouchSelectionController::ActivateInsertion() { | 364 void TouchSelectionController::ActivateInsertion() { |
| 355 DCHECK(!is_selection_active_); | 365 DCHECK(!is_selection_active_); |
| 356 | 366 |
| 357 if (!insertion_handle_) | 367 if (!insertion_handle_) |
| 358 insertion_handle_.reset( | 368 insertion_handle_.reset( |
| 359 new TouchHandle(this, TouchHandleOrientation::CENTER)); | 369 new TouchHandle(this, TouchHandleOrientation::CENTER)); |
| 360 | 370 |
| 361 if (!is_insertion_active_) { | 371 if (!is_insertion_active_) { |
| 362 is_insertion_active_ = true; | 372 is_insertion_active_ = true; |
| 363 insertion_handle_->SetEnabled(true); | 373 insertion_handle_->SetEnabled(true); |
| 374 insertion_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
| 375 insertion_handle_->SetViewportRect(viewport_rect_); |
| 364 client_->OnSelectionEvent(INSERTION_SHOWN, GetStartPosition()); | 376 client_->OnSelectionEvent(INSERTION_SHOWN, GetStartPosition()); |
| 365 } | 377 } |
| 366 } | 378 } |
| 367 | 379 |
| 368 void TouchSelectionController::DeactivateInsertion() { | 380 void TouchSelectionController::DeactivateInsertion() { |
| 369 if (!is_insertion_active_) | 381 if (!is_insertion_active_) |
| 370 return; | 382 return; |
| 371 DCHECK(insertion_handle_); | 383 DCHECK(insertion_handle_); |
| 372 is_insertion_active_ = false; | 384 is_insertion_active_ = false; |
| 373 insertion_handle_->SetEnabled(false); | 385 insertion_handle_->SetEnabled(false); |
| 374 client_->OnSelectionEvent(INSERTION_CLEARED, gfx::PointF()); | 386 client_->OnSelectionEvent(INSERTION_CLEARED, gfx::PointF()); |
| 375 } | 387 } |
| 376 | 388 |
| 377 void TouchSelectionController::ActivateSelection() { | 389 void TouchSelectionController::ActivateSelection() { |
| 378 DCHECK(!is_insertion_active_); | 390 DCHECK(!is_insertion_active_); |
| 379 | 391 |
| 380 if (!start_selection_handle_) { | 392 if (!start_selection_handle_) { |
| 381 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); | 393 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); |
| 382 } else { | 394 } else { |
| 383 start_selection_handle_->SetEnabled(true); | 395 start_selection_handle_->SetEnabled(true); |
| 396 start_selection_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
| 397 start_selection_handle_->SetViewportRect(viewport_rect_); |
| 384 start_selection_handle_->SetOrientation(start_orientation_); | 398 start_selection_handle_->SetOrientation(start_orientation_); |
| 385 } | 399 } |
| 386 | 400 |
| 387 if (!end_selection_handle_) { | 401 if (!end_selection_handle_) { |
| 388 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); | 402 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); |
| 389 } else { | 403 } else { |
| 390 end_selection_handle_->SetEnabled(true); | 404 end_selection_handle_->SetEnabled(true); |
| 405 end_selection_handle_->SetFocus(end_.edge_top(), end_.edge_bottom()); |
| 406 end_selection_handle_->SetViewportRect(viewport_rect_); |
| 391 end_selection_handle_->SetOrientation(end_orientation_); | 407 end_selection_handle_->SetOrientation(end_orientation_); |
| 392 } | 408 } |
| 393 | 409 |
| 394 // As a long press received while a selection is already active may trigger | 410 // As a long press received while a selection is already active may trigger |
| 395 // an entirely new selection, notify the client but avoid sending an | 411 // an entirely new selection, notify the client but avoid sending an |
| 396 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. | 412 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. |
| 397 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { | 413 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { |
| 398 if (is_selection_active_) { | 414 if (is_selection_active_) { |
| 399 // The active selection session finishes with the start of the new one. | 415 // The active selection session finishes with the start of the new one. |
| 400 LogSelectionEnd(); | 416 LogSelectionEnd(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | 484 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 469 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", | 485 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", |
| 470 duration, | 486 duration, |
| 471 base::TimeDelta::FromMilliseconds(500), | 487 base::TimeDelta::FromMilliseconds(500), |
| 472 base::TimeDelta::FromSeconds(60), | 488 base::TimeDelta::FromSeconds(60), |
| 473 60); | 489 60); |
| 474 } | 490 } |
| 475 } | 491 } |
| 476 | 492 |
| 477 } // namespace ui | 493 } // namespace ui |
| OLD | NEW |