| 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 514 } |
| 515 | 515 |
| 516 void TabDragController::SetMoveBehavior(MoveBehavior behavior) { | 516 void TabDragController::SetMoveBehavior(MoveBehavior behavior) { |
| 517 if (started_drag()) | 517 if (started_drag()) |
| 518 return; | 518 return; |
| 519 | 519 |
| 520 move_behavior_ = behavior; | 520 move_behavior_ = behavior; |
| 521 } | 521 } |
| 522 | 522 |
| 523 void TabDragController::Drag(const gfx::Point& point_in_screen) { | 523 void TabDragController::Drag(const gfx::Point& point_in_screen) { |
| 524 TRACE_EVENT1("views", "TabDragController::Drag", |
| 525 "point_in_screen", point_in_screen.ToString()); |
| 526 |
| 524 bring_to_front_timer_.Stop(); | 527 bring_to_front_timer_.Stop(); |
| 525 move_stacked_timer_.Stop(); | 528 move_stacked_timer_.Stop(); |
| 526 | 529 |
| 527 if (waiting_for_run_loop_to_exit_) | 530 if (waiting_for_run_loop_to_exit_) |
| 528 return; | 531 return; |
| 529 | 532 |
| 530 if (!started_drag_) { | 533 if (!started_drag_) { |
| 531 if (!CanStartDrag(point_in_screen)) | 534 if (!CanStartDrag(point_in_screen)) |
| 532 return; // User hasn't dragged far enough yet. | 535 return; // User hasn't dragged far enough yet. |
| 533 | 536 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 544 GetModel(source_tabstrip_)->count()) { | 547 GetModel(source_tabstrip_)->count()) { |
| 545 RunMoveLoop(GetWindowOffset(point_in_screen)); | 548 RunMoveLoop(GetWindowOffset(point_in_screen)); |
| 546 return; | 549 return; |
| 547 } | 550 } |
| 548 } | 551 } |
| 549 | 552 |
| 550 ContinueDragging(point_in_screen); | 553 ContinueDragging(point_in_screen); |
| 551 } | 554 } |
| 552 | 555 |
| 553 void TabDragController::EndDrag(EndDragReason reason) { | 556 void TabDragController::EndDrag(EndDragReason reason) { |
| 557 TRACE_EVENT0("views", "TabDragController::EndDrag"); |
| 558 |
| 554 // If we're dragging a window ignore capture lost since it'll ultimately | 559 // If we're dragging a window ignore capture lost since it'll ultimately |
| 555 // trigger the move loop to end and we'll revert the drag when RunMoveLoop() | 560 // trigger the move loop to end and we'll revert the drag when RunMoveLoop() |
| 556 // finishes. | 561 // finishes. |
| 557 if (reason == END_DRAG_CAPTURE_LOST && is_dragging_window_) | 562 if (reason == END_DRAG_CAPTURE_LOST && is_dragging_window_) |
| 558 return; | 563 return; |
| 559 EndDragImpl(reason != END_DRAG_COMPLETE && source_tabstrip_ ? | 564 EndDragImpl(reason != END_DRAG_COMPLETE && source_tabstrip_ ? |
| 560 CANCELED : NORMAL); | 565 CANCELED : NORMAL); |
| 561 } | 566 } |
| 562 | 567 |
| 563 void TabDragController::InitTabDragData(Tab* tab, | 568 void TabDragController::InitTabDragData(Tab* tab, |
| 564 TabDragData* drag_data) { | 569 TabDragData* drag_data) { |
| 570 TRACE_EVENT0("views", "TabDragController::InitTabDragData"); |
| 565 drag_data->source_model_index = | 571 drag_data->source_model_index = |
| 566 source_tabstrip_->GetModelIndexOfTab(tab); | 572 source_tabstrip_->GetModelIndexOfTab(tab); |
| 567 drag_data->contents = GetModel(source_tabstrip_)->GetWebContentsAt( | 573 drag_data->contents = GetModel(source_tabstrip_)->GetWebContentsAt( |
| 568 drag_data->source_model_index); | 574 drag_data->source_model_index); |
| 569 drag_data->pinned = source_tabstrip_->IsTabPinned(tab); | 575 drag_data->pinned = source_tabstrip_->IsTabPinned(tab); |
| 570 registrar_.Add( | 576 registrar_.Add( |
| 571 this, | 577 this, |
| 572 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 578 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 573 content::Source<WebContents>(drag_data->contents)); | 579 content::Source<WebContents>(drag_data->contents)); |
| 574 | 580 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // single view or window reliably receives events throughout all the various | 710 // single view or window reliably receives events throughout all the various |
| 705 // kinds of tab dragging. | 711 // kinds of tab dragging. |
| 706 if (ui::EventTypeFromNative(event) == ui::ET_KEY_PRESSED && | 712 if (ui::EventTypeFromNative(event) == ui::ET_KEY_PRESSED && |
| 707 ui::KeyboardCodeFromNative(event) == ui::VKEY_ESCAPE) { | 713 ui::KeyboardCodeFromNative(event) == ui::VKEY_ESCAPE) { |
| 708 EndDrag(END_DRAG_CANCEL); | 714 EndDrag(END_DRAG_CANCEL); |
| 709 } | 715 } |
| 710 } | 716 } |
| 711 | 717 |
| 712 void TabDragController::OnWidgetBoundsChanged(views::Widget* widget, | 718 void TabDragController::OnWidgetBoundsChanged(views::Widget* widget, |
| 713 const gfx::Rect& new_bounds) { | 719 const gfx::Rect& new_bounds) { |
| 720 TRACE_EVENT1("views", "TabDragController::OnWidgetBoundsChanged", |
| 721 "new_bounds", new_bounds.ToString()); |
| 722 |
| 714 Drag(GetCursorScreenPoint()); | 723 Drag(GetCursorScreenPoint()); |
| 715 } | 724 } |
| 716 | 725 |
| 717 void TabDragController::TabStripEmpty() { | 726 void TabDragController::TabStripEmpty() { |
| 718 DCHECK(detach_into_browser_); | 727 DCHECK(detach_into_browser_); |
| 719 GetModel(source_tabstrip_)->RemoveObserver(this); | 728 GetModel(source_tabstrip_)->RemoveObserver(this); |
| 720 // NULL out source_tabstrip_ so that we don't attempt to add back to it (in | 729 // NULL out source_tabstrip_ so that we don't attempt to add back to it (in |
| 721 // the case of a revert). | 730 // the case of a revert). |
| 722 source_tabstrip_ = NULL; | 731 source_tabstrip_ = NULL; |
| 723 } | 732 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 if (create_point.y() < work_area.y()) | 768 if (create_point.y() < work_area.y()) |
| 760 create_point.set_y(work_area.y()); | 769 create_point.set_y(work_area.y()); |
| 761 else if (create_point.y() > work_area.bottom()) | 770 else if (create_point.y() > work_area.bottom()) |
| 762 create_point.set_y(work_area.bottom()); | 771 create_point.set_y(work_area.bottom()); |
| 763 } | 772 } |
| 764 return gfx::Point(create_point.x() - window_create_point_.x(), | 773 return gfx::Point(create_point.x() - window_create_point_.x(), |
| 765 create_point.y() - window_create_point_.y()); | 774 create_point.y() - window_create_point_.y()); |
| 766 } | 775 } |
| 767 | 776 |
| 768 void TabDragController::UpdateDockInfo(const gfx::Point& point_in_screen) { | 777 void TabDragController::UpdateDockInfo(const gfx::Point& point_in_screen) { |
| 778 TRACE_EVENT1("views", "TabDragController::UpdateDockInfo", |
| 779 "point_in_screen", point_in_screen.ToString()); |
| 780 |
| 769 // Update the DockInfo for the current mouse coordinates. | 781 // Update the DockInfo for the current mouse coordinates. |
| 770 DockInfo dock_info = GetDockInfoAtPoint(point_in_screen); | 782 DockInfo dock_info = GetDockInfoAtPoint(point_in_screen); |
| 771 if (!dock_info.equals(dock_info_)) { | 783 if (!dock_info.equals(dock_info_)) { |
| 772 // DockInfo for current position differs. | 784 // DockInfo for current position differs. |
| 773 if (dock_info_.type() != DockInfo::NONE && | 785 if (dock_info_.type() != DockInfo::NONE && |
| 774 !dock_controllers_.empty()) { | 786 !dock_controllers_.empty()) { |
| 775 // Hide old visual indicator. | 787 // Hide old visual indicator. |
| 776 dock_controllers_.back()->Hide(); | 788 dock_controllers_.back()->Hide(); |
| 777 } | 789 } |
| 778 dock_info_ = dock_info; | 790 dock_info_ = dock_info; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 // Determine if the mouse has moved beyond a minimum elasticity distance in | 832 // Determine if the mouse has moved beyond a minimum elasticity distance in |
| 821 // any direction from the starting point. | 833 // any direction from the starting point. |
| 822 static const int kMinimumDragDistance = 10; | 834 static const int kMinimumDragDistance = 10; |
| 823 int x_offset = abs(point_in_screen.x() - start_point_in_screen_.x()); | 835 int x_offset = abs(point_in_screen.x() - start_point_in_screen_.x()); |
| 824 int y_offset = abs(point_in_screen.y() - start_point_in_screen_.y()); | 836 int y_offset = abs(point_in_screen.y() - start_point_in_screen_.y()); |
| 825 return sqrt(pow(static_cast<float>(x_offset), 2) + | 837 return sqrt(pow(static_cast<float>(x_offset), 2) + |
| 826 pow(static_cast<float>(y_offset), 2)) > kMinimumDragDistance; | 838 pow(static_cast<float>(y_offset), 2)) > kMinimumDragDistance; |
| 827 } | 839 } |
| 828 | 840 |
| 829 void TabDragController::ContinueDragging(const gfx::Point& point_in_screen) { | 841 void TabDragController::ContinueDragging(const gfx::Point& point_in_screen) { |
| 842 TRACE_EVENT1("views", "TabDragController::ContinueDragging", |
| 843 "point_in_screen", point_in_screen.ToString()); |
| 844 |
| 830 DCHECK(!detach_into_browser_ || attached_tabstrip_); | 845 DCHECK(!detach_into_browser_ || attached_tabstrip_); |
| 831 | 846 |
| 832 TabStrip* target_tabstrip = detach_behavior_ == DETACHABLE ? | 847 TabStrip* target_tabstrip = detach_behavior_ == DETACHABLE ? |
| 833 GetTargetTabStripForPoint(point_in_screen) : source_tabstrip_; | 848 GetTargetTabStripForPoint(point_in_screen) : source_tabstrip_; |
| 834 bool tab_strip_changed = (target_tabstrip != attached_tabstrip_); | 849 bool tab_strip_changed = (target_tabstrip != attached_tabstrip_); |
| 835 | 850 |
| 836 if (attached_tabstrip_) { | 851 if (attached_tabstrip_) { |
| 837 int move_delta = point_in_screen.x() - last_point_in_screen_.x(); | 852 int move_delta = point_in_screen.x() - last_point_in_screen_.x(); |
| 838 if (move_delta > 0) | 853 if (move_delta > 0) |
| 839 mouse_move_direction_ |= kMovedMouseRight; | 854 mouse_move_direction_ |= kMovedMouseRight; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 } else { | 894 } else { |
| 880 MoveDetached(point_in_screen); | 895 MoveDetached(point_in_screen); |
| 881 } | 896 } |
| 882 } | 897 } |
| 883 } | 898 } |
| 884 | 899 |
| 885 TabDragController::DragBrowserResultType | 900 TabDragController::DragBrowserResultType |
| 886 TabDragController::DragBrowserToNewTabStrip( | 901 TabDragController::DragBrowserToNewTabStrip( |
| 887 TabStrip* target_tabstrip, | 902 TabStrip* target_tabstrip, |
| 888 const gfx::Point& point_in_screen) { | 903 const gfx::Point& point_in_screen) { |
| 904 TRACE_EVENT1("views", "TabDragController::DragBrowserToNewTabStrip", |
| 905 "point_in_screen", point_in_screen.ToString()); |
| 906 |
| 889 if (!target_tabstrip) { | 907 if (!target_tabstrip) { |
| 890 DetachIntoNewBrowserAndRunMoveLoop(point_in_screen); | 908 DetachIntoNewBrowserAndRunMoveLoop(point_in_screen); |
| 891 return DRAG_BROWSER_RESULT_STOP; | 909 return DRAG_BROWSER_RESULT_STOP; |
| 892 } | 910 } |
| 893 if (is_dragging_window_) { | 911 if (is_dragging_window_) { |
| 894 // ReleaseCapture() is going to result in calling back to us (because it | 912 // ReleaseCapture() is going to result in calling back to us (because it |
| 895 // results in a move). That'll cause all sorts of problems. Reset the | 913 // results in a move). That'll cause all sorts of problems. Reset the |
| 896 // observer so we don't get notified and process the event. | 914 // observer so we don't get notified and process the event. |
| 897 if (host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) { | 915 if (host_desktop_type_ == chrome::HOST_DESKTOP_TYPE_ASH) { |
| 898 move_loop_widget_->RemoveObserver(this); | 916 move_loop_widget_->RemoveObserver(this); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 DockInfo info = DockInfo::GetDockInfoAtPoint( | 1170 DockInfo info = DockInfo::GetDockInfoAtPoint( |
| 1153 host_desktop_type_, | 1171 host_desktop_type_, |
| 1154 point_in_screen, | 1172 point_in_screen, |
| 1155 dock_windows_); | 1173 dock_windows_); |
| 1156 dock_windows_.erase(dragged_view); | 1174 dock_windows_.erase(dragged_view); |
| 1157 return info; | 1175 return info; |
| 1158 } | 1176 } |
| 1159 | 1177 |
| 1160 TabStrip* TabDragController::GetTargetTabStripForPoint( | 1178 TabStrip* TabDragController::GetTargetTabStripForPoint( |
| 1161 const gfx::Point& point_in_screen) { | 1179 const gfx::Point& point_in_screen) { |
| 1180 TRACE_EVENT1("views", "TabDragController::GetTargetTabStripForPoint", |
| 1181 "point_in_screen", point_in_screen.ToString()); |
| 1182 |
| 1162 if (move_only() && attached_tabstrip_) { | 1183 if (move_only() && attached_tabstrip_) { |
| 1163 DCHECK_EQ(DETACHABLE, detach_behavior_); | 1184 DCHECK_EQ(DETACHABLE, detach_behavior_); |
| 1164 // move_only() is intended for touch, in which case we only want to detach | 1185 // move_only() is intended for touch, in which case we only want to detach |
| 1165 // if the touch point moves significantly in the vertical distance. | 1186 // if the touch point moves significantly in the vertical distance. |
| 1166 gfx::Rect tabstrip_bounds = GetViewScreenBounds(attached_tabstrip_); | 1187 gfx::Rect tabstrip_bounds = GetViewScreenBounds(attached_tabstrip_); |
| 1167 if (DoesRectContainVerticalPointExpanded(tabstrip_bounds, | 1188 if (DoesRectContainVerticalPointExpanded(tabstrip_bounds, |
| 1168 kTouchVerticalDetachMagnetism, | 1189 kTouchVerticalDetachMagnetism, |
| 1169 point_in_screen.y())) | 1190 point_in_screen.y())) |
| 1170 return attached_tabstrip_; | 1191 return attached_tabstrip_; |
| 1171 } | 1192 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip); | 1238 gfx::Rect tabstrip_bounds = GetViewScreenBounds(tabstrip); |
| 1218 return point_in_screen.x() < tabstrip_bounds.right() && | 1239 return point_in_screen.x() < tabstrip_bounds.right() && |
| 1219 point_in_screen.x() >= tabstrip_bounds.x() && | 1240 point_in_screen.x() >= tabstrip_bounds.x() && |
| 1220 DoesRectContainVerticalPointExpanded(tabstrip_bounds, | 1241 DoesRectContainVerticalPointExpanded(tabstrip_bounds, |
| 1221 kVerticalDetachMagnetism, | 1242 kVerticalDetachMagnetism, |
| 1222 point_in_screen.y()); | 1243 point_in_screen.y()); |
| 1223 } | 1244 } |
| 1224 | 1245 |
| 1225 void TabDragController::Attach(TabStrip* attached_tabstrip, | 1246 void TabDragController::Attach(TabStrip* attached_tabstrip, |
| 1226 const gfx::Point& point_in_screen) { | 1247 const gfx::Point& point_in_screen) { |
| 1248 TRACE_EVENT1("views", "TabDragController::Attach", |
| 1249 "point_in_screen", point_in_screen.ToString()); |
| 1250 |
| 1227 DCHECK(!attached_tabstrip_); // We should already have detached by the time | 1251 DCHECK(!attached_tabstrip_); // We should already have detached by the time |
| 1228 // we get here. | 1252 // we get here. |
| 1229 | 1253 |
| 1230 attached_tabstrip_ = attached_tabstrip; | 1254 attached_tabstrip_ = attached_tabstrip; |
| 1231 | 1255 |
| 1232 // And we don't need the dragged view. | 1256 // And we don't need the dragged view. |
| 1233 view_.reset(); | 1257 view_.reset(); |
| 1234 | 1258 |
| 1235 std::vector<Tab*> tabs = | 1259 std::vector<Tab*> tabs = |
| 1236 GetTabsMatchingDraggedContents(attached_tabstrip_); | 1260 GetTabsMatchingDraggedContents(attached_tabstrip_); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 // Redirect all mouse events to the TabStrip so that the tab that originated | 1342 // Redirect all mouse events to the TabStrip so that the tab that originated |
| 1319 // the drag can safely be deleted. | 1343 // the drag can safely be deleted. |
| 1320 if (detach_into_browser_ || attached_tabstrip_ == source_tabstrip_) { | 1344 if (detach_into_browser_ || attached_tabstrip_ == source_tabstrip_) { |
| 1321 static_cast<views::internal::RootView*>( | 1345 static_cast<views::internal::RootView*>( |
| 1322 attached_tabstrip_->GetWidget()->GetRootView())->SetMouseHandler( | 1346 attached_tabstrip_->GetWidget()->GetRootView())->SetMouseHandler( |
| 1323 attached_tabstrip_); | 1347 attached_tabstrip_); |
| 1324 } | 1348 } |
| 1325 } | 1349 } |
| 1326 | 1350 |
| 1327 void TabDragController::Detach(ReleaseCapture release_capture) { | 1351 void TabDragController::Detach(ReleaseCapture release_capture) { |
| 1352 TRACE_EVENT1("views", "TabDragController::Detach", |
| 1353 "release_capture", release_capture); |
| 1354 |
| 1328 attach_index_ = -1; | 1355 attach_index_ = -1; |
| 1329 | 1356 |
| 1330 // When the user detaches we assume they want to reorder. | 1357 // When the user detaches we assume they want to reorder. |
| 1331 move_behavior_ = REORDER; | 1358 move_behavior_ = REORDER; |
| 1332 | 1359 |
| 1333 // Release ownership of the drag controller and mouse capture. When we | 1360 // Release ownership of the drag controller and mouse capture. When we |
| 1334 // reattach ownership is transfered. | 1361 // reattach ownership is transfered. |
| 1335 if (detach_into_browser_) { | 1362 if (detach_into_browser_) { |
| 1336 attached_tabstrip_->ReleaseDragController(); | 1363 attached_tabstrip_->ReleaseDragController(); |
| 1337 if (release_capture == RELEASE_CAPTURE) | 1364 if (release_capture == RELEASE_CAPTURE) |
| (...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2295 gfx::Vector2d TabDragController::GetWindowOffset( | 2322 gfx::Vector2d TabDragController::GetWindowOffset( |
| 2296 const gfx::Point& point_in_screen) { | 2323 const gfx::Point& point_in_screen) { |
| 2297 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 2324 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
| 2298 attached_tabstrip_ : source_tabstrip_; | 2325 attached_tabstrip_ : source_tabstrip_; |
| 2299 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2326 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
| 2300 | 2327 |
| 2301 gfx::Point point = point_in_screen; | 2328 gfx::Point point = point_in_screen; |
| 2302 views::View::ConvertPointFromScreen(toplevel_view, &point); | 2329 views::View::ConvertPointFromScreen(toplevel_view, &point); |
| 2303 return point.OffsetFromOrigin(); | 2330 return point.OffsetFromOrigin(); |
| 2304 } | 2331 } |
| OLD | NEW |