Home | History | Annotate | Download | only in gfx
      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)
     24 inline gboolean gtk_widget_get_mapped(GtkWidget* widget) {
     25   return GTK_WIDGET_MAPPED(widget);
     26 }
     27 
     28 inline gboolean gtk_widget_get_realized(GtkWidget* widget) {
     29   return GTK_WIDGET_REALIZED(widget);
     30 }
     31 
     32 inline gboolean gtk_widget_is_toplevel(GtkWidget* widget) {
     33   return GTK_WIDGET_TOPLEVEL(widget);
     34 }
     35 
     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 
     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 
     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)
     58 inline GdkWindow* gdk_drag_context_get_source_window(GdkDragContext *context) {
     59   return context->source_window;
     60 }
     61 
     62 inline gint gdk_visual_get_depth(GdkVisual* visual) {
     63   return visual->depth;
     64 }
     65 
     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)
     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 
     76 inline GdkDisplay* gdk_window_get_display(GdkWindow* window) {
     77   return gdk_drawable_get_display(GDK_DRAWABLE(window));
     78 }
     79 
     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 
     86 inline GdkScreen* gdk_window_get_screen(GdkWindow* window) {
     87   return gdk_drawable_get_screen(GDK_DRAWABLE(window));
     88 }
     89 
     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