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

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

Issue 9359052: GTK: Closing in on being completely GSEALed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_strip_gtk.h ('k') | ui/base/gtk/gtk_compat.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 gfx::Rect state(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x, 1443 gfx::Rect state(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x,
1444 tab_height); 1444 tab_height);
1445 tab_data_.at(i).ideal_bounds = state; 1445 tab_data_.at(i).ideal_bounds = state;
1446 tab_x = end_of_tab + GetTabHOffset(i + 1); 1446 tab_x = end_of_tab + GetTabHOffset(i + 1);
1447 } 1447 }
1448 } 1448 }
1449 1449
1450 void TabStripGtk::LayoutNewTabButton(double last_tab_right, 1450 void TabStripGtk::LayoutNewTabButton(double last_tab_right,
1451 double unselected_width) { 1451 double unselected_width) {
1452 GtkWidget* toplevel = gtk_widget_get_ancestor(widget(), GTK_TYPE_WINDOW); 1452 GtkWidget* toplevel = gtk_widget_get_ancestor(widget(), GTK_TYPE_WINDOW);
1453 bool is_maximized = toplevel && 1453 bool is_maximized = false;
1454 ((gdk_window_get_state(toplevel->window) & GDK_WINDOW_STATE_MAXIMIZED) 1454 if (toplevel) {
1455 != 0); 1455 GdkWindow* gdk_window = gtk_widget_get_window(toplevel);
1456 is_maximized = (gdk_window_get_state(gdk_window) &
1457 GDK_WINDOW_STATE_MAXIMIZED) != 0;
1458 }
1456 1459
1457 int y = is_maximized ? 0 : kNewTabButtonVOffset; 1460 int y = is_maximized ? 0 : kNewTabButtonVOffset;
1458 int height = newtab_surface_bounds_.height() + kNewTabButtonVOffset - y; 1461 int height = newtab_surface_bounds_.height() + kNewTabButtonVOffset - y;
1459 1462
1460 gfx::Rect bounds(0, y, newtab_surface_bounds_.width(), height); 1463 gfx::Rect bounds(0, y, newtab_surface_bounds_.width(), height);
1461 int delta = abs(Round(unselected_width) - TabGtk::GetStandardSize().width()); 1464 int delta = abs(Round(unselected_width) - TabGtk::GetStandardSize().width());
1462 if (delta > 1 && !needs_resize_layout_) { 1465 if (delta > 1 && !needs_resize_layout_) {
1463 // We're shrinking tabs, so we need to anchor the New Tab button to the 1466 // We're shrinking tabs, so we need to anchor the New Tab button to the
1464 // right edge of the TabStrip's bounds, rather than the right edge of the 1467 // right edge of the TabStrip's bounds, rather than the right edge of the
1465 // right-most Tab, otherwise it'll bounce when animating. 1468 // right-most Tab, otherwise it'll bounce when animating.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 drop_info_->drop_arrow = GetDropArrowImage(drop_info_->point_down); 1746 drop_info_->drop_arrow = GetDropArrowImage(drop_info_->point_down);
1744 } 1747 }
1745 } 1748 }
1746 1749
1747 gtk_window_move(GTK_WINDOW(drop_info_->container), 1750 gtk_window_move(GTK_WINDOW(drop_info_->container),
1748 drop_bounds.x(), drop_bounds.y()); 1751 drop_bounds.x(), drop_bounds.y());
1749 gtk_window_resize(GTK_WINDOW(drop_info_->container), 1752 gtk_window_resize(GTK_WINDOW(drop_info_->container),
1750 drop_bounds.width(), drop_bounds.height()); 1753 drop_bounds.width(), drop_bounds.height());
1751 } 1754 }
1752 1755
1753 bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) { 1756 bool TabStripGtk::CompleteDrop(const guchar* data, bool is_plain_text) {
1754 if (!drop_info_.get()) 1757 if (!drop_info_.get())
1755 return false; 1758 return false;
1756 1759
1757 const int drop_index = drop_info_->drop_index; 1760 const int drop_index = drop_info_->drop_index;
1758 const bool drop_before = drop_info_->drop_before; 1761 const bool drop_before = drop_info_->drop_before;
1759 1762
1760 // Destroy the drop indicator. 1763 // Destroy the drop indicator.
1761 drop_info_.reset(); 1764 drop_info_.reset();
1762 1765
1763 // Cancel any pending tab transition. 1766 // Cancel any pending tab transition.
1764 hover_tab_selector_.CancelTabTransition(); 1767 hover_tab_selector_.CancelTabTransition();
1765 1768
1766 GURL url; 1769 GURL url;
1767 if (is_plain_text) { 1770 if (is_plain_text) {
1768 AutocompleteMatch match; 1771 AutocompleteMatch match;
1769 model_->profile()->GetAutocompleteClassifier()->Classify( 1772 model_->profile()->GetAutocompleteClassifier()->Classify(
1770 UTF8ToUTF16(reinterpret_cast<char*>(data)), string16(), false, false, 1773 UTF8ToUTF16(reinterpret_cast<const char*>(data)), string16(),
1771 &match, NULL); 1774 false, false, &match, NULL);
1772 url = match.destination_url; 1775 url = match.destination_url;
1773 } else { 1776 } else {
1774 std::string url_string(reinterpret_cast<char*>(data)); 1777 std::string url_string(reinterpret_cast<const char*>(data));
1775 url = GURL(url_string.substr(0, url_string.find_first_of('\n'))); 1778 url = GURL(url_string.substr(0, url_string.find_first_of('\n')));
1776 } 1779 }
1777 if (!url.is_valid()) 1780 if (!url.is_valid())
1778 return false; 1781 return false;
1779 1782
1780 browser::NavigateParams params(window()->browser(), url, 1783 browser::NavigateParams params(window()->browser(), url,
1781 content::PAGE_TRANSITION_LINK); 1784 content::PAGE_TRANSITION_LINK);
1782 params.tabstrip_index = drop_index; 1785 params.tabstrip_index = drop_index;
1783 1786
1784 if (drop_before) { 1787 if (drop_before) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget, 1820 gboolean TabStripGtk::DropInfo::OnExposeEvent(GtkWidget* widget,
1818 GdkEventExpose* event) { 1821 GdkEventExpose* event) {
1819 TRACE_EVENT0("ui::gtk", "TabStripGtk::DropInfo::OnExposeEvent"); 1822 TRACE_EVENT0("ui::gtk", "TabStripGtk::DropInfo::OnExposeEvent");
1820 1823
1821 if (ui::IsScreenComposited()) { 1824 if (ui::IsScreenComposited()) {
1822 SetContainerTransparency(); 1825 SetContainerTransparency();
1823 } else { 1826 } else {
1824 SetContainerShapeMask(); 1827 SetContainerShapeMask();
1825 } 1828 }
1826 1829
1827 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 1830 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget));
1828 gdk_cairo_rectangle(cr, &event->area); 1831 gdk_cairo_rectangle(cr, &event->area);
1829 cairo_clip(cr); 1832 cairo_clip(cr);
1830 1833
1831 drop_arrow->ToCairo()->SetSource(cr, widget, 0, 0); 1834 drop_arrow->ToCairo()->SetSource(cr, widget, 0, 0);
1832 cairo_paint(cr); 1835 cairo_paint(cr);
1833 1836
1834 cairo_destroy(cr); 1837 cairo_destroy(cr);
1835 1838
1836 return FALSE; 1839 return FALSE;
1837 } 1840 }
1838 1841
1839 // Sets the color map of the container window to allow the window to be 1842 // Sets the color map of the container window to allow the window to be
1840 // transparent. 1843 // transparent.
1841 void TabStripGtk::DropInfo::SetContainerColorMap() { 1844 void TabStripGtk::DropInfo::SetContainerColorMap() {
1842 GdkScreen* screen = gtk_widget_get_screen(container); 1845 GdkScreen* screen = gtk_widget_get_screen(container);
1843 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); 1846 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen);
1844 1847
1845 // If rgba is not available, use rgb instead. 1848 // If rgba is not available, use rgb instead.
1846 if (!colormap) 1849 if (!colormap)
1847 colormap = gdk_screen_get_rgb_colormap(screen); 1850 colormap = gdk_screen_get_rgb_colormap(screen);
1848 1851
1849 gtk_widget_set_colormap(container, colormap); 1852 gtk_widget_set_colormap(container, colormap);
1850 } 1853 }
1851 1854
1852 // Sets full transparency for the container window. This is used if 1855 // Sets full transparency for the container window. This is used if
1853 // compositing is available for the screen. 1856 // compositing is available for the screen.
1854 void TabStripGtk::DropInfo::SetContainerTransparency() { 1857 void TabStripGtk::DropInfo::SetContainerTransparency() {
1855 cairo_t* cairo_context = gdk_cairo_create(container->window); 1858 cairo_t* cairo_context = gdk_cairo_create(gtk_widget_get_window(container));
1856 if (!cairo_context) 1859 if (!cairo_context)
1857 return; 1860 return;
1858 1861
1859 // Make the background of the dragged tab window fully transparent. All of 1862 // Make the background of the dragged tab window fully transparent. All of
1860 // the content of the window (child widgets) will be completely opaque. 1863 // the content of the window (child widgets) will be completely opaque.
1861 1864
1862 cairo_scale(cairo_context, static_cast<double>(drop_indicator_width), 1865 cairo_scale(cairo_context, static_cast<double>(drop_indicator_width),
1863 static_cast<double>(drop_indicator_height)); 1866 static_cast<double>(drop_indicator_height));
1864 cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f); 1867 cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f);
1865 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); 1868 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
(...skipping 17 matching lines...) Expand all
1883 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will 1886 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will
1884 // be opaque in the container window. 1887 // be opaque in the container window.
1885 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); 1888 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
1886 // We don't use CairoCachedSurface::SetSource() here because we're not 1889 // We don't use CairoCachedSurface::SetSource() here because we're not
1887 // rendering on a display server. 1890 // rendering on a display server.
1888 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow->ToGdkPixbuf(), 0, 0); 1891 gdk_cairo_set_source_pixbuf(cairo_context, drop_arrow->ToGdkPixbuf(), 0, 0);
1889 cairo_paint(cairo_context); 1892 cairo_paint(cairo_context);
1890 cairo_destroy(cairo_context); 1893 cairo_destroy(cairo_context);
1891 1894
1892 // Set the shape mask. 1895 // Set the shape mask.
1893 gdk_window_shape_combine_mask(container->window, pixmap, 0, 0); 1896 GdkWindow* gdk_window = gtk_widget_get_window(container);
1897 gdk_window_shape_combine_mask(gdk_window, pixmap, 0, 0);
1894 g_object_unref(pixmap); 1898 g_object_unref(pixmap);
1895 } 1899 }
1896 1900
1897 void TabStripGtk::DropInfo::CreateContainer() { 1901 void TabStripGtk::DropInfo::CreateContainer() {
1898 container = gtk_window_new(GTK_WINDOW_POPUP); 1902 container = gtk_window_new(GTK_WINDOW_POPUP);
1899 SetContainerColorMap(); 1903 SetContainerColorMap();
1900 gtk_widget_set_app_paintable(container, TRUE); 1904 gtk_widget_set_app_paintable(container, TRUE);
1901 g_signal_connect(container, "expose-event", 1905 g_signal_connect(container, "expose-event",
1902 G_CALLBACK(OnExposeEventThunk), this); 1906 G_CALLBACK(OnExposeEventThunk), this);
1903 gtk_widget_add_events(container, GDK_STRUCTURE_MASK); 1907 gtk_widget_add_events(container, GDK_STRUCTURE_MASK);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget, 2154 gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget,
2151 GdkDragContext* context, 2155 GdkDragContext* context,
2152 gint x, gint y, 2156 gint x, gint y,
2153 GtkSelectionData* data, 2157 GtkSelectionData* data,
2154 guint info, guint time) { 2158 guint info, guint time) {
2155 bool success = false; 2159 bool success = false;
2156 2160
2157 if (info == ui::TEXT_URI_LIST || 2161 if (info == ui::TEXT_URI_LIST ||
2158 info == ui::NETSCAPE_URL || 2162 info == ui::NETSCAPE_URL ||
2159 info == ui::TEXT_PLAIN) { 2163 info == ui::TEXT_PLAIN) {
2160 success = CompleteDrop(data->data, info == ui::TEXT_PLAIN); 2164 success = CompleteDrop(gtk_selection_data_get_data(data),
2165 info == ui::TEXT_PLAIN);
2161 } 2166 }
2162 2167
2163 gtk_drag_finish(context, success, FALSE, time); 2168 gtk_drag_finish(context, success, FALSE, time);
2164 return TRUE; 2169 return TRUE;
2165 } 2170 }
2166 2171
2167 void TabStripGtk::OnNewTabClicked(GtkWidget* widget) { 2172 void TabStripGtk::OnNewTabClicked(GtkWidget* widget) {
2168 GdkEvent* event = gtk_get_current_event(); 2173 GdkEvent* event = gtk_get_current_event();
2169 DCHECK_EQ(event->type, GDK_BUTTON_RELEASE); 2174 DCHECK_EQ(event->type, GDK_BUTTON_RELEASE);
2170 int mouse_button = event->button.button; 2175 int mouse_button = event->button.button;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 } 2252 }
2248 2253
2249 void TabStripGtk::SetNewTabButtonBackground() { 2254 void TabStripGtk::SetNewTabButtonBackground() {
2250 SkColor color = theme_service_->GetColor( 2255 SkColor color = theme_service_->GetColor(
2251 ThemeService::COLOR_BUTTON_BACKGROUND); 2256 ThemeService::COLOR_BUTTON_BACKGROUND);
2252 SkBitmap* background = theme_service_->GetBitmapNamed( 2257 SkBitmap* background = theme_service_->GetBitmapNamed(
2253 IDR_THEME_WINDOW_CONTROL_BACKGROUND); 2258 IDR_THEME_WINDOW_CONTROL_BACKGROUND);
2254 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); 2259 SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK);
2255 newtab_button_->SetBackground(color, background, mask); 2260 newtab_button_->SetBackground(color, background, mask);
2256 } 2261 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_strip_gtk.h ('k') | ui/base/gtk/gtk_compat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698