Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc

Issue 8890048: GTK: Remove deprecated drawing call and replace them with cairo. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_strip_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
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
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);
James Hawkins 2011/12/08 23:37:31 Can we get these values from the returned gfx::Ima
Elliot Glaysher 2011/12/08 23:39:59 Nope! Because a gfx::Image can have multiple repre
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 }
794 795
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 drop_info_->CreateContainer(); 1718 drop_info_->CreateContainer();
1718 } else if (drop_info_->drop_index == index && 1719 } else if (drop_info_->drop_index == index &&
1719 drop_info_->drop_before == drop_before) { 1720 drop_info_->drop_before == drop_before) {
1720 return; 1721 return;
1721 } 1722 }
1722 1723
1723 drop_info_->drop_index = index; 1724 drop_info_->drop_index = index;
1724 drop_info_->drop_before = drop_before; 1725 drop_info_->drop_before = drop_before;
1725 if (is_beneath == drop_info_->point_down) { 1726 if (is_beneath == drop_info_->point_down) {
1726 drop_info_->point_down = !is_beneath; 1727 drop_info_->point_down = !is_beneath;
1727 drop_info_->drop_arrow= GetDropArrowImage(drop_info_->point_down); 1728 drop_info_->drop_arrow = GetDropArrowImage(drop_info_->point_down);
1728 } 1729 }
1729 } 1730 }
1730 1731
1731 gtk_window_move(GTK_WINDOW(drop_info_->container), 1732 gtk_window_move(GTK_WINDOW(drop_info_->container),
1732 drop_bounds.x(), drop_bounds.y()); 1733 drop_bounds.x(), drop_bounds.y());
1733 gtk_window_resize(GTK_WINDOW(drop_info_->container), 1734 gtk_window_resize(GTK_WINDOW(drop_info_->container),
1734 drop_bounds.width(), drop_bounds.height()); 1735 drop_bounds.width(), drop_bounds.height());
1735 } 1736 }
1736 1737
1737 bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) { 1738 bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 params.disposition = CURRENT_TAB; 1772 params.disposition = CURRENT_TAB;
1772 params.source_contents = model_->GetTabContentsAt(drop_index); 1773 params.source_contents = model_->GetTabContentsAt(drop_index);
1773 } 1774 }
1774 1775
1775 browser::Navigate(&params); 1776 browser::Navigate(&params);
1776 1777
1777 return true; 1778 return true;
1778 } 1779 }
1779 1780
1780 // static 1781 // static
1781 GdkPixbuf* TabStripGtk::GetDropArrowImage(bool is_down) { 1782 gfx::Image* TabStripGtk::GetDropArrowImage(bool is_down) {
1782 return ResourceBundle::GetSharedInstance().GetNativeImageNamed( 1783 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
1783 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP); 1784 is_down ? IDR_TAB_DROP_DOWN : IDR_TAB_DROP_UP);
1784 } 1785 }
1785 1786
1786 // TabStripGtk::DropInfo ------------------------------------------------------- 1787 // TabStripGtk::DropInfo -------------------------------------------------------
1787 1788
1788 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before, 1789 TabStripGtk::DropInfo::DropInfo(int drop_index, bool drop_before,
1789 bool point_down) 1790 bool point_down)
1790 : drop_index(drop_index), 1791 : drop_index(drop_index),
1791 drop_before(drop_before), 1792 drop_before(drop_before),
1792 point_down(point_down) { 1793 point_down(point_down) {
1793 CreateContainer(); 1794 CreateContainer();
1794 drop_arrow = GetDropArrowImage(point_down); 1795 drop_arrow = GetDropArrowImage(point_down);
1795 } 1796 }
1796 1797
1797 TabStripGtk::DropInfo::~DropInfo() { 1798 TabStripGtk::DropInfo::~DropInfo() {
1798 DestroyContainer(); 1799 DestroyContainer();
1799 } 1800 }
1800 1801
1801 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, 1802 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget,
1802 GdkEventExpose* event) { 1803 GdkEventExpose* event) {
1803 if (ui::IsScreenComposited()) { 1804 if (ui::IsScreenComposited()) {
1804 SetContainerTransparency(); 1805 SetContainerTransparency();
1805 } else { 1806 } else {
1806 SetContainerShapeMask(); 1807 SetContainerShapeMask();
1807 } 1808 }
1808 1809
1809 gdk_pixbuf_render_to_drawable(drop_arrow, 1810 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
1810 container->window, 1811 gdk_cairo_rectangle(cr, &event->area);
1811 0, 0, 0, 1812 cairo_clip(cr);
1812 0, 0, 1813
1813 drop_indicator_width, 1814 drop_arrow->ToCairo()->SetSource(cr, widget, 0, 0);
1814 drop_indicator_height, 1815 cairo_paint(cr);
1815 GDK_RGB_DITHER_NONE, 0, 0); 1816
1817 cairo_destroy(cr);
1816 1818
1817 return FALSE; 1819 return FALSE;
1818 } 1820 }
1819 1821
1820 // Sets the color map of the container window to allow the window to be 1822 // Sets the color map of the container window to allow the window to be
1821 // transparent. 1823 // transparent.
1822 void TabStripGtk::DropInfo::SetContainerColorMap() { 1824 void TabStripGtk::DropInfo::SetContainerColorMap() {
1823 GdkScreen* screen = gtk_widget_get_screen(container); 1825 GdkScreen* screen = gtk_widget_get_screen(container);
1824 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); 1826 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);
1825 1827
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 drop_indicator_width, 1859 drop_indicator_width,
1858 drop_indicator_height, 1); 1860 drop_indicator_height, 1);
1859 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap)); 1861 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(pixmap));
1860 1862
1861 // Set the transparency. 1863 // Set the transparency.
1862 cairo_set_source_rgba(cairo_context, 1, 1, 1, 0); 1864 cairo_set_source_rgba(cairo_context, 1, 1, 1, 0);
1863 1865
1864 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will 1866 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will
1865 // be opaque in the container window. 1867 // be opaque in the container window.
1866 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); 1868 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
1867 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow, 0, 0); 1869 // We don't use CairoCachedSurface::SetSource() here because we're not
1870 // rendering on a display server.
1871 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow->ToGdkPixbuf(), 0, 0);
1868 cairo_paint(cairo_context); 1872 cairo_paint(cairo_context);
1869 cairo_destroy(cairo_context); 1873 cairo_destroy(cairo_context);
1870 1874
1871 // Set the shape mask. 1875 // Set the shape mask.
1872 gdk_window_shape_combine_mask(container->window, pixmap, 0, 0); 1876 gdk_window_shape_combine_mask(container->window, pixmap, 0, 0);
1873 g_object_unref(pixmap); 1877 g_object_unref(pixmap);
1874 } 1878 }
1875 1879
1876 void TabStripGtk::DropInfo::CreateContainer() { 1880 void TabStripGtk::DropInfo::CreateContainer() {
1877 container = gtk_window_new(GTK_WINDOW_POPUP); 1881 container = gtk_window_new(GTK_WINDOW_POPUP);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 } 2226 }
2223 2227
2224 void TabStripGtk::SetNewTabButtonBackground() { 2228 void TabStripGtk::SetNewTabButtonBackground() {
2225 SkColor color = theme_service_->GetColor( 2229 SkColor color = theme_service_->GetColor(
2226 ThemeService::COLOR_BUTTON_BACKGROUND); 2230 ThemeService::COLOR_BUTTON_BACKGROUND);
2227 SkBitmap* background = theme_service_->GetBitmapNamed( 2231 SkBitmap* background = theme_service_->GetBitmapNamed(
2228 IDR_THEME_WINDOW_CONTROL_BACKGROUND); 2232 IDR_THEME_WINDOW_CONTROL_BACKGROUND);
2229 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); 2233 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK);
2230 newtab_button_->SetBackground(color, background, mask); 2234 newtab_button_->SetBackground(color, background, mask);
2231 } 2235 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_strip_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698