| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tabs/dragged_tab_controller.h" | 5 #include "chrome/browser/views/tabs/dragged_tab_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/animation.h" | 10 #include "app/animation.h" |
| 11 #include "app/slide_animation.h" | 11 #include "app/slide_animation.h" |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/keyboard_codes.h" | 16 #include "base/keyboard_codes.h" |
| 17 #include "chrome/browser/browser_window.h" | 17 #include "chrome/browser/browser_window.h" |
| 18 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 18 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/metrics/user_metrics.h" | 20 #include "chrome/browser/metrics/user_metrics.h" |
| 21 #include "chrome/browser/views/frame/browser_view.h" | 21 #include "chrome/browser/views/frame/browser_view.h" |
| 22 #include "chrome/browser/views/tabs/dragged_tab_view.h" | 22 #include "chrome/browser/views/tabs/dragged_tab_view.h" |
| 23 #include "chrome/browser/views/tabs/native_view_photobooth.h" | 23 #include "chrome/browser/views/tabs/native_view_photobooth.h" |
| 24 #include "chrome/browser/views/tabs/tab.h" | 24 #include "chrome/browser/views/tabs/tab.h" |
| 25 #include "chrome/browser/views/tabs/tab_strip.h" | 25 #include "chrome/browser/views/tabs/tab_strip.h" |
| 26 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 27 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
| 28 #include "gfx/canvas.h" | 27 #include "gfx/canvas.h" |
| 29 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "views/event.h" | 30 #include "views/event.h" |
| 32 #include "views/widget/root_view.h" | 31 #include "views/widget/root_view.h" |
| 33 #include "views/widget/widget.h" | 32 #include "views/widget/widget.h" |
| 34 #include "views/window/window.h" | 33 #include "views/window/window.h" |
| 35 | 34 |
| 36 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 37 #include "views/widget/widget_win.h" | 36 #include "views/widget/widget_win.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 #if defined(OS_LINUX) | 39 #if defined(OS_LINUX) |
| 41 #include <gdk/gdk.h> | 40 #include <gdk/gdk.h> |
| 42 #include <gdk/gdkkeysyms.h> | 41 #include <gdk/gdkkeysyms.h> |
| 43 #endif | 42 #endif |
| 44 | 43 |
| 45 static const int kHorizontalMoveThreshold = 16; // pixels | 44 static const int kHorizontalMoveThreshold = 16; // Pixels. |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 // Delay, in ms, during dragging before we bring a window to front. | 48 // Delay, in ms, during dragging before we bring a window to front. |
| 50 const int kBringToFrontDelay = 750; | 49 const int kBringToFrontDelay = 750; |
| 51 | 50 |
| 52 // Radius of the rect drawn by DockView. | 51 // Radius of the rect drawn by DockView. |
| 53 const int kRoundedRectRadius = 4; | 52 const int kRoundedRectRadius = 4; |
| 54 | 53 |
| 55 // Spacing between tab icons when DockView is showing a docking location that | 54 // Spacing between tab icons when DockView is showing a docking location that |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 330 |
| 332 DraggedTabController::~DraggedTabController() { | 331 DraggedTabController::~DraggedTabController() { |
| 333 in_destructor_ = true; | 332 in_destructor_ = true; |
| 334 CleanUpSourceTab(); | 333 CleanUpSourceTab(); |
| 335 MessageLoopForUI::current()->RemoveObserver(this); | 334 MessageLoopForUI::current()->RemoveObserver(this); |
| 336 // Need to delete the view here manually _before_ we reset the dragged | 335 // Need to delete the view here manually _before_ we reset the dragged |
| 337 // contents to NULL, otherwise if the view is animating to its destination | 336 // contents to NULL, otherwise if the view is animating to its destination |
| 338 // bounds, it won't be able to clean up properly since its cleanup routine | 337 // bounds, it won't be able to clean up properly since its cleanup routine |
| 339 // uses GetIndexForDraggedContents, which will be invalid. | 338 // uses GetIndexForDraggedContents, which will be invalid. |
| 340 view_.reset(NULL); | 339 view_.reset(NULL); |
| 341 SetDraggedContents(NULL); // This removes our observer. | 340 SetDraggedContents(NULL); // This removes our observer. |
| 342 } | 341 } |
| 343 | 342 |
| 344 void DraggedTabController::CaptureDragInfo(const gfx::Point& mouse_offset) { | 343 void DraggedTabController::CaptureDragInfo(const gfx::Point& mouse_offset) { |
| 345 start_screen_point_ = GetCursorScreenPoint(); | 344 start_screen_point_ = GetCursorScreenPoint(); |
| 346 mouse_offset_ = mouse_offset; | 345 mouse_offset_ = mouse_offset; |
| 347 InitWindowCreatePoint(); | 346 InitWindowCreatePoint(); |
| 348 } | 347 } |
| 349 | 348 |
| 350 void DraggedTabController::Drag() { | 349 void DraggedTabController::Drag() { |
| 351 bring_to_front_timer_.Stop(); | 350 bring_to_front_timer_.Stop(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 // Update the View first, so we can ask it for its bounds and determine | 757 // Update the View first, so we can ask it for its bounds and determine |
| 759 // where to insert the hidden Tab. | 758 // where to insert the hidden Tab. |
| 760 | 759 |
| 761 // If this is the first time Attach is called for this drag, we're attaching | 760 // If this is the first time Attach is called for this drag, we're attaching |
| 762 // to the source TabStrip, and we should assume the tab count already | 761 // to the source TabStrip, and we should assume the tab count already |
| 763 // includes this Tab since we haven't been detached yet. If we don't do this, | 762 // includes this Tab since we haven't been detached yet. If we don't do this, |
| 764 // the dragged representation will be a different size to others in the | 763 // the dragged representation will be a different size to others in the |
| 765 // TabStrip. | 764 // TabStrip. |
| 766 int tab_count = attached_tabstrip_->GetTabCount(); | 765 int tab_count = attached_tabstrip_->GetTabCount(); |
| 767 int mini_tab_count = attached_tabstrip_->GetMiniTabCount(); | 766 int mini_tab_count = attached_tabstrip_->GetMiniTabCount(); |
| 767 int nano_tab_count = attached_tabstrip_->GetNanoTabCount(); |
| 768 if (!tab) | 768 if (!tab) |
| 769 ++tab_count; | 769 ++tab_count; |
| 770 double unselected_width, selected_width = 0; | 770 double unselected_width, selected_width = 0; |
| 771 attached_tabstrip_->GetDesiredTabWidths(tab_count, mini_tab_count, | 771 attached_tabstrip_->GetDesiredTabWidths(tab_count, mini_tab_count, |
| 772 &unselected_width, &selected_width); | 772 nano_tab_count, &unselected_width, |
| 773 &selected_width); |
| 773 EnsureDraggedView(); | 774 EnsureDraggedView(); |
| 774 int dragged_tab_width = | 775 int dragged_tab_width = |
| 775 mini_ ? Tab::GetMiniWidth() : static_cast<int>(selected_width); | 776 mini_ ? Tab::GetMiniWidth() : static_cast<int>(selected_width); |
| 776 view_->Attach(dragged_tab_width); | 777 view_->Attach(dragged_tab_width); |
| 777 | 778 |
| 778 if (!tab) { | 779 if (!tab) { |
| 779 // There is no Tab in |attached_tabstrip| that corresponds to the dragged | 780 // There is no Tab in |attached_tabstrip| that corresponds to the dragged |
| 780 // TabContents. We must now create one. | 781 // TabContents. We must now create one. |
| 781 | 782 |
| 782 // Remove ourselves as the delegate now that the dragged TabContents is | 783 // Remove ourselves as the delegate now that the dragged TabContents is |
| (...skipping 18 matching lines...) Expand all Loading... |
| 801 // representation and the ideal bounds of the other Tabs already in the | 802 // representation and the ideal bounds of the other Tabs already in the |
| 802 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are | 803 // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are |
| 803 // changing due to animation). | 804 // changing due to animation). |
| 804 gfx::Rect bounds = GetDraggedViewTabStripBounds(screen_point); | 805 gfx::Rect bounds = GetDraggedViewTabStripBounds(screen_point); |
| 805 int index = GetInsertionIndexForDraggedBounds(bounds, false); | 806 int index = GetInsertionIndexForDraggedBounds(bounds, false); |
| 806 attached_tabstrip_->model()->InsertTabContentsAt(index, dragged_contents_, | 807 attached_tabstrip_->model()->InsertTabContentsAt(index, dragged_contents_, |
| 807 true, false, pinned_); | 808 true, false, pinned_); |
| 808 | 809 |
| 809 tab = GetTabMatchingDraggedContents(attached_tabstrip_); | 810 tab = GetTabMatchingDraggedContents(attached_tabstrip_); |
| 810 } | 811 } |
| 811 DCHECK(tab); // We should now have a tab. | 812 DCHECK(tab); // We should now have a tab. |
| 812 tab->SetVisible(false); | 813 tab->SetVisible(false); |
| 813 | 814 |
| 814 // Move the corresponding window to the front. | 815 // Move the corresponding window to the front. |
| 815 attached_tabstrip_->GetWindow()->Activate(); | 816 attached_tabstrip_->GetWindow()->Activate(); |
| 816 } | 817 } |
| 817 | 818 |
| 818 void DraggedTabController::Detach() { | 819 void DraggedTabController::Detach() { |
| 819 // Prevent the TabContents' HWND from being hidden by any of the model | 820 // Prevent the TabContents' HWND from being hidden by any of the model |
| 820 // operations performed during the drag. | 821 // operations performed during the drag. |
| 821 dragged_contents_->set_capturing_contents(true); | 822 dragged_contents_->set_capturing_contents(true); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 | 1288 |
| 1288 // The previous call made the window appear on top of the dragged window, | 1289 // The previous call made the window appear on top of the dragged window, |
| 1289 // move the dragged window to the front. | 1290 // move the dragged window to the front. |
| 1290 SetWindowPos(view_->GetWidget()->GetNativeView(), HWND_TOP, 0, 0, 0, 0, | 1291 SetWindowPos(view_->GetWidget()->GetNativeView(), HWND_TOP, 0, 0, 0, 0, |
| 1291 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); | 1292 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 1292 #else | 1293 #else |
| 1293 NOTIMPLEMENTED(); | 1294 NOTIMPLEMENTED(); |
| 1294 #endif | 1295 #endif |
| 1295 } | 1296 } |
| 1296 } | 1297 } |
| OLD | NEW |