• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef UI_GFX_GTK_COMPAT_H_
6 #define UI_GFX_GTK_COMPAT_H_
7 
8 #include <gtk/gtk.h>
9 
10 // Google Chrome must depend on GTK 2.18, at least until the next LTS drops
11 // (and we might have to extend which version of GTK we want to target due to
12 // RHEL). To make our porting job for GTK3 easier, we define all the methods
13 // that replace deprecated APIs in this file and then include it everywhere.
14 //
15 // This file is organized first by version, and then with each version,
16 // alphabetically by method.
17 //
18 // For Google Chrome builds, we want to support RHEL 6, which uses GTK 2.18,
19 // but the official builder is Ubuntu Lucid with GTK 2.20. Thus for Google
20 // Chrome builds, we define the GTK 2.20.0 compatibility functions even though
21 // the system GTK provides the functions.
22 
23 #if !GTK_CHECK_VERSION(2, 20, 0) || defined(GOOGLE_CHROME_BUILD)
gtk_widget_get_mapped(GtkWidget * widget)24 inline gboolean gtk_widget_get_mapped(GtkWidget* widget) {
25   return GTK_WIDGET_MAPPED(widget);
26 }
27 
gtk_widget_get_realized(GtkWidget * widget)28 inline gboolean gtk_widget_get_realized(GtkWidget* widget) {
29   return GTK_WIDGET_REALIZED(widget);
30 }
31 
gtk_widget_is_toplevel(GtkWidget * widget)32 inline gboolean gtk_widget_is_toplevel(GtkWidget* widget) {
33   return GTK_WIDGET_TOPLEVEL(widget);
34 }
35 
gtk_widget_set_mapped(GtkWidget * widget,gboolean mapped)36 inline void gtk_widget_set_mapped(GtkWidget* widget,
37                                   gboolean mapped) {
38   if (mapped)
39     GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED);
40   else
41     GTK_WIDGET_UNSET_FLAGS(widget, GTK_MAPPED);
42 }
43 
gtk_widget_set_realized(GtkWidget * widget,gboolean realized)44 inline void gtk_widget_set_realized(GtkWidget* widget,
45                                     gboolean realized) {
46   if (realized)
47     GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
48   else
49     GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED);
50 }
51 
gtk_widget_style_attach(GtkWidget * widget)52 inline void gtk_widget_style_attach(GtkWidget* widget) {
53   widget->style = gtk_style_attach(widget->style, widget->window);
54 }
55 #endif  // !GTK_CHECK_VERSION(2, 20, 0) || defined(GOOGLE_CHROME_BUILD)
56 
57 #if !GTK_CHECK_VERSION(2, 22, 0)
gdk_drag_context_get_source_window(GdkDragContext * context)58 inline GdkWindow* gdk_drag_context_get_source_window(GdkDragContext *context) {
59   return context->source_window;
60 }
61 
gdk_visual_get_depth(GdkVisual * visual)62 inline gint gdk_visual_get_depth(GdkVisual* visual) {
63   return visual->depth;
64 }
65 
gtk_button_get_event_window(GtkButton * button)66 inline GdkWindow* gtk_button_get_event_window(GtkButton* button) {
67   return button->event_window;
68 }
69 #endif  // !GTK_CHECK_VERSION(2, 22, 0)
70 
71 #if !GTK_CHECK_VERSION(2, 24, 0)
gdk_pixmap_get_size(GdkPixmap * pixmap,gint * width,gint * height)72 inline void gdk_pixmap_get_size(GdkPixmap* pixmap, gint* width, gint* height) {
73   gdk_drawable_get_size(GDK_DRAWABLE(pixmap), width, height);
74 }
75 
gdk_window_get_display(GdkWindow * window)76 inline GdkDisplay* gdk_window_get_display(GdkWindow* window) {
77   return gdk_drawable_get_display(GDK_DRAWABLE(window));
78 }
79 
gdk_window_get_height(GdkWindow * window)80 inline int gdk_window_get_height(GdkWindow* window) {
81   int height;
82   gdk_drawable_get_size(GDK_DRAWABLE(window), NULL, &height);
83   return height;
84 }
85 
gdk_window_get_screen(GdkWindow * window)86 inline GdkScreen* gdk_window_get_screen(GdkWindow* window) {
87   return gdk_drawable_get_screen(GDK_DRAWABLE(window));
88 }
89 
gdk_window_get_width(GdkWindow * window)90 inline int gdk_window_get_width(GdkWindow* window) {
91   int width;
92   gdk_drawable_get_size(GDK_DRAWABLE(window), &width, NULL);
93   return width;
94 }
95 #endif  // !GTK_CHECK_VERSION(2, 24, 0)
96 
97 #endif  // UI_GFX_GTK_COMPAT_H_
98