OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/views/touchui/touch_selection_controller_impl.h" | 5 #include "ui/views/touchui/touch_selection_controller_impl.h" |
6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" |
7 #include "base/time/time.h" | 8 #include "base/time/time.h" |
8 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
9 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
10 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
16 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 selection_handle_1_(new EditingHandleView(this, | 409 selection_handle_1_(new EditingHandleView(this, |
409 client_view->GetNativeView(), | 410 client_view->GetNativeView(), |
410 false)), | 411 false)), |
411 selection_handle_2_(new EditingHandleView(this, | 412 selection_handle_2_(new EditingHandleView(this, |
412 client_view->GetNativeView(), | 413 client_view->GetNativeView(), |
413 false)), | 414 false)), |
414 cursor_handle_(new EditingHandleView(this, | 415 cursor_handle_(new EditingHandleView(this, |
415 client_view->GetNativeView(), | 416 client_view->GetNativeView(), |
416 true)), | 417 true)), |
417 context_menu_(nullptr), | 418 context_menu_(nullptr), |
| 419 command_executed_(false), |
418 dragging_handle_(nullptr) { | 420 dragging_handle_(nullptr) { |
| 421 selection_start_time_ = base::TimeTicks::Now(); |
419 aura::Window* client_window = client_view_->GetNativeView(); | 422 aura::Window* client_window = client_view_->GetNativeView(); |
420 client_window->AddObserver(this); | 423 client_window->AddObserver(this); |
421 client_widget_ = Widget::GetTopLevelWidgetForNativeView(client_window); | 424 client_widget_ = Widget::GetTopLevelWidgetForNativeView(client_window); |
422 if (client_widget_) | 425 if (client_widget_) |
423 client_widget_->AddObserver(this); | 426 client_widget_->AddObserver(this); |
424 aura::Env::GetInstance()->AddPreTargetHandler(this); | 427 aura::Env::GetInstance()->AddPreTargetHandler(this); |
425 } | 428 } |
426 | 429 |
427 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { | 430 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { |
| 431 UMA_HISTOGRAM_BOOLEAN("Event.TouchSelection.EndedWithAction", |
| 432 command_executed_); |
428 HideContextMenu(); | 433 HideContextMenu(); |
429 aura::Env::GetInstance()->RemovePreTargetHandler(this); | 434 aura::Env::GetInstance()->RemovePreTargetHandler(this); |
430 if (client_widget_) | 435 if (client_widget_) |
431 client_widget_->RemoveObserver(this); | 436 client_widget_->RemoveObserver(this); |
432 client_view_->GetNativeView()->RemoveObserver(this); | 437 client_view_->GetNativeView()->RemoveObserver(this); |
433 } | 438 } |
434 | 439 |
435 void TouchSelectionControllerImpl::SelectionChanged() { | 440 void TouchSelectionControllerImpl::SelectionChanged() { |
436 ui::SelectionBound anchor, focus; | 441 ui::SelectionBound anchor, focus; |
437 client_view_->GetSelectionEndPoints(&anchor, &focus); | 442 client_view_->GetSelectionEndPoints(&anchor, &focus); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 client_bounds.Inset(0, 0, 0, -kSelectionHandleBarBottomAllowance); | 592 client_bounds.Inset(0, 0, 0, -kSelectionHandleBarBottomAllowance); |
588 return client_bounds.Contains(BoundToRect(bound)); | 593 return client_bounds.Contains(BoundToRect(bound)); |
589 } | 594 } |
590 | 595 |
591 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { | 596 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { |
592 return client_view_->IsCommandIdEnabled(command_id); | 597 return client_view_->IsCommandIdEnabled(command_id); |
593 } | 598 } |
594 | 599 |
595 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, | 600 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, |
596 int event_flags) { | 601 int event_flags) { |
| 602 command_executed_ = true; |
| 603 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; |
| 604 // Note that we only log the duration stats for the 'successful' selections, |
| 605 // i.e. selections ending with the execution of a command. |
| 606 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.Duration", |
| 607 duration, |
| 608 base::TimeDelta::FromMilliseconds(500), |
| 609 base::TimeDelta::FromSeconds(60), |
| 610 60); |
597 HideContextMenu(); | 611 HideContextMenu(); |
598 client_view_->ExecuteCommand(command_id, event_flags); | 612 client_view_->ExecuteCommand(command_id, event_flags); |
599 } | 613 } |
600 | 614 |
601 void TouchSelectionControllerImpl::OpenContextMenu() { | 615 void TouchSelectionControllerImpl::OpenContextMenu() { |
602 // Context menu should appear centered on top of the selected region. | 616 // Context menu should appear centered on top of the selected region. |
603 const gfx::Rect rect = context_menu_->GetAnchorRect(); | 617 const gfx::Rect rect = context_menu_->GetAnchorRect(); |
604 const gfx::Point anchor(rect.CenterPoint().x(), rect.y()); | 618 const gfx::Point anchor(rect.CenterPoint().x(), rect.y()); |
605 HideContextMenu(); | 619 HideContextMenu(); |
606 client_view_->OpenContextMenu(anchor); | 620 client_view_->OpenContextMenu(anchor); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 749 |
736 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { | 750 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { |
737 return selection_handle_1_.get(); | 751 return selection_handle_1_.get(); |
738 } | 752 } |
739 | 753 |
740 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { | 754 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { |
741 return selection_handle_2_.get(); | 755 return selection_handle_2_.get(); |
742 } | 756 } |
743 | 757 |
744 } // namespace views | 758 } // namespace views |
OLD | NEW |