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

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

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix step one more time Created 8 years, 1 month 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
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/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 105 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
106 106
107 gfx::ImageSkia* high_icon = rb.GetImageSkiaNamed(IDR_DOCK_HIGH); 107 gfx::ImageSkia* high_icon = rb.GetImageSkiaNamed(IDR_DOCK_HIGH);
108 gfx::ImageSkia* wide_icon = rb.GetImageSkiaNamed(IDR_DOCK_WIDE); 108 gfx::ImageSkia* wide_icon = rb.GetImageSkiaNamed(IDR_DOCK_WIDE);
109 109
110 canvas->Save(); 110 canvas->Save();
111 bool rtl_ui = base::i18n::IsRTL(); 111 bool rtl_ui = base::i18n::IsRTL();
112 if (rtl_ui) { 112 if (rtl_ui) {
113 // Flip canvas to draw the mirrored tab images for RTL UI. 113 // Flip canvas to draw the mirrored tab images for RTL UI.
114 canvas->Translate(gfx::Point(width(), 0)); 114 canvas->Translate(gfx::Vector2d(width(), 0));
115 canvas->Scale(-1, 1); 115 canvas->Scale(-1, 1);
116 } 116 }
117 int x_of_active_tab = width() / 2 + kTabSpacing / 2; 117 int x_of_active_tab = width() / 2 + kTabSpacing / 2;
118 int x_of_inactive_tab = width() / 2 - high_icon->width() - kTabSpacing / 2; 118 int x_of_inactive_tab = width() / 2 - high_icon->width() - kTabSpacing / 2;
119 switch (type_) { 119 switch (type_) {
120 case DockInfo::LEFT_OF_WINDOW: 120 case DockInfo::LEFT_OF_WINDOW:
121 case DockInfo::LEFT_HALF: 121 case DockInfo::LEFT_HALF:
122 if (!rtl_ui) 122 if (!rtl_ui)
123 std::swap(x_of_active_tab, x_of_inactive_tab); 123 std::swap(x_of_active_tab, x_of_inactive_tab);
124 canvas->DrawImageInt(*high_icon, x_of_active_tab, 124 canvas->DrawImageInt(*high_icon, x_of_active_tab,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 if (!started_drag_) { 475 if (!started_drag_) {
476 if (!CanStartDrag(real_point_in_screen)) 476 if (!CanStartDrag(real_point_in_screen))
477 return; // User hasn't dragged far enough yet. 477 return; // User hasn't dragged far enough yet.
478 478
479 started_drag_ = true; 479 started_drag_ = true;
480 SaveFocus(); 480 SaveFocus();
481 Attach(source_tabstrip_, gfx::Point()); 481 Attach(source_tabstrip_, gfx::Point());
482 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == 482 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) ==
483 GetModel(source_tabstrip_)->count()) { 483 GetModel(source_tabstrip_)->count()) {
484 gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); 484 RunMoveLoop(GetWindowOffset(point_in_screen));
485 RunMoveLoop(dragged_view_point);
486 return; 485 return;
487 } 486 }
488 } 487 }
489 488
490 ContinueDragging(real_point_in_screen); 489 ContinueDragging(real_point_in_screen);
491 } 490 }
492 491
493 void TabDragController::EndDrag(EndDragReason reason) { 492 void TabDragController::EndDrag(EndDragReason reason) {
494 // If we're dragging a window ignore capture lost since it'll ultimately 493 // If we're dragging a window ignore capture lost since it'll ultimately
495 // trigger the move loop to end and we'll revert the drag when RunMoveLoop() 494 // trigger the move loop to end and we'll revert the drag when RunMoveLoop()
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 attached_tabstrip_ = NULL; 1264 attached_tabstrip_ = NULL;
1266 } 1265 }
1267 1266
1268 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( 1267 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop(
1269 const gfx::Point& point_in_screen) { 1268 const gfx::Point& point_in_screen) {
1270 if (GetModel(attached_tabstrip_)->count() == 1269 if (GetModel(attached_tabstrip_)->count() ==
1271 static_cast<int>(drag_data_.size())) { 1270 static_cast<int>(drag_data_.size())) {
1272 // All the tabs in a browser are being dragged but all the tabs weren't 1271 // All the tabs in a browser are being dragged but all the tabs weren't
1273 // initially being dragged. For this to happen the user would have to 1272 // initially being dragged. For this to happen the user would have to
1274 // start dragging a set of tabs, the other tabs close, then detach. 1273 // start dragging a set of tabs, the other tabs close, then detach.
1275 gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); 1274 RunMoveLoop(GetWindowOffset(point_in_screen));
1276 RunMoveLoop(dragged_view_point);
1277 return; 1275 return;
1278 } 1276 }
1279 1277
1280 // Create a new browser to house the dragged tabs and have the OS run a move 1278 // Create a new browser to house the dragged tabs and have the OS run a move
1281 // loop. 1279 // loop.
1282 1280
1283 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen); 1281 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen);
1284 1282
1285 // Calculate the bounds for the tabs from the attached_tab_strip. We do this 1283 // Calculate the bounds for the tabs from the attached_tab_strip. We do this
1286 // so that the tabs don't change size when detached. 1284 // so that the tabs don't change size when detached.
1287 std::vector<gfx::Rect> drag_bounds = 1285 std::vector<gfx::Rect> drag_bounds =
1288 CalculateBoundsForDraggedTabs(attached_point.x()); 1286 CalculateBoundsForDraggedTabs(attached_point.x());
1289 1287
1290 gfx::Point drag_offset; 1288 gfx::Vector2d drag_offset;
1291 Browser* browser = CreateBrowserForDrag( 1289 Browser* browser = CreateBrowserForDrag(
1292 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); 1290 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds);
1293 Detach(DONT_RELEASE_CAPTURE); 1291 Detach(DONT_RELEASE_CAPTURE);
1294 BrowserView* dragged_browser_view = 1292 BrowserView* dragged_browser_view =
1295 BrowserView::GetBrowserViewForBrowser(browser); 1293 BrowserView::GetBrowserViewForBrowser(browser);
1296 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( 1294 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(
1297 false); 1295 false);
1298 Attach(dragged_browser_view->tabstrip(), gfx::Point()); 1296 Attach(dragged_browser_view->tabstrip(), gfx::Point());
1299 // TODO: come up with a cleaner way to do this. 1297 // TODO: come up with a cleaner way to do this.
1300 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); 1298 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds);
1301 1299
1302 browser->window()->Show(); 1300 browser->window()->Show();
1303 browser->window()->Activate(); 1301 browser->window()->Activate();
1304 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( 1302 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled(
1305 true); 1303 true);
1306 RunMoveLoop(drag_offset); 1304 RunMoveLoop(drag_offset);
1307 } 1305 }
1308 1306
1309 void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { 1307 void TabDragController::RunMoveLoop(const gfx::Vector2d& drag_offset) {
1310 // If the user drags the whole window we'll assume they are going to attach to 1308 // If the user drags the whole window we'll assume they are going to attach to
1311 // another window and therefor want to reorder. 1309 // another window and therefor want to reorder.
1312 move_behavior_ = REORDER; 1310 move_behavior_ = REORDER;
1313 1311
1314 move_loop_widget_ = GetAttachedBrowserWidget(); 1312 move_loop_widget_ = GetAttachedBrowserWidget();
1315 DCHECK(move_loop_widget_); 1313 DCHECK(move_loop_widget_);
1316 move_loop_widget_->AddObserver(this); 1314 move_loop_widget_->AddObserver(this);
1317 is_dragging_window_ = true; 1315 is_dragging_window_ = true;
1318 bool destroyed = false; 1316 bool destroyed = false;
1319 destroyed_ = &destroyed; 1317 destroyed_ = &destroyed;
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 drag_data_[i].source_model_index) { 1928 drag_data_[i].source_model_index) {
1931 return false; 1929 return false;
1932 } 1930 }
1933 } 1931 }
1934 return true; 1932 return true;
1935 } 1933 }
1936 1934
1937 Browser* TabDragController::CreateBrowserForDrag( 1935 Browser* TabDragController::CreateBrowserForDrag(
1938 TabStrip* source, 1936 TabStrip* source,
1939 const gfx::Point& point_in_screen, 1937 const gfx::Point& point_in_screen,
1940 gfx::Point* drag_offset, 1938 gfx::Vector2d* drag_offset,
1941 std::vector<gfx::Rect>* drag_bounds) { 1939 std::vector<gfx::Rect>* drag_bounds) {
1942 gfx::Point center(0, source->height() / 2); 1940 gfx::Point center(0, source->height() / 2);
1943 views::View::ConvertPointToWidget(source, &center); 1941 views::View::ConvertPointToWidget(source, &center);
1944 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); 1942 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen());
1945 new_bounds.set_y(point_in_screen.y() - center.y()); 1943 new_bounds.set_y(point_in_screen.y() - center.y());
1946 switch (GetDetachPosition(point_in_screen)) { 1944 switch (GetDetachPosition(point_in_screen)) {
1947 case DETACH_BEFORE: 1945 case DETACH_BEFORE:
1948 new_bounds.set_x(point_in_screen.x() - center.x()); 1946 new_bounds.set_x(point_in_screen.x() - center.x());
1949 new_bounds.Offset(-mouse_offset_.x(), 0); 1947 new_bounds.Offset(-mouse_offset_.x(), 0);
1950 break; 1948 break;
1951 1949
1952 case DETACH_AFTER: { 1950 case DETACH_AFTER: {
1953 gfx::Point right_edge(source->width(), 0); 1951 gfx::Point right_edge(source->width(), 0);
1954 views::View::ConvertPointToWidget(source, &right_edge); 1952 views::View::ConvertPointToWidget(source, &right_edge);
1955 new_bounds.set_x(point_in_screen.x() - right_edge.x()); 1953 new_bounds.set_x(point_in_screen.x() - right_edge.x());
1956 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); 1954 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0);
1957 int delta = (*drag_bounds)[0].x(); 1955 int delta = (*drag_bounds)[0].x();
1958 for (size_t i = 0; i < drag_bounds->size(); ++i) 1956 for (size_t i = 0; i < drag_bounds->size(); ++i)
1959 (*drag_bounds)[i].Offset(-delta, 0); 1957 (*drag_bounds)[i].Offset(-delta, 0);
1960 break; 1958 break;
1961 } 1959 }
1962 1960
1963 default: 1961 default:
1964 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. 1962 break; // Nothing to do for DETACH_ABOVE_OR_BELOW.
1965 } 1963 }
1966 1964
1967 *drag_offset = point_in_screen.Subtract(new_bounds.origin()); 1965 *drag_offset = point_in_screen - new_bounds.origin();
1968 1966
1969 Browser::CreateParams create_params(drag_data_[0].contents->profile()); 1967 Browser::CreateParams create_params(drag_data_[0].contents->profile());
1970 create_params.initial_bounds = new_bounds; 1968 create_params.initial_bounds = new_bounds;
1971 Browser* browser = new Browser(create_params); 1969 Browser* browser = new Browser(create_params);
1972 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); 1970 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false);
1973 // If the window is created maximized then the bounds we supplied are ignored. 1971 // If the window is created maximized then the bounds we supplied are ignored.
1974 // We need to reset them again so they are honored. 1972 // We need to reset them again so they are honored.
1975 browser->window()->SetBounds(new_bounds); 1973 browser->window()->SetBounds(new_bounds);
1976 return browser; 1974 return browser;
1977 } 1975 }
1978 1976
1979 gfx::Point TabDragController::GetCursorScreenPoint() { 1977 gfx::Point TabDragController::GetCursorScreenPoint() {
1980 #if defined(USE_ASH) 1978 #if defined(USE_ASH)
1981 views::Widget* widget = GetAttachedBrowserWidget(); 1979 views::Widget* widget = GetAttachedBrowserWidget();
1982 DCHECK(widget); 1980 DCHECK(widget);
1983 if (aura::Env::GetInstance()->is_touch_down()) { 1981 if (aura::Env::GetInstance()->is_touch_down()) {
1984 aura::Window* widget_window = widget->GetNativeWindow(); 1982 aura::Window* widget_window = widget->GetNativeWindow();
1985 DCHECK(widget_window->GetRootWindow()); 1983 DCHECK(widget_window->GetRootWindow());
1986 gfx::Point touch_point; 1984 gfx::Point touch_point;
1987 bool got_touch_point = widget_window->GetRootWindow()-> 1985 bool got_touch_point = widget_window->GetRootWindow()->
1988 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, 1986 gesture_recognizer()->GetLastTouchPointForTarget(widget_window,
1989 &touch_point); 1987 &touch_point);
1990 DCHECK(got_touch_point); 1988 DCHECK(got_touch_point);
1991 return touch_point; 1989 return touch_point;
1992 } 1990 }
1993 #endif 1991 #endif
1994 return screen_->GetCursorScreenPoint(); 1992 return screen_->GetCursorScreenPoint();
1995 } 1993 }
1996 1994
1997 gfx::Point TabDragController::GetWindowOffset( 1995 gfx::Vector2d TabDragController::GetWindowOffset(
1998 const gfx::Point& point_in_screen) { 1996 const gfx::Point& point_in_screen) {
1999 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? 1997 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ?
2000 attached_tabstrip_ : source_tabstrip_; 1998 attached_tabstrip_ : source_tabstrip_;
2001 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); 1999 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView();
2002 2000
2003 gfx::Point offset = point_in_screen; 2001 gfx::Point point = point_in_screen;
2004 views::View::ConvertPointFromScreen(toplevel_view, &offset); 2002 views::View::ConvertPointFromScreen(toplevel_view, &point);
2005 return offset; 2003 return point.OffsetFromOrigin();
2006 } 2004 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698