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/tab_strip_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_strip_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/debug/trace_event.h" |
10 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete.h" | 14 #include "chrome/browser/autocomplete/autocomplete.h" |
14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 16 #include "chrome/browser/autocomplete/autocomplete_match.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 18 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
18 #include "chrome/browser/themes/theme_service.h" | 19 #include "chrome/browser/themes/theme_service.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 955 |
955 return NULL; | 956 return NULL; |
956 } | 957 } |
957 | 958 |
958 //////////////////////////////////////////////////////////////////////////////// | 959 //////////////////////////////////////////////////////////////////////////////// |
959 // TabStripGtk, TabStripModelObserver implementation: | 960 // TabStripGtk, TabStripModelObserver implementation: |
960 | 961 |
961 void TabStripGtk::TabInsertedAt(TabContentsWrapper* contents, | 962 void TabStripGtk::TabInsertedAt(TabContentsWrapper* contents, |
962 int index, | 963 int index, |
963 bool foreground) { | 964 bool foreground) { |
| 965 TRACE_EVENT0("ui::gtk", "TabStripGtk::TabInsertedAt"); |
| 966 |
964 DCHECK(contents); | 967 DCHECK(contents); |
965 DCHECK(index == TabStripModel::kNoTab || model_->ContainsIndex(index)); | 968 DCHECK(index == TabStripModel::kNoTab || model_->ContainsIndex(index)); |
966 | 969 |
967 StopAnimation(); | 970 StopAnimation(); |
968 | 971 |
969 bool contains_tab = false; | 972 bool contains_tab = false; |
970 TabGtk* tab = NULL; | 973 TabGtk* tab = NULL; |
971 // First see if this Tab is one that was dragged out of this TabStrip and is | 974 // First see if this Tab is one that was dragged out of this TabStrip and is |
972 // now being dragged back in. In this case, the DraggedTabController actually | 975 // now being dragged back in. In this case, the DraggedTabController actually |
973 // has the Tab already constructed and we can just insert it into our list | 976 // has the Tab already constructed and we can just insert it into our list |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 // Have to do this _after_ calling StartRemoveTabAnimation, so that any | 1030 // Have to do this _after_ calling StartRemoveTabAnimation, so that any |
1028 // previous remove is completed fully and index is valid in sync with the | 1031 // previous remove is completed fully and index is valid in sync with the |
1029 // model index. | 1032 // model index. |
1030 GetTabAt(index)->set_closing(true); | 1033 GetTabAt(index)->set_closing(true); |
1031 } | 1034 } |
1032 | 1035 |
1033 void TabStripGtk::ActiveTabChanged(TabContentsWrapper* old_contents, | 1036 void TabStripGtk::ActiveTabChanged(TabContentsWrapper* old_contents, |
1034 TabContentsWrapper* new_contents, | 1037 TabContentsWrapper* new_contents, |
1035 int index, | 1038 int index, |
1036 bool user_gesture) { | 1039 bool user_gesture) { |
| 1040 TRACE_EVENT0("ui::gtk", "TabStripGtk::ActiveTabChanged"); |
1037 ReStack(); | 1041 ReStack(); |
1038 } | 1042 } |
1039 | 1043 |
1040 void TabStripGtk::TabSelectionChanged(TabStripModel* tab_strip_model, | 1044 void TabStripGtk::TabSelectionChanged(TabStripModel* tab_strip_model, |
1041 const TabStripSelectionModel& old_model) { | 1045 const TabStripSelectionModel& old_model) { |
1042 // We have "tiny tabs" if the tabs are so tiny that the unselected ones are | 1046 // We have "tiny tabs" if the tabs are so tiny that the unselected ones are |
1043 // a different size to the selected ones. | 1047 // a different size to the selected ones. |
1044 bool tiny_tabs = current_unselected_width_ != current_selected_width_; | 1048 bool tiny_tabs = current_unselected_width_ != current_selected_width_; |
1045 if (!IsAnimating() && (!needs_resize_layout_ || tiny_tabs)) | 1049 if (!IsAnimating() && (!needs_resize_layout_ || tiny_tabs)) |
1046 Layout(); | 1050 Layout(); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1597 GdkScreen* screen = gdk_screen_get_default(); | 1601 GdkScreen* screen = gdk_screen_get_default(); |
1598 GdkDisplay* display = gdk_screen_get_display(screen); | 1602 GdkDisplay* display = gdk_screen_get_display(screen); |
1599 gint x, y; | 1603 gint x, y; |
1600 gdk_display_get_pointer(display, NULL, &x, &y, NULL); | 1604 gdk_display_get_pointer(display, NULL, &x, &y, NULL); |
1601 gfx::Point cursor_point(x, y); | 1605 gfx::Point cursor_point(x, y); |
1602 | 1606 |
1603 return bds.Contains(cursor_point); | 1607 return bds.Contains(cursor_point); |
1604 } | 1608 } |
1605 | 1609 |
1606 void TabStripGtk::ReStack() { | 1610 void TabStripGtk::ReStack() { |
| 1611 TRACE_EVENT0("ui::gtk", "TabStripGtk::ReStack"); |
| 1612 |
1607 if (!gtk_widget_get_realized(tabstrip_.get())) { | 1613 if (!gtk_widget_get_realized(tabstrip_.get())) { |
1608 // If the window isn't realized yet, we can't stack them yet. It will be | 1614 // If the window isn't realized yet, we can't stack them yet. It will be |
1609 // done by the OnMap signal handler. | 1615 // done by the OnMap signal handler. |
1610 return; | 1616 return; |
1611 } | 1617 } |
1612 int tab_count = GetTabCount(); | 1618 int tab_count = GetTabCount(); |
1613 TabGtk* active_tab = NULL; | 1619 TabGtk* active_tab = NULL; |
1614 for (int i = tab_count - 1; i >= 0; --i) { | 1620 for (int i = tab_count - 1; i >= 0; --i) { |
1615 TabGtk* tab = GetTabAt(i); | 1621 TabGtk* tab = GetTabAt(i); |
1616 if (tab->IsActive()) | 1622 if (tab->IsActive()) |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 CreateContainer(); | 1799 CreateContainer(); |
1794 drop_arrow = GetDropArrowImage(point_down); | 1800 drop_arrow = GetDropArrowImage(point_down); |
1795 } | 1801 } |
1796 | 1802 |
1797 TabStripGtk::DropInfo::~DropInfo() { | 1803 TabStripGtk::DropInfo::~DropInfo() { |
1798 DestroyContainer(); | 1804 DestroyContainer(); |
1799 } | 1805 } |
1800 | 1806 |
1801 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, | 1807 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, |
1802 GdkEventExpose* event) { | 1808 GdkEventExpose* event) { |
| 1809 TRACE_EVENT0("ui::gtk", "TabStripGtk::DropInfo::OnExposeEvent"); |
| 1810 |
1803 if (ui::IsScreenComposited()) { | 1811 if (ui::IsScreenComposited()) { |
1804 SetContainerTransparency(); | 1812 SetContainerTransparency(); |
1805 } else { | 1813 } else { |
1806 SetContainerShapeMask(); | 1814 SetContainerShapeMask(); |
1807 } | 1815 } |
1808 | 1816 |
1809 gdk_pixbuf_render_to_drawable(drop_arrow, | 1817 gdk_pixbuf_render_to_drawable(drop_arrow, |
1810 container->window, | 1818 container->window, |
1811 0, 0, 0, | 1819 0, 0, 0, |
1812 0, 0, | 1820 0, 0, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 | 1985 |
1978 if (layout) | 1986 if (layout) |
1979 Layout(); | 1987 Layout(); |
1980 } | 1988 } |
1981 | 1989 |
1982 void TabStripGtk::OnMap(GtkWidget* widget) { | 1990 void TabStripGtk::OnMap(GtkWidget* widget) { |
1983 ReStack(); | 1991 ReStack(); |
1984 } | 1992 } |
1985 | 1993 |
1986 gboolean TabStripGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { | 1994 gboolean TabStripGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { |
| 1995 TRACE_EVENT0("ui::gtk", "TabStripGtk::OnExpose"); |
| 1996 |
1987 if (gdk_region_empty(event->region)) | 1997 if (gdk_region_empty(event->region)) |
1988 return TRUE; | 1998 return TRUE; |
1989 | 1999 |
1990 // If we're only repainting favicons, optimize the paint path and only draw | 2000 // If we're only repainting favicons, optimize the paint path and only draw |
1991 // the favicons. | 2001 // the favicons. |
1992 GdkRectangle* rects; | 2002 GdkRectangle* rects; |
1993 gint num_rects; | 2003 gint num_rects; |
1994 gdk_region_get_rectangles(event->region, &rects, &num_rects); | 2004 gdk_region_get_rectangles(event->region, &rects, &num_rects); |
1995 qsort(rects, num_rects, sizeof(GdkRectangle), CompareGdkRectangles); | 2005 qsort(rects, num_rects, sizeof(GdkRectangle), CompareGdkRectangles); |
1996 std::vector<int> tabs_to_repaint; | 2006 std::vector<int> tabs_to_repaint; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 // Paint the selected tab last, so it overlaps all the others. | 2066 // Paint the selected tab last, so it overlaps all the others. |
2057 if (selected_tab) { | 2067 if (selected_tab) { |
2058 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), | 2068 gtk_container_propagate_expose(GTK_CONTAINER(tabstrip_.get()), |
2059 selected_tab->widget(), event); | 2069 selected_tab->widget(), event); |
2060 } | 2070 } |
2061 | 2071 |
2062 return TRUE; | 2072 return TRUE; |
2063 } | 2073 } |
2064 | 2074 |
2065 void TabStripGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { | 2075 void TabStripGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { |
| 2076 TRACE_EVENT0("ui::gtk", "TabStripGtk::OnSizeAllocate"); |
| 2077 |
2066 gfx::Rect bounds = gfx::Rect(allocation->x, allocation->y, | 2078 gfx::Rect bounds = gfx::Rect(allocation->x, allocation->y, |
2067 allocation->width, allocation->height); | 2079 allocation->width, allocation->height); |
2068 | 2080 |
2069 // Nothing to do if the bounds are the same. If we don't catch this, we'll | 2081 // Nothing to do if the bounds are the same. If we don't catch this, we'll |
2070 // get an infinite loop of size-allocate signals. | 2082 // get an infinite loop of size-allocate signals. |
2071 if (bounds_ == bounds) | 2083 if (bounds_ == bounds) |
2072 return; | 2084 return; |
2073 | 2085 |
2074 SetBounds(bounds); | 2086 SetBounds(bounds); |
2075 | 2087 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2222 } | 2234 } |
2223 | 2235 |
2224 void TabStripGtk::SetNewTabButtonBackground() { | 2236 void TabStripGtk::SetNewTabButtonBackground() { |
2225 SkColor color = theme_service_->GetColor( | 2237 SkColor color = theme_service_->GetColor( |
2226 ThemeService::COLOR_BUTTON_BACKGROUND); | 2238 ThemeService::COLOR_BUTTON_BACKGROUND); |
2227 SkBitmap* background = theme_service_->GetBitmapNamed( | 2239 SkBitmap* background = theme_service_->GetBitmapNamed( |
2228 IDR_THEME_WINDOW_CONTROL_BACKGROUND); | 2240 IDR_THEME_WINDOW_CONTROL_BACKGROUND); |
2229 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); | 2241 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); |
2230 newtab_button_->SetBackground(color, background, mask); | 2242 newtab_button_->SetBackground(color, background, mask); |
2231 } | 2243 } |
OLD | NEW |