| 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/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
| 10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Horizontal Padding | 51 // Horizontal Padding |
| 52 // | 52 // |
| 53 const int kSelectionHandleVerticalDragOffset = 5; | 53 const int kSelectionHandleVerticalDragOffset = 5; |
| 54 | 54 |
| 55 // Padding around the selection handle defining the area that will be included | 55 // Padding around the selection handle defining the area that will be included |
| 56 // in the touch target to make dragging the handle easier (see pic above). | 56 // in the touch target to make dragging the handle easier (see pic above). |
| 57 const int kSelectionHandleHorizPadding = 10; | 57 const int kSelectionHandleHorizPadding = 10; |
| 58 const int kSelectionHandleVertPadding = 20; | 58 const int kSelectionHandleVertPadding = 20; |
| 59 | 59 |
| 60 const int kContextMenuTimoutMs = 200; | 60 const int kContextMenuTimoutMs = 200; |
| 61 bool g_open_quick_menu_immediately_for_test = false; |
| 61 | 62 |
| 62 const int kSelectionHandleQuickFadeDurationMs = 50; | 63 const int kSelectionHandleQuickFadeDurationMs = 50; |
| 63 | 64 |
| 64 // Minimum height for selection handle bar. If the bar height is going to be | 65 // Minimum height for selection handle bar. If the bar height is going to be |
| 65 // less than this value, handle will not be shown. | 66 // less than this value, handle will not be shown. |
| 66 const int kSelectionHandleBarMinHeight = 5; | 67 const int kSelectionHandleBarMinHeight = 5; |
| 67 // Maximum amount that selection handle bar can stick out of client view's | 68 // Maximum amount that selection handle bar can stick out of client view's |
| 68 // boundaries. | 69 // boundaries. |
| 69 const int kSelectionHandleBarBottomAllowance = 3; | 70 const int kSelectionHandleBarBottomAllowance = 3; |
| 70 | 71 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 aura::Env::GetInstance()->AddPreTargetHandler(this); | 336 aura::Env::GetInstance()->AddPreTargetHandler(this); |
| 336 } | 337 } |
| 337 | 338 |
| 338 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { | 339 TouchSelectionControllerImpl::~TouchSelectionControllerImpl() { |
| 339 HideContextMenu(); | 340 HideContextMenu(); |
| 340 aura::Env::GetInstance()->RemovePreTargetHandler(this); | 341 aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| 341 if (client_widget_) | 342 if (client_widget_) |
| 342 client_widget_->RemoveObserver(this); | 343 client_widget_->RemoveObserver(this); |
| 343 } | 344 } |
| 344 | 345 |
| 346 // static |
| 347 void TouchSelectionControllerImpl::SetOpenQuickMenuImmediatelyForTest( |
| 348 bool immediate) { |
| 349 g_open_quick_menu_immediately_for_test = immediate; |
| 350 } |
| 351 |
| 345 void TouchSelectionControllerImpl::SelectionChanged() { | 352 void TouchSelectionControllerImpl::SelectionChanged() { |
| 346 gfx::Rect r1, r2; | 353 gfx::Rect r1, r2; |
| 347 client_view_->GetSelectionEndPoints(&r1, &r2); | 354 client_view_->GetSelectionEndPoints(&r1, &r2); |
| 348 gfx::Rect screen_rect_1 = ConvertToScreen(client_view_, r1); | 355 gfx::Rect screen_rect_1 = ConvertToScreen(client_view_, r1); |
| 349 gfx::Rect screen_rect_2 = ConvertToScreen(client_view_, r2); | 356 gfx::Rect screen_rect_2 = ConvertToScreen(client_view_, r2); |
| 350 gfx::Rect client_bounds = client_view_->GetBounds(); | 357 gfx::Rect client_bounds = client_view_->GetBounds(); |
| 351 if (r1.y() < client_bounds.y()) | 358 if (r1.y() < client_bounds.y()) |
| 352 r1.Inset(0, client_bounds.y() - r1.y(), 0, 0); | 359 r1.Inset(0, client_bounds.y() - r1.y(), 0, 0); |
| 353 if (r2.y() < client_bounds.y()) | 360 if (r2.y() < client_bounds.y()) |
| 354 r2.Inset(0, client_bounds.y() - r2.y(), 0, 0); | 361 r2.Inset(0, client_bounds.y() - r2.y(), 0, 0); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 580 |
| 574 DCHECK(!context_menu_); | 581 DCHECK(!context_menu_); |
| 575 context_menu_ = TouchEditingMenuView::Create(this, menu_anchor, | 582 context_menu_ = TouchEditingMenuView::Create(this, menu_anchor, |
| 576 GetHandleImageSize(), | 583 GetHandleImageSize(), |
| 577 client_view_->GetNativeView()); | 584 client_view_->GetNativeView()); |
| 578 } | 585 } |
| 579 | 586 |
| 580 void TouchSelectionControllerImpl::StartContextMenuTimer() { | 587 void TouchSelectionControllerImpl::StartContextMenuTimer() { |
| 581 if (context_menu_timer_.IsRunning()) | 588 if (context_menu_timer_.IsRunning()) |
| 582 return; | 589 return; |
| 590 if (g_open_quick_menu_immediately_for_test) { |
| 591 ContextMenuTimerFired(); |
| 592 return; |
| 593 } |
| 583 context_menu_timer_.Start( | 594 context_menu_timer_.Start( |
| 584 FROM_HERE, | 595 FROM_HERE, |
| 585 base::TimeDelta::FromMilliseconds(kContextMenuTimoutMs), | 596 base::TimeDelta::FromMilliseconds(kContextMenuTimoutMs), |
| 586 this, | 597 this, |
| 587 &TouchSelectionControllerImpl::ContextMenuTimerFired); | 598 &TouchSelectionControllerImpl::ContextMenuTimerFired); |
| 588 } | 599 } |
| 589 | 600 |
| 590 void TouchSelectionControllerImpl::UpdateContextMenu() { | 601 void TouchSelectionControllerImpl::UpdateContextMenu() { |
| 591 // Hide context menu to be shown when the timer fires. | 602 // Hide context menu to be shown when the timer fires. |
| 592 HideContextMenu(); | 603 HideContextMenu(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 622 | 633 |
| 623 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 634 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
| 624 return selection_handle_2_->IsWidgetVisible(); | 635 return selection_handle_2_->IsWidgetVisible(); |
| 625 } | 636 } |
| 626 | 637 |
| 627 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { | 638 bool TouchSelectionControllerImpl::IsCursorHandleVisible() { |
| 628 return cursor_handle_->IsWidgetVisible(); | 639 return cursor_handle_->IsWidgetVisible(); |
| 629 } | 640 } |
| 630 | 641 |
| 631 } // namespace views | 642 } // namespace views |
| OLD | NEW |