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/gtk/tabs/tab_strip_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/gtk_dnd_util.h" | 9 #include "app/gtk_dnd_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "app/slide_animation.h" | 11 #include "app/slide_animation.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "chrome/browser/autocomplete/autocomplete.h" | 14 #include "chrome/browser/autocomplete/autocomplete.h" |
| 15 #include "chrome/browser/browser.h" |
15 #include "chrome/browser/gtk/browser_window_gtk.h" | 16 #include "chrome/browser/gtk/browser_window_gtk.h" |
16 #include "chrome/browser/gtk/custom_button.h" | 17 #include "chrome/browser/gtk/custom_button.h" |
17 #include "chrome/browser/gtk/gtk_theme_provider.h" | 18 #include "chrome/browser/gtk/gtk_theme_provider.h" |
18 #include "chrome/browser/gtk/gtk_util.h" | 19 #include "chrome/browser/gtk/gtk_util.h" |
19 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" | 20 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" |
20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
22 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 23 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
23 #include "chrome/browser/themes/browser_theme_provider.h" | 24 #include "chrome/browser/themes/browser_theme_provider.h" |
| 25 #include "chrome/browser/ui/browser_navigator.h" |
24 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
25 #include "chrome/common/notification_type.h" | 27 #include "chrome/common/notification_type.h" |
26 #include "gfx/gtk_util.h" | 28 #include "gfx/gtk_util.h" |
27 #include "gfx/point.h" | 29 #include "gfx/point.h" |
28 #include "grit/app_resources.h" | 30 #include "grit/app_resources.h" |
29 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 const int kDefaultAnimationDurationMs = 100; | 35 const int kDefaultAnimationDurationMs = 100; |
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 const bool drop_before = drop_info_->drop_before; | 1607 const bool drop_before = drop_info_->drop_before; |
1606 | 1608 |
1607 // Destroy the drop indicator. | 1609 // Destroy the drop indicator. |
1608 drop_info_.reset(); | 1610 drop_info_.reset(); |
1609 | 1611 |
1610 std::string url_string(reinterpret_cast<char*>(data)); | 1612 std::string url_string(reinterpret_cast<char*>(data)); |
1611 GURL url(url_string.substr(0, url_string.find_first_of('\n'))); | 1613 GURL url(url_string.substr(0, url_string.find_first_of('\n'))); |
1612 if (!url.is_valid()) | 1614 if (!url.is_valid()) |
1613 return false; | 1615 return false; |
1614 | 1616 |
| 1617 browser::NavigateParams params(window()->browser(), url, |
| 1618 PageTransition::LINK); |
| 1619 params.tabstrip_index = drop_index; |
| 1620 |
1615 if (drop_before) { | 1621 if (drop_before) { |
1616 // Insert a new tab. | 1622 params.disposition = NEW_FOREGROUND_TAB; |
1617 TabContents* contents = | |
1618 model_->delegate()->CreateTabContentsForURL( | |
1619 url, GURL(), model_->profile(), PageTransition::TYPED, false, | |
1620 NULL); | |
1621 model_->AddTabContents(contents, drop_index, PageTransition::GENERATED, | |
1622 TabStripModel::ADD_SELECTED); | |
1623 } else { | 1623 } else { |
1624 model_->GetTabContentsAt(drop_index)->controller().LoadURL( | 1624 params.disposition = CURRENT_TAB; |
1625 url, GURL(), PageTransition::GENERATED); | 1625 params.source_contents = model_->GetTabContentsAt(drop_index); |
1626 model_->SelectTabContentsAt(drop_index, true); | |
1627 } | 1626 } |
1628 | 1627 |
| 1628 browser::Navigate(¶ms); |
| 1629 |
1629 return true; | 1630 return true; |
1630 } | 1631 } |
1631 | 1632 |
1632 // static | 1633 // static |
1633 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { | 1634 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { |
1634 return ResourceBundle::GetSharedInstance().GetPixbufNamed( | 1635 return ResourceBundle::GetSharedInstance().GetPixbufNamed( |
1635 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); | 1636 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); |
1636 } | 1637 } |
1637 | 1638 |
1638 // TabStripGtk::DropInfo ------------------------------------------------------- | 1639 // TabStripGtk::DropInfo ------------------------------------------------------- |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 case 1: | 1968 case 1: |
1968 model_->delegate()->AddBlankTab(true); | 1969 model_->delegate()->AddBlankTab(true); |
1969 break; | 1970 break; |
1970 case 2: { | 1971 case 2: { |
1971 // On middle-click, try to parse the PRIMARY selection as a URL and load | 1972 // On middle-click, try to parse the PRIMARY selection as a URL and load |
1972 // it instead of creating a blank page. | 1973 // it instead of creating a blank page. |
1973 GURL url; | 1974 GURL url; |
1974 if (!gtk_util::URLFromPrimarySelection(model_->profile(), &url)) | 1975 if (!gtk_util::URLFromPrimarySelection(model_->profile(), &url)) |
1975 return; | 1976 return; |
1976 | 1977 |
1977 TabContents* contents = | 1978 Browser* browser = window_->browser(); |
1978 model_->delegate()->CreateTabContentsForURL( | 1979 DCHECK(browser); |
1979 url, | 1980 browser->AddSelectedTabWithURL(url, PageTransition::TYPED); |
1980 GURL(), // referrer | |
1981 model_->profile(), | |
1982 PageTransition::TYPED, | |
1983 false, // defer_load | |
1984 NULL); // instance | |
1985 model_->AddTabContents( | |
1986 contents, | |
1987 -1, // index | |
1988 PageTransition::TYPED, | |
1989 TabStripModel::ADD_SELECTED); | |
1990 break; | 1981 break; |
1991 } | 1982 } |
1992 default: | 1983 default: |
1993 NOTREACHED() << "Got click on new tab button with unhandled mouse " | 1984 NOTREACHED() << "Got click on new tab button with unhandled mouse " |
1994 << "button " << mouse_button; | 1985 << "button " << mouse_button; |
1995 } | 1986 } |
1996 } | 1987 } |
1997 | 1988 |
1998 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { | 1989 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { |
1999 gfx::Rect bds = bounds; | 1990 gfx::Rect bds = bounds; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 | 2026 |
2036 // Let the middle mouse button initiate clicks as well. | 2027 // Let the middle mouse button initiate clicks as well. |
2037 gtk_util::SetButtonTriggersNavigation(button->widget()); | 2028 gtk_util::SetButtonTriggersNavigation(button->widget()); |
2038 g_signal_connect(button->widget(), "clicked", | 2029 g_signal_connect(button->widget(), "clicked", |
2039 G_CALLBACK(OnNewTabClickedThunk), this); | 2030 G_CALLBACK(OnNewTabClickedThunk), this); |
2040 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 2031 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
2041 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); | 2032 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); |
2042 | 2033 |
2043 return button; | 2034 return button; |
2044 } | 2035 } |
OLD | NEW |