| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk/tabs/dragged_tab_controller_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
| 13 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 14 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 17 #include "chrome/browser/ui/gtk/gtk_util.h" | 17 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 18 #include "chrome/browser/ui/gtk/tabs/dragged_view_gtk.h" | 18 #include "chrome/browser/ui/gtk/tabs/dragged_view_gtk.h" |
| 19 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" | 19 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "ui/base/gtk/gtk_screen_util.h" |
| 24 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 25 | 26 |
| 26 using content::OpenURLParams; | 27 using content::OpenURLParams; |
| 27 using content::WebContents; | 28 using content::WebContents; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Delay, in ms, during dragging before we bring a window to front. | 32 // Delay, in ms, during dragging before we bring a window to front. |
| 32 const int kBringToFrontDelay = 750; | 33 const int kBringToFrontDelay = 750; |
| 33 | 34 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 return NULL; | 370 return NULL; |
| 370 | 371 |
| 371 return GetTabStripIfItContains(other_tabstrip, screen_point); | 372 return GetTabStripIfItContains(other_tabstrip, screen_point); |
| 372 } | 373 } |
| 373 | 374 |
| 374 TabStripGtk* DraggedTabControllerGtk::GetTabStripIfItContains( | 375 TabStripGtk* DraggedTabControllerGtk::GetTabStripIfItContains( |
| 375 TabStripGtk* tabstrip, const gfx::Point& screen_point) const { | 376 TabStripGtk* tabstrip, const gfx::Point& screen_point) const { |
| 376 // Make sure the specified screen point is actually within the bounds of the | 377 // Make sure the specified screen point is actually within the bounds of the |
| 377 // specified tabstrip... | 378 // specified tabstrip... |
| 378 gfx::Rect tabstrip_bounds = | 379 gfx::Rect tabstrip_bounds = |
| 379 gtk_util::GetWidgetScreenBounds(tabstrip->tabstrip_.get()); | 380 ui::GetWidgetScreenBounds(tabstrip->tabstrip_.get()); |
| 380 if (screen_point.x() < tabstrip_bounds.right() && | 381 if (screen_point.x() < tabstrip_bounds.right() && |
| 381 screen_point.x() >= tabstrip_bounds.x()) { | 382 screen_point.x() >= tabstrip_bounds.x()) { |
| 382 // TODO(beng): make this be relative to the start position of the mouse for | 383 // TODO(beng): make this be relative to the start position of the mouse for |
| 383 // the source TabStrip. | 384 // the source TabStrip. |
| 384 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism; | 385 int upper_threshold = tabstrip_bounds.bottom() + kVerticalDetachMagnetism; |
| 385 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism; | 386 int lower_threshold = tabstrip_bounds.y() - kVerticalDetachMagnetism; |
| 386 if (screen_point.y() >= lower_threshold && | 387 if (screen_point.y() >= lower_threshold && |
| 387 screen_point.y() <= upper_threshold) { | 388 screen_point.y() <= upper_threshold) { |
| 388 return tabstrip; | 389 return tabstrip; |
| 389 } | 390 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 414 tab_count += drag_data_->size(); | 415 tab_count += drag_data_->size(); |
| 415 mini_tab_count += drag_data_->mini_tab_count(); | 416 mini_tab_count += drag_data_->mini_tab_count(); |
| 416 } | 417 } |
| 417 | 418 |
| 418 double unselected_width = 0, selected_width = 0; | 419 double unselected_width = 0, selected_width = 0; |
| 419 attached_tabstrip_->GetDesiredTabWidths(tab_count, mini_tab_count, | 420 attached_tabstrip_->GetDesiredTabWidths(tab_count, mini_tab_count, |
| 420 &unselected_width, &selected_width); | 421 &unselected_width, &selected_width); |
| 421 | 422 |
| 422 GtkWidget* parent_window = gtk_widget_get_parent( | 423 GtkWidget* parent_window = gtk_widget_get_parent( |
| 423 gtk_widget_get_parent(attached_tabstrip_->tabstrip_.get())); | 424 gtk_widget_get_parent(attached_tabstrip_->tabstrip_.get())); |
| 424 gfx::Rect window_bounds = gtk_util::GetWidgetScreenBounds(parent_window); | 425 gfx::Rect window_bounds = ui::GetWidgetScreenBounds(parent_window); |
| 425 dragged_view_->Attach(static_cast<int>(floor(selected_width + 0.5)), | 426 dragged_view_->Attach(static_cast<int>(floor(selected_width + 0.5)), |
| 426 TabGtk::GetMiniWidth(), window_bounds.width()); | 427 TabGtk::GetMiniWidth(), window_bounds.width()); |
| 427 | 428 |
| 428 if (attached_dragged_tabs.size() == 0) { | 429 if (attached_dragged_tabs.size() == 0) { |
| 429 // There is no tab in |attached_tabstrip| that corresponds to the dragged | 430 // There is no tab in |attached_tabstrip| that corresponds to the dragged |
| 430 // TabContents. We must now create one. | 431 // TabContents. We must now create one. |
| 431 | 432 |
| 432 // Remove ourselves as the delegate now that the dragged TabContents is | 433 // Remove ourselves as the delegate now that the dragged TabContents is |
| 433 // being inserted back into a Browser. | 434 // being inserted back into a Browser. |
| 434 for (size_t i = 0; i < drag_data_->size(); ++i) { | 435 for (size_t i = 0; i < drag_data_->size(); ++i) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 // Detaching resets the delegate, but we still want to be the delegate. | 498 // Detaching resets the delegate, but we still want to be the delegate. |
| 498 for (size_t i = 0; i < drag_data_->size(); ++i) | 499 for (size_t i = 0; i < drag_data_->size(); ++i) |
| 499 drag_data_->get(i)->contents_->web_contents()->SetDelegate(this); | 500 drag_data_->get(i)->contents_->web_contents()->SetDelegate(this); |
| 500 | 501 |
| 501 attached_tabstrip_ = NULL; | 502 attached_tabstrip_ = NULL; |
| 502 } | 503 } |
| 503 | 504 |
| 504 gfx::Point DraggedTabControllerGtk::ConvertScreenPointToTabStripPoint( | 505 gfx::Point DraggedTabControllerGtk::ConvertScreenPointToTabStripPoint( |
| 505 TabStripGtk* tabstrip, const gfx::Point& screen_point) { | 506 TabStripGtk* tabstrip, const gfx::Point& screen_point) { |
| 506 gfx::Point tabstrip_screen_point = | 507 gfx::Point tabstrip_screen_point = |
| 507 gtk_util::GetWidgetScreenPosition(tabstrip->tabstrip_.get()); | 508 ui::GetWidgetScreenPosition(tabstrip->tabstrip_.get()); |
| 508 return screen_point.Subtract(tabstrip_screen_point); | 509 return screen_point.Subtract(tabstrip_screen_point); |
| 509 } | 510 } |
| 510 | 511 |
| 511 gfx::Rect DraggedTabControllerGtk::GetDraggedViewTabStripBounds( | 512 gfx::Rect DraggedTabControllerGtk::GetDraggedViewTabStripBounds( |
| 512 const gfx::Point& screen_point) { | 513 const gfx::Point& screen_point) { |
| 513 gfx::Point client_point = | 514 gfx::Point client_point = |
| 514 ConvertScreenPointToTabStripPoint(attached_tabstrip_, screen_point); | 515 ConvertScreenPointToTabStripPoint(attached_tabstrip_, screen_point); |
| 515 gfx::Size tab_size = dragged_view_->attached_tab_size(); | 516 gfx::Size tab_size = dragged_view_->attached_tab_size(); |
| 516 return gfx::Rect(client_point.x(), client_point.y(), | 517 return gfx::Rect(client_point.x(), client_point.y(), |
| 517 dragged_view_->GetTotalWidthInTabStrip(), tab_size.height()); | 518 dragged_view_->GetTotalWidthInTabStrip(), tab_size.height()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 570 |
| 570 gfx::Point DraggedTabControllerGtk::GetDraggedViewPoint( | 571 gfx::Point DraggedTabControllerGtk::GetDraggedViewPoint( |
| 571 const gfx::Point& screen_point) { | 572 const gfx::Point& screen_point) { |
| 572 int x = screen_point.x() - | 573 int x = screen_point.x() - |
| 573 dragged_view_->GetWidthInTabStripUpToMousePointer(); | 574 dragged_view_->GetWidthInTabStripUpToMousePointer(); |
| 574 int y = screen_point.y() - mouse_offset_.y(); | 575 int y = screen_point.y() - mouse_offset_.y(); |
| 575 | 576 |
| 576 // If we're not attached, we just use x and y from above. | 577 // If we're not attached, we just use x and y from above. |
| 577 if (attached_tabstrip_) { | 578 if (attached_tabstrip_) { |
| 578 gfx::Rect tabstrip_bounds = | 579 gfx::Rect tabstrip_bounds = |
| 579 gtk_util::GetWidgetScreenBounds(attached_tabstrip_->tabstrip_.get()); | 580 ui::GetWidgetScreenBounds(attached_tabstrip_->tabstrip_.get()); |
| 580 // Snap the dragged tab to the tabstrip if we are attached, detaching | 581 // Snap the dragged tab to the tabstrip if we are attached, detaching |
| 581 // only when the mouse position (screen_point) exceeds the screen bounds | 582 // only when the mouse position (screen_point) exceeds the screen bounds |
| 582 // of the tabstrip. | 583 // of the tabstrip. |
| 583 if (x < tabstrip_bounds.x() && screen_point.x() >= tabstrip_bounds.x()) | 584 if (x < tabstrip_bounds.x() && screen_point.x() >= tabstrip_bounds.x()) |
| 584 x = tabstrip_bounds.x(); | 585 x = tabstrip_bounds.x(); |
| 585 | 586 |
| 586 gfx::Size tab_size = dragged_view_->attached_tab_size(); | 587 gfx::Size tab_size = dragged_view_->attached_tab_size(); |
| 587 int vertical_drag_magnetism = tab_size.height() * 2; | 588 int vertical_drag_magnetism = tab_size.height() * 2; |
| 588 int vertical_detach_point = tabstrip_bounds.y() - vertical_drag_magnetism; | 589 int vertical_detach_point = tabstrip_bounds.y() - vertical_drag_magnetism; |
| 589 if (y < tabstrip_bounds.y() && screen_point.y() >= vertical_detach_point) | 590 if (y < tabstrip_bounds.y() && screen_point.y() >= vertical_detach_point) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 // | 814 // |
| 814 // We use the requested bounds instead of the allocation because the | 815 // We use the requested bounds instead of the allocation because the |
| 815 // allocation is relative to the first windowed widget ancestor of the tab. | 816 // allocation is relative to the first windowed widget ancestor of the tab. |
| 816 // Because of this, we can't use the tabs allocation to get the screen bounds. | 817 // Because of this, we can't use the tabs allocation to get the screen bounds. |
| 817 std::vector<TabGtk*> tabs = GetTabsMatchingDraggedContents( | 818 std::vector<TabGtk*> tabs = GetTabsMatchingDraggedContents( |
| 818 attached_tabstrip_); | 819 attached_tabstrip_); |
| 819 TabGtk* tab = !base::i18n::IsRTL() ? tabs.front() : tabs.back(); | 820 TabGtk* tab = !base::i18n::IsRTL() ? tabs.front() : tabs.back(); |
| 820 gfx::Rect bounds = tab->GetRequisition(); | 821 gfx::Rect bounds = tab->GetRequisition(); |
| 821 GtkWidget* widget = tab->widget(); | 822 GtkWidget* widget = tab->widget(); |
| 822 GtkWidget* parent = gtk_widget_get_parent(widget); | 823 GtkWidget* parent = gtk_widget_get_parent(widget); |
| 823 gfx::Point point = gtk_util::GetWidgetScreenPosition(parent); | 824 gfx::Point point = ui::GetWidgetScreenPosition(parent); |
| 824 bounds.Offset(point); | 825 bounds.Offset(point); |
| 825 | 826 |
| 826 return gfx::Rect(bounds.x(), bounds.y(), | 827 return gfx::Rect(bounds.x(), bounds.y(), |
| 827 dragged_view_->GetTotalWidthInTabStrip(), bounds.height()); | 828 dragged_view_->GetTotalWidthInTabStrip(), bounds.height()); |
| 828 } | 829 } |
| 829 | 830 |
| 830 void DraggedTabControllerGtk::HideWindow() { | 831 void DraggedTabControllerGtk::HideWindow() { |
| 831 GtkWidget* tabstrip = source_tabstrip_->widget(); | 832 GtkWidget* tabstrip = source_tabstrip_->widget(); |
| 832 GtkWindow* window = platform_util::GetTopLevel(tabstrip); | 833 GtkWindow* window = platform_util::GetTopLevel(tabstrip); |
| 833 gtk_widget_hide(GTK_WIDGET(window)); | 834 gtk_widget_hide(GTK_WIDGET(window)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 | 894 |
| 894 bool DraggedTabControllerGtk::AreTabsConsecutive() { | 895 bool DraggedTabControllerGtk::AreTabsConsecutive() { |
| 895 for (size_t i = 1; i < drag_data_->size(); ++i) { | 896 for (size_t i = 1; i < drag_data_->size(); ++i) { |
| 896 if (drag_data_->get(i - 1)->source_model_index_ + 1 != | 897 if (drag_data_->get(i - 1)->source_model_index_ + 1 != |
| 897 drag_data_->get(i)->source_model_index_) { | 898 drag_data_->get(i)->source_model_index_) { |
| 898 return false; | 899 return false; |
| 899 } | 900 } |
| 900 } | 901 } |
| 901 return true; | 902 return true; |
| 902 } | 903 } |
| OLD | NEW |