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 #include <gtk/gtk.h> | |
Lei Zhang
2011/12/09 20:57:33
nit: C includes before C++ includes.
| |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.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" |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 newtab_button_.reset(MakeNewTabButton()); | 774 newtab_button_.reset(MakeNewTabButton()); |
774 newtab_surface_bounds_.SetRect(0, 0, newtab_button_->SurfaceWidth(), | 775 newtab_surface_bounds_.SetRect(0, 0, newtab_button_->SurfaceWidth(), |
775 newtab_button_->SurfaceHeight()); | 776 newtab_button_->SurfaceHeight()); |
776 | 777 |
777 gtk_widget_show_all(tabstrip_.get()); | 778 gtk_widget_show_all(tabstrip_.get()); |
778 | 779 |
779 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); | 780 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); |
780 | 781 |
781 if (drop_indicator_width == 0) { | 782 if (drop_indicator_width == 0) { |
782 // Direction doesn't matter, both images are the same size. | 783 // Direction doesn't matter, both images are the same size. |
783 GdkPixbuf* drop_image = GetDropArrowImage(true); | 784 GdkPixbuf* drop_image = GetDropArrowImage(true)->ToGdkPixbuf(); |
784 drop_indicator_width = gdk_pixbuf_get_width(drop_image); | 785 drop_indicator_width = gdk_pixbuf_get_width(drop_image); |
785 drop_indicator_height = gdk_pixbuf_get_height(drop_image); | 786 drop_indicator_height = gdk_pixbuf_get_height(drop_image); |
786 } | 787 } |
787 | 788 |
788 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 789 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
789 content::Source<ThemeService>(theme_service_)); | 790 content::Source<ThemeService>(theme_service_)); |
790 theme_service_->InitThemesFor(this); | 791 theme_service_->InitThemesFor(this); |
791 | 792 |
792 ViewIDUtil::SetDelegateForWidget(widget(), this); | 793 ViewIDUtil::SetDelegateForWidget(widget(), this); |
793 } | 794 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 int x, y; | 922 int x, y; |
922 if (!gtk_widget_translate_coordinates(widget(), target, | 923 if (!gtk_widget_translate_coordinates(widget(), target, |
923 -widget()->allocation.x, 0, &x, &y)) { | 924 -widget()->allocation.x, 0, &x, &y)) { |
924 // If the tab strip isn't showing, give the coordinates relative to the | 925 // If the tab strip isn't showing, give the coordinates relative to the |
925 // toplevel instead. | 926 // toplevel instead. |
926 if (!gtk_widget_translate_coordinates( | 927 if (!gtk_widget_translate_coordinates( |
927 gtk_widget_get_toplevel(widget()), target, 0, 0, &x, &y)) { | 928 gtk_widget_get_toplevel(widget()), target, 0, 0, &x, &y)) { |
928 NOTREACHED(); | 929 NOTREACHED(); |
929 } | 930 } |
930 } | 931 } |
931 if (GTK_WIDGET_NO_WINDOW(target)) { | 932 if (!gtk_widget_get_has_window(target)) { |
932 x += target->allocation.x; | 933 GtkAllocation allocation; |
933 y += target->allocation.y; | 934 gtk_widget_get_allocation(target, &allocation); |
935 x += allocation.x; | |
936 y += allocation.y; | |
934 } | 937 } |
935 return gfx::Point(x, y); | 938 return gfx::Point(x, y); |
936 } | 939 } |
937 | 940 |
938 //////////////////////////////////////////////////////////////////////////////// | 941 //////////////////////////////////////////////////////////////////////////////// |
939 // ViewIDUtil::Delegate implementation | 942 // ViewIDUtil::Delegate implementation |
940 | 943 |
941 GtkWidget* TabStripGtk::GetWidgetForViewID(ViewID view_id) { | 944 GtkWidget* TabStripGtk::GetWidgetForViewID(ViewID view_id) { |
942 if (GetTabCount() > 0) { | 945 if (GetTabCount() > 0) { |
943 if (view_id == VIEW_ID_TAB_LAST) { | 946 if (view_id == VIEW_ID_TAB_LAST) { |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1717 drop_info_->CreateContainer(); | 1720 drop_info_->CreateContainer(); |
1718 } else if (drop_info_->drop_index == index && | 1721 } else if (drop_info_->drop_index == index && |
1719 drop_info_->drop_before == drop_before) { | 1722 drop_info_->drop_before == drop_before) { |
1720 return; | 1723 return; |
1721 } | 1724 } |
1722 | 1725 |
1723 drop_info_->drop_index = index; | 1726 drop_info_->drop_index = index; |
1724 drop_info_->drop_before = drop_before; | 1727 drop_info_->drop_before = drop_before; |
1725 if (is_beneath == drop_info_->point_down) { | 1728 if (is_beneath == drop_info_->point_down) { |
1726 drop_info_->point_down = !is_beneath; | 1729 drop_info_->point_down = !is_beneath; |
1727 drop_info_->drop_arrow= GetDropArrowImage(drop_info_->point_down); | 1730 drop_info_->drop_arrow = GetDropArrowImage(drop_info_->point_down); |
1728 } | 1731 } |
1729 } | 1732 } |
1730 | 1733 |
1731 gtk_window_move(GTK_WINDOW(drop_info_->container), | 1734 gtk_window_move(GTK_WINDOW(drop_info_->container), |
1732 drop_bounds.x(), drop_bounds.y()); | 1735 drop_bounds.x(), drop_bounds.y()); |
1733 gtk_window_resize(GTK_WINDOW(drop_info_->container), | 1736 gtk_window_resize(GTK_WINDOW(drop_info_->container), |
1734 drop_bounds.width(), drop_bounds.height()); | 1737 drop_bounds.width(), drop_bounds.height()); |
1735 } | 1738 } |
1736 | 1739 |
1737 bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) { | 1740 bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1771 params.disposition = CURRENT_TAB; | 1774 params.disposition = CURRENT_TAB; |
1772 params.source_contents = model_->GetTabContentsAt(drop_index); | 1775 params.source_contents = model_->GetTabContentsAt(drop_index); |
1773 } | 1776 } |
1774 | 1777 |
1775 browser::Navigate(¶ms); | 1778 browser::Navigate(¶ms); |
1776 | 1779 |
1777 return true; | 1780 return true; |
1778 } | 1781 } |
1779 | 1782 |
1780 // static | 1783 // static |
1781 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { | 1784 gfx::Image* TabStripGtk::GetDropArrowImage(bool is_down) { |
1782 return ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 1785 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
1783 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); | 1786 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); |
1784 } | 1787 } |
1785 | 1788 |
1786 // TabStripGtk::DropInfo ------------------------------------------------------- | 1789 // TabStripGtk::DropInfo ------------------------------------------------------- |
1787 | 1790 |
1788 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before, | 1791 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before, |
1789 bool point_down) | 1792 bool point_down) |
1790 : drop_index(drop_index), | 1793 : drop_index(drop_index), |
1791 drop_before(drop_before), | 1794 drop_before(drop_before), |
1792 point_down(point_down) { | 1795 point_down(point_down) { |
1793 CreateContainer(); | 1796 CreateContainer(); |
1794 drop_arrow = GetDropArrowImage(point_down); | 1797 drop_arrow = GetDropArrowImage(point_down); |
1795 } | 1798 } |
1796 | 1799 |
1797 TabStripGtk::DropInfo::~DropInfo() { | 1800 TabStripGtk::DropInfo::~DropInfo() { |
1798 DestroyContainer(); | 1801 DestroyContainer(); |
1799 } | 1802 } |
1800 | 1803 |
1801 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, | 1804 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, |
1802 GdkEventExpose* event) { | 1805 GdkEventExpose* event) { |
1803 if (ui::IsScreenComposited()) { | 1806 if (ui::IsScreenComposited()) { |
1804 SetContainerTransparency(); | 1807 SetContainerTransparency(); |
1805 } else { | 1808 } else { |
1806 SetContainerShapeMask(); | 1809 SetContainerShapeMask(); |
1807 } | 1810 } |
1808 | 1811 |
1809 gdk_pixbuf_render_to_drawable(drop_arrow, | 1812 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
1810 container->window, | 1813 gdk_cairo_rectangle(cr, &event->area); |
1811 0, 0, 0, | 1814 cairo_clip(cr); |
1812 0, 0, | 1815 |
1813 drop_indicator_width, | 1816 drop_arrow->ToCairo()->SetSource(cr, widget, 0, 0); |
1814 drop_indicator_height, | 1817 cairo_paint(cr); |
1815 GDK_RGB_DITHER_NONE, 0, 0); | 1818 |
1819 cairo_destroy(cr); | |
1816 | 1820 |
1817 return FALSE; | 1821 return FALSE; |
1818 } | 1822 } |
1819 | 1823 |
1820 // Sets the color map of the container window to allow the window to be | 1824 // Sets the color map of the container window to allow the window to be |
1821 // transparent. | 1825 // transparent. |
1822 void TabStripGtk::DropInfo::SetContainerColorMap() { | 1826 void TabStripGtk::DropInfo::SetContainerColorMap() { |
1823 GdkScreen* screen = gtk_widget_get_screen(container); | 1827 GdkScreen* screen = gtk_widget_get_screen(container); |
1824 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); | 1828 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); |
1825 | 1829 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1857 drop_indicator_width, | 1861 drop_indicator_width, |
1858 drop_indicator_height, 1); | 1862 drop_indicator_height, 1); |
1859 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap)); | 1863 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap)); |
1860 | 1864 |
1861 // Set the transparency. | 1865 // Set the transparency. |
1862 cairo_set_source_rgba(cairo_context, 1, 1, 1, 0); | 1866 cairo_set_source_rgba(cairo_context, 1, 1, 1, 0); |
1863 | 1867 |
1864 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will | 1868 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will |
1865 // be opaque in the container window. | 1869 // be opaque in the container window. |
1866 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); | 1870 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); |
1867 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow, 0, 0); | 1871 // We don't use CairoCachedSurface::SetSource() here because we're not |
1872 // rendering on a display server. | |
1873 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow->ToGdkPixbuf(), 0, 0); | |
1868 cairo_paint(cairo_context); | 1874 cairo_paint(cairo_context); |
1869 cairo_destroy(cairo_context); | 1875 cairo_destroy(cairo_context); |
1870 | 1876 |
1871 // Set the shape mask. | 1877 // Set the shape mask. |
1872 gdk_window_shape_combine_mask(container->window, pixmap, 0, 0); | 1878 gdk_window_shape_combine_mask(container->window, pixmap, 0, 0); |
1873 g_object_unref(pixmap); | 1879 g_object_unref(pixmap); |
1874 } | 1880 } |
1875 | 1881 |
1876 void TabStripGtk::DropInfo::CreateContainer() { | 1882 void TabStripGtk::DropInfo::CreateContainer() { |
1877 container = gtk_window_new(GTK_WINDOW_POPUP); | 1883 container = gtk_window_new(GTK_WINDOW_POPUP); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2222 } | 2228 } |
2223 | 2229 |
2224 void TabStripGtk::SetNewTabButtonBackground() { | 2230 void TabStripGtk::SetNewTabButtonBackground() { |
2225 SkColor color = theme_service_->GetColor( | 2231 SkColor color = theme_service_->GetColor( |
2226 ThemeService::COLOR_BUTTON_BACKGROUND); | 2232 ThemeService::COLOR_BUTTON_BACKGROUND); |
2227 SkBitmap* background = theme_service_->GetBitmapNamed( | 2233 SkBitmap* background = theme_service_->GetBitmapNamed( |
2228 IDR_THEME_WINDOW_CONTROL_BACKGROUND); | 2234 IDR_THEME_WINDOW_CONTROL_BACKGROUND); |
2229 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); | 2235 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); |
2230 newtab_button_->SetBackground(color, background, mask); | 2236 newtab_button_->SetBackground(color, background, mask); |
2231 } | 2237 } |
OLD | NEW |