| 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/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/base/ui_base_switches_util.h" | 11 #include "ui/base/ui_base_switches_util.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 14 #include "ui/gfx/path.h" | 14 #include "ui/gfx/path.h" |
| 15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
| 17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 18 #include "ui/views/corewm/shadow_types.h" | 18 #include "ui/views/corewm/shadow_types.h" |
| 19 #include "ui/views/corewm/window_animations.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 #include "ui/wm/public/masked_window_targeter.h" | 21 #include "ui/wm/public/masked_window_targeter.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Constants defining the visual attributes of selection handles | 25 // Constants defining the visual attributes of selection handles |
| 25 const int kSelectionHandleLineWidth = 1; | 26 const int kSelectionHandleLineWidth = 1; |
| 26 const SkColor kSelectionHandleLineColor = | 27 const SkColor kSelectionHandleLineColor = |
| 27 SkColorSetRGB(0x42, 0x81, 0xf4); | 28 SkColorSetRGB(0x42, 0x81, 0xf4); |
| 28 | 29 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 // | 51 // |
| 51 const int kSelectionHandleVerticalDragOffset = 5; | 52 const int kSelectionHandleVerticalDragOffset = 5; |
| 52 | 53 |
| 53 // Padding around the selection handle defining the area that will be included | 54 // Padding around the selection handle defining the area that will be included |
| 54 // in the touch target to make dragging the handle easier (see pic above). | 55 // in the touch target to make dragging the handle easier (see pic above). |
| 55 const int kSelectionHandleHorizPadding = 10; | 56 const int kSelectionHandleHorizPadding = 10; |
| 56 const int kSelectionHandleVertPadding = 20; | 57 const int kSelectionHandleVertPadding = 20; |
| 57 | 58 |
| 58 const int kContextMenuTimoutMs = 200; | 59 const int kContextMenuTimoutMs = 200; |
| 59 | 60 |
| 61 const int kSelectionHandleQuickFadeDurationMs = 50; |
| 62 |
| 60 // Creates a widget to host SelectionHandleView. | 63 // Creates a widget to host SelectionHandleView. |
| 61 views::Widget* CreateTouchSelectionPopupWidget( | 64 views::Widget* CreateTouchSelectionPopupWidget( |
| 62 gfx::NativeView context, | 65 gfx::NativeView context, |
| 63 views::WidgetDelegate* widget_delegate) { | 66 views::WidgetDelegate* widget_delegate) { |
| 64 views::Widget* widget = new views::Widget; | 67 views::Widget* widget = new views::Widget; |
| 65 views::Widget::InitParams params(views::Widget::InitParams::TYPE_TOOLTIP); | 68 views::Widget::InitParams params(views::Widget::InitParams::TYPE_TOOLTIP); |
| 66 params.can_activate = false; | 69 params.can_activate = false; |
| 67 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 70 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 68 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 71 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 69 params.context = context; | 72 params.context = context; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 gfx::Size image_size = GetHandleImageSize(); | 224 gfx::Size image_size = GetHandleImageSize(); |
| 222 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, | 225 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, |
| 223 image_size.height() + selection_rect_.height() + | 226 image_size.height() + selection_rect_.height() + |
| 224 kSelectionHandleVertPadding); | 227 kSelectionHandleVertPadding); |
| 225 } | 228 } |
| 226 | 229 |
| 227 bool IsWidgetVisible() const { | 230 bool IsWidgetVisible() const { |
| 228 return widget_->IsVisible(); | 231 return widget_->IsVisible(); |
| 229 } | 232 } |
| 230 | 233 |
| 231 void SetWidgetVisible(bool visible) { | 234 void SetWidgetVisible(bool visible, bool quick) { |
| 232 if (widget_->IsVisible() == visible) | 235 if (widget_->IsVisible() == visible) |
| 233 return; | 236 return; |
| 234 if (visible) | 237 if (visible) { |
| 238 corewm::SetWindowShowAnimationDuration( |
| 239 widget_->GetNativeView(), |
| 240 base::TimeDelta::FromMilliseconds( |
| 241 quick ? kSelectionHandleQuickFadeDurationMs : 0)); |
| 235 widget_->Show(); | 242 widget_->Show(); |
| 236 else | 243 } else { |
| 244 corewm::SetWindowHideAnimationDuration( |
| 245 widget_->GetNativeView(), |
| 246 base::TimeDelta::FromMilliseconds( |
| 247 quick ? kSelectionHandleQuickFadeDurationMs : 0)); |
| 237 widget_->Hide(); | 248 widget_->Hide(); |
| 249 } |
| 238 } | 250 } |
| 239 | 251 |
| 240 void SetSelectionRectInScreen(const gfx::Rect& rect) { | 252 void SetSelectionRectInScreen(const gfx::Rect& rect) { |
| 241 gfx::Size image_size = GetHandleImageSize(); | 253 gfx::Size image_size = GetHandleImageSize(); |
| 242 selection_rect_ = rect; | 254 selection_rect_ = rect; |
| 243 gfx::Rect widget_bounds( | 255 gfx::Rect widget_bounds( |
| 244 rect.x() - image_size.width() / 2 - kSelectionHandleHorizPadding, | 256 rect.x() - image_size.width() / 2 - kSelectionHandleHorizPadding, |
| 245 rect.y(), | 257 rect.y(), |
| 246 image_size.width() + 2 * kSelectionHandleHorizPadding, | 258 image_size.width() + 2 * kSelectionHandleHorizPadding, |
| 247 rect.height() + image_size.height() + kSelectionHandleVertPadding); | 259 rect.height() + image_size.height() + kSelectionHandleVertPadding); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 selection_end_point_1_ = screen_rect_2; | 380 selection_end_point_1_ = screen_rect_2; |
| 369 selection_end_point_2_ = screen_rect_1; | 381 selection_end_point_2_ = screen_rect_1; |
| 370 } | 382 } |
| 371 SetHandleSelectionRect(non_dragging_handle, r1, screen_rect_1); | 383 SetHandleSelectionRect(non_dragging_handle, r1, screen_rect_1); |
| 372 } | 384 } |
| 373 } else { | 385 } else { |
| 374 UpdateContextMenu(r1.origin(), r2.origin()); | 386 UpdateContextMenu(r1.origin(), r2.origin()); |
| 375 | 387 |
| 376 // Check if there is any selection at all. | 388 // Check if there is any selection at all. |
| 377 if (screen_pos_1 == screen_pos_2) { | 389 if (screen_pos_1 == screen_pos_2) { |
| 378 selection_handle_1_->SetWidgetVisible(false); | 390 selection_handle_1_->SetWidgetVisible(false, false); |
| 379 selection_handle_2_->SetWidgetVisible(false); | 391 selection_handle_2_->SetWidgetVisible(false, false); |
| 380 SetHandleSelectionRect(cursor_handle_.get(), r1, screen_rect_1); | 392 SetHandleSelectionRect(cursor_handle_.get(), r1, screen_rect_1); |
| 381 return; | 393 return; |
| 382 } | 394 } |
| 383 | 395 |
| 384 cursor_handle_->SetWidgetVisible(false); | 396 cursor_handle_->SetWidgetVisible(false, false); |
| 385 SetHandleSelectionRect(selection_handle_1_.get(), r1, screen_rect_1); | 397 SetHandleSelectionRect(selection_handle_1_.get(), r1, screen_rect_1); |
| 386 SetHandleSelectionRect(selection_handle_2_.get(), r2, screen_rect_2); | 398 SetHandleSelectionRect(selection_handle_2_.get(), r2, screen_rect_2); |
| 387 } | 399 } |
| 388 } | 400 } |
| 389 | 401 |
| 390 bool TouchSelectionControllerImpl::IsHandleDragInProgress() { | 402 bool TouchSelectionControllerImpl::IsHandleDragInProgress() { |
| 391 return !!dragging_handle_; | 403 return !!dragging_handle_; |
| 392 } | 404 } |
| 393 | 405 |
| 406 void TouchSelectionControllerImpl::HideHandles(bool quick) { |
| 407 selection_handle_1_->SetWidgetVisible(false, quick); |
| 408 selection_handle_2_->SetWidgetVisible(false, quick); |
| 409 cursor_handle_->SetWidgetVisible(false, quick); |
| 410 } |
| 411 |
| 394 void TouchSelectionControllerImpl::SetDraggingHandle( | 412 void TouchSelectionControllerImpl::SetDraggingHandle( |
| 395 EditingHandleView* handle) { | 413 EditingHandleView* handle) { |
| 396 dragging_handle_ = handle; | 414 dragging_handle_ = handle; |
| 397 if (dragging_handle_) | 415 if (dragging_handle_) |
| 398 HideContextMenu(); | 416 HideContextMenu(); |
| 399 else | 417 else |
| 400 StartContextMenuTimer(); | 418 StartContextMenuTimer(); |
| 401 } | 419 } |
| 402 | 420 |
| 403 void TouchSelectionControllerImpl::SelectionHandleDragged( | 421 void TouchSelectionControllerImpl::SelectionHandleDragged( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 433 void TouchSelectionControllerImpl::ConvertPointToClientView( | 451 void TouchSelectionControllerImpl::ConvertPointToClientView( |
| 434 EditingHandleView* source, gfx::Point* point) { | 452 EditingHandleView* source, gfx::Point* point) { |
| 435 View::ConvertPointToScreen(source, point); | 453 View::ConvertPointToScreen(source, point); |
| 436 client_view_->ConvertPointFromScreen(point); | 454 client_view_->ConvertPointFromScreen(point); |
| 437 } | 455 } |
| 438 | 456 |
| 439 void TouchSelectionControllerImpl::SetHandleSelectionRect( | 457 void TouchSelectionControllerImpl::SetHandleSelectionRect( |
| 440 EditingHandleView* handle, | 458 EditingHandleView* handle, |
| 441 const gfx::Rect& rect, | 459 const gfx::Rect& rect, |
| 442 const gfx::Rect& rect_in_screen) { | 460 const gfx::Rect& rect_in_screen) { |
| 443 handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect)); | 461 handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect), false); |
| 444 if (handle->IsWidgetVisible()) | 462 if (handle->IsWidgetVisible()) |
| 445 handle->SetSelectionRectInScreen(rect_in_screen); | 463 handle->SetSelectionRectInScreen(rect_in_screen); |
| 446 } | 464 } |
| 447 | 465 |
| 448 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { | 466 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { |
| 449 return client_view_->IsCommandIdEnabled(command_id); | 467 return client_view_->IsCommandIdEnabled(command_id); |
| 450 } | 468 } |
| 451 | 469 |
| 452 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, | 470 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, |
| 453 int event_flags) { | 471 int event_flags) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 587 } |
| 570 | 588 |
| 571 ui::TouchSelectionController* ViewsTouchSelectionControllerFactory::create( | 589 ui::TouchSelectionController* ViewsTouchSelectionControllerFactory::create( |
| 572 ui::TouchEditable* client_view) { | 590 ui::TouchEditable* client_view) { |
| 573 if (switches::IsTouchEditingEnabled()) | 591 if (switches::IsTouchEditingEnabled()) |
| 574 return new views::TouchSelectionControllerImpl(client_view); | 592 return new views::TouchSelectionControllerImpl(client_view); |
| 575 return NULL; | 593 return NULL; |
| 576 } | 594 } |
| 577 | 595 |
| 578 } // namespace views | 596 } // namespace views |
| OLD | NEW |