| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 selection_handle_2_(new EditingHandleView(this, | 439 selection_handle_2_(new EditingHandleView(this, |
| 440 client_view->GetNativeView(), | 440 client_view->GetNativeView(), |
| 441 false)), | 441 false)), |
| 442 cursor_handle_(new EditingHandleView(this, | 442 cursor_handle_(new EditingHandleView(this, |
| 443 client_view->GetNativeView(), | 443 client_view->GetNativeView(), |
| 444 true)), | 444 true)), |
| 445 command_executed_(false), | 445 command_executed_(false), |
| 446 dragging_handle_(nullptr) { | 446 dragging_handle_(nullptr) { |
| 447 selection_start_time_ = base::TimeTicks::Now(); | 447 selection_start_time_ = base::TimeTicks::Now(); |
| 448 aura::Window* client_window = client_view_->GetNativeView(); | 448 aura::Window* client_window = client_view_->GetNativeView(); |
| 449 client_window->AddObserver(this); | |
| 450 client_widget_ = Widget::GetTopLevelWidgetForNativeView(client_window); | 449 client_widget_ = Widget::GetTopLevelWidgetForNativeView(client_window); |
| 451 if (client_widget_) | 450 if (client_widget_) |
| 452 client_widget_->AddObserver(this); | 451 client_widget_->AddObserver(this); |
| 453 aura::Env::GetInstance()->AddPreTargetHandler(this); | 452 aura::Env::GetInstance()->AddPreTargetHandler(this); |
| 454 } | 453 } |
| 455 | 454 |
| 456 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { | 455 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { |
| 457 UMA_HISTOGRAM_BOOLEAN("Event.TouchSelection.EndedWithAction", | 456 UMA_HISTOGRAM_BOOLEAN("Event.TouchSelection.EndedWithAction", |
| 458 command_executed_); | 457 command_executed_); |
| 459 HideQuickMenu(); | 458 HideQuickMenu(); |
| 460 aura::Env::GetInstance()->RemovePreTargetHandler(this); | 459 aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| 461 if (client_widget_) | 460 if (client_widget_) |
| 462 client_widget_->RemoveObserver(this); | 461 client_widget_->RemoveObserver(this); |
| 463 client_view_->GetNativeView()->RemoveObserver(this); | |
| 464 } | 462 } |
| 465 | 463 |
| 466 void TouchSelectionControllerImpl::SelectionChanged() { | 464 void TouchSelectionControllerImpl::SelectionChanged() { |
| 467 gfx::SelectionBound anchor, focus; | 465 gfx::SelectionBound anchor, focus; |
| 468 client_view_->GetSelectionEndPoints(&anchor, &focus); | 466 client_view_->GetSelectionEndPoints(&anchor, &focus); |
| 469 gfx::SelectionBound screen_bound_anchor = | 467 gfx::SelectionBound screen_bound_anchor = |
| 470 ConvertToScreen(client_view_, anchor); | 468 ConvertToScreen(client_view_, anchor); |
| 471 gfx::SelectionBound screen_bound_focus = ConvertToScreen(client_view_, focus); | 469 gfx::SelectionBound screen_bound_focus = ConvertToScreen(client_view_, focus); |
| 472 gfx::Rect client_bounds = client_view_->GetBounds(); | 470 gfx::Rect client_bounds = client_view_->GetBounds(); |
| 473 if (anchor.edge_top().y() < client_bounds.y()) { | 471 if (anchor.edge_top().y() < client_bounds.y()) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 client_view_->ExecuteCommand(command_id, event_flags); | 634 client_view_->ExecuteCommand(command_id, event_flags); |
| 637 } | 635 } |
| 638 | 636 |
| 639 void TouchSelectionControllerImpl::RunContextMenu() { | 637 void TouchSelectionControllerImpl::RunContextMenu() { |
| 640 // Context menu should appear centered on top of the selected region. | 638 // Context menu should appear centered on top of the selected region. |
| 641 const gfx::Rect rect = GetQuickMenuAnchorRect(); | 639 const gfx::Rect rect = GetQuickMenuAnchorRect(); |
| 642 const gfx::Point anchor(rect.CenterPoint().x(), rect.y()); | 640 const gfx::Point anchor(rect.CenterPoint().x(), rect.y()); |
| 643 client_view_->OpenContextMenu(anchor); | 641 client_view_->OpenContextMenu(anchor); |
| 644 } | 642 } |
| 645 | 643 |
| 646 void TouchSelectionControllerImpl::OnAncestorWindowTransformed( | |
| 647 aura::Window* window, | |
| 648 aura::Window* ancestor) { | |
| 649 client_view_->DestroyTouchSelection(); | |
| 650 } | |
| 651 | |
| 652 void TouchSelectionControllerImpl::OnWidgetClosing(Widget* widget) { | 644 void TouchSelectionControllerImpl::OnWidgetClosing(Widget* widget) { |
| 653 DCHECK_EQ(client_widget_, widget); | 645 DCHECK_EQ(client_widget_, widget); |
| 654 client_widget_->RemoveObserver(this); | 646 client_widget_->RemoveObserver(this); |
| 655 client_widget_ = nullptr; | 647 client_widget_ = nullptr; |
| 656 } | 648 } |
| 657 | 649 |
| 658 void TouchSelectionControllerImpl::OnWidgetBoundsChanged( | 650 void TouchSelectionControllerImpl::OnWidgetBoundsChanged( |
| 659 Widget* widget, | 651 Widget* widget, |
| 660 const gfx::Rect& new_bounds) { | 652 const gfx::Rect& new_bounds) { |
| 661 DCHECK_EQ(client_widget_, widget); | 653 DCHECK_EQ(client_widget_, widget); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 780 |
| 789 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { | 781 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle1View() { |
| 790 return selection_handle_1_.get(); | 782 return selection_handle_1_.get(); |
| 791 } | 783 } |
| 792 | 784 |
| 793 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { | 785 views::WidgetDelegateView* TouchSelectionControllerImpl::GetHandle2View() { |
| 794 return selection_handle_2_.get(); | 786 return selection_handle_2_.get(); |
| 795 } | 787 } |
| 796 | 788 |
| 797 } // namespace views | 789 } // namespace views |
| OLD | NEW |