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" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "app/slide_animation.h" | 12 #include "app/slide_animation.h" |
13 #include "base/gfx/gtk_util.h" | 13 #include "base/gfx/gtk_util.h" |
14 #include "base/gfx/point.h" | 14 #include "base/gfx/point.h" |
15 #include "chrome/browser/browser_theme_provider.h" | 15 #include "chrome/browser/browser_theme_provider.h" |
16 #include "chrome/browser/gtk/custom_button.h" | 16 #include "chrome/browser/gtk/custom_button.h" |
17 #include "chrome/browser/gtk/gtk_dnd_util.h" | 17 #include "chrome/browser/gtk/gtk_dnd_util.h" |
18 #include "chrome/browser/gtk/gtk_theme_provider.h" | 18 #include "chrome/browser/gtk/gtk_theme_provider.h" |
19 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" | 19 #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h" |
20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
21 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
22 #include "chrome/common/gtk_util.h" | 22 #include "chrome/common/gtk_util.h" |
23 #include "grit/app_resources.h" | 23 #include "grit/app_resources.h" |
24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
25 | 25 |
26 #if defined(LINUX2) | 26 #if defined(OS_CHROMEOS) |
27 #include "chrome/browser/browser.h" | 27 #include "chrome/browser/browser.h" |
28 #include "chrome/browser/browser_list.h" | 28 #include "chrome/browser/browser_list.h" |
29 #include "chrome/browser/gtk/browser_window_gtk.h" | 29 #include "chrome/browser/gtk/browser_window_gtk.h" |
30 #include "chrome/browser/metrics/user_metrics.h" | 30 #include "chrome/browser/metrics/user_metrics.h" |
31 #include "chrome/browser/views/tabs/tab_overview_types.h" | 31 #include "chrome/browser/views/tabs/tab_overview_types.h" |
32 #include "chrome/common/x11_util.h" | 32 #include "chrome/common/x11_util.h" |
33 #endif | 33 #endif |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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", | 497 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-failed", |
498 G_CALLBACK(OnDragFailed), this); | 498 G_CALLBACK(OnDragFailed), this); |
499 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-data-received", | 499 g_signal_connect(G_OBJECT(tabstrip_.get()), "drag-data-received", |
500 G_CALLBACK(OnDragDataReceived), this); | 500 G_CALLBACK(OnDragDataReceived), this); |
501 | 501 |
502 newtab_button_.reset(MakeNewTabButton()); | 502 newtab_button_.reset(MakeNewTabButton()); |
503 | 503 |
504 #if defined(LINUX2) | 504 #if defined(OS_CHROMEOS) |
505 tab_overview_button_.reset(MakeTabOverviewButton()); | 505 tab_overview_button_.reset(MakeTabOverviewButton()); |
506 #endif | 506 #endif |
507 | 507 |
508 gtk_widget_show_all(tabstrip_.get()); | 508 gtk_widget_show_all(tabstrip_.get()); |
509 | 509 |
510 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); | 510 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); |
511 | 511 |
512 if (drop_indicator_width == 0) { | 512 if (drop_indicator_width == 0) { |
513 // Direction doesn't matter, both images are the same size. | 513 // Direction doesn't matter, both images are the same size. |
514 GdkPixbuf* drop_image = GetDropArrowImage(true); | 514 GdkPixbuf* drop_image = GetDropArrowImage(true); |
(...skipping 21 matching lines...) Expand all Loading... |
536 int tab_count = GetTabCount(); | 536 int tab_count = GetTabCount(); |
537 int tab_right = 0; | 537 int tab_right = 0; |
538 for (int i = 0; i < tab_count; ++i) { | 538 for (int i = 0; i < tab_count; ++i) { |
539 const gfx::Rect& bounds = tab_data_.at(i).ideal_bounds; | 539 const gfx::Rect& bounds = tab_data_.at(i).ideal_bounds; |
540 TabGtk* tab = GetTabAt(i); | 540 TabGtk* tab = GetTabAt(i); |
541 SetTabBounds(tab, bounds); | 541 SetTabBounds(tab, bounds); |
542 tab_right = bounds.right() + kTabHOffset; | 542 tab_right = bounds.right() + kTabHOffset; |
543 } | 543 } |
544 | 544 |
545 LayoutNewTabButton(static_cast<double>(tab_right), current_unselected_width_); | 545 LayoutNewTabButton(static_cast<double>(tab_right), current_unselected_width_); |
546 #if defined(LINUX2) | 546 #if defined(OS_CHROMEOS) |
547 gtk_fixed_move(GTK_FIXED(tabstrip_.get()), tab_overview_button_->widget(), | 547 gtk_fixed_move(GTK_FIXED(tabstrip_.get()), tab_overview_button_->widget(), |
548 bounds_.width() - tab_overview_button_->width(), 0); | 548 bounds_.width() - tab_overview_button_->width(), 0); |
549 #endif | 549 #endif |
550 gtk_widget_queue_draw(tabstrip_.get()); | 550 gtk_widget_queue_draw(tabstrip_.get()); |
551 } | 551 } |
552 | 552 |
553 void TabStripGtk::SchedulePaint() { | 553 void TabStripGtk::SchedulePaint() { |
554 gtk_widget_queue_draw(tabstrip_.get()); | 554 gtk_widget_queue_draw(tabstrip_.get()); |
555 } | 555 } |
556 | 556 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 | 978 |
979 void TabStripGtk::LayoutNewTabButton(double last_tab_right, | 979 void TabStripGtk::LayoutNewTabButton(double last_tab_right, |
980 double unselected_width) { | 980 double unselected_width) { |
981 gfx::Rect bounds(0, kNewTabButtonVOffset, | 981 gfx::Rect bounds(0, kNewTabButtonVOffset, |
982 newtab_button_->width(), newtab_button_->height()); | 982 newtab_button_->width(), newtab_button_->height()); |
983 int delta = abs(Round(unselected_width) - TabGtk::GetStandardSize().width()); | 983 int delta = abs(Round(unselected_width) - TabGtk::GetStandardSize().width()); |
984 if (delta > 1 && !resize_layout_scheduled_) { | 984 if (delta > 1 && !resize_layout_scheduled_) { |
985 // We're shrinking tabs, so we need to anchor the New Tab button to the | 985 // We're shrinking tabs, so we need to anchor the New Tab button to the |
986 // right edge of the TabStrip's bounds, rather than the right edge of the | 986 // right edge of the TabStrip's bounds, rather than the right edge of the |
987 // right-most Tab, otherwise it'll bounce when animating. | 987 // right-most Tab, otherwise it'll bounce when animating. |
988 #if defined(LINUX2) | 988 #if defined(OS_CHROMEOS) |
989 bounds.set_x(bounds_.width() - newtab_button_->width() - | 989 bounds.set_x(bounds_.width() - newtab_button_->width() - |
990 tab_overview_button_->width()); | 990 tab_overview_button_->width()); |
991 #else | 991 #else |
992 bounds.set_x(bounds_.width() - newtab_button_->width()); | 992 bounds.set_x(bounds_.width() - newtab_button_->width()); |
993 #endif | 993 #endif |
994 } else { | 994 } else { |
995 bounds.set_x(Round(last_tab_right - kTabHOffset) + kNewTabButtonHOffset); | 995 bounds.set_x(Round(last_tab_right - kTabHOffset) + kNewTabButtonHOffset); |
996 } | 996 } |
997 bounds.set_x(gtk_util::MirroredLeftPointForRect(tabstrip_.get(), bounds)); | 997 bounds.set_x(gtk_util::MirroredLeftPointForRect(tabstrip_.get(), bounds)); |
998 | 998 |
(...skipping 15 matching lines...) Expand all Loading... |
1014 *selected_width = min_selected_width; | 1014 *selected_width = min_selected_width; |
1015 return; | 1015 return; |
1016 } | 1016 } |
1017 | 1017 |
1018 // Determine how much space we can actually allocate to tabs. | 1018 // Determine how much space we can actually allocate to tabs. |
1019 int available_width = tabstrip_->allocation.width; | 1019 int available_width = tabstrip_->allocation.width; |
1020 if (available_width_for_tabs_ < 0) { | 1020 if (available_width_for_tabs_ < 0) { |
1021 available_width = bounds_.width(); | 1021 available_width = bounds_.width(); |
1022 available_width -= | 1022 available_width -= |
1023 (kNewTabButtonHOffset + newtab_button_->width()); | 1023 (kNewTabButtonHOffset + newtab_button_->width()); |
1024 #if defined(LINUX2) | 1024 #if defined(OS_CHROMEOS) |
1025 available_width -= tab_overview_button_->width(); | 1025 available_width -= tab_overview_button_->width(); |
1026 #endif | 1026 #endif |
1027 } else { | 1027 } else { |
1028 // Interesting corner case: if |available_width_for_tabs_| > the result | 1028 // Interesting corner case: if |available_width_for_tabs_| > the result |
1029 // of the calculation in the conditional arm above, the strip is in | 1029 // of the calculation in the conditional arm above, the strip is in |
1030 // overflow. We can either use the specified width or the true available | 1030 // overflow. We can either use the specified width or the true available |
1031 // width here; the first preserves the consistent "leave the last tab under | 1031 // width here; the first preserves the consistent "leave the last tab under |
1032 // the user's mouse so they can close many tabs" behavior at the cost of | 1032 // the user's mouse so they can close many tabs" behavior at the cost of |
1033 // prolonging the glitchy appearance of the overflow state, while the second | 1033 // prolonging the glitchy appearance of the overflow state, while the second |
1034 // gets us out of overflow as soon as possible but forces the user to move | 1034 // gets us out of overflow as soon as possible but forces the user to move |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 event->area.x = 0; | 1446 event->area.x = 0; |
1447 event->area.y = 0; | 1447 event->area.y = 0; |
1448 event->area.width = tabstrip->bounds_.width(); | 1448 event->area.width = tabstrip->bounds_.width(); |
1449 event->area.height = tabstrip->bounds_.height(); | 1449 event->area.height = tabstrip->bounds_.height(); |
1450 gdk_region_union_with_rect(event->region, &event->area); | 1450 gdk_region_union_with_rect(event->region, &event->area); |
1451 | 1451 |
1452 // Paint the New Tab button. | 1452 // Paint the New Tab button. |
1453 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), | 1453 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), |
1454 tabstrip->newtab_button_->widget(), event); | 1454 tabstrip->newtab_button_->widget(), event); |
1455 | 1455 |
1456 #if defined(LINUX2) | 1456 #if defined(OS_CHROMEOS) |
1457 // Paint the tab overview button. | 1457 // Paint the tab overview button. |
1458 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), | 1458 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), |
1459 tabstrip->tab_overview_button_->widget(), event); | 1459 tabstrip->tab_overview_button_->widget(), event); |
1460 #endif | 1460 #endif |
1461 | 1461 |
1462 // Paint the tabs in reverse order, so they stack to the left. | 1462 // Paint the tabs in reverse order, so they stack to the left. |
1463 TabGtk* selected_tab = NULL; | 1463 TabGtk* selected_tab = NULL; |
1464 int tab_count = tabstrip->GetTabCount(); | 1464 int tab_count = tabstrip->GetTabCount(); |
1465 for (int i = tab_count - 1; i >= 0; --i) { | 1465 for (int i = tab_count - 1; i >= 0; --i) { |
1466 TabGtk* tab = tabstrip->GetTabAt(i); | 1466 TabGtk* tab = tabstrip->GetTabAt(i); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 IDR_NEWTAB_BUTTON_P, IDR_NEWTAB_BUTTON_H, 0, NULL); | 1588 IDR_NEWTAB_BUTTON_P, IDR_NEWTAB_BUTTON_H, 0, NULL); |
1589 | 1589 |
1590 g_signal_connect(G_OBJECT(button->widget()), "clicked", | 1590 g_signal_connect(G_OBJECT(button->widget()), "clicked", |
1591 G_CALLBACK(OnNewTabClicked), this); | 1591 G_CALLBACK(OnNewTabClicked), this); |
1592 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 1592 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
1593 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); | 1593 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); |
1594 | 1594 |
1595 return button; | 1595 return button; |
1596 } | 1596 } |
1597 | 1597 |
1598 #if defined(LINUX2) | 1598 #if defined(OS_CHROMEOS) |
1599 CustomDrawButton* TabStripGtk::MakeTabOverviewButton() { | 1599 CustomDrawButton* TabStripGtk::MakeTabOverviewButton() { |
1600 CustomDrawButton* button = | 1600 CustomDrawButton* button = |
1601 new CustomDrawButton(IDR_TAB_OVERVIEW_BUTTON_ICON, 0, 0, 0, NULL); | 1601 new CustomDrawButton(IDR_TAB_OVERVIEW_BUTTON_ICON, 0, 0, 0, NULL); |
1602 | 1602 |
1603 g_signal_connect(G_OBJECT(button->widget()), "clicked", | 1603 g_signal_connect(G_OBJECT(button->widget()), "clicked", |
1604 G_CALLBACK(OnTabOverviewButtonClicked), this); | 1604 G_CALLBACK(OnTabOverviewButtonClicked), this); |
1605 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 1605 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
1606 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); | 1606 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); |
1607 | 1607 |
1608 return button; | 1608 return button; |
1609 } | 1609 } |
1610 | 1610 |
1611 // static | 1611 // static |
1612 void TabStripGtk::OnTabOverviewButtonClicked(GtkWidget* widget, | 1612 void TabStripGtk::OnTabOverviewButtonClicked(GtkWidget* widget, |
1613 TabStripGtk* tabstrip) { | 1613 TabStripGtk* tabstrip) { |
1614 Browser* browser = BrowserList::GetLastActive(); | 1614 Browser* browser = BrowserList::GetLastActive(); |
1615 DCHECK(browser); // In order for the user to click on the tab there should | 1615 DCHECK(browser); // In order for the user to click on the tab there should |
1616 // be an active browser. | 1616 // be an active browser. |
1617 TabOverviewTypes::Message message; | 1617 TabOverviewTypes::Message message; |
1618 message.set_type(TabOverviewTypes::Message::WM_SWITCH_TO_OVERVIEW_MODE); | 1618 message.set_type(TabOverviewTypes::Message::WM_SWITCH_TO_OVERVIEW_MODE); |
1619 GtkWidget* browser_widget = GTK_WIDGET( | 1619 GtkWidget* browser_widget = GTK_WIDGET( |
1620 static_cast<BrowserWindowGtk*>(browser->window())->GetNativeHandle()); | 1620 static_cast<BrowserWindowGtk*>(browser->window())->GetNativeHandle()); |
1621 message.set_param(0, x11_util::GetX11WindowFromGtkWidget(browser_widget)); | 1621 message.set_param(0, x11_util::GetX11WindowFromGtkWidget(browser_widget)); |
1622 TabOverviewTypes::instance()->SendMessage(message); | 1622 TabOverviewTypes::instance()->SendMessage(message); |
1623 | 1623 |
1624 UserMetrics::RecordAction(L"TabOverview_PressedTabOverviewButton", | 1624 UserMetrics::RecordAction(L"TabOverview_PressedTabOverviewButton", |
1625 tabstrip->model_->profile()); | 1625 tabstrip->model_->profile()); |
1626 } | 1626 } |
1627 #endif | 1627 #endif |
OLD | NEW |