| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gfx/canvas_paint.h" | 9 #include "app/gfx/canvas_paint.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", | 487 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", |
| 488 G_CALLBACK(OnExpose), this); | 488 G_CALLBACK(OnExpose), this); |
| 489 g_signal_connect(G_OBJECT(tabstrip_.get()), "size-allocate", | 489 g_signal_connect(G_OBJECT(tabstrip_.get()), "size-allocate", |
| 490 G_CALLBACK(OnSizeAllocate), this); | 490 G_CALLBACK(OnSizeAllocate), this); |
| 491 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-motion", | 491 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-motion", |
| 492 G_CALLBACK(OnDragMotion), this); | 492 G_CALLBACK(OnDragMotion), this); |
| 493 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-drop", | 493 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-drop", |
| 494 G_CALLBACK(OnDragDrop), this); | 494 G_CALLBACK(OnDragDrop), this); |
| 495 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-leave", | 495 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-leave", |
| 496 G_CALLBACK(OnDragLeave), this); | 496 G_CALLBACK(OnDragLeave), this); |
| 497 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-failed", | |
| 498 G_CALLBACK(OnDragFailed), this); | |
| 499 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-data-received", | 497 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-data-received", |
| 500 G_CALLBACK(OnDragDataReceived), this); | 498 G_CALLBACK(OnDragDataReceived), this); |
| 501 | 499 |
| 502 newtab_button_.reset(MakeNewTabButton()); | 500 newtab_button_.reset(MakeNewTabButton()); |
| 503 | 501 |
| 504 #if defined(OS_CHROMEOS) | 502 #if defined(OS_CHROMEOS) |
| 505 tab_overview_button_.reset(MakeTabOverviewButton()); | 503 tab_overview_button_.reset(MakeTabOverviewButton()); |
| 506 #endif | 504 #endif |
| 507 | 505 |
| 508 gtk_widget_show_all(tabstrip_.get()); | 506 gtk_widget_show_all(tabstrip_.get()); |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 drop_info_->drop_arrow= GetDropArrowImage(drop_info_->point_down); | 1215 drop_info_->drop_arrow= GetDropArrowImage(drop_info_->point_down); |
| 1218 } | 1216 } |
| 1219 } | 1217 } |
| 1220 | 1218 |
| 1221 gtk_window_move(GTK_WINDOW(drop_info_->container), | 1219 gtk_window_move(GTK_WINDOW(drop_info_->container), |
| 1222 drop_bounds.x(), drop_bounds.y()); | 1220 drop_bounds.x(), drop_bounds.y()); |
| 1223 gtk_window_resize(GTK_WINDOW(drop_info_->container), | 1221 gtk_window_resize(GTK_WINDOW(drop_info_->container), |
| 1224 drop_bounds.width(), drop_bounds.height()); | 1222 drop_bounds.width(), drop_bounds.height()); |
| 1225 } | 1223 } |
| 1226 | 1224 |
| 1227 void TabStripGtk::CompleteDrop(guchar* data) { | 1225 bool TabStripGtk::CompleteDrop(guchar* data) { |
| 1228 if (!drop_info_.get()) | 1226 if (!drop_info_.get()) |
| 1229 return; | 1227 return false; |
| 1230 | 1228 |
| 1231 const int drop_index = drop_info_->drop_index; | 1229 const int drop_index = drop_info_->drop_index; |
| 1232 const bool drop_before = drop_info_->drop_before; | 1230 const bool drop_before = drop_info_->drop_before; |
| 1233 | 1231 |
| 1234 // Hide the drop indicator. | 1232 // Destroy the drop indicator. |
| 1235 SetDropIndex(-1, false); | 1233 drop_info_.reset(); |
| 1236 | 1234 |
| 1237 GURL url(reinterpret_cast<char*>(data)); | 1235 GURL url(reinterpret_cast<char*>(data)); |
| 1238 if (!url.is_valid()) | 1236 if (!url.is_valid()) |
| 1239 return; | 1237 return false; |
| 1240 | 1238 |
| 1241 if (drop_before) { | 1239 if (drop_before) { |
| 1242 // Insert a new tab. | 1240 // Insert a new tab. |
| 1243 TabContents* contents = | 1241 TabContents* contents = |
| 1244 model_->delegate()->CreateTabContentsForURL( | 1242 model_->delegate()->CreateTabContentsForURL( |
| 1245 url, GURL(), model_->profile(), PageTransition::TYPED, false, | 1243 url, GURL(), model_->profile(), PageTransition::TYPED, false, |
| 1246 NULL); | 1244 NULL); |
| 1247 model_->AddTabContents(contents, drop_index, false, | 1245 model_->AddTabContents(contents, drop_index, false, |
| 1248 PageTransition::GENERATED, true); | 1246 PageTransition::GENERATED, true); |
| 1249 } else { | 1247 } else { |
| 1250 model_->GetTabContentsAt(drop_index)->controller().LoadURL( | 1248 model_->GetTabContentsAt(drop_index)->controller().LoadURL( |
| 1251 url, GURL(), PageTransition::GENERATED); | 1249 url, GURL(), PageTransition::GENERATED); |
| 1252 model_->SelectTabContentsAt(drop_index, true); | 1250 model_->SelectTabContentsAt(drop_index, true); |
| 1253 } | 1251 } |
| 1252 |
| 1253 return true; |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 // static | 1256 // static |
| 1257 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { | 1257 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { |
| 1258 return ResourceBundle::GetSharedInstance().GetPixbufNamed( | 1258 return ResourceBundle::GetSharedInstance().GetPixbufNamed( |
| 1259 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); | 1259 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); |
| 1260 } | 1260 } |
| 1261 | 1261 |
| 1262 // TabStripGtk::DropInfo ------------------------------------------------------- | 1262 // TabStripGtk::DropInfo ------------------------------------------------------- |
| 1263 | 1263 |
| 1264 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before, | 1264 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before, |
| 1265 bool point_down) | 1265 bool point_down) |
| 1266 : drop_index(drop_index), | 1266 : drop_index(drop_index), |
| 1267 drop_before(drop_before), | 1267 drop_before(drop_before), |
| 1268 point_down(point_down) { | 1268 point_down(point_down) { |
| 1269 container = gtk_window_new(GTK_WINDOW_POPUP); | 1269 container = gtk_window_new(GTK_WINDOW_POPUP); |
| 1270 SetContainerColorMap(); | 1270 SetContainerColorMap(); |
| 1271 gtk_widget_set_app_paintable(container, TRUE); | 1271 gtk_widget_set_app_paintable(container, TRUE); |
| 1272 g_signal_connect(G_OBJECT(container), "expose-event", | 1272 g_signal_connect(G_OBJECT(container), "expose-event", |
| 1273 G_CALLBACK(OnExposeEvent), this); | 1273 G_CALLBACK(OnExposeEvent), this); |
| 1274 gtk_widget_add_events(container, GDK_STRUCTURE_MASK); | 1274 gtk_widget_add_events(container, GDK_STRUCTURE_MASK); |
| 1275 gtk_window_move(GTK_WINDOW(container), 0, 0); |
| 1276 gtk_window_resize(GTK_WINDOW(container), |
| 1277 drop_indicator_width, drop_indicator_height); |
| 1275 gtk_widget_show_all(container); | 1278 gtk_widget_show_all(container); |
| 1276 | 1279 |
| 1277 drop_arrow = GetDropArrowImage(point_down); | 1280 drop_arrow = GetDropArrowImage(point_down); |
| 1278 | |
| 1279 gtk_window_move(GTK_WINDOW(container), 0, 0); | |
| 1280 gtk_window_resize(GTK_WINDOW(container), | |
| 1281 drop_indicator_width, drop_indicator_height); | |
| 1282 } | 1281 } |
| 1283 | 1282 |
| 1284 TabStripGtk::DropInfo::~DropInfo() { | 1283 TabStripGtk::DropInfo::~DropInfo() { |
| 1285 gtk_widget_destroy(container); | 1284 gtk_widget_destroy(container); |
| 1286 } | 1285 } |
| 1287 | 1286 |
| 1288 // static | 1287 // static |
| 1289 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, | 1288 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, |
| 1290 GdkEventExpose* event, | 1289 GdkEventExpose* event, |
| 1291 DropInfo* drop_info) { | 1290 DropInfo* drop_info) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 gtk_drag_finish(context, FALSE, FALSE, time); | 1542 gtk_drag_finish(context, FALSE, FALSE, time); |
| 1544 else | 1543 else |
| 1545 gtk_drag_get_data(widget, context, target, time); | 1544 gtk_drag_get_data(widget, context, target, time); |
| 1546 | 1545 |
| 1547 return TRUE; | 1546 return TRUE; |
| 1548 } | 1547 } |
| 1549 | 1548 |
| 1550 // static | 1549 // static |
| 1551 gboolean TabStripGtk::OnDragLeave(GtkWidget* widget, GdkDragContext* context, | 1550 gboolean TabStripGtk::OnDragLeave(GtkWidget* widget, GdkDragContext* context, |
| 1552 guint time, TabStripGtk* tabstrip) { | 1551 guint time, TabStripGtk* tabstrip) { |
| 1553 // Hide the drop indicator. | 1552 // Destroy the drop indicator. |
| 1554 tabstrip->SetDropIndex(-1, false); | 1553 tabstrip->drop_info_.reset(); |
| 1555 return FALSE; | |
| 1556 } | |
| 1557 | |
| 1558 // static | |
| 1559 gboolean TabStripGtk::OnDragFailed(GtkWidget* widget, GdkDragContext* context, | |
| 1560 GtkDragResult result, | |
| 1561 TabStripGtk* tabstrip) { | |
| 1562 // Hide the drop indicator. | |
| 1563 tabstrip->SetDropIndex(-1, false); | |
| 1564 return FALSE; | 1554 return FALSE; |
| 1565 } | 1555 } |
| 1566 | 1556 |
| 1567 // static | 1557 // static |
| 1568 gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget, | 1558 gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget, |
| 1569 GdkDragContext* context, | 1559 GdkDragContext* context, |
| 1570 gint x, gint y, | 1560 gint x, gint y, |
| 1571 GtkSelectionData* data, | 1561 GtkSelectionData* data, |
| 1572 guint info, guint time, | 1562 guint info, guint time, |
| 1573 TabStripGtk* tabstrip) { | 1563 TabStripGtk* tabstrip) { |
| 1564 bool success = false; |
| 1565 |
| 1574 // TODO(jhawkins): Parse URI lists. | 1566 // TODO(jhawkins): Parse URI lists. |
| 1575 if (info == GtkDndUtil::X_CHROME_TEXT_PLAIN) { | 1567 if (info == GtkDndUtil::X_CHROME_TEXT_PLAIN) { |
| 1576 tabstrip->CompleteDrop(data->data); | 1568 success = tabstrip->CompleteDrop(data->data); |
| 1577 gtk_drag_finish(context, TRUE, TRUE, time); | |
| 1578 } | 1569 } |
| 1579 | 1570 |
| 1571 gtk_drag_finish(context, success, success, time); |
| 1580 return TRUE; | 1572 return TRUE; |
| 1581 } | 1573 } |
| 1582 | 1574 |
| 1583 // static | 1575 // static |
| 1584 void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) { | 1576 void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) { |
| 1585 tabstrip->model_->delegate()->AddBlankTab(true); | 1577 tabstrip->model_->delegate()->AddBlankTab(true); |
| 1586 } | 1578 } |
| 1587 | 1579 |
| 1588 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { | 1580 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { |
| 1589 gfx::Rect bds = bounds; | 1581 gfx::Rect bds = bounds; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 message.set_type(TabOverviewTypes::Message::WM_SWITCH_TO_OVERVIEW_MODE); | 1620 message.set_type(TabOverviewTypes::Message::WM_SWITCH_TO_OVERVIEW_MODE); |
| 1629 GtkWidget* browser_widget = GTK_WIDGET( | 1621 GtkWidget* browser_widget = GTK_WIDGET( |
| 1630 static_cast<BrowserWindowGtk*>(browser->window())->GetNativeHandle()); | 1622 static_cast<BrowserWindowGtk*>(browser->window())->GetNativeHandle()); |
| 1631 message.set_param(0, x11_util::GetX11WindowFromGtkWidget(browser_widget)); | 1623 message.set_param(0, x11_util::GetX11WindowFromGtkWidget(browser_widget)); |
| 1632 TabOverviewTypes::instance()->SendMessage(message); | 1624 TabOverviewTypes::instance()->SendMessage(message); |
| 1633 | 1625 |
| 1634 UserMetrics::RecordAction(L"TabOverview_PressedTabOverviewButton", | 1626 UserMetrics::RecordAction(L"TabOverview_PressedTabOverviewButton", |
| 1635 tabstrip->model_->profile()); | 1627 tabstrip->model_->profile()); |
| 1636 } | 1628 } |
| 1637 #endif | 1629 #endif |
| OLD | NEW |