| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/tabs/tab_drag_controller.h" | 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // static | 191 // static |
| 192 const int TabDragController::kTouchVerticalDetachMagnetism = 50; | 192 const int TabDragController::kTouchVerticalDetachMagnetism = 50; |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 const int TabDragController::kVerticalDetachMagnetism = 15; | 195 const int TabDragController::kVerticalDetachMagnetism = 15; |
| 196 | 196 |
| 197 TabDragController::TabDragController() | 197 TabDragController::TabDragController() |
| 198 : event_source_(EVENT_SOURCE_MOUSE), | 198 : event_source_(EVENT_SOURCE_MOUSE), |
| 199 source_tabstrip_(NULL), | 199 source_tabstrip_(NULL), |
| 200 attached_tabstrip_(NULL), | 200 attached_tabstrip_(NULL), |
| 201 screen_(NULL), | |
| 202 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 201 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| 203 can_release_capture_(true), | 202 can_release_capture_(true), |
| 204 offset_to_width_ratio_(0), | 203 offset_to_width_ratio_(0), |
| 205 old_focused_view_id_( | 204 old_focused_view_id_( |
| 206 views::ViewStorage::GetInstance()->CreateStorageID()), | 205 views::ViewStorage::GetInstance()->CreateStorageID()), |
| 207 last_move_screen_loc_(0), | 206 last_move_screen_loc_(0), |
| 208 started_drag_(false), | 207 started_drag_(false), |
| 209 active_(true), | 208 active_(true), |
| 210 source_tab_index_(std::numeric_limits<size_t>::max()), | 209 source_tab_index_(std::numeric_limits<size_t>::max()), |
| 211 initial_move_(true), | 210 initial_move_(true), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 const gfx::Point& mouse_offset, | 255 const gfx::Point& mouse_offset, |
| 257 int source_tab_offset, | 256 int source_tab_offset, |
| 258 const ui::ListSelectionModel& initial_selection_model, | 257 const ui::ListSelectionModel& initial_selection_model, |
| 259 MoveBehavior move_behavior, | 258 MoveBehavior move_behavior, |
| 260 EventSource event_source) { | 259 EventSource event_source) { |
| 261 DCHECK(!tabs.empty()); | 260 DCHECK(!tabs.empty()); |
| 262 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end()); | 261 DCHECK(std::find(tabs.begin(), tabs.end(), source_tab) != tabs.end()); |
| 263 source_tabstrip_ = source_tabstrip; | 262 source_tabstrip_ = source_tabstrip; |
| 264 was_source_maximized_ = source_tabstrip->GetWidget()->IsMaximized(); | 263 was_source_maximized_ = source_tabstrip->GetWidget()->IsMaximized(); |
| 265 was_source_fullscreen_ = source_tabstrip->GetWidget()->IsFullscreen(); | 264 was_source_fullscreen_ = source_tabstrip->GetWidget()->IsFullscreen(); |
| 266 screen_ = gfx::Screen::GetScreenFor( | |
| 267 source_tabstrip->GetWidget()->GetNativeView()); | |
| 268 host_desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 265 host_desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
| 269 source_tabstrip->GetWidget()->GetNativeView()); | 266 source_tabstrip->GetWidget()->GetNativeView()); |
| 270 // Do not release capture when transferring capture between widgets on: | 267 // Do not release capture when transferring capture between widgets on: |
| 271 // - Desktop Linux | 268 // - Desktop Linux |
| 272 // Mouse capture is not synchronous on desktop Linux. Chrome makes | 269 // Mouse capture is not synchronous on desktop Linux. Chrome makes |
| 273 // transferring capture between widgets without releasing capture appear | 270 // transferring capture between widgets without releasing capture appear |
| 274 // synchronous on desktop Linux, so use that. | 271 // synchronous on desktop Linux, so use that. |
| 275 // - Ash | 272 // - Ash |
| 276 // Releasing capture on Ash cancels gestures so avoid it. | 273 // Releasing capture on Ash cancels gestures so avoid it. |
| 277 #if defined(OS_LINUX) | 274 #if defined(OS_LINUX) |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 views::View* first_tab = source_tabstrip_->tab_at(0); | 472 views::View* first_tab = source_tabstrip_->tab_at(0); |
| 476 views::View::ConvertPointToWidget(first_tab, &first_source_tab_point_); | 473 views::View::ConvertPointToWidget(first_tab, &first_source_tab_point_); |
| 477 window_create_point_ = first_source_tab_point_; | 474 window_create_point_ = first_source_tab_point_; |
| 478 window_create_point_.Offset(mouse_offset_.x(), mouse_offset_.y()); | 475 window_create_point_.Offset(mouse_offset_.x(), mouse_offset_.y()); |
| 479 } | 476 } |
| 480 | 477 |
| 481 gfx::Point TabDragController::GetWindowCreatePoint( | 478 gfx::Point TabDragController::GetWindowCreatePoint( |
| 482 const gfx::Point& origin) const { | 479 const gfx::Point& origin) const { |
| 483 // If the cursor is outside the monitor area, move it inside. For example, | 480 // If the cursor is outside the monitor area, move it inside. For example, |
| 484 // dropping a tab onto the task bar on Windows produces this situation. | 481 // dropping a tab onto the task bar on Windows produces this situation. |
| 485 gfx::Rect work_area = screen_->GetDisplayNearestPoint(origin).work_area(); | 482 gfx::Rect work_area = |
| 483 gfx::Screen::GetScreen()->GetDisplayNearestPoint(origin).work_area(); |
| 486 gfx::Point create_point(origin); | 484 gfx::Point create_point(origin); |
| 487 if (!work_area.IsEmpty()) { | 485 if (!work_area.IsEmpty()) { |
| 488 if (create_point.x() < work_area.x()) | 486 if (create_point.x() < work_area.x()) |
| 489 create_point.set_x(work_area.x()); | 487 create_point.set_x(work_area.x()); |
| 490 else if (create_point.x() > work_area.right()) | 488 else if (create_point.x() > work_area.right()) |
| 491 create_point.set_x(work_area.right()); | 489 create_point.set_x(work_area.right()); |
| 492 if (create_point.y() < work_area.y()) | 490 if (create_point.y() < work_area.y()) |
| 493 create_point.set_y(work_area.y()); | 491 create_point.set_y(work_area.y()); |
| 494 else if (create_point.y() > work_area.bottom()) | 492 else if (create_point.y() > work_area.bottom()) |
| 495 create_point.set_y(work_area.bottom()); | 493 create_point.set_y(work_area.bottom()); |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 } | 1638 } |
| 1641 | 1639 |
| 1642 gfx::Rect TabDragController::CalculateDraggedBrowserBounds( | 1640 gfx::Rect TabDragController::CalculateDraggedBrowserBounds( |
| 1643 TabStrip* source, | 1641 TabStrip* source, |
| 1644 const gfx::Point& point_in_screen, | 1642 const gfx::Point& point_in_screen, |
| 1645 std::vector<gfx::Rect>* drag_bounds) { | 1643 std::vector<gfx::Rect>* drag_bounds) { |
| 1646 gfx::Point center(0, source->height() / 2); | 1644 gfx::Point center(0, source->height() / 2); |
| 1647 views::View::ConvertPointToWidget(source, ¢er); | 1645 views::View::ConvertPointToWidget(source, ¢er); |
| 1648 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds()); | 1646 gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds()); |
| 1649 | 1647 |
| 1650 gfx::Rect work_area = | 1648 gfx::Rect work_area = gfx::Screen::GetScreen() |
| 1651 screen_->GetDisplayNearestPoint(last_point_in_screen_).work_area(); | 1649 ->GetDisplayNearestPoint(last_point_in_screen_) |
| 1650 .work_area(); |
| 1652 if (new_bounds.size().width() >= work_area.size().width() && | 1651 if (new_bounds.size().width() >= work_area.size().width() && |
| 1653 new_bounds.size().height() >= work_area.size().height()) { | 1652 new_bounds.size().height() >= work_area.size().height()) { |
| 1654 new_bounds = work_area; | 1653 new_bounds = work_area; |
| 1655 new_bounds.Inset(kMaximizedWindowInset, kMaximizedWindowInset, | 1654 new_bounds.Inset(kMaximizedWindowInset, kMaximizedWindowInset, |
| 1656 kMaximizedWindowInset, kMaximizedWindowInset); | 1655 kMaximizedWindowInset, kMaximizedWindowInset); |
| 1657 // Behave as if the |source| was maximized at the start of a drag since this | 1656 // Behave as if the |source| was maximized at the start of a drag since this |
| 1658 // is consistent with a browser window creation logic in case of windows | 1657 // is consistent with a browser window creation logic in case of windows |
| 1659 // that are as large as the |work_area|. | 1658 // that are as large as the |work_area|. |
| 1660 was_source_maximized_ = true; | 1659 was_source_maximized_ = true; |
| 1661 } | 1660 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 gfx::PointF touch_point_f; | 1774 gfx::PointF touch_point_f; |
| 1776 bool got_touch_point = ui::GestureRecognizer::Get()-> | 1775 bool got_touch_point = ui::GestureRecognizer::Get()-> |
| 1777 GetLastTouchPointForTarget(widget_window, &touch_point_f); | 1776 GetLastTouchPointForTarget(widget_window, &touch_point_f); |
| 1778 CHECK(got_touch_point); | 1777 CHECK(got_touch_point); |
| 1779 gfx::Point touch_point = gfx::ToFlooredPoint(touch_point_f); | 1778 gfx::Point touch_point = gfx::ToFlooredPoint(touch_point_f); |
| 1780 wm::ConvertPointToScreen(widget_window->GetRootWindow(), &touch_point); | 1779 wm::ConvertPointToScreen(widget_window->GetRootWindow(), &touch_point); |
| 1781 return touch_point; | 1780 return touch_point; |
| 1782 } | 1781 } |
| 1783 #endif | 1782 #endif |
| 1784 | 1783 |
| 1785 return screen_->GetCursorScreenPoint(); | 1784 return gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1786 } | 1785 } |
| 1787 | 1786 |
| 1788 gfx::Vector2d TabDragController::GetWindowOffset( | 1787 gfx::Vector2d TabDragController::GetWindowOffset( |
| 1789 const gfx::Point& point_in_screen) { | 1788 const gfx::Point& point_in_screen) { |
| 1790 TabStrip* owning_tabstrip = attached_tabstrip_ ? | 1789 TabStrip* owning_tabstrip = attached_tabstrip_ ? |
| 1791 attached_tabstrip_ : source_tabstrip_; | 1790 attached_tabstrip_ : source_tabstrip_; |
| 1792 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 1791 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
| 1793 | 1792 |
| 1794 gfx::Point point = point_in_screen; | 1793 gfx::Point point = point_in_screen; |
| 1795 views::View::ConvertPointFromScreen(toplevel_view, &point); | 1794 views::View::ConvertPointFromScreen(toplevel_view, &point); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1818 it != browser_list->end(); ++it) { | 1817 it != browser_list->end(); ++it) { |
| 1819 if ((*it)->tab_strip_model()->empty()) | 1818 if ((*it)->tab_strip_model()->empty()) |
| 1820 exclude.insert((*it)->window()->GetNativeWindow()); | 1819 exclude.insert((*it)->window()->GetNativeWindow()); |
| 1821 } | 1820 } |
| 1822 #endif | 1821 #endif |
| 1823 return GetLocalProcessWindowAtPoint(host_desktop_type_, | 1822 return GetLocalProcessWindowAtPoint(host_desktop_type_, |
| 1824 screen_point, | 1823 screen_point, |
| 1825 exclude); | 1824 exclude); |
| 1826 | 1825 |
| 1827 } | 1826 } |
| OLD | NEW |