| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 150 |
| 148 aura::Window* window = widget_->GetNativeWindow(); | 151 aura::Window* window = widget_->GetNativeWindow(); |
| 149 window->set_event_targeter(scoped_ptr<ui::EventTargeter>( | 152 window->set_event_targeter(scoped_ptr<ui::EventTargeter>( |
| 150 new TouchHandleWindowTargeter(window, this))); | 153 new TouchHandleWindowTargeter(window, this))); |
| 151 | 154 |
| 152 // We are owned by the TouchSelectionController. | 155 // We are owned by the TouchSelectionController. |
| 153 set_owned_by_client(); | 156 set_owned_by_client(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 virtual ~EditingHandleView() { | 159 virtual ~EditingHandleView() { |
| 160 SetWidgetVisible(false, false); |
| 157 } | 161 } |
| 158 | 162 |
| 159 // Overridden from views::WidgetDelegateView: | 163 // Overridden from views::WidgetDelegateView: |
| 160 virtual bool WidgetHasHitTestMask() const OVERRIDE { | 164 virtual bool WidgetHasHitTestMask() const OVERRIDE { |
| 161 return true; | 165 return true; |
| 162 } | 166 } |
| 163 | 167 |
| 164 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE { | 168 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE { |
| 165 gfx::Size image_size = GetHandleImageSize(); | 169 gfx::Size image_size = GetHandleImageSize(); |
| 166 mask->addRect(SkIntToScalar(0), SkIntToScalar(selection_rect_.height()), | 170 mask->addRect(SkIntToScalar(0), SkIntToScalar(selection_rect_.height()), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 gfx::Size image_size = GetHandleImageSize(); | 225 gfx::Size image_size = GetHandleImageSize(); |
| 222 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, | 226 return gfx::Size(image_size.width() + 2 * kSelectionHandleHorizPadding, |
| 223 image_size.height() + selection_rect_.height() + | 227 image_size.height() + selection_rect_.height() + |
| 224 kSelectionHandleVertPadding); | 228 kSelectionHandleVertPadding); |
| 225 } | 229 } |
| 226 | 230 |
| 227 bool IsWidgetVisible() const { | 231 bool IsWidgetVisible() const { |
| 228 return widget_->IsVisible(); | 232 return widget_->IsVisible(); |
| 229 } | 233 } |
| 230 | 234 |
| 231 void SetWidgetVisible(bool visible) { | 235 void SetWidgetVisible(bool visible, bool quick) { |
| 232 if (widget_->IsVisible() == visible) | 236 if (widget_->IsVisible() == visible) |
| 233 return; | 237 return; |
| 234 if (visible) | 238 if (visible) { |
| 239 corewm::SetWindowShowAnimationDuration( |
| 240 widget_->GetNativeView(), |
| 241 base::TimeDelta::FromMilliseconds( |
| 242 quick ? kSelectionHandleQuickFadeDurationMs : 0)); |
| 235 widget_->Show(); | 243 widget_->Show(); |
| 236 else | 244 } else { |
| 245 corewm::SetWindowHideAnimationDuration( |
| 246 widget_->GetNativeView(), |
| 247 base::TimeDelta::FromMilliseconds( |
| 248 quick ? kSelectionHandleQuickFadeDurationMs : 0)); |
| 237 widget_->Hide(); | 249 widget_->Hide(); |
| 250 } |
| 238 } | 251 } |
| 239 | 252 |
| 240 void SetSelectionRectInScreen(const gfx::Rect& rect) { | 253 void SetSelectionRectInScreen(const gfx::Rect& rect) { |
| 241 gfx::Size image_size = GetHandleImageSize(); | 254 gfx::Size image_size = GetHandleImageSize(); |
| 242 selection_rect_ = rect; | 255 selection_rect_ = rect; |
| 243 gfx::Rect widget_bounds( | 256 gfx::Rect widget_bounds( |
| 244 rect.x() - image_size.width() / 2 - kSelectionHandleHorizPadding, | 257 rect.x() - image_size.width() / 2 - kSelectionHandleHorizPadding, |
| 245 rect.y(), | 258 rect.y(), |
| 246 image_size.width() + 2 * kSelectionHandleHorizPadding, | 259 image_size.width() + 2 * kSelectionHandleHorizPadding, |
| 247 rect.height() + image_size.height() + kSelectionHandleVertPadding); | 260 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; | 381 selection_end_point_1_ = screen_rect_2; |
| 369 selection_end_point_2_ = screen_rect_1; | 382 selection_end_point_2_ = screen_rect_1; |
| 370 } | 383 } |
| 371 SetHandleSelectionRect(non_dragging_handle, r1, screen_rect_1); | 384 SetHandleSelectionRect(non_dragging_handle, r1, screen_rect_1); |
| 372 } | 385 } |
| 373 } else { | 386 } else { |
| 374 UpdateContextMenu(r1.origin(), r2.origin()); | 387 UpdateContextMenu(r1.origin(), r2.origin()); |
| 375 | 388 |
| 376 // Check if there is any selection at all. | 389 // Check if there is any selection at all. |
| 377 if (screen_pos_1 == screen_pos_2) { | 390 if (screen_pos_1 == screen_pos_2) { |
| 378 selection_handle_1_->SetWidgetVisible(false); | 391 selection_handle_1_->SetWidgetVisible(false, false); |
| 379 selection_handle_2_->SetWidgetVisible(false); | 392 selection_handle_2_->SetWidgetVisible(false, false); |
| 380 SetHandleSelectionRect(cursor_handle_.get(), r1, screen_rect_1); | 393 SetHandleSelectionRect(cursor_handle_.get(), r1, screen_rect_1); |
| 381 return; | 394 return; |
| 382 } | 395 } |
| 383 | 396 |
| 384 cursor_handle_->SetWidgetVisible(false); | 397 cursor_handle_->SetWidgetVisible(false, false); |
| 385 SetHandleSelectionRect(selection_handle_1_.get(), r1, screen_rect_1); | 398 SetHandleSelectionRect(selection_handle_1_.get(), r1, screen_rect_1); |
| 386 SetHandleSelectionRect(selection_handle_2_.get(), r2, screen_rect_2); | 399 SetHandleSelectionRect(selection_handle_2_.get(), r2, screen_rect_2); |
| 387 } | 400 } |
| 388 } | 401 } |
| 389 | 402 |
| 390 bool TouchSelectionControllerImpl::IsHandleDragInProgress() { | 403 bool TouchSelectionControllerImpl::IsHandleDragInProgress() { |
| 391 return !!dragging_handle_; | 404 return !!dragging_handle_; |
| 392 } | 405 } |
| 393 | 406 |
| 407 void TouchSelectionControllerImpl::HideHandles(bool quick) { |
| 408 selection_handle_1_->SetWidgetVisible(false, quick); |
| 409 selection_handle_2_->SetWidgetVisible(false, quick); |
| 410 cursor_handle_->SetWidgetVisible(false, quick); |
| 411 } |
| 412 |
| 394 void TouchSelectionControllerImpl::SetDraggingHandle( | 413 void TouchSelectionControllerImpl::SetDraggingHandle( |
| 395 EditingHandleView* handle) { | 414 EditingHandleView* handle) { |
| 396 dragging_handle_ = handle; | 415 dragging_handle_ = handle; |
| 397 if (dragging_handle_) | 416 if (dragging_handle_) |
| 398 HideContextMenu(); | 417 HideContextMenu(); |
| 399 else | 418 else |
| 400 StartContextMenuTimer(); | 419 StartContextMenuTimer(); |
| 401 } | 420 } |
| 402 | 421 |
| 403 void TouchSelectionControllerImpl::SelectionHandleDragged( | 422 void TouchSelectionControllerImpl::SelectionHandleDragged( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 433 void TouchSelectionControllerImpl::ConvertPointToClientView( | 452 void TouchSelectionControllerImpl::ConvertPointToClientView( |
| 434 EditingHandleView* source, gfx::Point* point) { | 453 EditingHandleView* source, gfx::Point* point) { |
| 435 View::ConvertPointToScreen(source, point); | 454 View::ConvertPointToScreen(source, point); |
| 436 client_view_->ConvertPointFromScreen(point); | 455 client_view_->ConvertPointFromScreen(point); |
| 437 } | 456 } |
| 438 | 457 |
| 439 void TouchSelectionControllerImpl::SetHandleSelectionRect( | 458 void TouchSelectionControllerImpl::SetHandleSelectionRect( |
| 440 EditingHandleView* handle, | 459 EditingHandleView* handle, |
| 441 const gfx::Rect& rect, | 460 const gfx::Rect& rect, |
| 442 const gfx::Rect& rect_in_screen) { | 461 const gfx::Rect& rect_in_screen) { |
| 443 handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect)); | 462 handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect), false); |
| 444 if (handle->IsWidgetVisible()) | 463 if (handle->IsWidgetVisible()) |
| 445 handle->SetSelectionRectInScreen(rect_in_screen); | 464 handle->SetSelectionRectInScreen(rect_in_screen); |
| 446 } | 465 } |
| 447 | 466 |
| 448 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { | 467 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { |
| 449 return client_view_->IsCommandIdEnabled(command_id); | 468 return client_view_->IsCommandIdEnabled(command_id); |
| 450 } | 469 } |
| 451 | 470 |
| 452 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, | 471 void TouchSelectionControllerImpl::ExecuteCommand(int command_id, |
| 453 int event_flags) { | 472 int event_flags) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 588 } |
| 570 | 589 |
| 571 ui::TouchSelectionController* ViewsTouchSelectionControllerFactory::create( | 590 ui::TouchSelectionController* ViewsTouchSelectionControllerFactory::create( |
| 572 ui::TouchEditable* client_view) { | 591 ui::TouchEditable* client_view) { |
| 573 if (switches::IsTouchEditingEnabled()) | 592 if (switches::IsTouchEditingEnabled()) |
| 574 return new views::TouchSelectionControllerImpl(client_view); | 593 return new views::TouchSelectionControllerImpl(client_view); |
| 575 return NULL; | 594 return NULL; |
| 576 } | 595 } |
| 577 | 596 |
| 578 } // namespace views | 597 } // namespace views |
| OLD | NEW |