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

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

Issue 895903003: Adding UMA logging to touch text selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback. Created 5 years, 10 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 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 29 matching lines...) Expand all
48 tap_slop_(tap_slop), 49 tap_slop_(tap_slop),
49 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), 50 response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
50 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 51 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED),
51 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 52 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED),
52 is_insertion_active_(false), 53 is_insertion_active_(false),
53 activate_insertion_automatically_(false), 54 activate_insertion_automatically_(false),
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),
60 selection_handle_dragged_(false) {
59 DCHECK(client_); 61 DCHECK(client_);
60 HideAndDisallowShowingAutomatically(); 62 HideAndDisallowShowingAutomatically();
61 } 63 }
62 64
63 TouchSelectionController::~TouchSelectionController() { 65 TouchSelectionController::~TouchSelectionController() {
66 if (is_selection_active_)
67 LogSelectionEnd();
64 } 68 }
65 69
66 void TouchSelectionController::OnSelectionBoundsChanged( 70 void TouchSelectionController::OnSelectionBoundsChanged(
67 const SelectionBound& start, 71 const SelectionBound& start,
68 const SelectionBound& end) { 72 const SelectionBound& end) {
69 if (start == start_ && end_ == end) 73 if (start == start_ && end_ == end)
70 return; 74 return;
71 75
72 start_ = start; 76 start_ = start;
73 end_ = end; 77 end_ = end;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 236 }
233 237
234 gfx::PointF base, extent; 238 gfx::PointF base, extent;
235 if (&handle == start_selection_handle_.get()) { 239 if (&handle == start_selection_handle_.get()) {
236 base = end_selection_handle_->position() + GetEndLineOffset(); 240 base = end_selection_handle_->position() + GetEndLineOffset();
237 extent = start_selection_handle_->position() + GetStartLineOffset(); 241 extent = start_selection_handle_->position() + GetStartLineOffset();
238 } else { 242 } else {
239 base = start_selection_handle_->position() + GetStartLineOffset(); 243 base = start_selection_handle_->position() + GetStartLineOffset();
240 extent = end_selection_handle_->position() + GetEndLineOffset(); 244 extent = end_selection_handle_->position() + GetEndLineOffset();
241 } 245 }
246 selection_handle_dragged_ = true;
242 247
243 // When moving the handle we want to move only the extent point. Before doing 248 // When moving the handle we want to move only the extent point. Before doing
244 // so we must make sure that the base point is set correctly. 249 // so we must make sure that the base point is set correctly.
245 client_->SelectBetweenCoordinates(base, extent); 250 client_->SelectBetweenCoordinates(base, extent);
246 251
247 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); 252 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position());
248 } 253 }
249 254
250 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 255 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
251 const gfx::PointF& position) { 256 const gfx::PointF& position) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 383 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
379 } else { 384 } else {
380 end_selection_handle_->SetEnabled(true); 385 end_selection_handle_->SetEnabled(true);
381 end_selection_handle_->SetOrientation(end_orientation_); 386 end_selection_handle_->SetOrientation(end_orientation_);
382 } 387 }
383 388
384 // As a long press received while a selection is already active may trigger 389 // 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 390 // an entirely new selection, notify the client but avoid sending an
386 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. 391 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
387 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { 392 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) {
393 if (is_selection_active_) {
394 // The active selection session finishes with the start of the new one.
395 LogSelectionEnd();
396 }
388 is_selection_active_ = true; 397 is_selection_active_ = true;
398 selection_handle_dragged_ = false;
399 selection_start_time_ = base::TimeTicks::Now();
389 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 400 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
390 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition()); 401 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition());
391 } 402 }
392 } 403 }
393 404
394 void TouchSelectionController::DeactivateSelection() { 405 void TouchSelectionController::DeactivateSelection() {
395 if (!is_selection_active_) 406 if (!is_selection_active_)
396 return; 407 return;
397 DCHECK(start_selection_handle_); 408 DCHECK(start_selection_handle_);
398 DCHECK(end_selection_handle_); 409 DCHECK(end_selection_handle_);
410 LogSelectionEnd();
399 start_selection_handle_->SetEnabled(false); 411 start_selection_handle_->SetEnabled(false);
400 end_selection_handle_->SetEnabled(false); 412 end_selection_handle_->SetEnabled(false);
401 is_selection_active_ = false; 413 is_selection_active_ = false;
402 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); 414 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF());
403 } 415 }
404 416
405 void TouchSelectionController::ResetCachedValuesIfInactive() { 417 void TouchSelectionController::ResetCachedValuesIfInactive() {
406 if (is_selection_active_ || is_insertion_active_) 418 if (is_selection_active_ || is_insertion_active_)
407 return; 419 return;
408 start_ = SelectionBound(); 420 start_ = SelectionBound();
(...skipping 26 matching lines...) Expand all
435 return end_.visible() && !temporarily_hidden_; 447 return end_.visible() && !temporarily_hidden_;
436 } 448 }
437 449
438 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 450 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
439 bool was_active) const { 451 bool was_active) const {
440 return was_active && client_->SupportsAnimation() 452 return was_active && client_->SupportsAnimation()
441 ? TouchHandle::ANIMATION_SMOOTH 453 ? TouchHandle::ANIMATION_SMOOTH
442 : TouchHandle::ANIMATION_NONE; 454 : TouchHandle::ANIMATION_NONE;
443 } 455 }
444 456
457 void TouchSelectionController::LogSelectionEnd() {
458 // Don't log the duration for the case when the selection handles are not
459 // dragged at all during the selection session - it's not very interesting,
460 // plus this may be an accidental selection.
461 // TODO(mfomitchev): Once we are able to tell between 'successful' and
462 // 'unsuccessful' selections - only log the time stats for successful
463 // selection. Successful selections are the ones ending with an execution of a
464 // copy/cut/paste command.
465 if (selection_handle_dragged_) {
jdduke (slow) 2015/02/09 19:24:48 I was thinking we'd only log the cumulative durati
mfomitchev 2015/02/09 19:39:26 I don't like logging individual drags b/c that can
466 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
467 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelectionDuration",
468 duration,
469 base::TimeDelta::FromMilliseconds(1),
470 base::TimeDelta::FromSeconds(60),
471 50);
472 }
473 }
474
445 } // namespace ui 475 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | ui/views/touchui/touch_selection_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698