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

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: Changed duration's min to 500ms instead of 1000ms 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() {
64 } 66 }
65 67
66 void TouchSelectionController::OnSelectionBoundsChanged( 68 void TouchSelectionController::OnSelectionBoundsChanged(
67 const SelectionBound& start, 69 const SelectionBound& start,
68 const SelectionBound& end) { 70 const SelectionBound& end) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 234 }
233 235
234 gfx::PointF base, extent; 236 gfx::PointF base, extent;
235 if (&handle == start_selection_handle_.get()) { 237 if (&handle == start_selection_handle_.get()) {
236 base = end_selection_handle_->position() + GetEndLineOffset(); 238 base = end_selection_handle_->position() + GetEndLineOffset();
237 extent = start_selection_handle_->position() + GetStartLineOffset(); 239 extent = start_selection_handle_->position() + GetStartLineOffset();
238 } else { 240 } else {
239 base = start_selection_handle_->position() + GetStartLineOffset(); 241 base = start_selection_handle_->position() + GetStartLineOffset();
240 extent = end_selection_handle_->position() + GetEndLineOffset(); 242 extent = end_selection_handle_->position() + GetEndLineOffset();
241 } 243 }
244 selection_handle_dragged_ = true;
242 245
243 // When moving the handle we want to move only the extent point. Before doing 246 // 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. 247 // so we must make sure that the base point is set correctly.
245 client_->SelectBetweenCoordinates(base, extent); 248 client_->SelectBetweenCoordinates(base, extent);
246 249
247 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); 250 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position());
248 } 251 }
249 252
250 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, 253 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
251 const gfx::PointF& position) { 254 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_)); 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_handle_dragged_ = false;
397 selection_start_time_ = base::TimeTicks::Now();
389 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 398 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
390 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition()); 399 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition());
391 } 400 }
392 } 401 }
393 402
394 void TouchSelectionController::DeactivateSelection() { 403 void TouchSelectionController::DeactivateSelection() {
395 if (!is_selection_active_) 404 if (!is_selection_active_)
396 return; 405 return;
397 DCHECK(start_selection_handle_); 406 DCHECK(start_selection_handle_);
398 DCHECK(end_selection_handle_); 407 DCHECK(end_selection_handle_);
408 LogSelectionEnd();
399 start_selection_handle_->SetEnabled(false); 409 start_selection_handle_->SetEnabled(false);
400 end_selection_handle_->SetEnabled(false); 410 end_selection_handle_->SetEnabled(false);
401 is_selection_active_ = false; 411 is_selection_active_ = false;
402 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); 412 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF());
403 } 413 }
404 414
405 void TouchSelectionController::ResetCachedValuesIfInactive() { 415 void TouchSelectionController::ResetCachedValuesIfInactive() {
406 if (is_selection_active_ || is_insertion_active_) 416 if (is_selection_active_ || is_insertion_active_)
407 return; 417 return;
408 start_ = SelectionBound(); 418 start_ = SelectionBound();
(...skipping 26 matching lines...) Expand all
435 return end_.visible() && !temporarily_hidden_; 445 return end_.visible() && !temporarily_hidden_;
436 } 446 }
437 447
438 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 448 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
439 bool was_active) const { 449 bool was_active) const {
440 return was_active && client_->SupportsAnimation() 450 return was_active && client_->SupportsAnimation()
441 ? TouchHandle::ANIMATION_SMOOTH 451 ? TouchHandle::ANIMATION_SMOOTH
442 : TouchHandle::ANIMATION_NONE; 452 : TouchHandle::ANIMATION_NONE;
443 } 453 }
444 454
455 void TouchSelectionController::LogSelectionEnd() {
456 // TODO(mfomitchev): Once we are able to tell the difference between
457 // 'successful' and 'unsuccessful' selections - log
458 // Event.TouchSelection.Duration instead and get rid of
459 // Event.TouchSelectionD.WasDraggeduration.
460 if (selection_handle_dragged_) {
461 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
462 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
463 duration,
464 base::TimeDelta::FromMilliseconds(500),
465 base::TimeDelta::FromSeconds(60),
466 60);
467 }
468 }
469
445 } // namespace ui 470 } // 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