Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller.cc

Issue 10479010: Gesture related changes for views: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test and add some mores Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/callback.h" 10 #include "base/callback.h"
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 move_loop_widget_->RemoveObserver(this); 771 move_loop_widget_->RemoveObserver(this);
772 move_loop_widget_ = NULL; 772 move_loop_widget_ = NULL;
773 #endif 773 #endif
774 views::Widget* browser_widget = GetAttachedBrowserWidget(); 774 views::Widget* browser_widget = GetAttachedBrowserWidget();
775 // Need to release the drag controller before starting the move loop as it's 775 // Need to release the drag controller before starting the move loop as it's
776 // going to trigger capture lost, which cancels drag. 776 // going to trigger capture lost, which cancels drag.
777 attached_tabstrip_->ReleaseDragController(); 777 attached_tabstrip_->ReleaseDragController();
778 target_tabstrip->OwnDragController(this); 778 target_tabstrip->OwnDragController(this);
779 // Disable animations so that we don't see a close animation on aero. 779 // Disable animations so that we don't see a close animation on aero.
780 browser_widget->SetVisibilityChangedAnimationsEnabled(false); 780 browser_widget->SetVisibilityChangedAnimationsEnabled(false);
781 browser_widget->ReleaseMouseCapture(); 781 browser_widget->ReleaseCapture();
782 // EndMoveLoop is going to snap the window back to its original location. 782 // EndMoveLoop is going to snap the window back to its original location.
783 // Hide it so users don't see this. 783 // Hide it so users don't see this.
784 browser_widget->Hide(); 784 browser_widget->Hide();
785 browser_widget->EndMoveLoop(); 785 browser_widget->EndMoveLoop();
786 786
787 // Ideally we would always swap the tabs now, but on windows it seems that 787 // Ideally we would always swap the tabs now, but on windows it seems that
788 // running the move loop implicitly activates the window when done, leading 788 // running the move loop implicitly activates the window when done, leading
789 // to all sorts of flicker. So, on windows, instead we process the move 789 // to all sorts of flicker. So, on windows, instead we process the move
790 // after the loop completes. But on chromeos, we can do tab swapping now to 790 // after the loop completes. But on chromeos, we can do tab swapping now to
791 // avoid the tab flashing issue(crbug.com/116329). 791 // avoid the tab flashing issue(crbug.com/116329).
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 int new_x = attached_tabstrip_->GetSizeNeededForTabs(tabs_to_source) - 1111 int new_x = attached_tabstrip_->GetSizeNeededForTabs(tabs_to_source) -
1112 tabs[source_tab_index_]->width() + 1112 tabs[source_tab_index_]->width() +
1113 static_cast<int>(offset_to_width_ratio_ * 1113 static_cast<int>(offset_to_width_ratio_ *
1114 tabs[source_tab_index_]->width()); 1114 tabs[source_tab_index_]->width());
1115 mouse_offset_.set_x(new_x); 1115 mouse_offset_.set_x(new_x);
1116 1116
1117 // Transfer ownership of us to the new tabstrip as well as making sure the 1117 // Transfer ownership of us to the new tabstrip as well as making sure the
1118 // window has mouse capture. This is important so that if activation changes 1118 // window has mouse capture. This is important so that if activation changes
1119 // the drag isn't prematurely canceled. 1119 // the drag isn't prematurely canceled.
1120 if (detach_into_browser_) { 1120 if (detach_into_browser_) {
1121 attached_tabstrip_->GetWidget()->SetMouseCapture(attached_tabstrip_); 1121 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_);
1122 attached_tabstrip_->OwnDragController(this); 1122 attached_tabstrip_->OwnDragController(this);
1123 } 1123 }
1124 1124
1125 // Redirect all mouse events to the TabStrip so that the tab that originated 1125 // Redirect all mouse events to the TabStrip so that the tab that originated
1126 // the drag can safely be deleted. 1126 // the drag can safely be deleted.
1127 if (detach_into_browser_ || attached_tabstrip_ == source_tabstrip_) { 1127 if (detach_into_browser_ || attached_tabstrip_ == source_tabstrip_) {
1128 static_cast<views::internal::RootView*>( 1128 static_cast<views::internal::RootView*>(
1129 attached_tabstrip_->GetWidget()->GetRootView())->SetMouseHandler( 1129 attached_tabstrip_->GetWidget()->GetRootView())->SetMouseHandler(
1130 attached_tabstrip_); 1130 attached_tabstrip_);
1131 } 1131 }
1132 } 1132 }
1133 1133
1134 void TabDragController::Detach() { 1134 void TabDragController::Detach() {
1135 // Release ownership of the drag controller and mouse capture. When we 1135 // Release ownership of the drag controller and mouse capture. When we
1136 // reattach ownership is transfered. 1136 // reattach ownership is transfered.
1137 if (detach_into_browser_) { 1137 if (detach_into_browser_) {
1138 attached_tabstrip_->ReleaseDragController(); 1138 attached_tabstrip_->ReleaseDragController();
1139 attached_tabstrip_->GetWidget()->ReleaseMouseCapture(); 1139 attached_tabstrip_->GetWidget()->ReleaseCapture();
1140 } 1140 }
1141 1141
1142 mouse_move_direction_ = kMovedMouseLeft | kMovedMouseRight; 1142 mouse_move_direction_ = kMovedMouseLeft | kMovedMouseRight;
1143 1143
1144 // Prevent the WebContents HWND from being hidden by any of the model 1144 // Prevent the WebContents HWND from being hidden by any of the model
1145 // operations performed during the drag. 1145 // operations performed during the drag.
1146 if (!detach_into_browser_) 1146 if (!detach_into_browser_)
1147 source_dragged_contents()->web_contents()->SetCapturingContents(true); 1147 source_dragged_contents()->web_contents()->SetCapturingContents(true);
1148 1148
1149 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(0); 1149 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(0);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 move_loop_widget_ = GetAttachedBrowserWidget(); 1246 move_loop_widget_ = GetAttachedBrowserWidget();
1247 DCHECK(move_loop_widget_); 1247 DCHECK(move_loop_widget_);
1248 move_loop_widget_->AddObserver(this); 1248 move_loop_widget_->AddObserver(this);
1249 is_dragging_window_ = true; 1249 is_dragging_window_ = true;
1250 bool destroyed = false; 1250 bool destroyed = false;
1251 destroyed_ = &destroyed; 1251 destroyed_ = &destroyed;
1252 // Running the move loop releases mouse capture on windows, which triggers 1252 // Running the move loop releases mouse capture on windows, which triggers
1253 // destroying the drag loop. Release mouse capture ourself before this while 1253 // destroying the drag loop. Release mouse capture ourself before this while
1254 // the DragController isn't owned by the TabStrip. 1254 // the DragController isn't owned by the TabStrip.
1255 attached_tabstrip_->ReleaseDragController(); 1255 attached_tabstrip_->ReleaseDragController();
1256 attached_tabstrip_->GetWidget()->ReleaseMouseCapture(); 1256 attached_tabstrip_->GetWidget()->ReleaseCapture();
1257 attached_tabstrip_->OwnDragController(this); 1257 attached_tabstrip_->OwnDragController(this);
1258 views::Widget::MoveLoopResult result = move_loop_widget_->RunMoveLoop(); 1258 views::Widget::MoveLoopResult result = move_loop_widget_->RunMoveLoop();
1259 content::NotificationService::current()->Notify( 1259 content::NotificationService::current()->Notify(
1260 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, 1260 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE,
1261 content::NotificationService::AllBrowserContextsAndSources(), 1261 content::NotificationService::AllBrowserContextsAndSources(),
1262 content::NotificationService::NoDetails()); 1262 content::NotificationService::NoDetails());
1263 1263
1264 if (destroyed) 1264 if (destroyed)
1265 return; 1265 return;
1266 destroyed_ = NULL; 1266 destroyed_ = NULL;
(...skipping 10 matching lines...) Expand all
1277 Detach(); 1277 Detach();
1278 // TODO: this needs to query the event. 1278 // TODO: this needs to query the event.
1279 gfx::Point screen_point(gfx::Screen::GetCursorScreenPoint()); 1279 gfx::Point screen_point(gfx::Screen::GetCursorScreenPoint());
1280 Attach(tab_strip_to_attach_to_after_exit_, screen_point); 1280 Attach(tab_strip_to_attach_to_after_exit_, screen_point);
1281 // Move the tabs into position. 1281 // Move the tabs into position.
1282 MoveAttached(screen_point); 1282 MoveAttached(screen_point);
1283 attached_tabstrip_->GetWidget()->Activate(); 1283 attached_tabstrip_->GetWidget()->Activate();
1284 tab_strip_to_attach_to_after_exit_ = NULL; 1284 tab_strip_to_attach_to_after_exit_ = NULL;
1285 } 1285 }
1286 DCHECK(attached_tabstrip_); 1286 DCHECK(attached_tabstrip_);
1287 attached_tabstrip_->GetWidget()->SetMouseCapture(attached_tabstrip_); 1287 attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_);
1288 } else if (active_) { 1288 } else if (active_) {
1289 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED); 1289 EndDrag(result == views::Widget::MOVE_LOOP_CANCELED);
1290 } 1290 }
1291 } 1291 }
1292 1292
1293 int TabDragController::GetInsertionIndexFrom(const gfx::Rect& dragged_bounds, 1293 int TabDragController::GetInsertionIndexFrom(const gfx::Rect& dragged_bounds,
1294 int start, 1294 int start,
1295 int delta) const { 1295 int delta) const {
1296 for (int i = start, tab_count = attached_tabstrip_->tab_count(); 1296 for (int i = start, tab_count = attached_tabstrip_->tab_count();
1297 i >= 0 && i < tab_count; i += delta) { 1297 i >= 0 && i < tab_count; i += delta) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 } 1877 }
1878 1878
1879 default: 1879 default:
1880 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. 1880 break; // Nothing to do for DETACH_ABOVE_OR_BELOW.
1881 } 1881 }
1882 1882
1883 SetTrackedByWorkspace(browser->window()->GetNativeHandle(), false); 1883 SetTrackedByWorkspace(browser->window()->GetNativeHandle(), false);
1884 browser->window()->SetBounds(new_bounds); 1884 browser->window()->SetBounds(new_bounds);
1885 return browser; 1885 return browser;
1886 } 1886 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698