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 | 10 |
| 10 namespace ui { | 11 namespace ui { |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) { | 14 gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) { |
| 14 gfx::Vector2dF line_offset = | 15 gfx::Vector2dF line_offset = |
| 15 gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f); | 16 gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f); |
| 16 // An offset of 5 DIPs is sufficient for most line sizes. For small lines, | 17 // An offset of 5 DIPs is sufficient for most line sizes. For small lines, |
| 17 // using half the line height avoids synthesizing a point on a line above | 18 // using half the line height avoids synthesizing a point on a line above |
| 18 // (or below) the intended line. | 19 // (or below) the intended line. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 is_selection_active_(false), | 55 is_selection_active_(false), |
| 55 activate_selection_automatically_(false), | 56 activate_selection_automatically_(false), |
| 56 selection_empty_(false), | 57 selection_empty_(false), |
| 57 selection_editable_(false), | 58 selection_editable_(false), |
| 58 temporarily_hidden_(false) { | 59 temporarily_hidden_(false) { |
| 59 DCHECK(client_); | 60 DCHECK(client_); |
| 60 HideAndDisallowShowingAutomatically(); | 61 HideAndDisallowShowingAutomatically(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 TouchSelectionController::~TouchSelectionController() { | 64 TouchSelectionController::~TouchSelectionController() { |
| 65 if (is_selection_active_) | |
| 66 LogSelectionEnd(); | |
| 64 } | 67 } |
| 65 | 68 |
| 66 void TouchSelectionController::OnSelectionBoundsChanged( | 69 void TouchSelectionController::OnSelectionBoundsChanged( |
| 67 const SelectionBound& start, | 70 const SelectionBound& start, |
| 68 const SelectionBound& end) { | 71 const SelectionBound& end) { |
| 69 if (start == start_ && end_ == end) | 72 if (start == start_ && end_ == end) |
| 70 return; | 73 return; |
| 71 | 74 |
| 72 start_ = start; | 75 start_ = start; |
| 73 end_ = end; | 76 end_ = end; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); | 381 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); |
| 379 } else { | 382 } else { |
| 380 end_selection_handle_->SetEnabled(true); | 383 end_selection_handle_->SetEnabled(true); |
| 381 end_selection_handle_->SetOrientation(end_orientation_); | 384 end_selection_handle_->SetOrientation(end_orientation_); |
| 382 } | 385 } |
| 383 | 386 |
| 384 // As a long press received while a selection is already active may trigger | 387 // As a long press received while a selection is already active may trigger |
| 385 // an entirely new selection, notify the client but avoid sending an | 388 // an entirely new selection, notify the client but avoid sending an |
| 386 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. | 389 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. |
| 387 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { | 390 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { |
| 391 if (is_selection_active_) { | |
| 392 // The active selection session finishes with the start of the new one. | |
| 393 LogSelectionEnd(); | |
| 394 } | |
| 388 is_selection_active_ = true; | 395 is_selection_active_ = true; |
| 396 selection_start_time_ = base::TimeTicks::Now(); | |
| 389 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; | 397 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; |
| 390 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition()); | 398 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition()); |
| 391 } | 399 } |
| 392 } | 400 } |
| 393 | 401 |
| 394 void TouchSelectionController::DeactivateSelection() { | 402 void TouchSelectionController::DeactivateSelection() { |
| 395 if (!is_selection_active_) | 403 if (!is_selection_active_) |
| 396 return; | 404 return; |
| 397 DCHECK(start_selection_handle_); | 405 DCHECK(start_selection_handle_); |
| 398 DCHECK(end_selection_handle_); | 406 DCHECK(end_selection_handle_); |
| 407 LogSelectionEnd(); | |
| 399 start_selection_handle_->SetEnabled(false); | 408 start_selection_handle_->SetEnabled(false); |
| 400 end_selection_handle_->SetEnabled(false); | 409 end_selection_handle_->SetEnabled(false); |
| 401 is_selection_active_ = false; | 410 is_selection_active_ = false; |
| 402 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); | 411 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); |
| 403 } | 412 } |
| 404 | 413 |
| 405 void TouchSelectionController::ResetCachedValuesIfInactive() { | 414 void TouchSelectionController::ResetCachedValuesIfInactive() { |
| 406 if (is_selection_active_ || is_insertion_active_) | 415 if (is_selection_active_ || is_insertion_active_) |
| 407 return; | 416 return; |
| 408 start_ = SelectionBound(); | 417 start_ = SelectionBound(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 435 return end_.visible() && !temporarily_hidden_; | 444 return end_.visible() && !temporarily_hidden_; |
| 436 } | 445 } |
| 437 | 446 |
| 438 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 447 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
| 439 bool was_active) const { | 448 bool was_active) const { |
| 440 return was_active && client_->SupportsAnimation() | 449 return was_active && client_->SupportsAnimation() |
| 441 ? TouchHandle::ANIMATION_SMOOTH | 450 ? TouchHandle::ANIMATION_SMOOTH |
| 442 : TouchHandle::ANIMATION_NONE; | 451 : TouchHandle::ANIMATION_NONE; |
| 443 } | 452 } |
| 444 | 453 |
| 454 void TouchSelectionController::LogSelectionEnd() { | |
|
jdduke (slow)
2015/02/09 16:10:56
Hmm, on second thought, if this will need to chang
mfomitchev
2015/02/09 17:09:32
My hope is that getting this into M42 will help us
| |
| 455 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; | |
| 456 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelectionDuration", | |
| 457 duration, | |
| 458 base::TimeDelta::FromMilliseconds(1), | |
| 459 base::TimeDelta::FromSeconds(60), | |
| 460 50); | |
| 461 } | |
| 462 | |
| 445 } // namespace ui | 463 } // namespace ui |
| OLD | NEW |