Backing out d883ab4b8f41:7540abc35c97
authorVladimir Vukicevic <vladimir@pobox.com>
Wed, 06 Aug 2008 16:24:13 -0700
changeset 16458 5482151cfd1055d0b10155498eb42c201e5ad5c6
parent 16457 2ed34bcabbc6721d58ea134d6a2c57497e49acc0
child 16459 8e6782e9aaeda6f2a13b348b6af4a3bd88c6ec55
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a2pre
Backing out d883ab4b8f41:7540abc35c97
config/autoconf.mk.in
config/system-headers
gfx/thebes/public/gfxGdkNativeRenderer.h
gfx/thebes/public/gfxXlibNativeRenderer.h
gfx/thebes/src/cairo-gdk-utils.c
gfx/thebes/src/cairo-gdk-utils.h
gfx/thebes/src/cairo-xlib-utils.c
gfx/thebes/src/cairo-xlib-utils.h
gfx/thebes/src/gfxGdkNativeRenderer.cpp
gfx/thebes/src/gfxPlatformGtk.cpp
gfx/thebes/src/gfxXlibNativeRenderer.cpp
layout/generic/nsObjectFrame.cpp
modules/plugin/base/src/nsPluginHostImpl.cpp
modules/plugin/samples/default/unix/nullplugin.c
toolkit/library/libxul-config.mk
toolkit/toolkit-tiers.mk
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsNativeAppSupportUnix.cpp
widget/src/Makefile.in
widget/src/gtk2/Makefile.in
widget/src/gtk2/keysym2ucs.h
widget/src/gtk2/nsBidiKeyboard.cpp
widget/src/gtk2/nsGtkKeyUtils.cpp
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/gtk2/nsScreenGtk.cpp
widget/src/gtk2/nsScreenGtk.h
widget/src/gtk2/nsScreenManagerGtk.cpp
widget/src/gtk2/nsScreenManagerGtk.h
widget/src/gtk2/nsWidgetFactory.cpp
widget/src/gtk2/nsWindow.cpp
widget/src/gtk2/nsWindow.h
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -79,21 +79,18 @@ LIBXUL_DIST = $(DIST)
 endif
 
 XULRUNNER_STUB_NAME = @XULRUNNER_STUB_NAME@
 
 MOZ_CHROME_FILE_FORMAT	= @MOZ_CHROME_FILE_FORMAT@
 
 MOZ_WIDGET_TOOLKIT	= @MOZ_WIDGET_TOOLKIT@
 MOZ_GFX_TOOLKIT		= @MOZ_GFX_TOOLKIT@
-MOZ_DFB			= @MOZ_DFB@
 MOZ_X11			= @MOZ_X11@
 
-MOZ_PANGO = @MOZ_PANGO@
-
 MOZ_JS_LIBS		   = @MOZ_JS_LIBS@
 
 MOZ_DEBUG	= @MOZ_DEBUG@
 MOZ_DEBUG_MODULES = @MOZ_DEBUG_MODULES@
 MOZ_PROFILE_MODULES = @MOZ_PROFILE_MODULES@
 MOZ_DEBUG_ENABLE_DEFS		= @MOZ_DEBUG_ENABLE_DEFS@
 MOZ_DEBUG_DISABLE_DEFS	= @MOZ_DEBUG_DISABLE_DEFS@
 MOZ_DEBUG_FLAGS	= @MOZ_DEBUG_FLAGS@
--- a/config/system-headers
+++ b/config/system-headers
@@ -75,25 +75,24 @@ byteswap.h
 #define WRAP_CAIRO_HEADERS
 #endif
 #ifdef WRAP_CAIRO_HEADERS
 cairo.h
 cairo-atsui.h
 cairo-beos.h
 cairo-ft.h
 cairo-glitz.h
+cairo-nquartz.h
 cairo-os2.h
 cairo-pdf.h
 cairo-ps.h
 cairo-quartz.h
 cairo-win32.h
 cairo-xlib.h
 cairo-xlib-xrender.h
-cairo-directfb.h
-cairo-qpainter.h
 #endif
 callconv.h
 Carbon/Carbon.h
 CarbonEvents.h
 Carbon.h
 cassert
 c_asm.h
 cctype
deleted file mode 100644
--- a/gfx/thebes/public/gfxGdkNativeRenderer.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Novell code.
- *
- * The Initial Developer of the Original Code is Novell.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   rocallahan@novell.com
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef GFXGDKNATIVERENDER_H_
-#define GFXGDKNATIVERENDER_H_
-
-#include "gfxColor.h"
-#include <gdk/gdk.h>
-
-class gfxASurface;
-class gfxContext;
-
-/**
- * This class lets us take code that draws into an GDK drawable and lets us
- * use it to draw into any Thebes context. The user should subclass this class,
- * override NativeDraw, and then call Draw(). The drawing will be subjected
- * to all Thebes transformations, clipping etc.
- */
-class THEBES_API gfxGdkNativeRenderer {
-public:
-    /**
-     * Perform the native drawing.
-     * @param offsetX draw at this offset into the given drawable
-     * @param offsetY draw at this offset into the given drawable
-     * @param clipRects an array of rects; clip to the union
-     * @param numClipRects the number of rects in the array, or zero if
-     * no clipping is required
-     */
-    virtual nsresult NativeDraw(GdkDrawable * drawable, short offsetX, 
-            short offsetY, GdkRectangle * clipRects, PRUint32 numClipRects) = 0;
-  
-    enum {
-        // If set, then Draw() is opaque, i.e., every pixel in the intersection
-        // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
-        // will be set and there is no dependence on what the existing pixels
-        // in the drawable are set to.
-        DRAW_IS_OPAQUE = 0x01,
-        // If set, then offset may be non-zero; if not set, then Draw() can
-        // only be called with offset==(0,0)
-        DRAW_SUPPORTS_OFFSET = 0x02,
-        // If set, then numClipRects can be zero or one
-        DRAW_SUPPORTS_CLIP_RECT = 0x04,
-        // If set, then numClipRects can be any value. If neither this
-        // nor CLIP_RECT are set, then numClipRects will be zero
-        DRAW_SUPPORTS_CLIP_LIST = 0x08,
-        // If set, then the visual passed in can be any visual, otherwise the
-        // visual passed in must be the default visual for dpy's default screen
-        DRAW_SUPPORTS_NONDEFAULT_VISUAL = 0x10,
-        // If set, then the Screen 'screen' in the callback can be different
-        // from the default Screen of the display passed to 'Draw' and can be
-        // on a different display.
-        DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20
-    };
-
-    struct DrawOutput {
-        nsRefPtr<gfxASurface> mSurface;
-        PRPackedBool mUniformAlpha;
-        PRPackedBool mUniformColor;
-        gfxRGBA      mColor;
-    };
-
-    /**
-     * @param flags see above
-     * @param bounds Draw()'s drawing is guaranteed to be restricted to
-     * the rectangle (offset.x,offset.y,bounds.width,bounds.height)
-     * @param dpy a display to use for the drawing if ctx doesn't have one
-     * @param resultSurface if non-null, we will try to capture a copy of the
-     * rendered image into a surface similar to the surface of ctx; if
-     * successful, a pointer to the new gfxASurface is stored in *resultSurface,
-     * otherwise *resultSurface is set to nsnull.
-     */
-    nsresult Draw(gfxContext* ctx, int width, int height,
-                  PRUint32 flags, DrawOutput* output);
-};
-
-#endif /*GFXGDKNATIVERENDER_H_*/
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/public/gfxXlibNativeRenderer.h
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Novell code.
+ *
+ * The Initial Developer of the Original Code is Novell.
+ * Portions created by the Initial Developer are Copyright (C) 2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   rocallahan@novell.com
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef GFXXLIBNATIVERENDER_H_
+#define GFXXLIBNATIVERENDER_H_
+
+#include "gfxColor.h"
+#include <X11/Xlib.h>
+
+class gfxASurface;
+class gfxContext;
+
+/**
+ * This class lets us take code that draws into an X drawable and lets us
+ * use it to draw into any Thebes context. The user should subclass this class,
+ * override NativeDraw, and then call Draw(). The drawing will be subjected
+ * to all Thebes transformations, clipping etc.
+ */
+class THEBES_API gfxXlibNativeRenderer {
+public:
+    /**
+     * Perform the native drawing.
+     * @param offsetX draw at this offset into the given drawable
+     * @param offsetY draw at this offset into the given drawable
+     * @param clipRects an array of rects; clip to the union
+     * @param numClipRects the number of rects in the array, or zero if
+     * no clipping is required
+     */
+    virtual nsresult NativeDraw(Screen* screen, Drawable drawable,
+                                Visual* visual, Colormap colormap,
+                                short offsetX, short offsetY,
+                                XRectangle* clipRects, PRUint32 numClipRects) = 0;
+  
+    enum {
+        // If set, then Draw() is opaque, i.e., every pixel in the intersection
+        // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
+        // will be set and there is no dependence on what the existing pixels
+        // in the drawable are set to.
+        DRAW_IS_OPAQUE = 0x01,
+        // If set, then offset may be non-zero; if not set, then Draw() can
+        // only be called with offset==(0,0)
+        DRAW_SUPPORTS_OFFSET = 0x02,
+        // If set, then numClipRects can be zero or one
+        DRAW_SUPPORTS_CLIP_RECT = 0x04,
+        // If set, then numClipRects can be any value. If neither this
+        // nor CLIP_RECT are set, then numClipRects will be zero
+        DRAW_SUPPORTS_CLIP_LIST = 0x08,
+        // If set, then the visual passed in can be any visual, otherwise the
+        // visual passed in must be the default visual for 'screen'
+        DRAW_SUPPORTS_NONDEFAULT_VISUAL = 0x10,
+        // If set, then the Screen 'screen' in the callback can be different
+        // from the default Screen of the display passed to 'Draw' and can be
+        // on a different display.
+        DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20
+    };
+
+    struct DrawOutput {
+        nsRefPtr<gfxASurface> mSurface;
+        PRPackedBool mUniformAlpha;
+        PRPackedBool mUniformColor;
+        gfxRGBA      mColor;
+    };
+
+    /**
+     * @param flags see above
+     * @param bounds Draw()'s drawing is guaranteed to be restricted to
+     * the rectangle (offset.x,offset.y,bounds.width,bounds.height)
+     * @param dpy a display to use for the drawing if ctx doesn't have one
+     * @param resultSurface if non-null, we will try to capture a copy of the
+     * rendered image into a surface similar to the surface of ctx; if
+     * successful, a pointer to the new gfxASurface is stored in *resultSurface,
+     * otherwise *resultSurface is set to nsnull.
+     */
+    nsresult Draw(Display* dpy, gfxContext* ctx, int width, int height,
+                  PRUint32 flags, DrawOutput* output);
+};
+
+#endif /*GFXXLIBNATIVERENDER_H_*/
deleted file mode 100644
--- a/gfx/thebes/src/cairo-gdk-utils.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Novell code.
- *
- * The Initial Developer of the Original Code is Novell.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   rocallahan@novell.com
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "cairo-gdk-utils.h"
-
-#include <stdlib.h>
-
-#if   HAVE_STDINT_H
-#include <stdint.h>
-#elif HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_SYS_INT_TYPES_H
-#include <sys/int_types.h>
-#endif
-
-
-/* We have three basic strategies available:
-   1) 'direct': cr targets a native surface, and other conditions are met: we can
-      pass the underlying drawable directly to the callback
-   2) 'opaque': the image is opaque: we can create a temporary cairo native surface,
-      pass its underlying drawable to the callback, and paint the result
-      using cairo
-   3) 'default': create a temporary cairo native surface, fill with black, pass its
-      underlying drawable to the callback, copy the results to a cairo
-      image surface, repeat with a white background, update the on-black
-      image alpha values by comparing the two images, then paint the on-black
-      image using cairo
-   Sure would be nice to have an X extension to do 3 for us on the server...
-*/
-
-static cairo_bool_t
-_convert_coord_to_short (double coord, short *v)
-{
-    *v = (short)coord;
-    /* XXX allow some tolerance here? */
-    return *v == coord;
-}
-
-static cairo_bool_t
-_convert_coord_to_unsigned_short (double coord, unsigned short *v)
-{
-    *v = (unsigned short)coord;
-    /* XXX allow some tolerance here? */
-    return *v == coord;
-}
-
-
-void cairo_draw_with_gdk (cairo_t *cr,
-                           GdkDrawable * drawable,
-                           cairo_gdk_drawing_callback callback,
-                           void * closure,
-                           unsigned int width, unsigned int height,
-                           cairo_gdk_drawing_opacity_t is_opaque,
-                           cairo_gdk_drawing_support_t capabilities,
-                           cairo_gdk_drawing_result_t *result)
-{
-    double device_offset_x, device_offset_y;
-    short offset_x = 0, offset_y = 0;
-    //cairo_surface_t * target = cairo_get_group_target (cr);
-    cairo_surface_t * target = cairo_get_target (cr);
-    cairo_matrix_t matrix;
-
-    cairo_surface_get_device_offset (target, &device_offset_x, &device_offset_y);
-    cairo_get_matrix (cr, &matrix);
-
-    _convert_coord_to_short (matrix.x0 + device_offset_x, &offset_x);
-    _convert_coord_to_short (matrix.y0 + device_offset_y, &offset_y);
-
-    cairo_surface_flush (target);
-    callback (closure, drawable, offset_x, offset_y, NULL, 0);
-    cairo_surface_mark_dirty (target);
-}
-
-
deleted file mode 100644
--- a/gfx/thebes/src/cairo-gdk-utils.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Novell code.
- *
- * The Initial Developer of the Original Code is Novell.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   rocallahan@novell.com
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef CAIROGDKUTILS_H_
-#define CAIROGDKUTILS_H_
-
-#include "cairo.h"
-#include <gdk/gdk.h>
-
-CAIRO_BEGIN_DECLS
-
-/**
- * This callback encapsulates GDK-based rendering. We assume that the
- * execution of the callback is equivalent to compositing some RGBA image of
- * size (bounds_width, bounds_height) onto the drawable at offset (offset_x,
- * offset_y), clipped to the union of the clip_rects if num_rects is greater
- * than zero. This includes the assumption that the same RGBA image
- * is composited if you call the callback multiple times with the same closure,
- * display and visual during a single cairo_draw_with_gdk call.
- * 
- * @return True on success, False on non-recoverable error
- */
-typedef cairo_bool_t (* cairo_gdk_drawing_callback)
-    (void *closure,
-     GdkDrawable * drawable,
-     short offset_x, short offset_y,
-     GdkRectangle * clip_rects, unsigned int num_rects);
-
-/**
- * This structure captures the result of the native drawing, in case the
- * caller may wish to reapply the drawing efficiently later.
- */
-typedef struct {
-    cairo_surface_t *surface;
-    cairo_bool_t    uniform_alpha;
-    cairo_bool_t    uniform_color;
-    double          alpha; /* valid only if uniform_alpha is TRUE */
-    double          r, g, b; /* valid only if uniform_color is TRUE */
-} cairo_gdk_drawing_result_t;
-
-/**
- * This type specifies whether the native drawing callback draws all pixels
- * in its bounds opaquely, independent of the contents of the target drawable,
- * or whether it leaves pixels transparent/translucent or depends on the
- * existing contents of the target drawable in some way.
- */
-typedef enum _cairo_gdk_drawing_opacity {
-    CAIRO_GDK_DRAWING_OPAQUE,
-    CAIRO_GDK_DRAWING_TRANSPARENT
-} cairo_gdk_drawing_opacity_t;
-
-/**
- * This type encodes the capabilities of the native drawing callback.
- * 
- * If CAIRO_GDK_DRAWING_SUPPORTS_OFFSET is set, 'offset_x' and 'offset_y'
- * can be nonzero in the call to the callback; otherwise they will be zero.
- * 
- * If CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT is set, then 'num_rects' can be
- * zero or one in the call to the callback. If
- * CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST is set, then 'num_rects' can be
- * anything in the call to the callback. Otherwise 'num_rects' will be zero.
- * Do not set both of these values.
- * 
- * If CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_DISPLAY is set, then 'dpy' can be
- * any display, otherwise it will be the display passed into
- * cairo_draw_with_gdk.
- * 
- * If CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL is set, then 'visual' can be
- * any visual, otherwise it will be equal to
- * DefaultVisual (dpy, DefaultScreen (dpy)).
- */
-typedef enum {
-    CAIRO_GDK_DRAWING_SUPPORTS_OFFSET = 0x01,
-    CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT = 0x02,
-    CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST = 0x04,
-    CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN = 0x08,
-    CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL = 0x10
-} cairo_gdk_drawing_support_t;
-
-/**
- * Draw GDK output into any cairo context. All cairo transforms and effects
- * are honored, including the current operator. This is equivalent to a
- * cairo_set_source_surface and then cairo_paint.
- * @param cr the context to draw into
- * @param drawable a GDK Drawable that we're targetting
- * @param callback the code to perform GDK rendering
- * @param closure associated data
- * @param width the width of the putative image drawn by the callback
- * @param height the height of the putative image drawn by the callback
- * @param is_opaque set to CAIRO_GDK_DRAWING_IS_OPAQUE to indicate
- * that all alpha values of the putative image will be 1.0; the pixels drawn into
- * the Drawable must not depend on the prior contents of the Drawable
- * in any way
- * @param capabilities the capabilities of the callback as described above.
- * @param result if non-NULL, we *may* fill in the struct with information about
- * the rendered image. 'surface' may be filled in with a surface representing
- * the image, similar to the target of 'cr'. If 'uniform_alpha' is True then
- * every pixel of the image has the same alpha value 'alpha'. If
- * 'uniform_color' is True then every pixel of the image has the same RGB
- * color (r, g, b). If the image has uniform color and alpha (or alpha is zero,
- * in which case the color is always uniform) then we won't bother returning
- * a surface for it.
- */
-void cairo_draw_with_gdk (cairo_t *cr,
-                          GdkDrawable * drawable,
-                          cairo_gdk_drawing_callback callback,
-                          void * closure,
-                          unsigned int width, unsigned int height,
-                          cairo_gdk_drawing_opacity_t is_opaque,
-                          cairo_gdk_drawing_support_t capabilities,
-                          cairo_gdk_drawing_result_t *result);
-
-CAIRO_END_DECLS
-
-#endif /*CAIROGDKUTILS_H_*/
--- a/gfx/thebes/src/cairo-xlib-utils.c
+++ b/gfx/thebes/src/cairo-xlib-utils.c
@@ -30,43 +30,48 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "cairo-gdk-utils.h"
+#include "cairo-xlib-utils.h"
 
 #include "cairo-xlib.h"
 #include <stdlib.h>
 
 #if   HAVE_STDINT_H
 #include <stdint.h>
 #elif HAVE_INTTYPES_H
 #include <inttypes.h>
 #elif HAVE_SYS_INT_TYPES_H
 #include <sys/int_types.h>
 #endif
 
-#include <gdk/gdkx.h>
-
 #if 0
 #include <stdio.h>
-#define CAIRO_GDK_DRAWING_NOTE(m) fprintf(stderr, m)
+#define CAIRO_XLIB_DRAWING_NOTE(m) fprintf(stderr, m)
 #else
-#define CAIRO_GDK_DRAWING_NOTE(m) do {} while (0)
+#define CAIRO_XLIB_DRAWING_NOTE(m) do {} while (0)
 #endif
 
 static cairo_user_data_key_t pixmap_free_key;
+
+typedef struct {
+    Display *dpy;
+    Pixmap   pixmap;
+} pixmap_free_struct;
+
 static void pixmap_free_func (void *data)
 {
-    GdkPixmap *pixmap = (GdkPixmap *) data;
-    g_object_unref(pixmap);
+    pixmap_free_struct *pfs = (pixmap_free_struct *) data;
+    XFreePixmap (pfs->dpy, pfs->pixmap);
+    free (pfs);
 }
 
 /* We have three basic strategies available:
    1) 'direct': cr targets an xlib surface, and other conditions are met: we can
       pass the underlying drawable directly to the callback
    2) 'opaque': the image is opaque: we can create a temporary cairo xlib surface,
       pass its underlying drawable to the callback, and paint the result
       using cairo
@@ -74,19 +79,27 @@ static void pixmap_free_func (void *data
       underlying drawable to the callback, copy the results to a cairo
       image surface, repeat with a white background, update the on-black
       image alpha values by comparing the two images, then paint the on-black
       image using cairo
    Sure would be nice to have an X extension to do 3 for us on the server...
 */
 
 static cairo_bool_t
-_convert_coord_to_int (double coord, int *v)
+_convert_coord_to_short (double coord, short *v)
 {
-    *v = (int)coord;
+    *v = (short)coord;
+    /* XXX allow some tolerance here? */
+    return *v == coord;
+}
+
+static cairo_bool_t
+_convert_coord_to_unsigned_short (double coord, unsigned short *v)
+{
+    *v = (unsigned short)coord;
     /* XXX allow some tolerance here? */
     return *v == coord;
 }
 
 static cairo_bool_t
 _intersect_interval (double a_begin, double a_end, double b_begin, double b_end,
                      double *out_begin, double *out_end)
 {
@@ -101,17 +114,17 @@ static cairo_bool_t
     return *out_begin < *out_end;
 }
 
 static cairo_bool_t
 _get_rectangular_clip (cairo_t *cr,
                        int bounds_x, int bounds_y,
                        int bounds_width, int bounds_height,
                        cairo_bool_t *need_clip,
-                       GdkRectangle *rectangles, int max_rectangles,
+                       XRectangle *rectangles, int max_rectangles,
                        int *num_rectangles)
 {
     cairo_rectangle_list_t *cliplist;
     cairo_rectangle_t *clips;
     int i;
     double b_x = bounds_x;
     double b_y = bounds_y;
     double b_x_most = bounds_x + bounds_width;
@@ -143,27 +156,27 @@ static cairo_bool_t
             *need_clip = False;
             goto FINISH;
         }
         
         if (_intersect_interval (b_x, b_x_most, clips[i].x, clips[i].x + clips[i].width,
                                  &intersect_x, &intersect_x_most) &&
             _intersect_interval (b_y, b_y_most, clips[i].y, clips[i].y + clips[i].height,
                                  &intersect_y, &intersect_y_most)) {
-            GdkRectangle *rect = &rectangles[rect_count];
+            XRectangle *rect = &rectangles[rect_count];
 
             if (rect_count >= max_rectangles) {
                 retval = False;
                 goto FINISH;
             }
 
-            if (!_convert_coord_to_int (intersect_x, &rect->x) ||
-                !_convert_coord_to_int (intersect_y, &rect->y) ||
-                !_convert_coord_to_int (intersect_x_most - intersect_x, &rect->width) ||
-                !_convert_coord_to_int (intersect_y_most - intersect_y, &rect->height))
+            if (!_convert_coord_to_short (intersect_x, &rect->x) ||
+                !_convert_coord_to_short (intersect_y, &rect->y) ||
+                !_convert_coord_to_unsigned_short (intersect_x_most - intersect_x, &rect->width) ||
+                !_convert_coord_to_unsigned_short (intersect_y_most - intersect_y, &rect->height))
             {
                 retval = False;
                 goto FINISH;
             }
 
             ++rect_count;
         }
     }
@@ -182,198 +195,216 @@ FINISH:
 /**
  * Try the direct path.
  * @param status the status returned by the callback, if we took the direct path
  * @return True if we took the direct path
  */
 static cairo_bool_t
 _draw_with_xlib_direct (cairo_t *cr,
                         Display *default_display,
-                        cairo_gdk_drawing_callback callback,
+                        cairo_xlib_drawing_callback callback,
                         void *closure,
                         int bounds_width, int bounds_height,
-                        cairo_gdk_drawing_support_t capabilities)
+                        cairo_xlib_drawing_support_t capabilities)
 {
     cairo_surface_t *target;
     Drawable d;
     cairo_matrix_t matrix;
-    int offset_x, offset_y;
+    short offset_x, offset_y;
     cairo_bool_t needs_clip;
-    GdkRectangle rectangles[MAX_STATIC_CLIP_RECTANGLES];
+    XRectangle rectangles[MAX_STATIC_CLIP_RECTANGLES];
     int rect_count;
     double device_offset_x, device_offset_y;
     int max_rectangles;
     Screen *screen;
     Visual *visual;
     cairo_bool_t have_rectangular_clip;
 
     target = cairo_get_group_target (cr);
     cairo_surface_get_device_offset (target, &device_offset_x, &device_offset_y);
     d = cairo_xlib_surface_get_drawable (target);
 
     cairo_get_matrix (cr, &matrix);
     
     /* Check that the matrix is a pure translation */
     /* XXX test some approximation to == 1.0 here? */
     if (matrix.xx != 1.0 || matrix.yy != 1.0 || matrix.xy != 0.0 || matrix.yx != 0.0) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: matrix not a pure translation\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: matrix not a pure translation\n");
         return False;
     }
     /* Check that the matrix translation offsets (adjusted for
        device offset) are integers */
-    if (!_convert_coord_to_int (matrix.x0 + device_offset_x, &offset_x) ||
-        !_convert_coord_to_int (matrix.y0 + device_offset_y, &offset_y)) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: non-integer offset\n");
+    if (!_convert_coord_to_short (matrix.x0 + device_offset_x, &offset_x) ||
+        !_convert_coord_to_short (matrix.y0 + device_offset_y, &offset_y)) {
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-integer offset\n");
         return False;
     }
     
     max_rectangles = 0;
-    if (capabilities & CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT) {
+    if (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT) {
       max_rectangles = 1;
     }
-    if (capabilities & CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST) {
+    if (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST) {
       max_rectangles = MAX_STATIC_CLIP_RECTANGLES;
     }
     
     /* Check that the clip is rectangular and aligned on unit boundaries. */
     /* Temporarily set the matrix for _get_rectangular_clip. It's basically
        the identity matrix, but we must adjust for the fact that our
        offset-rect is in device coordinates. */
     cairo_identity_matrix (cr);
     cairo_translate (cr, -device_offset_x, -device_offset_y);
     have_rectangular_clip =
         _get_rectangular_clip (cr,
                                offset_x, offset_y, bounds_width, bounds_height,
                                &needs_clip,
                                rectangles, max_rectangles, &rect_count);
     cairo_set_matrix (cr, &matrix);
     if (!have_rectangular_clip) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: unsupported clip\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: unsupported clip\n");
         return False;
     }
 
     /* Stop now if everything is clipped out */
     if (needs_clip && rect_count == 0) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING FAST PATH: all clipped\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING FAST PATH: all clipped\n");
         return True;
     }
       
     /* Check that the operator is OVER */
     if (cairo_get_operator (cr) != CAIRO_OPERATOR_OVER) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: non-OVER operator\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-OVER operator\n");
         return False;
     }
     
     /* Check that the offset is supported */  
-    if (!(capabilities & CAIRO_GDK_DRAWING_SUPPORTS_OFFSET) &&
+    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET) &&
         (offset_x != 0 || offset_y != 0)) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: unsupported offset\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: unsupported offset\n");
         return False;
     }
     
     /* Check that the target surface is an xlib surface. Do this late because
        we might complete early above when when the object to be drawn is
        completely clipped out. */
     if (!d) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: non-X surface\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-X surface\n");
         return False;
     }
     
     /* Check that the display is supported */  
     screen = cairo_xlib_surface_get_screen (target);
-    if (!(capabilities & CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN) &&
+    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN) &&
         screen != DefaultScreenOfDisplay (default_display)) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: non-default display\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default display\n");
         return False;
     }
         
     /* Check that there is a visual */
     visual = cairo_xlib_surface_get_visual (target);
     if (!visual) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: no Visual for surface\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: no Visual for surface\n");
         return False;
     }        
     /* Check that the visual is supported */
-    if (!(capabilities & CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL) &&
+    if (!(capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL) &&
         DefaultVisualOfScreen (screen) != visual) {
-        CAIRO_GDK_DRAWING_NOTE("TAKING SLOW PATH: non-default visual\n");
+        CAIRO_XLIB_DRAWING_NOTE("TAKING SLOW PATH: non-default visual\n");
         return False;
     }
   
     /* we're good to go! */
-    CAIRO_GDK_DRAWING_NOTE("TAKING FAST PATH\n");
+    CAIRO_XLIB_DRAWING_NOTE("TAKING FAST PATH\n");
     cairo_surface_flush (target);
-    callback (closure, GDK_DRAWABLE(gdk_xid_table_lookup(d)), 
-              offset_x, offset_y, rectangles,
+    callback (closure, screen, d, visual, offset_x, offset_y, rectangles,
               needs_clip ? rect_count : 0);
     cairo_surface_mark_dirty (target);
     return True;
 }
 
 static cairo_surface_t *
 _create_temp_xlib_surface (cairo_t *cr, Display *dpy, int width, int height,
-                           cairo_gdk_drawing_support_t capabilities)
+                           cairo_xlib_drawing_support_t capabilities)
 {
-    cairo_surface_t *result = NULL;
-
     /* base the temp surface on the *screen* surface, not any intermediate
      * group surface, because the screen surface is more likely to have
      * characteristics that the xlib-using code is likely to be happy with */
     cairo_surface_t *target = cairo_get_target (cr);
     Drawable target_drawable = cairo_xlib_surface_get_drawable (target);
-    GdkDrawable *gdk_target_drawable = GDK_DRAWABLE(gdk_xid_table_lookup(target_drawable));
 
-    GdkPixmap *pixmap = NULL;
-    if (gdk_target_drawable) {
-        pixmap = gdk_pixmap_new(gdk_target_drawable,
-                                width, height,
-                                -1);
-    } else {
-        int screen_index = DefaultScreen (dpy);
-        int depth = DefaultDepth (dpy, screen_index);
+    int screen_index = DefaultScreen (dpy);
+    Drawable drawable = RootWindow (dpy, screen_index);
+    Screen *screen = DefaultScreenOfDisplay (dpy);
+    Visual *visual = DefaultVisual (dpy, screen_index);
+    int depth = DefaultDepth (dpy, screen_index);
 
-        pixmap = gdk_pixmap_new(NULL,
-                                width, height,
-                                depth);
+    Pixmap pixmap;
+    cairo_surface_t *result;
+    pixmap_free_struct *pfs;
+    
+    /* make the temporary surface match target_drawable to the extent supported
+       by the native rendering code */
+    if (target_drawable) {
+        Screen *target_screen = cairo_xlib_surface_get_screen (target);
+        Visual *target_visual = cairo_xlib_surface_get_visual (target);
+        if ((target_screen == screen ||
+             (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN)) &&
+            target_visual &&
+            (target_visual == DefaultVisualOfScreen (target_screen) ||
+             (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL))) {
+            drawable = target_drawable;
+            dpy = cairo_xlib_surface_get_display (target);
+            visual = target_visual;
+            depth = cairo_xlib_surface_get_depth (target);
+        }
     }
-
-    result = cairo_xlib_surface_create (gdk_x11_drawable_get_xdisplay(pixmap),
-                                        gdk_x11_drawable_get_xid(pixmap),
-                                        gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(pixmap)),
-                                        width, height);
+    
+    pfs = malloc (sizeof(pixmap_free_struct));
+    if (pfs == NULL)
+        return NULL;
+        
+    pixmap = XCreatePixmap (dpy, drawable, width, height, depth);
+    if (!pixmap) {
+        free (pfs);
+        return NULL;
+    }
+    pfs->dpy = dpy;
+    pfs->pixmap = pixmap;
+  
+    result = cairo_xlib_surface_create (dpy, pixmap, visual, width, height);
     if (cairo_surface_status (result) != CAIRO_STATUS_SUCCESS) {
-        pixmap_free_func (pixmap);
+        pixmap_free_func (pfs);
         return NULL;
     }
     
-    cairo_surface_set_user_data (result, &pixmap_free_key, pixmap, pixmap_free_func);
+    cairo_surface_set_user_data (result, &pixmap_free_key, pfs, pixmap_free_func);
     return result;
 }
 
 static cairo_bool_t
 _draw_onto_temp_xlib_surface (cairo_surface_t *temp_xlib_surface,
-                              cairo_gdk_drawing_callback callback,
+                              cairo_xlib_drawing_callback callback,
                               void *closure,
                               double background_gray_value)
 {
     Drawable d = cairo_xlib_surface_get_drawable (temp_xlib_surface);
+    Screen *screen = cairo_xlib_surface_get_screen (temp_xlib_surface);
+    Visual *visual = cairo_xlib_surface_get_visual (temp_xlib_surface);
     cairo_bool_t result;
-
     cairo_t *cr = cairo_create (temp_xlib_surface);
     cairo_set_source_rgb (cr, background_gray_value, background_gray_value,
                           background_gray_value);
     cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
     cairo_paint (cr);
     cairo_destroy (cr);
     
     cairo_surface_flush (temp_xlib_surface);
     /* no clipping is needed because the callback can't draw outside the native
        surface anyway */
-    result = callback (closure, GDK_DRAWABLE(gdk_xid_table_lookup(d)),
-            0, 0, NULL, 0);
+    result = callback (closure, screen, d, visual, 0, 0, NULL, 0);
     cairo_surface_mark_dirty (temp_xlib_surface);
     return result;
 }
 
 static cairo_surface_t *
 _copy_xlib_surface_to_image (cairo_surface_t *temp_xlib_surface,
                              cairo_format_t format,
                              int width, int height,
@@ -415,17 +446,17 @@ static cairo_surface_t *
  * matter what color channel we pick for the alpha computation, but we'll
  * pick green because if we went through a color channel downsample the green
  * bits are likely to be the most accurate.
  */
 static void
 _compute_alpha_values (uint32_t *black_data,
                        uint32_t *white_data,
                        int width, int height,
-                       cairo_gdk_drawing_result_t *analysis)
+                       cairo_xlib_drawing_result_t *analysis)
 {
     int num_pixels = width*height;
     int i;
     uint32_t first;
     uint32_t deltas = 0;
     unsigned char first_alpha;
   
     if (num_pixels == 0) {
@@ -475,32 +506,31 @@ static void
                     analysis->g = ((first >> 8) & 0xFF)/d_first_alpha;
                     analysis->b = ((first >> 16) & 0xFF)/d_first_alpha;
                 }
             }
         }
     }
 }
 
-void 
-cairo_draw_with_gdk (cairo_t *cr,
-                     GdkDrawable * drawable,
-                     cairo_gdk_drawing_callback callback,
-                     void * closure,
-                     unsigned int width, unsigned int height,
-                     cairo_gdk_drawing_opacity_t is_opaque,
-                     cairo_gdk_drawing_support_t capabilities,
-                     cairo_gdk_drawing_result_t *result)
+void
+cairo_draw_with_xlib (cairo_t *cr,
+                      cairo_xlib_drawing_callback callback,
+                      void *closure,
+                      Display *dpy,
+                      unsigned int width, unsigned int height,
+                      cairo_xlib_drawing_opacity_t is_opaque,
+                      cairo_xlib_drawing_support_t capabilities,
+                      cairo_xlib_drawing_result_t *result)
 {
     cairo_surface_t *temp_xlib_surface;
     cairo_surface_t *black_image_surface;
     cairo_surface_t *white_image_surface;
     unsigned char *black_data;
     unsigned char *white_data;
-    Display *dpy = gdk_x11_drawable_get_xdisplay(drawable);
   
     if (result) {
         result->surface = NULL;
         result->uniform_alpha = False;
         result->uniform_color = False;
     }
     
     /* exit early if there's no work to do. This is actually important
@@ -521,17 +551,17 @@ cairo_draw_with_gdk (cairo_t *cr,
        be different now, if cr was referring to an xlib surface on a different display */
     dpy = cairo_xlib_surface_get_display (temp_xlib_surface);
   
     if (!_draw_onto_temp_xlib_surface (temp_xlib_surface, callback, closure, 0.0)) {
         cairo_surface_destroy (temp_xlib_surface);
         return;
     }
   
-    if (is_opaque == CAIRO_GDK_DRAWING_OPAQUE) {
+    if (is_opaque == CAIRO_XLIB_DRAWING_OPAQUE) {
         cairo_set_source_surface (cr, temp_xlib_surface, 0.0, 0.0);
         cairo_paint (cr);
         if (result) {
             result->surface = temp_xlib_surface;
             /* fill in the result with what we know, which is really just what our
                assumption was */
             result->uniform_alpha = True;
             result->alpha = 1.0;
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/src/cairo-xlib-utils.h
@@ -0,0 +1,151 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Novell code.
+ *
+ * The Initial Developer of the Original Code is Novell.
+ * Portions created by the Initial Developer are Copyright (C) 2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   rocallahan@novell.com
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef CAIROXLIBUTILS_H_
+#define CAIROXLIBUTILS_H_
+
+#include "cairo.h"
+#include <X11/Xlib.h>
+
+CAIRO_BEGIN_DECLS
+
+/**
+ * This callback encapsulates Xlib-based rendering. We assume that the
+ * execution of the callback is equivalent to compositing some RGBA image of
+ * size (bounds_width, bounds_height) onto the drawable at offset (offset_x,
+ * offset_y), clipped to the union of the clip_rects if num_rects is greater
+ * than zero. This includes the assumption that the same RGBA image
+ * is composited if you call the callback multiple times with the same closure,
+ * display and visual during a single cairo_draw_with_xlib call.
+ * 
+ * @return True on success, False on non-recoverable error
+ */
+typedef cairo_bool_t (* cairo_xlib_drawing_callback)
+    (void *closure,
+     Screen *screen,
+     Drawable drawable,
+     Visual *visual,
+     short offset_x, short offset_y,
+     XRectangle* clip_rects, unsigned int num_rects);
+
+/**
+ * This structure captures the result of the native drawing, in case the
+ * caller may wish to reapply the drawing efficiently later.
+ */
+typedef struct {
+    cairo_surface_t *surface;
+    cairo_bool_t    uniform_alpha;
+    cairo_bool_t    uniform_color;
+    double          alpha; /* valid only if uniform_alpha is TRUE */
+    double          r, g, b; /* valid only if uniform_color is TRUE */
+} cairo_xlib_drawing_result_t;
+
+/**
+ * This type specifies whether the native drawing callback draws all pixels
+ * in its bounds opaquely, independent of the contents of the target drawable,
+ * or whether it leaves pixels transparent/translucent or depends on the
+ * existing contents of the target drawable in some way.
+ */
+typedef enum _cairo_xlib_drawing_opacity {
+    CAIRO_XLIB_DRAWING_OPAQUE,
+    CAIRO_XLIB_DRAWING_TRANSPARENT
+} cairo_xlib_drawing_opacity_t;
+
+/**
+ * This type encodes the capabilities of the native drawing callback.
+ * 
+ * If CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET is set, 'offset_x' and 'offset_y'
+ * can be nonzero in the call to the callback; otherwise they will be zero.
+ * 
+ * If CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT is set, then 'num_rects' can be
+ * zero or one in the call to the callback. If
+ * CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST is set, then 'num_rects' can be
+ * anything in the call to the callback. Otherwise 'num_rects' will be zero.
+ * Do not set both of these values.
+ * 
+ * If CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN is set, then 'screen' can
+ * be any screen on any display, otherwise it will be the default screen of
+ * the display passed into cairo_draw_with_xlib.
+ * 
+ * If CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL is set, then 'visual' can be
+ * any visual, otherwise it will be equal to
+ * DefaultVisualOfScreen (screen).
+ */
+typedef enum {
+    CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET = 0x01,
+    CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT = 0x02,
+    CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST = 0x04,
+    CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN = 0x08,
+    CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL = 0x10
+} cairo_xlib_drawing_support_t;
+
+/**
+ * Draw Xlib output into any cairo context. All cairo transforms and effects
+ * are honored, including the current operator. This is equivalent to a
+ * cairo_set_source_surface and then cairo_paint.
+ * @param cr the context to draw into
+ * @param callback the code to perform Xlib rendering
+ * @param closure associated data
+ * @param dpy an X display to use in case the cairo context has no associated X display
+ * @param width the width of the putative image drawn by the callback
+ * @param height the height of the putative image drawn by the callback
+ * @param is_opaque set to CAIRO_XLIB_DRAWING_IS_OPAQUE to indicate
+ * that all alpha values of the putative image will be 1.0; the pixels drawn into
+ * the Drawable must not depend on the prior contents of the Drawable
+ * in any way
+ * @param capabilities the capabilities of the callback as described above.
+ * @param result if non-NULL, we *may* fill in the struct with information about
+ * the rendered image. 'surface' may be filled in with a surface representing
+ * the image, similar to the target of 'cr'. If 'uniform_alpha' is True then
+ * every pixel of the image has the same alpha value 'alpha'. If
+ * 'uniform_color' is True then every pixel of the image has the same RGB
+ * color (r, g, b). If the image has uniform color and alpha (or alpha is zero,
+ * in which case the color is always uniform) then we won't bother returning
+ * a surface for it.
+ */
+void cairo_draw_with_xlib (cairo_t *cr,
+                           cairo_xlib_drawing_callback callback,
+                           void *closure,
+                           Display *dpy,
+                           unsigned int width, unsigned int height,
+                           cairo_xlib_drawing_opacity_t is_opaque,
+                           cairo_xlib_drawing_support_t capabilities,
+                           cairo_xlib_drawing_result_t *result);
+
+CAIRO_END_DECLS
+
+#endif /*CAIROXLIBUTILS_H_*/
deleted file mode 100644
--- a/gfx/thebes/src/gfxGdkNativeRenderer.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Novell code.
- *
- * The Initial Developer of the Original Code is Novell.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   rocallahan@novell.com
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "gfxGdkNativeRenderer.h"
-#include "gfxContext.h"
-
-#include "cairo-gdk-utils.h"
-
-#include "gfxPlatformGtk.h"
-
-typedef struct {
-    gfxGdkNativeRenderer* mRenderer;
-    nsresult               mRV;
-} NativeRenderingClosure;
-
-
-static cairo_bool_t
-NativeRendering(void *closure,
-                GdkDrawable * drawable,
-                short offset_x, short offset_y,
-                GdkRectangle * rectangles, unsigned int num_rects)
-{
-    NativeRenderingClosure* cl = (NativeRenderingClosure*)closure;
-    nsresult rv = cl->mRenderer->
-        NativeDraw(drawable, offset_x, offset_y,
-                   rectangles, num_rects);
-    cl->mRV = rv;
-    return NS_SUCCEEDED(rv);
-}
-
-
-nsresult
-gfxGdkNativeRenderer::Draw(gfxContext* ctx, int width, int height,
-                            PRUint32 flags, DrawOutput* output)
-{
-    NativeRenderingClosure closure = { this, NS_OK };
-    cairo_gdk_drawing_result_t result;
-    // Make sure result.surface is null to start with; we rely on it
-    // being non-null meaning that a surface actually got allocated.
-    result.surface = NULL;
-  
-    if (output) {
-        output->mSurface = NULL;
-        output->mUniformAlpha = PR_FALSE;
-        output->mUniformColor = PR_FALSE;
-    }
-
-    int cairoFlags = 0;
-    if (flags & DRAW_SUPPORTS_OFFSET) {
-        cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_OFFSET;
-    }
-    if (flags & DRAW_SUPPORTS_CLIP_RECT) {
-        cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_RECT;
-    }
-    if (flags & DRAW_SUPPORTS_CLIP_LIST) {
-        cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_CLIP_LIST;
-    }
-    if (flags & DRAW_SUPPORTS_ALTERNATE_SCREEN) {
-        cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_ALTERNATE_SCREEN;
-    }
-    if (flags & DRAW_SUPPORTS_NONDEFAULT_VISUAL) {
-        cairoFlags |= CAIRO_GDK_DRAWING_SUPPORTS_NONDEFAULT_VISUAL;
-    }
-    cairo_draw_with_gdk(ctx->GetCairo(),
-                        gfxPlatformGtk::GetPlatform()->GetGdkDrawable(ctx->OriginalSurface()),
-                        NativeRendering, 
-                        &closure, width, height,
-                        (flags & DRAW_IS_OPAQUE) ? CAIRO_GDK_DRAWING_OPAQUE : CAIRO_GDK_DRAWING_TRANSPARENT,
-                        (cairo_gdk_drawing_support_t)cairoFlags,
-                        output ? &result : NULL);
-    if (NS_FAILED(closure.mRV)) {
-        if (result.surface) {
-            NS_ASSERTION(output, "How did that happen?");
-            cairo_surface_destroy (result.surface);
-        }
-        return closure.mRV;
-    }
-
-    if (output) {
-        if (result.surface) {
-            output->mSurface = gfxASurface::Wrap(result.surface);
-            if (!output->mSurface) {
-                cairo_surface_destroy (result.surface);
-                return NS_ERROR_OUT_OF_MEMORY;
-            }
-        }
-
-        output->mUniformAlpha = result.uniform_alpha;
-        output->mUniformColor = result.uniform_color;
-        output->mColor = gfxRGBA(result.r, result.g, result.b, result.alpha);
-    }
-  
-    return NS_OK;
-}
--- a/gfx/thebes/src/gfxPlatformGtk.cpp
+++ b/gfx/thebes/src/gfxPlatformGtk.cpp
@@ -115,19 +115,23 @@ gfxPlatformGtk::gfxPlatformGtk()
 #endif
     if (!sFontconfigUtils)
         sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
 
 #ifndef MOZ_PANGO
     FT_Init_FreeType(&gPlatformFTLibrary);
 
     gPlatformFonts = new FontTable();
-    gPlatformFonts->Init(100);
+    /* FIXME: DFB */
+    //gPlatformFonts->Init(100);
+    gPlatformFonts->Init(20);
     gPlatformFontAliases = new FontTable();
-    gPlatformFontAliases->Init(100);
+    /* FIXME: DFB */
+    //gPlatformFontAliases->Init(100);
+    gPlatformFontAliases->Init(20);
     UpdateFontList();
 #endif
 
     InitDPI();
 }
 
 gfxPlatformGtk::~gfxPlatformGtk()
 {
@@ -256,20 +260,16 @@ gfxPlatformGtk::CreateOffscreenSurface(c
                                  NULL);
 
         glitz_surface_attach(gsurf, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
         newSurface = new gfxGlitzSurface(gdraw, gsurf, PR_TRUE);
 #endif
     }
 #endif
 
-#ifdef MOZ_DFB
-    newSurface = new gfxDirectFBSurface(size, imageFormat);
-#endif
-
     if (newSurface) {
         gfxContext tmpCtx(newSurface);
         tmpCtx.SetOperator(gfxContext::OPERATOR_CLEAR);
         tmpCtx.Paint();
     }
 
     return newSurface.forget();
 }
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/src/gfxXlibNativeRenderer.cpp
@@ -0,0 +1,209 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Novell code.
+ *
+ * The Initial Developer of the Original Code is Novell.
+ * Portions created by the Initial Developer are Copyright (C) 2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   rocallahan@novell.com
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "gfxXlibNativeRenderer.h"
+#include "gfxContext.h"
+
+#include "cairo-xlib-utils.h"
+
+#ifdef MOZ_WIDGET_GTK2
+#include <gdk/gdkscreen.h>
+#include <gdk/gdkx.h>
+#endif
+
+// Look for an existing Colormap that known to be associated with visual.
+static Colormap
+LookupColormapForVisual(const Screen* screen, const Visual* visual)
+{
+    // common case
+    if (visual == DefaultVisualOfScreen(screen))
+        return DefaultColormapOfScreen(screen);
+
+#ifdef MOZ_WIDGET_GTK2
+    // I wish there were a gdk_x11_display_lookup_screen.
+    Display* dpy = DisplayOfScreen(screen);
+    GdkDisplay* gdkDpy = gdk_x11_lookup_xdisplay(dpy);
+    if (gdkDpy) {
+        gint screen_num = 0;
+        for (int s = 0; s < ScreenCount(dpy); ++s) {
+            if (ScreenOfDisplay(dpy, s) == screen) {
+                screen_num = s;
+                break;
+            }
+        }
+        GdkScreen* gdkScreen = gdk_display_get_screen(gdkDpy, screen_num);
+
+        GdkColormap* gdkColormap = NULL;
+        if (visual ==
+            GDK_VISUAL_XVISUAL(gdk_screen_get_rgb_visual(gdkScreen))) {
+            // widget/src/gtk2/mozcontainer.c uses gdk_rgb_get_colormap()
+            // which is inherited by child widgets, so this is the visual
+            // expected when drawing directly to widget surfaces or surfaces
+            // created using cairo_surface_create_similar with
+            // CAIRO_CONTENT_COLOR.
+            // gdk_screen_get_rgb_colormap is the generalization of
+            // gdk_rgb_get_colormap for any screen.
+            gdkColormap = gdk_screen_get_rgb_colormap(gdkScreen);
+        }
+        else if (visual ==
+             GDK_VISUAL_XVISUAL(gdk_screen_get_rgba_visual(gdkScreen))) {
+            // This is the visual expected on displays with the Composite
+            // extension enabled when the surface has been created using
+            // cairo_surface_create_similar with CAIRO_CONTENT_COLOR_ALPHA,
+            // as happens with non-unit opacity.
+            gdkColormap = gdk_screen_get_rgba_colormap(gdkScreen);
+        }
+        if (gdkColormap != NULL)
+            return GDK_COLORMAP_XCOLORMAP(gdkColormap);
+    }
+#endif
+
+    return None;
+}
+
+typedef struct {
+    gfxXlibNativeRenderer* mRenderer;
+    nsresult               mRV;
+} NativeRenderingClosure;
+
+static cairo_bool_t
+NativeRendering(void *closure,
+                Screen *screen,
+                Drawable drawable,
+                Visual *visual,
+                short offset_x, short offset_y,
+                XRectangle* rectangles, unsigned int num_rects)
+{
+    // Cairo doesn't provide a Colormap.
+    // See if a suitable existing Colormap is known.
+    Colormap colormap = LookupColormapForVisual(screen, visual);
+    PRBool allocColormap = colormap == None;
+    if (allocColormap) {
+        // No existing colormap found.
+        // This case is not expected with MOZ_WIDGET_GTK2.
+        // Create a Colormap for the Visual.
+        // This is only really useful for Visual classes with predefined
+        // Colormap entries, but cairo would be all confused with
+        // non-default non-TrueColor colormaps anyway.
+        NS_ASSERTION(visual->c_class == TrueColor ||
+                     visual->c_class == StaticColor ||
+                     visual->c_class == StaticGray,
+                     "Creating empty colormap");
+        // If this case were expected then it might be worth considering
+        // using a service that maintains a set of Colormaps for associated
+        // Visuals so as to avoid repeating the LockDisplay required in
+        // XCreateColormap, but then it's no worse than the XCreatePixmap
+        // that produced the Drawable here.
+        colormap = XCreateColormap(DisplayOfScreen(screen),
+                                   RootWindowOfScreen(screen),
+                                   visual, AllocNone);
+    }
+
+    NativeRenderingClosure* cl = (NativeRenderingClosure*)closure;
+    nsresult rv = cl->mRenderer->
+        NativeDraw(screen, drawable, visual, colormap, offset_x, offset_y,
+                   rectangles, num_rects);
+    cl->mRV = rv;
+
+    if (allocColormap) {
+        XFreeColormap(DisplayOfScreen(screen), colormap);
+    }
+    return NS_SUCCEEDED(rv);
+}
+
+nsresult
+gfxXlibNativeRenderer::Draw(Display* dpy, gfxContext* ctx, int width, int height,
+                            PRUint32 flags, DrawOutput* output)
+{
+    NativeRenderingClosure closure = { this, NS_OK };
+    cairo_xlib_drawing_result_t result;
+    // Make sure result.surface is null to start with; we rely on it
+    // being non-null meaning that a surface actually got allocated.
+    result.surface = NULL;
+
+    if (output) {
+        output->mSurface = NULL;
+        output->mUniformAlpha = PR_FALSE;
+        output->mUniformColor = PR_FALSE;
+    }
+
+    int cairoFlags = 0;
+    if (flags & DRAW_SUPPORTS_OFFSET) {
+        cairoFlags |= CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET;
+    }
+    if (flags & DRAW_SUPPORTS_CLIP_RECT) {
+        cairoFlags |= CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT;
+    }
+    if (flags & DRAW_SUPPORTS_CLIP_LIST) {
+        cairoFlags |= CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST;
+    }
+    if (flags & DRAW_SUPPORTS_ALTERNATE_SCREEN) {
+        cairoFlags |= CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN;
+    }
+    if (flags & DRAW_SUPPORTS_NONDEFAULT_VISUAL) {
+        cairoFlags |= CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL;
+    }
+    cairo_draw_with_xlib(ctx->GetCairo(), NativeRendering, &closure, dpy,
+                         width, height,
+                         (flags & DRAW_IS_OPAQUE) ? CAIRO_XLIB_DRAWING_OPAQUE
+                                                  : CAIRO_XLIB_DRAWING_TRANSPARENT,
+                         (cairo_xlib_drawing_support_t)cairoFlags,
+                         output ? &result : NULL);
+    if (NS_FAILED(closure.mRV)) {
+        if (result.surface) {
+            NS_ASSERTION(output, "How did that happen?");
+            cairo_surface_destroy (result.surface);
+        }
+        return closure.mRV;
+    }
+
+    if (output) {
+        if (result.surface) {
+            output->mSurface = gfxASurface::Wrap(result.surface);
+            if (!output->mSurface) {
+                cairo_surface_destroy (result.surface);
+                return NS_ERROR_OUT_OF_MEMORY;
+            }
+        }
+
+        output->mUniformAlpha = result.uniform_alpha;
+        output->mUniformColor = result.uniform_color;
+        output->mColor = gfxRGBA(result.r, result.g, result.b, result.alpha);
+    }
+  
+    return NS_OK;
+}
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -154,26 +154,23 @@ static NS_DEFINE_CID(kAppShellCID, NS_AP
 
 #ifdef MOZ_X11
 #include <X11/Xlib.h>
 /* X headers suck */
 enum { XKeyPress = KeyPress };
 #ifdef KeyPress
 #undef KeyPress
 #endif
+#include "gfxXlibNativeRenderer.h"
 #ifdef MOZ_WIDGET_GTK2
 #include <gdk/gdkwindow.h>
 #include <gdk/gdkx.h>
 #endif
 #endif
 
-#ifdef MOZ_WIDGET_GTK2
-#include "gfxGdkNativeRenderer.h"
-#endif
-
 #ifdef XP_WIN
 #include <wtypes.h>
 #include <winuser.h>
 #endif
 
 #ifdef CreateEvent // Thank you MS.
 #undef CreateEvent
 #endif
@@ -359,17 +356,17 @@ public:
 
   //nsIEventListener interface
   nsEventStatus ProcessEvent(const nsGUIEvent & anEvent);
   
 #ifdef XP_WIN
   void Paint(const nsRect& aDirtyRect, HDC ndc);
 #elif defined(XP_MACOSX)
   void Paint(const nsRect& aDirtyRect);  
-#elif defined(MOZ_X11) || defined(MOZ_DFB)
+#elif defined(MOZ_X11)
   void Paint(gfxContext* aContext,
              const gfxRect& aFrameRect,
              const gfxRect& aDirtyRect);
 #elif defined(XP_OS2)
   void Paint(const nsRect& aDirtyRect, HPS aHPS);
 #endif
 
   // nsITimerCallback interface
@@ -475,26 +472,28 @@ private:
   nsRefPtr<nsPluginDOMContextMenuListener> mCXMenuListener;
 
   nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent);
   nsresult DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent);
   nsresult DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent);
 
   nsresult EnsureCachedAttrParamArrays();
 
-#ifdef MOZ_WIDGET_GTK2
-  class Renderer : public gfxGdkNativeRenderer {
+#ifdef MOZ_X11
+  class Renderer : public gfxXlibNativeRenderer {
   public:
     Renderer(nsPluginWindow* aWindow, nsIPluginInstance* aInstance,
              const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect)
       : mWindow(aWindow), mInstance(aInstance),
         mPluginSize(aPluginSize), mDirtyRect(aDirtyRect)
     {}
-    virtual nsresult NativeDraw(GdkDrawable * drawable, short offsetX, 
-            short offsetY, GdkRectangle * clipRects, PRUint32 numClipRects);
+    virtual nsresult NativeDraw(Screen* screen, Drawable drawable,
+                                Visual* visual, Colormap colormap,
+                                short offsetX, short offsetY,
+                                XRectangle* clipRects, PRUint32 numClipRects);
   private:
     nsPluginWindow* mWindow;
     nsIPluginInstance* mInstance;
     const nsIntSize& mPluginSize;
     const nsIntRect& mDirtyRect;
   };
 #endif
 
@@ -1368,17 +1367,17 @@ nsObjectFrame::PaintPlugin(nsIRenderingC
 
       mInstanceOwner->Paint(aDirtyRect);
 
       nativeDrawing.EndNativeDrawing();
     } else {
       mInstanceOwner->Paint(aDirtyRect);
     }
   }
-#elif defined(MOZ_X11) || defined(MOZ_DFB)
+#elif defined(MOZ_X11)
   if (mInstanceOwner)
     {
       nsPluginWindow * window;
       mInstanceOwner->GetWindow(window);
 
       if (window->type == nsPluginWindowType_Drawable) {
         gfxRect frameGfxRect =
           PresContext()->AppUnitsToGfxUnits(nsRect(aFramePt, GetSize()));
@@ -2498,19 +2497,17 @@ NS_IMETHODIMP nsPluginInstanceOwner::Get
         nsIWidget* win = mOwner->GetWindow();
         if (!win)
           return rv;
         GdkWindow* gdkWindow =
           static_cast<GdkWindow*>(win->GetNativeData(NS_NATIVE_WINDOW));
         if (!gdkWindow)
           return rv;
         gdkWindow = gdk_window_get_toplevel(gdkWindow);
-#ifdef MOZ_X11
         *static_cast<Window*>(value) = GDK_WINDOW_XID(gdkWindow);
-#endif
         return NS_OK;
 #endif
       } else NS_ASSERTION(mOwner, "plugin owner has no owner in getting doc's window handle");
       break;
     }
   }
 
   return rv;
@@ -4040,17 +4037,17 @@ void nsPluginInstanceOwner::Paint(const 
   pluginEvent.event = WM_PAINT;
   pluginEvent.wParam = (uint32)aHPS;
   pluginEvent.lParam = (uint32)&rectl;
   PRBool eventHandled = PR_FALSE;
   mInstance->HandleEvent(&pluginEvent, &eventHandled);
 }
 #endif
 
-#if defined(MOZ_X11) || defined(MOZ_DFB)
+#ifdef MOZ_X11
 void nsPluginInstanceOwner::Paint(gfxContext* aContext,
                                   const gfxRect& aFrameRect,
                                   const gfxRect& aDirtyRect)
 {
   if (!mInstance || !mOwner)
     return;
 
   // Align to device pixels where sensible
@@ -4103,49 +4100,48 @@ void nsPluginInstanceOwner::Paint(gfxCon
                       (void *)&transparent);
   if (!transparent)
     rendererFlags |= Renderer::DRAW_IS_OPAQUE;
 
   // Renderer::Draw() draws a rectangle with top-left at the aContext origin.
   gfxContextAutoSaveRestore autoSR(aContext);
   aContext->Translate(pluginRect.pos);
 
-  renderer.Draw(aContext, window->width, window->height,
+  // The display used by gfxXlibNativeRenderer will be the one for the cairo
+  // surface (provided that it is an Xlib surface) but the display argument
+  // here needs to be non-NULL for cairo_draw_with_xlib ->
+  // _create_temp_xlib_surface -> DefaultScreen(dpy).
+  NPSetWindowCallbackStruct* ws_info = 
+    static_cast<NPSetWindowCallbackStruct*>(window->ws_info);
+  renderer.Draw(ws_info->display, aContext, pluginSize.width, pluginSize.height,
                 rendererFlags, nsnull);
 }
 
-#ifdef MOZ_X11
 static int
 DepthOfVisual(const Screen* screen, const Visual* visual)
 {
   for (int d = 0; d < screen->ndepths; d++) {
     Depth *d_info = &screen->depths[d];
     for (int v = 0; v < d_info->nvisuals; v++) {
       if (&d_info->visuals[v] == visual)
         return d_info->depth;
     }
   }
 
   NS_ERROR("Visual not on Screen.");
   return 0;
 }
-#endif
 
 nsresult
-nsPluginInstanceOwner::Renderer::NativeDraw(GdkDrawable * drawable, 
+nsPluginInstanceOwner::Renderer::NativeDraw(Screen* screen, Drawable drawable,
+                                            Visual* visual, Colormap colormap,
                                             short offsetX, short offsetY,
-                                            GdkRectangle * clipRects, 
+                                            XRectangle* clipRects,
                                             PRUint32 numClipRects)
-
 {
-#ifdef MOZ_X11
-  Visual * visual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(drawable));
-  Colormap colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(drawable));
-  Screen * screen = GDK_SCREEN_XSCREEN (gdk_drawable_get_screen(drawable));
-#endif
   // See if the plugin must be notified of new window parameters.
   PRBool doupdatewindow = PR_FALSE;
 
   if (mWindow->x != offsetX || mWindow->y != offsetY) {
     mWindow->x = offsetX;
     mWindow->y = offsetY;
     doupdatewindow = PR_TRUE;
   }
@@ -4186,56 +4182,52 @@ nsPluginInstanceOwner::Renderer::NativeD
       mWindow->clipRect.right   != newClipRect.right  ||
       mWindow->clipRect.bottom  != newClipRect.bottom) {
     mWindow->clipRect = newClipRect;
     doupdatewindow = PR_TRUE;
   }
 
   NPSetWindowCallbackStruct* ws_info = 
     static_cast<NPSetWindowCallbackStruct*>(mWindow->ws_info);
-#ifdef MOZ_X11
   if (ws_info->visual != visual || ws_info->colormap != colormap) {
     ws_info->visual = visual;
     ws_info->colormap = colormap;
     ws_info->depth = DepthOfVisual(screen, visual);
     doupdatewindow = PR_TRUE;
   }
-#endif
 
   if (doupdatewindow)
       mInstance->SetWindow(mWindow);
 
-#ifdef MOZ_X11
   // Translate the dirty rect to drawable coordinates.
   nsIntRect dirtyRect = mDirtyRect + nsIntPoint(offsetX, offsetY);
   // Intersect the dirty rect with the clip rect to ensure that it lies within
   // the drawable.
   if (!dirtyRect.IntersectRect(dirtyRect, clipRect))
     return NS_OK;
 
   nsPluginEvent pluginEvent;
   XGraphicsExposeEvent& exposeEvent = pluginEvent.event.xgraphicsexpose;
   // set the drawing info
   exposeEvent.type = GraphicsExpose;
   exposeEvent.display = DisplayOfScreen(screen);
-  exposeEvent.drawable = GDK_DRAWABLE_XID(drawable);
-  exposeEvent.x = mDirtyRect.x + offsetX;
-  exposeEvent.y = mDirtyRect.y + offsetY;
-  exposeEvent.width  = mDirtyRect.width;
-  exposeEvent.height = mDirtyRect.height;
+  exposeEvent.drawable = drawable;
+  exposeEvent.x = dirtyRect.x;
+  exposeEvent.y = dirtyRect.y;
+  exposeEvent.width  = dirtyRect.width;
+  exposeEvent.height = dirtyRect.height;
   exposeEvent.count = 0;
   // information not set:
   exposeEvent.serial = 0;
   exposeEvent.send_event = False;
   exposeEvent.major_code = 0;
   exposeEvent.minor_code = 0;
 
   PRBool eventHandled = PR_FALSE;
   mInstance->HandleEvent(&pluginEvent, &eventHandled);
-#endif
 
   return NS_OK;
 }
 #endif
 
 // Here's how we give idle time to plugins.
 
 NS_IMETHODIMP nsPluginInstanceOwner::Notify(nsITimer* /* timer */)
--- a/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -169,17 +169,17 @@
 #include "nsISupportsArray.h"
 #include "nsIDocShell.h"
 #include "nsPluginNativeWindow.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIContentPolicy.h"
 #include "nsContentPolicyUtils.h"
 #include "nsContentErrors.h"
 
-#if defined(XP_UNIX) && defined(MOZ_WIDGET_GTK2) & defined(MOZ_X11)
+#if defined(XP_UNIX) && defined(MOZ_WIDGET_GTK2)
 #include <gdk/gdkx.h> // for GDK_DISPLAY()
 #endif
 
 #ifdef XP_MACOSX
 #include <Carbon/Carbon.h> // for ::UseInputWindow()
 #include <mach-o/loader.h>
 #include <mach-o/fat.h>
 #endif
--- a/modules/plugin/samples/default/unix/nullplugin.c
+++ b/modules/plugin/samples/default/unix/nullplugin.c
@@ -45,19 +45,17 @@
  * dp <dp@netscape.com>
  * updated 5/1998 <pollmann@netscape.com>
  * updated 9/2000 <smak@sun.com>
  *
  */
 
 #include <stdio.h>
 #include <gtk/gtk.h>
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
-#endif
 #include <gdk/gdkkeysyms.h>
 
 /* Xlib/Xt stuff */
 #ifdef MOZ_X11
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 #include <X11/cursorfont.h>
 #endif
--- a/toolkit/library/libxul-config.mk
+++ b/toolkit/library/libxul-config.mk
@@ -272,20 +272,18 @@ endif
 ifdef MOZ_ENABLE_GTK2
 COMPONENT_LIBS += widget_gtk2
 ifdef MOZ_PREF_EXTENSIONS
 COMPONENT_LIBS += system-pref
 endif
 endif
 
 ifdef MOZ_ENABLE_GTK2
-ifdef MOZ_X11
 STATIC_LIBS += gtkxtbin
 endif
-endif
 
 ifdef MOZ_IPCD
 DEFINES += -DMOZ_IPCD
 COMPONENT_LIBS += ipcdc
 endif
 
 ifdef MOZ_ENABLE_POSTSCRIPT
 DEFINES += -DMOZ_ENABLE_POSTSCRIPT
--- a/toolkit/toolkit-tiers.mk
+++ b/toolkit/toolkit-tiers.mk
@@ -79,20 +79,18 @@ endif
 #
 
 tier_gecko_dirs += \
 		js/src/xpconnect \
 		intl/chardet \
 		$(NULL)
 
 ifdef MOZ_ENABLE_GTK2
-ifdef MOZ_X11
 tier_gecko_dirs     += widget/src/gtkxtbin
 endif
-endif
 
 ifdef MOZ_IPCD
 tier_gecko_dirs += ipc/ipcd
 endif
 
 tier_gecko_dirs	+= \
 		modules/libutil \
 		modules/libjar \
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -264,19 +264,17 @@ char **gArgv;
 static char gToolkitVersion[20];
 static char gToolkitBuildID[40];
 
 static int    gRestartArgc;
 static char **gRestartArgv;
 
 #if defined(MOZ_WIDGET_GTK2)
 #include <gtk/gtk.h>
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
-#endif /* MOZ_X11 */
 #include "nsGTKToolkit.h"
 #endif
 
 // Save the given word to the specified environment variable.
 static void
 SaveWordToEnv(const char *name, const nsACString & word)
 {
   char *expr = PR_smprintf("%s=%s", name, PromiseFlatCString(word).get());
@@ -2383,27 +2381,23 @@ static void MOZ_gdk_display_close(GdkDis
     g_free(theme_name);
   }
 
   // gdk_display_close was broken prior to gtk+-2.10.0.
   // (http://bugzilla.gnome.org/show_bug.cgi?id=85715)
   // gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL)
   // was also broken.
   if (gtk_check_version(2,10,0) != NULL) {
-#ifdef MOZ_X11
     // Version check failed - broken gdk_display_close.
     //
     // Let the gdk structures leak but at least close the Display,
     // assuming that gdk will not use it again.
     Display* dpy = GDK_DISPLAY_XDISPLAY(display);
     if (!theme_is_qt)
       XCloseDisplay(dpy);
-#else
-    gdk_display_close(display);
-#endif /* MOZ_X11 */
   }
   else {
     if (!theme_is_qt)
       gdk_display_close(display);
 #if GTK_CHECK_VERSION(2,8,0) && \
   (defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) || defined(NS_TRACE_MALLOC))
     cairo_debug_reset_static_data();
 #endif
--- a/toolkit/xre/nsNativeAppSupportUnix.cpp
+++ b/toolkit/xre/nsNativeAppSupportUnix.cpp
@@ -292,18 +292,16 @@ nsNativeAppSupportUnix::Start(PRBool *aR
                        nsnull,
                        OssoHardwareCallback,
                        &m_hw_state);
 
 #endif
 
   *aRetVal = PR_TRUE;
 
-#ifdef MOZ_X11
-
   PRLibrary *gnomeuiLib = PR_LoadLibrary("libgnomeui-2.so.0");
   if (!gnomeuiLib)
     return NS_OK;
 
   PRLibrary *gnomeLib = PR_LoadLibrary("libgnome-2.so.0");
   if (!gnomeLib) {
     PR_UnloadLibrary(gnomeuiLib);
     return NS_OK;
@@ -313,58 +311,52 @@ nsNativeAppSupportUnix::Start(PRBool *aR
     (_gnome_program_init_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_init");
   _libgnomeui_module_info_get_fn libgnomeui_module_info_get = (_libgnomeui_module_info_get_fn)PR_FindFunctionSymbol(gnomeuiLib, "libgnomeui_module_info_get");
   if (!gnome_program_init || !libgnomeui_module_info_get) {
     PR_UnloadLibrary(gnomeuiLib);
     PR_UnloadLibrary(gnomeLib);
     return NS_OK;
   }
 
-#endif /* MOZ_X11 */
-
 #ifdef ACCESSIBILITY
   // We will load gail, atk-bridge by ourself later
   // We can't run atk-bridge init here, because gail get the control
   // Set GNOME_ACCESSIBILITY to 0 can avoid this
   static const char *accEnv = "GNOME_ACCESSIBILITY";
   const char *accOldValue = getenv(accEnv);
   setenv(accEnv, "0", 1);
 #endif
 
-#ifdef MOZ_X11
   gnome_program_init("Gecko", "1.0", libgnomeui_module_info_get(), gArgc, gArgv, NULL);
-#endif /* MOZ_X11 */
 
 #ifdef ACCESSIBILITY
   if (accOldValue) { 
     setenv(accEnv, accOldValue, 1);
   } else {
     unsetenv(accEnv);
   }
 #endif
 
   // Careful! These libraries cannot be unloaded after this point because
   // gnome_program_init causes atexit handlers to be registered. Strange
   // crashes will occur if these libraries are unloaded.
 
-#ifdef MOZ_X11
   gnome_client_request_interaction = (_gnome_client_request_interaction_fn)
     PR_FindFunctionSymbol(gnomeuiLib, "gnome_client_request_interaction");
   gnome_interaction_key_return = (_gnome_interaction_key_return_fn)
     PR_FindFunctionSymbol(gnomeuiLib, "gnome_interaction_key_return");
   gnome_client_set_restart_command = (_gnome_client_set_restart_command_fn)
     PR_FindFunctionSymbol(gnomeuiLib, "gnome_client_set_restart_command");
 
   _gnome_master_client_fn gnome_master_client = (_gnome_master_client_fn)
     PR_FindFunctionSymbol(gnomeuiLib, "gnome_master_client");
 
   GnomeClient *client = gnome_master_client();
   g_signal_connect(client, "save-yourself", G_CALLBACK(save_yourself_cb), NULL);
   g_signal_connect(client, "die", G_CALLBACK(die_cb), NULL);
-#endif /* MOZ_X11 */
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNativeAppSupportUnix::Stop( PRBool *aResult )
 {
   NS_ENSURE_ARG( aResult );
--- a/widget/src/Makefile.in
+++ b/widget/src/Makefile.in
@@ -65,19 +65,17 @@ endif
 # Don't build the DSO under the 'build' directory as windows does.
 #
 # The DSOs get built in the toolkit dir itself.  Do this so that 
 # multiple implementations of widget can be built on the same
 # source tree.
 #
 ifdef MOZ_ENABLE_GTK2
 DIRS		+= gtk2
-ifdef MOZ_X11
 DIRS		+= gtkxtbin
 endif
-endif
 
 ifdef MOZ_ENABLE_PHOTON
 DIRS		+= photon
 endif
 
 include $(topsrcdir)/config/rules.mk
 
--- a/widget/src/gtk2/Makefile.in
+++ b/widget/src/gtk2/Makefile.in
@@ -58,30 +58,27 @@ REQUIRES	= xpcom \
 		  string \
 		  gfx \
 		  pref \
 		  dom \
 		  docshell \
 		  necko \
 		  uconv \
 		  intl \
+		  gtkxtbin \
 		  imglib2 \
 		  view \
 		  content \
 		  layout \
 		  util \
 		  locale \
 		  thebes \
 		  cairo \
 		  $(NULL)
 
-ifdef MOZ_X11
-REQUIRES += gtkxtbin
-endif
-
 ifeq ($(MOZ_ENABLE_GLITZ),1)
 REQUIRES += glitz glitzglx
 endif
 
 CSRCS		= \
 		mozcontainer.c \
 		mozdrawingarea.c \
 		keysym2ucs.c \
@@ -96,70 +93,61 @@ CPPSRCS		= \
 		nsWindow.cpp \
 		nsAppShell.cpp \
 		nsWidgetFactory.cpp \
 		nsToolkit.cpp \
 		nsBidiKeyboard.cpp \
 		nsCommonWidget.cpp \
 		nsLookAndFeel.cpp \
 		nsGtkKeyUtils.cpp \
+		nsClipboard.cpp \
+		nsDragService.cpp \
 		nsFilePicker.cpp \
 		nsSound.cpp \
 		nsNativeKeyBindings.cpp \
 		nsScreenGtk.cpp \
 		nsScreenManagerGtk.cpp \
 		nsImageToPixbuf.cpp \
 		nsAccessibilityHelper.cpp \
 		$(NULL)
 
 ifdef NS_OSSO
 CPPSRCS         += nsIdleServiceOSSO.cpp
 else
-ifdef MOZ_X11
 CPPSRCS         += nsIdleServiceGTK.cpp
 endif
-endif
 
 ifdef NS_PRINTING
 CPPSRCS		+= \
 		nsDeviceContextSpecG.cpp \
 		nsPrintOptionsGTK.cpp \
 		nsPrintDialogGTK.cpp \
 		nsPrintSettingsGTK.cpp \
 		$(NULL)
 endif
 
-ifdef MOZ_X11
-CPPSRCS += 	nsClipboard.cpp \
-		nsDragService.cpp \
-		$(NULL)
-endif
-
 # build our subdirs, too
 ifdef ACCESSIBILITY
 REQUIRES	+= accessibility
 endif
 
 SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
 
 EXTRA_DSO_LDOPTS += \
 		$(MOZ_COMPONENT_LIBS) \
 		-lgkgfx \
+		-lgtkxtbin \
                 $(MOZ_STARTUP_NOTIFICATION_LIBS) \
 		$(XLDFLAGS) \
 		$(XLIBS) \
 		$(MOZ_GTK2_LIBS) \
 		-lthebes \
 		$(LCMS_LIBS) \
 		$(NULL)
 
-ifdef MOZ_X11
-EXTRA_DSO_LDOPTS += -lgtkxtbin
-endif
-
 EXPORTS		= \
                 nsGTKToolkit.h \
 		nsIImageToPixbuf.h \
 		mozdrawingarea.h \
 		mozcontainer.h \
 		$(NULL)
 
 ifdef NATIVE_THEME_SUPPORT
--- a/widget/src/gtk2/keysym2ucs.h
+++ b/widget/src/gtk2/keysym2ucs.h
@@ -40,21 +40,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 /*
  * This module converts keysym values into the corresponding ISO 10646-1
  * (UCS, Unicode) values.
  */
 
-#ifdef MOZ_X11
 #include <X11/X.h>
-#else
-#define KeySym unsigned int
-#endif /* MOZ_X11 */
 
 #ifdef __cplusplus
 extern "C" { 
 #endif
 
 long keysym2ucs(KeySym keysym); 
 
 #ifdef __cplusplus
--- a/widget/src/gtk2/nsBidiKeyboard.cpp
+++ b/widget/src/gtk2/nsBidiKeyboard.cpp
@@ -48,25 +48,18 @@ static PRLibrary *gtklib = nsnull;
 typedef gboolean (PR_CALLBACK *GdkKeymapHaveBidiLayoutsType)(GdkKeymap *keymap);
 static GdkKeymapHaveBidiLayoutsType GdkKeymapHaveBidiLayouts = nsnull;
 
 
 NS_IMPL_ISUPPORTS1(nsBidiKeyboard, nsIBidiKeyboard)
 
 nsBidiKeyboard::nsBidiKeyboard()
 {
-#if defined(MOZ_X11)
     if (!gtklib)
         gtklib = PR_LoadLibrary("libgtk-x11-2.0.so.0");
-#elif defined(MOZ_DFB)
-    if (!gtklib)
-        gtklib = PR_LoadLibrary("libgtk-directfb-2.0.so.0");
-#else
-    return;
-#endif
 
     if (gtklib && !GdkKeymapHaveBidiLayouts)
             GdkKeymapHaveBidiLayouts = (GdkKeymapHaveBidiLayoutsType) PR_FindFunctionSymbol(gtklib, "gdk_keymap_have_bidi_layouts");
 
     SetHaveBidiKeyboards();
 }
 
 nsBidiKeyboard::~nsBidiKeyboard()
--- a/widget/src/gtk2/nsGtkKeyUtils.cpp
+++ b/widget/src/gtk2/nsGtkKeyUtils.cpp
@@ -34,19 +34,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkevents.h>
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
-#endif /* MOZ_X11 */
 #include "nsGUIEvent.h"
 #include "keysym2ucs.h"
 
 struct nsKeyConverter {
     int vkCode; // Platform independent key code
     int keysym; // GDK keysym key code
 };
 
@@ -151,20 +149,18 @@ struct nsKeyConverter nsKeycodes[] = {
     { NS_VK_7, GDK_ampersand },
     { NS_VK_8, GDK_asterisk },
     { NS_VK_9, GDK_parenleft },
     { NS_VK_0, GDK_parenright },
     { NS_VK_SUBTRACT, GDK_underscore },
     { NS_VK_EQUALS, GDK_plus }
 };
 
-#ifdef MOZ_X11
 #define IS_XSUN_XSERVER(dpy) \
     (strstr(XServerVendor(dpy), "Sun Microsystems") != NULL)
-#endif /* MOZ_X11 */
 
 // map Sun Keyboard special keysyms on to NS_VK keys
 struct nsKeyConverter nsSunKeycodes[] = {
     {NS_VK_ESCAPE, GDK_F11 }, //bug 57262, Sun Stop key generates F11 keysym
     {NS_VK_F1, GDK_Help }, //Mapping Help key to F1
     {NS_VK_F11, 0x1005ff10 }, //Sun F11 key generates SunF36(0x1005ff10) keysym
     {NS_VK_F12, 0x1005ff11 }, //Sun F12 key generates SunF37(0x1005ff11) keysym
     {NS_VK_PAGE_UP,    GDK_F29 }, //KP_Prior
@@ -192,26 +188,24 @@ GdkKeyCodeToDOMKeyCode(int aKeysym)
     // numbers
     if (aKeysym >= GDK_0 && aKeysym <= GDK_9)
         return aKeysym - GDK_0 + NS_VK_0;
 
     // keypad numbers
     if (aKeysym >= GDK_KP_0 && aKeysym <= GDK_KP_9)
         return aKeysym - GDK_KP_0 + NS_VK_NUMPAD0;
 
-#ifdef MOZ_X11
     // map Sun Keyboard special keysyms
     if (IS_XSUN_XSERVER(GDK_DISPLAY())) {
         length = sizeof(nsSunKeycodes) / sizeof(struct nsKeyConverter);
         for (i = 0; i < length; i++) {
             if (nsSunKeycodes[i].keysym == aKeysym)
                 return(nsSunKeycodes[i].vkCode);
         }
     }
-#endif /* MOZ_X11 */
 
     // misc other things
     length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter);
     for (i = 0; i < length; i++) {
         if (nsKeycodes[i].keysym == aKeysym)
             return(nsKeycodes[i].vkCode);
     }
 
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -57,25 +57,26 @@
 #include "nsGfxCIID.h"
 #include "nsTransform2D.h"
 #include "nsIMenuFrame.h"
 #include "prlink.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsWidgetAtoms.h"
 
 #include <gdk/gdkprivate.h>
+#include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 
 #include "gfxContext.h"
 #include "gfxPlatformGtk.h"
-#include "gfxGdkNativeRenderer.h"
+#include "gfxXlibNativeRenderer.h"
 
 NS_IMPL_ISUPPORTS2(nsNativeThemeGTK, nsITheme, nsIObserver)
 
-static int gLastGdkError;
+static int gLastXError;
 
 static inline bool IsCheckboxWidgetType(PRUint8 aWidgetType)
 {
   return (aWidgetType == NS_THEME_CHECKBOX || aWidgetType == NS_THEME_CHECKBOX_SMALL);
 }
 
 static inline bool IsRadioWidgetType(PRUint8 aWidgetType)
 {
@@ -610,51 +611,87 @@ nsNativeThemeGTK::GetGtkWidgetAndState(P
     break;
   default:
     return PR_FALSE;
   }
 
   return PR_TRUE;
 }
 
-class ThemeRenderer : public gfxGdkNativeRenderer {
+static int
+NativeThemeErrorHandler(Display* dpy, XErrorEvent* error) {
+  gLastXError = error->error_code;
+  return 0;
+}
+
+class ThemeRenderer : public gfxXlibNativeRenderer {
 public:
   ThemeRenderer(GtkWidgetState aState, GtkThemeWidgetType aGTKWidgetType,
                 gint aFlags, GtkTextDirection aDirection,
                 const GdkRectangle& aGDKRect, const GdkRectangle& aGDKClip)
     : mState(aState), mGTKWidgetType(aGTKWidgetType), mFlags(aFlags),
       mDirection(aDirection), mGDKRect(aGDKRect), mGDKClip(aGDKClip) {}
-  nsresult NativeDraw(GdkDrawable * drawable, short offsetX, short offsetY,
-                      GdkRectangle * clipRects, PRUint32 numClipRects);
+  nsresult NativeDraw(Screen* screen, Drawable drawable, Visual* visual,
+                      Colormap colormap, short offsetX, short offsetY,
+                      XRectangle* clipRects, PRUint32 numClipRects);
 private:
   GtkWidgetState mState;
   GtkThemeWidgetType mGTKWidgetType;
   gint mFlags;
   GtkTextDirection mDirection;
   GdkWindow* mWindow;
   const GdkRectangle& mGDKRect;
   const GdkRectangle& mGDKClip;
 };
 
 nsresult
-ThemeRenderer::NativeDraw(GdkDrawable * drawable, short offsetX, 
-        short offsetY, GdkRectangle * clipRects, PRUint32 numClipRects)
+ThemeRenderer::NativeDraw(Screen* screen, Drawable drawable, Visual* visual,
+                          Colormap colormap, short offsetX, short offsetY,
+                          XRectangle* clipRects, PRUint32 numClipRects)
 {
   GdkRectangle gdk_rect = mGDKRect;
   gdk_rect.x += offsetX;
   gdk_rect.y += offsetY;
 
   GdkRectangle gdk_clip = mGDKClip;
   gdk_clip.x += offsetX;
   gdk_clip.y += offsetY;
   
+  GdkDisplay* gdkDpy = gdk_x11_lookup_xdisplay(DisplayOfScreen(screen));
+  if (!gdkDpy)
+    return NS_ERROR_FAILURE;
+
+  GdkPixmap* gdkPixmap = gdk_pixmap_lookup_for_display(gdkDpy, drawable);
+  if (gdkPixmap) {
+    g_object_ref(G_OBJECT(gdkPixmap));
+  } else {
+    // XXX gtk+-2.10 has gdk_pixmap_foreign_new_for_screen which would not
+    // use XGetGeometry.
+    gdkPixmap = gdk_pixmap_foreign_new_for_display(gdkDpy, drawable);
+    if (!gdkPixmap)
+      return NS_ERROR_FAILURE;
+
+    // We requested that gfxXlibNativeRenderer give us the default screen
+    GdkScreen* gdkScreen = gdk_display_get_default_screen(gdkDpy);
+    NS_ASSERTION(screen == GDK_SCREEN_XSCREEN(gdkScreen),
+                 "'screen' should be the default Screen");
+    // GDK requires a GdkColormap to be set on the GdkPixmap.
+    GdkVisual* gdkVisual =
+      gdk_x11_screen_lookup_visual(gdkScreen, visual->visualid);
+    GdkColormap* gdkColormap =
+      gdk_x11_colormap_foreign_new(gdkVisual, colormap);
+    gdk_drawable_set_colormap(gdkPixmap, gdkColormap);
+    g_object_unref(G_OBJECT(gdkColormap));
+  }
+
   NS_ASSERTION(numClipRects == 0, "We don't support clipping!!!");
-  moz_gtk_widget_paint(mGTKWidgetType, drawable, &gdk_rect, &gdk_clip,
-                       &mState, mFlags, mDirection);
+  moz_gtk_widget_paint(mGTKWidgetType, gdkPixmap, &gdk_rect, &gdk_clip, &mState,
+                       mFlags, mDirection);
 
+  g_object_unref(G_OBJECT(gdkPixmap));
   return NS_OK;
 }
 
 static PRBool
 GetExtraSizeForWidget(PRUint8 aWidgetType, nsIntMargin* aExtra)
 {
   *aExtra = nsIntMargin(0,0,0,0);
   // Allow an extra one pixel above and below the thumb for certain
@@ -762,46 +799,49 @@ nsNativeThemeGTK::DrawWidgetBackground(n
   ThemeRenderer renderer(state, gtkWidgetType, flags, direction,
                          gdk_rect, gdk_clip);
 
   // We require the use of the default screen and visual
   // because I'm afraid that otherwise the GTK theme may explode.
   // Some themes (e.g. Clearlooks) just don't clip properly to any
   // clip rect we provide, so we cannot advertise support for clipping within
   // the widget bounds.
-  PRUint32 rendererFlags = gfxGdkNativeRenderer::DRAW_SUPPORTS_OFFSET;
-
+  PRUint32 rendererFlags = gfxXlibNativeRenderer::DRAW_SUPPORTS_OFFSET;
+   
   // translate everything so (0,0) is the top left of the drawingRect
   gfxContextAutoSaveRestore autoSR(ctx);
   if (snapXY) {
     // Rects are in device coords.
     ctx->IdentityMatrix(); 
   }
   ctx->Translate(rect.pos + gfxPoint(drawingRect.x, drawingRect.y));
 
   NS_ASSERTION(!IsWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType),
                "Trying to render an unsafe widget!");
 
   PRBool safeState = IsWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state);
+  XErrorHandler oldHandler = nsnull;
   if (!safeState) {
-    gLastGdkError = 0;
-    gdk_error_trap_push ();
+    gLastXError = 0;
+    oldHandler = XSetErrorHandler(NativeThemeErrorHandler);
   }
 
-  renderer.Draw(ctx, drawingRect.width, drawingRect.height, rendererFlags, nsnull);
+  renderer.Draw(gdk_x11_get_default_xdisplay(), ctx,
+                drawingRect.width, drawingRect.height,
+                rendererFlags, nsnull);
 
   if (!safeState) {
     gdk_flush();
-    gLastGdkError = gdk_error_trap_pop ();
+    XSetErrorHandler(oldHandler);
 
-    if (gLastGdkError) {
+    if (gLastXError) {
 #ifdef DEBUG
       printf("GTK theme failed for widget type %d, error was %d, state was "
              "[active=%d,focused=%d,inHover=%d,disabled=%d]\n",
-             aWidgetType, gLastGdkError, state.active, state.focused,
+             aWidgetType, gLastXError, state.active, state.focused,
              state.inHover, state.disabled);
 #endif
       NS_WARNING("GTK theme failed; disabling unsafe widget");
       SetWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType);
       // force refresh of the window, because the widget was not
       // successfully drawn it must be redrawn using the default look
       RefreshWidgetWindow(aFrame);
     } else {
--- a/widget/src/gtk2/nsScreenGtk.cpp
+++ b/widget/src/gtk2/nsScreenGtk.cpp
@@ -33,22 +33,19 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsScreenGtk.h"
 
-#include <gdk/gdk.h>
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
+#include <gtk/gtk.h>
 #include <X11/Xatom.h>
-#endif
-#include <gtk/gtk.h>
 
 nsScreenGtk :: nsScreenGtk (  )
   : mScreenNum(0),
     mRect(0, 0, 0, 0),
     mAvailRect(0, 0, 0, 0)
 {
 }
 
@@ -111,17 +108,16 @@ void
 nsScreenGtk :: Init (GdkWindow *aRootWindow)
 {
   // We listen for configure events on the root window to pick up
   // changes to this rect.  We could listen for "size_changed" signals
   // on the default screen to do this, except that doesn't work with
   // versions of GDK predating the GdkScreen object.  See bug 256646.
   mAvailRect = mRect = nsRect(0, 0, gdk_screen_width(), gdk_screen_height());
 
-#ifdef MOZ_X11
   // We need to account for the taskbar, etc in the available rect.
   // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771
 
   // XXX do we care about _NET_WM_STRUT_PARTIAL?  That will
   // add much more complexity to the code here (our screen
   // could have a non-rectangular shape), but should
   // lead to greater accuracy.
 
@@ -175,23 +171,20 @@ nsScreenGtk :: Init (GdkWindow *aRootWin
         NS_WARNING("Invalid bounds");
         continue;
       }
 
       mAvailRect.IntersectRect(mAvailRect, workarea);
     }
   }
   g_free (workareas);
-#endif
 }
 
-#ifdef MOZ_X11
 void
 nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo)
 {
   nsRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org,
                   aScreenInfo->width, aScreenInfo->height);
 
   mScreenNum = aScreenInfo->screen_number;
 
   mAvailRect = mRect = xineRect;
 }
-#endif
--- a/widget/src/gtk2/nsScreenGtk.h
+++ b/widget/src/gtk2/nsScreenGtk.h
@@ -36,44 +36,40 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsScreenGtk_h___
 #define nsScreenGtk_h___
 
 #include "nsIScreen.h"
 #include "nsRect.h"
 #include "gdk/gdk.h"
-#ifdef MOZ_X11
 #include <X11/Xlib.h>
 
 // from Xinerama.h
 typedef struct {
    int   screen_number;
    short x_org;
    short y_org;
    short width;
    short height;
 } XineramaScreenInfo;
-#endif /* MOZ_X11 */
 
 //------------------------------------------------------------------------
 
 class nsScreenGtk : public nsIScreen
 {
 public:
   nsScreenGtk();
   ~nsScreenGtk();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISCREEN
 
   void Init(GdkWindow *aRootWindow);
-#ifdef MOZ_X11
   void Init(XineramaScreenInfo *aScreenInfo);
-#endif /* MOZ_X11 */
 
 private:
   PRUint32 mScreenNum;
   nsRect mRect; // in pixels, not twips
   nsRect mAvailRect; // in pixels, not twips
 };
 
 #endif  // nsScreenGtk_h___ 
--- a/widget/src/gtk2/nsScreenManagerGtk.cpp
+++ b/widget/src/gtk2/nsScreenManagerGtk.cpp
@@ -38,39 +38,31 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsScreenManagerGtk.h"
 #include "nsScreenGtk.h"
 #include "nsIComponentManager.h"
 #include "nsRect.h"
 #include "nsAutoPtr.h"
 
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
 #define SCREEN_MANAGER_LIBRARY_LOAD_FAILED ((PRLibrary*)1)
 
-#ifdef MOZ_DFB
-#include <directfb.h>
-#endif
-
-#ifdef MOZ_X11
-#include <gdk/gdkx.h>
 // prototypes from Xinerama.h
 typedef Bool (*_XnrmIsActive_fn)(Display *dpy);
 typedef XineramaScreenInfo* (*_XnrmQueryScreens_fn)(Display *dpy, int *number);
-#endif
-
-#include <gtk/gtk.h>
-
 
 static GdkFilterReturn
 root_window_event_filter(GdkXEvent *aGdkXEvent, GdkEvent *aGdkEvent,
                          gpointer aClosure)
 {
+  XEvent *xevent = static_cast<XEvent*>(aGdkXEvent);
   nsScreenManagerGtk *manager = static_cast<nsScreenManagerGtk*>(aClosure);
-#ifdef MOZ_X11
-  XEvent *xevent = static_cast<XEvent*>(aGdkXEvent);
 
   // See comments in nsScreenGtk::Init below.
   switch (xevent->type) {
     case ConfigureNotify:
       manager->Init();
       break;
     case PropertyNotify:
       {
@@ -78,34 +70,16 @@ root_window_event_filter(GdkXEvent *aGdk
         if (propertyEvent->atom == manager->NetWorkareaAtom()) {
           manager->Init();
         }
       }
       break;
     default:
       break;
   }
-#endif
-
-#ifdef MOZ_DFB
-  DFBWindowEvent * dfbEvent = static_cast<DFBWindowEvent *> (aGdkXEvent);
-
-  switch (dfbEvent->type)
-  {
-      case DWET_POSITION :
-      case DWET_SIZE :
-          manager->Init();
-      break;
-
-          /* TODO: Need to find out PropertyNotify equivalent in
-           * DFB.. */
-      default :
-      break;
-  }
-#endif
 
   return GDK_FILTER_CONTINUE;
 }
 
 nsScreenManagerGtk :: nsScreenManagerGtk ( )
   : mXineramalib(nsnull)
   , mRootWindow(nsnull)
 {
@@ -118,21 +92,19 @@ nsScreenManagerGtk :: nsScreenManagerGtk
 nsScreenManagerGtk :: ~nsScreenManagerGtk()
 {
   if (mRootWindow) {
     gdk_window_remove_filter(mRootWindow, root_window_event_filter, this);
     g_object_unref(mRootWindow);
     mRootWindow = nsnull;
   }
 
-#ifdef MOZ_X11
   if (mXineramalib && mXineramalib != SCREEN_MANAGER_LIBRARY_LOAD_FAILED) {
     PR_UnloadLibrary(mXineramalib);
   }
-#endif
 }
 
 
 // addref, release, QI
 NS_IMPL_ISUPPORTS1(nsScreenManagerGtk, nsIScreenManager)
 
 
 // this function will make sure that everything has been initialized.
@@ -151,28 +123,25 @@ nsScreenManagerGtk :: EnsureInit()
 
   // GDK_STRUCTURE_MASK ==> StructureNotifyMask, for ConfigureNotify
   // GDK_PROPERTY_CHANGE_MASK ==> PropertyChangeMask, for PropertyNotify
   gdk_window_set_events(mRootWindow,
                         GdkEventMask(gdk_window_get_events(mRootWindow) |
                                      GDK_STRUCTURE_MASK |
                                      GDK_PROPERTY_CHANGE_MASK));
   gdk_window_add_filter(mRootWindow, root_window_event_filter, this);
-#ifdef MOZ_X11
   mNetWorkareaAtom =
     XInternAtom(GDK_WINDOW_XDISPLAY(mRootWindow), "_NET_WORKAREA", False);
-#endif
 
   return Init();
 }
 
 nsresult
 nsScreenManagerGtk :: Init()
 {
-#ifdef MOZ_X11
   XineramaScreenInfo *screenInfo = NULL;
   int numScreens;
 
   if (!mXineramalib) {
     mXineramalib = PR_LoadLibrary("libXinerama.so.1");
     if (!mXineramalib) {
       mXineramalib = SCREEN_MANAGER_LIBRARY_LOAD_FAILED;
     }
@@ -188,31 +157,29 @@ nsScreenManagerGtk :: Init()
     if (_XnrmIsActive && _XnrmQueryScreens &&
         _XnrmIsActive(GDK_DISPLAY())) {
       screenInfo = _XnrmQueryScreens(GDK_DISPLAY(), &numScreens);
     }
   }
   // screenInfo == NULL if either Xinerama couldn't be loaded or
   // isn't running on the current display
   if (!screenInfo || numScreens == 1) {
+    nsRefPtr<nsScreenGtk> screen;
     numScreens = 1;
-#endif
-    nsRefPtr<nsScreenGtk> screen;
 
     if (mCachedScreenArray.Count() > 0) {
       screen = static_cast<nsScreenGtk*>(mCachedScreenArray[0]);
     } else {
       screen = new nsScreenGtk();
       if (!screen || !mCachedScreenArray.AppendObject(screen)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }
 
     screen->Init(mRootWindow);
-#ifdef MOZ_X11
   }
   // If Xinerama is enabled and there's more than one screen, fill
   // in the info for all of the screens.  If that's not the case
   // then nsScreenGTK() defaults to the screen width + height
   else {
 #ifdef DEBUG
     printf("Xinerama superpowers activated for %d screens!\n", numScreens);
 #endif
@@ -234,17 +201,16 @@ nsScreenManagerGtk :: Init()
   // Remove any screens that are no longer present.
   while (mCachedScreenArray.Count() > numScreens) {
     mCachedScreenArray.RemoveObjectAt(mCachedScreenArray.Count() - 1);
   }
 
   if (screenInfo) {
     XFree(screenInfo);
   }
-#endif
 
   return NS_OK;
 }
 
 
 //
 // ScreenForRect 
 //
--- a/widget/src/gtk2/nsScreenManagerGtk.h
+++ b/widget/src/gtk2/nsScreenManagerGtk.h
@@ -40,46 +40,40 @@
 #define nsScreenManagerGtk_h___
 
 #include "nsIScreenManager.h"
 #include "nsIScreen.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "prlink.h"
 #include "gdk/gdk.h"
-#ifdef MOZ_X11
 #include <X11/Xlib.h>
-#endif
 
 //------------------------------------------------------------------------
 
 class nsScreenManagerGtk : public nsIScreenManager
 {
 public:
   nsScreenManagerGtk ( );
   virtual ~nsScreenManagerGtk();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSISCREENMANAGER
 
-#ifdef MOZ_X11
   Atom NetWorkareaAtom() { return mNetWorkareaAtom; }
-#endif
   
   // For internal use, or reinitialization from change notification.
   nsresult Init();
 
 private:
 
   nsresult EnsureInit();
 
   // Cached screen array.  Its length is the number of screens we have.
   nsCOMArray<nsIScreen> mCachedScreenArray;
 
   PRLibrary *mXineramalib;
 
   GdkWindow *mRootWindow;
-#ifdef MOZ_X11
   Atom mNetWorkareaAtom;
-#endif
 };
 
 #endif  // nsScreenManagerGtk_h___ 
--- a/widget/src/gtk2/nsWidgetFactory.cpp
+++ b/widget/src/gtk2/nsWidgetFactory.cpp
@@ -220,30 +220,28 @@ static const nsModuleComponentInfo compo
     { "Gtk2 Sound",
       NS_SOUND_CID,
       "@mozilla.org/sound;1",
       nsSoundConstructor },
   { "Transferable",
     NS_TRANSFERABLE_CID,
     "@mozilla.org/widget/transferable;1",
     nsTransferableConstructor },
-#ifdef MOZ_X11
   { "Gtk Clipboard",
     NS_CLIPBOARD_CID,
     "@mozilla.org/widget/clipboard;1",
     nsClipboardConstructor },
   { "Clipboard Helper",
     NS_CLIPBOARDHELPER_CID,
     "@mozilla.org/widget/clipboardhelper;1",
     nsClipboardHelperConstructor },
   { "Gtk Drag Service",
     NS_DRAGSERVICE_CID,
     "@mozilla.org/widget/dragservice;1",
     nsDragServiceConstructor },
-#endif
   { "HTML Format Converter",
     NS_HTMLFORMATCONVERTER_CID,
     "@mozilla.org/widget/htmlformatconverter;1",
     nsHTMLFormatConverterConstructor },
   { "Gtk2 Bidi Keyboard",
     NS_BIDIKEYBOARD_CID,
     "@mozilla.org/widget/bidikeyboard;1",
     nsBidiKeyboardConstructor },
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -52,30 +52,29 @@
 #include "nsWidgetsCID.h"
 #include "nsIDragService.h"
 #include "nsIDragSessionGTK.h"
 
 #include "nsGtkKeyUtils.h"
 #include "nsGtkCursors.h"
 
 #include <gtk/gtkwindow.h>
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
 #include <X11/XF86keysym.h>
-#include "gtk2xtbin.h"
-#endif /* MOZ_X11 */
-#include <gdk/gdkkeysyms.h>
 
 #include "nsWidgetAtoms.h"
 
 #ifdef MOZ_ENABLE_STARTUP_NOTIFICATION
 #define SN_API_NOT_YET_FROZEN
 #include <startup-notification-1.0/libsn/sn.h>
 #endif
 
+#include "gtk2xtbin.h"
+
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #include "nsGfxCIID.h"
 
 #ifdef ACCESSIBILITY
 #include "nsIAccessibleRole.h"
@@ -104,39 +103,20 @@ static const char sAccessibilityKey [] =
 #include "gfxIImageFrame.h"
 #include "nsGfxCIID.h"
 #include "nsIImage.h"
 #include "nsImageToPixbuf.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsAutoPtr.h"
 
 #include "gfxPlatformGtk.h"
+#include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
 
-#ifdef MOZ_X11
-#include "gfxXlibSurface.h"
-#endif
-
-#ifdef MOZ_DFB
-extern "C" {
-#ifdef MOZ_DIRECT_DEBUG
-#define DIRECT_ENABLE_DEBUG
-#endif
-
-#include <direct/debug.h>
-
-D_DEBUG_DOMAIN( ns_Window, "nsWindow", "nsWindow" );
-}
-#include "gfxDirectFBSurface.h"
-#define GDK_WINDOW_XWINDOW(_win) _win
-#else
-#define D_DEBUG_AT(x,y...)    do {} while (0)
-#endif
-
 #ifdef MOZ_ENABLE_GLITZ
 #include "gfxGlitzSurface.h"
 #include "glitz-glx.h"
 #endif
 
 /* For PrepareNativeWidget */
 static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
 
@@ -199,24 +179,22 @@ static gboolean window_state_event_cb   
 static void     theme_changed_cb          (GtkSettings *settings,
                                            GParamSpec *pspec,
                                            nsWindow *data);
 static nsWindow* GetFirstNSWindowForGDKWindow (GdkWindow *aGdkWindow);
 
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
-#ifdef MOZ_X11
 static GdkFilterReturn plugin_window_filter_func (GdkXEvent *gdk_xevent,
                                                   GdkEvent *event,
                                                   gpointer data);
 static GdkFilterReturn plugin_client_message_filter (GdkXEvent *xevent,
                                                      GdkEvent *event,
                                                      gpointer data);
-#endif /* MOZ_X11 */
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
 
 static gboolean drag_motion_event_cb      (GtkWidget *aWidget,
                                            GdkDragContext *aDragContext,
                                            gint aX,
                                            gint aY,
@@ -237,22 +215,20 @@ static void    drag_data_received_event_
                                            gint aX,
                                            gint aY,
                                            GtkSelectionData  *aSelectionData,
                                            guint aInfo,
                                            guint32 aTime,
                                            gpointer aData);
 
 static GdkModifierType gdk_keyboard_get_modifiers();
-#ifdef MOZ_X11
 static PRBool gdk_keyboard_get_modmap_masks(Display*  aDisplay,
                                             PRUint32* aCapsLockMask,
                                             PRUint32* aNumLockMask,
                                             PRUint32* aScrollLockMask);
-#endif /* MOZ_X11 */
 
 /* initialization static functions */
 static nsresult    initialize_prefs        (void);
 
 // this is the last window that had a drag event happen on it.
 nsWindow *nsWindow::mLastDragMotionWindow = NULL;
 PRBool nsWindow::sIsDraggingOutOf = PR_FALSE;
 
@@ -342,19 +318,17 @@ nsWindow::nsWindow()
     mContainerBlockFocus = PR_FALSE;
     mIsVisible           = PR_FALSE;
     mRetryPointerGrab    = PR_FALSE;
     mRetryKeyboardGrab   = PR_FALSE;
     mActivatePending     = PR_FALSE;
     mTransientParent     = nsnull;
     mWindowType          = eWindowType_child;
     mSizeState           = nsSizeMode_Normal;
-#ifdef MOZ_X11
     mOldFocusWindow      = 0;
-#endif /* MOZ_X11 */
     mPluginType          = PluginType_NONE;
 
     if (!gGlobalsInitialized) {
         gGlobalsInitialized = PR_TRUE;
 
         // It's OK if either of these fail, but it may not be one day.
         initialize_prefs();
     }
@@ -378,46 +352,28 @@ nsWindow::nsWindow()
     mRootAccessible  = nsnull;
 #endif
 
     mIsTransparent = PR_FALSE;
     mTransparencyBitmap = nsnull;
 
     mTransparencyBitmapWidth  = 0;
     mTransparencyBitmapHeight = 0;
-
-#ifdef MOZ_DFB
-    mDFBCursorX     = 0;
-    mDFBCursorY     = 0;
-
-    mDFBCursorCount = 0;
-
-    mDFB            = NULL;
-    mDFBLayer       = NULL;
-#endif
 }
 
 nsWindow::~nsWindow()
 {
     LOG(("nsWindow::~nsWindow() [%p]\n", (void *)this));
     if (mLastDragMotionWindow == this) {
         mLastDragMotionWindow = NULL;
     }
 
     delete[] mTransparencyBitmap;
     mTransparencyBitmap = nsnull;
 
-#ifdef MOZ_DFB
-    if (mDFBLayer)
-         mDFBLayer->Release( mDFBLayer );
-         
-    if (mDFB)
-         mDFB->Release( mDFB );
-#endif
-
     Destroy();
 }
 
 /* static */ void
 nsWindow::ReleaseGlobals()
 {
   for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gCursorCache); ++i) {
     if (gCursorCache[i]) {
@@ -497,22 +453,20 @@ nsWindow::Destroy(void)
 #endif
 
     // make sure that we remove ourself as the focus window
     if (gFocusWindow == this) {
         LOGFOCUS(("automatically losing focus...\n"));
         gFocusWindow = nsnull;
     }
 
-#ifdef MOZ_X11
     // make sure that we remove ourself as the plugin focus window
     if (gPluginFocusWindow == this) {
         gPluginFocusWindow->LoseNonXEmbedPluginFocus();
     }
-#endif /* MOZ_X11 */
 
     if (mWindowGroup) {
         g_object_unref(G_OBJECT(mWindowGroup));
         mWindowGroup = nsnull;
     }
 
     // Destroy thebes surface now. Badness can happen if we destroy
     // the surface after its X Window.
@@ -1269,23 +1223,16 @@ nsWindow::SetColorMap(nsColorMap *aColor
 NS_IMETHODIMP
 nsWindow::Scroll(PRInt32  aDx,
                  PRInt32  aDy,
                  nsRect  *aClipRect)
 {
     if (!mDrawingarea)
         return NS_OK;
 
-    D_DEBUG_AT( ns_Window, "%s( %4d,%4d )\n", __FUNCTION__, aDx, aDy );
-
-    if (aClipRect) {
-         D_DEBUG_AT( ns_Window, "  -> aClipRect: %4d,%4d-%4dx%4d\n",
-                     aClipRect->x, aClipRect->y, aClipRect->width, aClipRect->height );
-    }
-
     moz_drawingarea_scroll(mDrawingarea, aDx, aDy);
 
     // Update bounds on our child windows
     for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
         nsRect bounds;
         kid->GetBounds(bounds);
         bounds.x += aDx;
         bounds.y += aDy;
@@ -1329,21 +1276,17 @@ nsWindow::GetNativeData(PRUint32 aDataTy
         break;
     }
 
     case NS_NATIVE_PLUGIN_PORT:
         return SetupPluginPort();
         break;
 
     case NS_NATIVE_DISPLAY:
-#ifdef MOZ_X11
         return GDK_DISPLAY();
-#else
-        return nsnull;
-#endif /* MOZ_X11 */
         break;
 
     case NS_NATIVE_GRAPHIC: {
         NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");
         return (void *)static_cast<nsGTKToolkit *>(mToolkit)->GetSharedGC();
         break;
     }
 
@@ -1611,17 +1554,16 @@ nsWindow::LoseFocus(void)
 // Paint flashing code
 
 #define CAPS_LOCK_IS_ON \
 (gdk_keyboard_get_modifiers() & GDK_LOCK_MASK)
 
 #define WANT_PAINT_FLASHING \
 (debug_WantPaintFlashing() && CAPS_LOCK_IS_ON)
 
-#ifdef MOZ_X11
 static void
 gdk_window_flash(GdkWindow *    aGdkWindow,
                  unsigned int   aTimes,
                  unsigned int   aInterval,  // Milliseconds
                  GdkRegion *    aRegion)
 {
   gint         x;
   gint         y;
@@ -1671,17 +1613,16 @@ gdk_window_flash(GdkWindow *    aGdkWind
     
     PR_Sleep(PR_MillisecondsToInterval(aInterval));
   }
 
   gdk_gc_destroy(gc);
 
   gdk_region_offset(aRegion, -x, -y);
 }
-#endif /* MOZ_X11 */
 #endif // DEBUG
 
 gboolean
 nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent)
 {
     if (mIsDestroyed) {
         LOG(("Expose event on destroyed window [%p] window %p\n",
              (void *)this, (void *)aEvent->window));
@@ -1715,38 +1656,16 @@ nsWindow::OnExposeEvent(GtkWidget *aWidg
 
     GdkRectangle *r;
     GdkRectangle *r_end = rects + nrects;
     for (r = rects; r < r_end; ++r) {
         updateRegion->Union(r->x, r->y, r->width, r->height);
         LOGDRAW(("\t%d %d %d %d\n", r->x, r->y, r->width, r->height));
     }
 
-#ifdef MOZ_DFB
-    nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
-    if (NS_UNLIKELY(!rc)) {
-        g_free(rects);
-        return FALSE;
-    }
-
-    // do double-buffering and clipping here
-    nsRefPtr<gfxContext> ctx = rc->ThebesContext();
-
-    gfxPlatformGtk::GetPlatform()->SetGdkDrawable(ctx->OriginalSurface(), GDK_DRAWABLE(mDrawingarea->inner_window));
-
-    // clip to the update region
-    ctx->Save();
-    ctx->NewPath();
-    for (r = rects; r < r_end; ++r) {
-        ctx->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
-    }
-    ctx->Clip();
-#endif
-
-#ifdef MOZ_X11
     nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
     if (NS_UNLIKELY(!rc)) {
         g_free(rects);
         return FALSE;
     }
 
     PRBool translucent;
     GetHasTransparentBackground(translucent);
@@ -1784,27 +1703,23 @@ nsWindow::OnExposeEvent(GtkWidget *aWidg
 #else // MOZ_ENABLE_GLITZ
         // Instead of just doing PushGroup we're going to do a little dance
         // to ensure that GDK creates the pixmap, so it doesn't go all
         // XGetGeometry on us in gdk_pixmap_foreign_new_for_display when we
         // paint native themes
         GdkDrawable* d = GDK_DRAWABLE(mDrawingarea->inner_window);
         gint depth = gdk_drawable_get_depth(d);
         bufferPixmap = gdk_pixmap_new(d, boundsRect.width, boundsRect.height, depth);
-
         if (bufferPixmap) {
             bufferPixmapSurface = GetSurfaceForGdkDrawable(GDK_DRAWABLE(bufferPixmap),
                                                            boundsRect.Size());
             if (bufferPixmapSurface && bufferPixmapSurface->CairoStatus()) {
                 bufferPixmapSurface = nsnull;
             }
             if (bufferPixmapSurface) {
-                gfxPlatformGtk::GetPlatform()->SetGdkDrawable(
-                        static_cast<gfxASurface *>(bufferPixmapSurface), 
-                        GDK_DRAWABLE(bufferPixmap));
                 bufferPixmapSurface->SetDeviceOffset(gfxPoint(-boundsRect.x, -boundsRect.y));
                 nsCOMPtr<nsIRenderingContext> newRC;
                 nsresult rv = GetDeviceContext()->
                     CreateRenderingContextInstance(*getter_AddRefs(newRC));
                 if (NS_FAILED(rv)) {
                     bufferPixmapSurface = nsnull;
                 } else {
                     rv = newRC->Init(GetDeviceContext(), bufferPixmapSurface);
@@ -1824,29 +1739,26 @@ nsWindow::OnExposeEvent(GtkWidget *aWidg
     // cairo inflates the update region, etc.  So don't paint flash
     // for cairo.
 #ifdef DEBUG
     if (WANT_PAINT_FLASHING && aEvent->window)
         gdk_window_flash(aEvent->window, 1, 100, aEvent->region);
 #endif
 #endif
 
-#endif // MOZ_X11
-
     nsPaintEvent event(PR_TRUE, NS_PAINT, this);
     event.refPoint.x = aEvent->area.x;
     event.refPoint.y = aEvent->area.y;
     event.rect = nsnull;
     event.region = updateRegion;
     event.renderingContext = rc;
 
     nsEventStatus status;
     DispatchEvent(&event, status);
 
-#ifdef MOZ_X11
     // DispatchEvent can Destroy us (bug 378273), avoid doing any paint
     // operations below if that happened - it will lead to XError and exit().
     if (NS_LIKELY(!mIsDestroyed)) {
         if (status != nsEventStatus_eIgnore) {
             if (translucent) {
                 nsRefPtr<gfxPattern> pattern = ctx->PopGroup();
                 ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
                 ctx->SetPattern(pattern);
@@ -1892,21 +1804,16 @@ nsWindow::OnExposeEvent(GtkWidget *aWidg
         }
 
         if (bufferPixmap) {
             g_object_unref(G_OBJECT(bufferPixmap));
         }
 
         ctx->Restore();
     }
-#endif // MOZ_X11
-
-#ifdef MOZ_DFB
-    ctx->Restore();
-#endif
 
     g_free(rects);
 
     // check the return value!
     return TRUE;
 }
 
 gboolean
@@ -2037,128 +1944,54 @@ nsWindow::OnLeaveNotifyEvent(GtkWidget *
         ? nsMouseEvent::eTopLevel : nsMouseEvent::eChild;
 
     LOG(("OnLeaveNotify: %p\n", (void *)this));
 
     nsEventStatus status;
     DispatchEvent(&event, status);
 }
 
-#ifdef MOZ_DFB
-void
-nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent)
-{
-    int cursorX = (int) aEvent->x_root;
-    int cursorY = (int) aEvent->y_root;
-
-    D_DEBUG_AT( ns_Window, "%s( %4d,%4d - [%d] )\n", __FUNCTION__, cursorX, cursorY, mDFBCursorCount );
-
-    D_ASSUME( mDFBLayer != NULL );
-
-    if (mDFBLayer)
-         mDFBLayer->GetCursorPosition( mDFBLayer, &cursorX, &cursorY );
-
-    mDFBCursorCount++;
-
-#if D_DEBUG_ENABLED
-    if (cursorX != (int) aEvent->x_root || cursorY != (int) aEvent->y_root)
-         D_DEBUG_AT( ns_Window, "  -> forward to %4d,%4d\n", cursorX, cursorY );
-#endif
-
-    if (cursorX == mDFBCursorX && cursorY == mDFBCursorY) {
-         D_DEBUG_AT( ns_Window, "  -> dropping %4d,%4d\n", cursorX, cursorY );
-
-         /* drop zero motion */
-         return;
-    }
-
-    mDFBCursorX = cursorX;
-    mDFBCursorY = cursorY;
-
-
-    // when we receive this, it must be that the gtk dragging is over,
-    // it is dropped either in or out of mozilla, clear the flag
-    sIsDraggingOutOf = PR_FALSE;
-
-    nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal);
-
-    nsRect windowRect;
-    ScreenToWidget(nsRect(nscoord(cursorX), nscoord(cursorY), 1, 1), windowRect);
-
-    event.refPoint.x = windowRect.x;
-    event.refPoint.y = windowRect.y;
-
-    event.isShift   = (aEvent->state & GDK_SHIFT_MASK)
-        ? PR_TRUE : PR_FALSE;
-    event.isControl = (aEvent->state & GDK_CONTROL_MASK)
-        ? PR_TRUE : PR_FALSE;
-    event.isAlt     = (aEvent->state & GDK_MOD1_MASK)
-        ? PR_TRUE : PR_FALSE;
-
-    event.time = aEvent->time;
-
-    nsEventStatus status;
-    DispatchEvent(&event, status);
-}
-#else
 void
 nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent)
 {
     // when we receive this, it must be that the gtk dragging is over,
     // it is dropped either in or out of mozilla, clear the flag
     sIsDraggingOutOf = PR_FALSE;
 
     // see if we can compress this event
     // XXXldb Why skip every other motion event when we have multiple,
     // but not more than that?
+    XEvent xevent;
     PRPackedBool synthEvent = PR_FALSE;
-#ifdef MOZ_X11
-    XEvent xevent;
-    
     while (XCheckWindowEvent(GDK_WINDOW_XDISPLAY(aEvent->window),
                              GDK_WINDOW_XWINDOW(aEvent->window),
                              ButtonMotionMask, &xevent)) {
         synthEvent = PR_TRUE;
     }
 
     // if plugins still keeps the focus, get it back
     if (gPluginFocusWindow && gPluginFocusWindow != this) {
         nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
         gPluginFocusWindow->LoseNonXEmbedPluginFocus();
     }
-#endif /* MOZ_X11 */
 
     nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal);
 
     if (synthEvent) {
-#ifdef MOZ_X11
         event.refPoint.x = nscoord(xevent.xmotion.x);
         event.refPoint.y = nscoord(xevent.xmotion.y);
 
         event.isShift   = (xevent.xmotion.state & GDK_SHIFT_MASK)
             ? PR_TRUE : PR_FALSE;
         event.isControl = (xevent.xmotion.state & GDK_CONTROL_MASK)
             ? PR_TRUE : PR_FALSE;
         event.isAlt     = (xevent.xmotion.state & GDK_MOD1_MASK)
             ? PR_TRUE : PR_FALSE;
 
         event.time = xevent.xmotion.time;
-#else
-        event.refPoint.x = nscoord(aEvent->x);
-        event.refPoint.y = nscoord(aEvent->y);
-
-        event.isShift   = (aEvent->state & GDK_SHIFT_MASK)
-            ? PR_TRUE : PR_FALSE;
-        event.isControl = (aEvent->state & GDK_CONTROL_MASK)
-            ? PR_TRUE : PR_FALSE;
-        event.isAlt     = (aEvent->state & GDK_MOD1_MASK)
-            ? PR_TRUE : PR_FALSE;
-
-        event.time = aEvent->time;
-#endif /* MOZ_X11 */
     }
     else {
         // XXX see OnScrollEvent()
         if (aEvent->window == mDrawingarea->inner_window) {
             event.refPoint.x = nscoord(aEvent->x);
             event.refPoint.y = nscoord(aEvent->y);
         } else {
             nsRect windowRect;
@@ -2176,17 +2009,16 @@ nsWindow::OnMotionNotifyEvent(GtkWidget 
             ? PR_TRUE : PR_FALSE;
 
         event.time = aEvent->time;
     }
 
     nsEventStatus status;
     DispatchEvent(&event, status);
 }
-#endif
 
 void
 nsWindow::InitButtonEvent(nsMouseEvent &aEvent,
                           GdkEventButton *aGdkEvent)
 {
     // XXX see OnScrollEvent()
     if (aGdkEvent->window == mDrawingarea->inner_window) {
         aEvent.refPoint.x = nscoord(aGdkEvent->x);
@@ -2378,23 +2210,21 @@ nsWindow::OnContainerFocusInEvent(GtkWid
     LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this));
 }
 
 void
 nsWindow::OnContainerFocusOutEvent(GtkWidget *aWidget, GdkEventFocus *aEvent)
 {
     LOGFOCUS(("OnContainerFocusOutEvent [%p]\n", (void *)this));
 
-#ifdef MOZ_X11
     // plugin lose focus
     if (gPluginFocusWindow) {
         nsRefPtr<nsWindow> kungFuDeathGrip = gPluginFocusWindow;
         gPluginFocusWindow->LoseNonXEmbedPluginFocus();
     }
-#endif /* MOZ_X11 */
 
     // Figure out if the focus widget is the child of this window.  If
     // it is, send a focus out and deactivate event for it.
     if (!gFocusWindow)
         return;
 
     GdkWindow *tmpWindow;
     tmpWindow = (GdkWindow *)gFocusWindow->GetNativeData(NS_NATIVE_WINDOW);
@@ -2543,17 +2373,16 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWi
         || aEvent->keyval == GDK_Control_R
         || aEvent->keyval == GDK_Alt_L
         || aEvent->keyval == GDK_Alt_R
         || aEvent->keyval == GDK_Meta_L
         || aEvent->keyval == GDK_Meta_R) {
         return TRUE;
     }
 
-#ifdef MOZ_X11
     // Look for specialized app-command keys
     switch (aEvent->keyval) {
         case XF86XK_Back:
             return DispatchCommandEvent(nsWidgetAtoms::Back);
         case XF86XK_Forward:
             return DispatchCommandEvent(nsWidgetAtoms::Forward);
         case XF86XK_Refresh:
             return DispatchCommandEvent(nsWidgetAtoms::Reload);
@@ -2561,17 +2390,16 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWi
             return DispatchCommandEvent(nsWidgetAtoms::Stop);
         case XF86XK_Search:
             return DispatchCommandEvent(nsWidgetAtoms::Search);
         case XF86XK_Favorites:
             return DispatchCommandEvent(nsWidgetAtoms::Bookmarks);
         case XF86XK_HomePage:
             return DispatchCommandEvent(nsWidgetAtoms::Home);
     }
-#endif /* MOZ_X11 */
 
     nsKeyEvent event(PR_TRUE, NS_KEY_PRESS, this);
     InitKeyEvent(event, aEvent);
     if (isKeyDownCancelled) {
       // If prevent default set for onkeydown, do the same for onkeypress
       event.flags |= NS_EVENT_FLAG_NO_DEFAULT;
     }
     event.charCode = nsConvertCharCodeToUnicode(aEvent);
@@ -3417,23 +3245,18 @@ nsWindow::NativeCreate(nsIWidget        
         }
     }
         break;
     default:
         break;
     }
     // Disable the double buffer because it will make the caret crazy
     // For bug#153805 (Gtk2 double buffer makes carets misbehave)
-    // DirectFB's expose code depends on gtk double buffering
-    // XXX - I think this bug is probably dead, we can just use gtk's
-    // double-buffering everywhere
-#ifdef MOZ_X11
     if (mContainer)
         gtk_widget_set_double_buffered (GTK_WIDGET(mContainer),FALSE);
-#endif
 
     // label the drawing area with this object so we can find our way
     // home
     g_object_set_data(G_OBJECT(mDrawingarea->clip_window), "nsWindow",
                       this);
     g_object_set_data(G_OBJECT(mDrawingarea->inner_window), "nsWindow",
                       this);
 
@@ -3567,42 +3390,25 @@ nsWindow::NativeCreate(nsIWidget        
         }
     }
     if (sAccessibilityEnabled) {
         LOG(("nsWindow:: Create Toplevel Accessibility\n"));
         CreateRootAccessible();
     }
 #endif
 
-#ifdef MOZ_DFB
-    if (!mDFB) {
-         DirectFBCreate( &mDFB );
-
-         D_ASSUME( mDFB != NULL );
-
-         if (mDFB)
-              mDFB->GetDisplayLayer( mDFB, DLID_PRIMARY, &mDFBLayer );
-
-         D_ASSUME( mDFBLayer != NULL );
-
-         if (mDFBLayer)
-              mDFBLayer->GetCursorPosition( mDFBLayer, &mDFBCursorX, &mDFBCursorY );
-    }
-#endif
-
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::SetWindowClass(const nsAString &xulWinType)
 {
   if (!mShell)
     return NS_ERROR_FAILURE;
 
-#ifdef MOZ_X11
   nsXPIDLString brandName;
   GetBrandName(brandName);
 
   XClassHint *class_hint = XAllocClassHint();
   if (!class_hint)
     return NS_ERROR_OUT_OF_MEMORY;
   const char *role = NULL;
   class_hint->res_name = ToNewCString(xulWinType);
@@ -3636,49 +3442,16 @@ nsWindow::SetWindowClass(const nsAString
   // Can't use gtk_window_set_wmclass() for this; it prints
   // a warning & refuses to make the change.
   XSetClassHint(GDK_DISPLAY(),
                 GDK_WINDOW_XWINDOW(GTK_WIDGET(mShell)->window),
                 class_hint);
   nsMemory::Free(class_hint->res_class);
   nsMemory::Free(class_hint->res_name);
   XFree(class_hint);
-#else /* MOZ_X11 */
-
-  char *res_name;
-
-  res_name = ToNewCString(xulWinType);
-  if (!res_name)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  printf("WARN: res_name = '%s'\n", res_name);
-
-
-  const char *role = NULL;
-
-  // Parse res_name into a name and role. Characters other than
-  // [A-Za-z0-9_-] are converted to '_'. Anything after the first
-  // colon is assigned to role; if there's no colon, assign the
-  // whole thing to both role and res_name.
-  for (char *c = res_name; *c; c++) {
-    if (':' == *c) {
-      *c = 0;
-      role = c + 1;
-    }
-    else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c)))
-      *c = '_';
-  }
-  res_name[0] = toupper(res_name[0]);
-  if (!role) role = res_name;
-
-  gdk_window_set_role(GTK_WIDGET(mShell)->window, role);
-
-  nsMemory::Free(res_name);
-
-#endif /* MOZ_X11 */
   return NS_OK;
 }
 
 void
 nsWindow::NativeResize(PRInt32 aWidth, PRInt32 aHeight, PRBool  aRepaint)
 {
     LOG(("nsWindow::NativeResize [%p] %d %d\n", (void *)this,
          aWidth, aHeight));
@@ -4192,32 +3965,30 @@ nsWindow::SetupPluginPort(void)
         return nsnull;
 
     if (GDK_WINDOW_OBJECT(mDrawingarea->inner_window)->destroyed == TRUE)
         return nsnull;
 
     // we have to flush the X queue here so that any plugins that
     // might be running on separate X connections will be able to use
     // this window in case it was just created
-#ifdef MOZ_X11
     XWindowAttributes xattrs;
     XGetWindowAttributes(GDK_DISPLAY (),
                          GDK_WINDOW_XWINDOW(mDrawingarea->inner_window),
                          &xattrs);
     XSelectInput (GDK_DISPLAY (),
                   GDK_WINDOW_XWINDOW(mDrawingarea->inner_window),
                   xattrs.your_event_mask |
                   SubstructureNotifyMask);
 
     gdk_window_add_filter(mDrawingarea->inner_window,
                           plugin_window_filter_func,
                           this);
 
     XSync(GDK_DISPLAY(), False);
-#endif /* MOZ_X11 */
 
     return (void *)GDK_WINDOW_XWINDOW(mDrawingarea->inner_window);
 }
 
 nsresult
 nsWindow::SetWindowIconList(const nsCStringArray &aIconList)
 {
     GList *list = NULL;
@@ -4251,17 +4022,16 @@ nsWindow::SetDefaultIcon(void)
 }
 
 void
 nsWindow::SetPluginType(PluginType aPluginType)
 {
     mPluginType = aPluginType;
 }
 
-#ifdef MOZ_X11
 void
 nsWindow::SetNonXEmbedPluginFocus()
 {
     if (gPluginFocusWindow == this || mPluginType!=PluginType_NONXEMBED) {
         return;
     }
 
     if (gPluginFocusWindow) {
@@ -4346,17 +4116,16 @@ nsWindow::LoseNonXEmbedPluginFocus()
         gdk_error_trap_pop();
     }
     gPluginFocusWindow = NULL;
     mOldFocusWindow = 0;
     gdk_window_remove_filter(NULL, plugin_client_message_filter, this);
 
     LOGFOCUS(("nsWindow::LoseNonXEmbedPluginFocus end\n"));
 }
-#endif /* MOZ_X11 */
 
 
 gint
 nsWindow::ConvertBorderStyles(nsBorderStyle aStyle)
 {
     gint w = 0;
 
     if (aStyle == eBorderStyle_default)
@@ -4430,21 +4199,17 @@ nsWindow::HideWindowChrome(PRBool aShoul
     if (wasVisible)
         gdk_window_show(mShell->window);
 
     // For some window managers, adding or removing window decorations
     // requires unmapping and remapping our toplevel window.  Go ahead
     // and flush the queue here so that we don't end up with a BadWindow
     // error later when this happens (when the persistence timer fires
     // and GetWindowPos is called)
-#ifdef MOZ_X11
     XSync(GDK_DISPLAY(), False);
-#else
-    gdk_flush ();
-#endif /* MOZ_X11 */
 
     return NS_OK;
 }
 
 PRBool
 check_for_rollup(GdkWindow *aWindow, gdouble aMouseX, gdouble aMouseY,
                  PRBool aIsWheel)
 {
@@ -4942,17 +4707,16 @@ focus_out_event_cb(GtkWidget *widget, Gd
     if (!window)
         return FALSE;
 
     window->OnContainerFocusOutEvent(widget, event);
 
     return FALSE;
 }
 
-#ifdef MOZ_X11
 /* static */
 GdkFilterReturn
 plugin_window_filter_func(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
 {
     GtkWidget *widget;
     GdkWindow *plugin_window;
     gpointer  user_data;
     XEvent    *xevent;
@@ -5041,17 +4805,16 @@ plugin_client_message_filter(GdkXEvent *
     if ((Atom) xevent->xclient.data.l[0] ==
             gdk_x11_get_xatom_by_name("WM_TAKE_FOCUS")) {
         // block it from gtk2.0 focus proxy
         return_val = GDK_FILTER_REMOVE;
     }
 
     return return_val;
 }
-#endif /* MOZ_X11 */
 
 /* static */
 gboolean
 key_press_event_cb(GtkWidget *widget, GdkEventKey *event)
 {
     LOG(("key_press_event_cb\n"));
     // find the window with focus and dispatch this event to that widget
     nsWindow *window = get_window_for_gtk_widget(widget);
@@ -5428,17 +5191,16 @@ gdk_keyboard_get_modifiers()
 {
     GdkModifierType m = (GdkModifierType) 0;
 
     gdk_window_get_pointer(NULL, NULL, NULL, &m);
 
     return m;
 }
 
-#ifdef MOZ_X11
 // Get the modifier masks for GDK_Caps_Lock, GDK_Num_Lock and GDK_Scroll_Lock.
 // Return PR_TRUE on success, PR_FALSE on error.
 static PRBool
 gdk_keyboard_get_modmap_masks(Display*  aDisplay,
                               PRUint32* aCapsLockMask,
                               PRUint32* aNumLockMask,
                               PRUint32* aScrollLockMask)
 {
@@ -5486,17 +5248,16 @@ gdk_keyboard_get_modmap_masks(Display*  
             }
         }
     }
 
     XFreeModifiermap(xmodmap);
     XFree(xkeymap);
     return PR_TRUE;
 }
-#endif /* MOZ_X11 */
 
 #ifdef ACCESSIBILITY
 /**
  * void
  * nsWindow::CreateRootAccessible
  *
  * request to create the nsIAccessible Object for the toplevel window
  **/
@@ -6144,18 +5905,16 @@ nsWindow::CancelIMEComposition()
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState)
 {
     NS_ENSURE_ARG_POINTER(aLEDState);
 
-#ifdef MOZ_X11
-
     GdkModifierType modifiers = gdk_keyboard_get_modifiers();
     PRUint32 capsLockMask, numLockMask, scrollLockMask;
     PRBool foundMasks = gdk_keyboard_get_modmap_masks(
                           GDK_WINDOW_XDISPLAY(mDrawingarea->inner_window),
                           &capsLockMask, &numLockMask, &scrollLockMask);
     if (!foundMasks)
         return NS_ERROR_NOT_IMPLEMENTED;
 
@@ -6165,19 +5924,16 @@ nsWindow::GetToggledKeyState(PRUint32 aK
         case NS_VK_NUM_LOCK:    mask = numLockMask;    break;
         case NS_VK_SCROLL_LOCK: mask = scrollLockMask; break;
     }
     if (mask == 0)
         return NS_ERROR_NOT_IMPLEMENTED;
 
     *aLEDState = (modifiers & mask) != 0;
     return NS_OK;
-#else
-    return NS_ERROR_NOT_IMPLEMENTED;
-#endif /* MOZ_X11 */
 }
 
 /* static */
 void
 IM_preedit_changed_cb(GtkIMContext *aContext,
                       nsWindow     *aWindow)
 {
     gchar *preedit_string;
@@ -6446,65 +6202,105 @@ IM_get_input_context(nsWindow *aWindow)
         return data->mContext;
     if (data->mEnabled == nsIWidget::IME_STATUS_PASSWORD)
         return data->mSimpleContext;
     return data->mDummyContext;
 }
 
 #endif
 
-#ifdef MOZ_X11
 /* static */ already_AddRefed<gfxASurface>
 nsWindow::GetSurfaceForGdkDrawable(GdkDrawable* aDrawable,
                                    const nsSize& aSize)
 {
     GdkVisual* visual = gdk_drawable_get_visual(aDrawable);
     Visual* xVisual = gdk_x11_visual_get_xvisual(visual);
     Display* xDisplay = gdk_x11_drawable_get_xdisplay(aDrawable);
     Drawable xDrawable = gdk_x11_drawable_get_xid(aDrawable);
 
     gfxASurface* result = new gfxXlibSurface(xDisplay, xDrawable, xVisual,
                                        gfxIntSize(aSize.width, aSize.height));
     NS_IF_ADDREF(result);
     return result;
 }
-#endif
 
 // return the gfxASurface for rendering to this widget
 gfxASurface*
 nsWindow::GetThebesSurface()
 {
-    GdkDrawable* d;
-    gint x_offset, y_offset;
-    gdk_window_get_internal_paint_info(mDrawingarea->inner_window,
-                                       &d, &x_offset, &y_offset);
-
-#ifdef MOZ_X11
-    gint width, height;
-    gdk_drawable_get_size(d, &width, &height);
-    // Owen Taylor says this is the right thing to do!
-    width = PR_MIN(32767, width);
-    height = PR_MIN(32767, height);
-
-    mThebesSurface = new gfxXlibSurface
-        (GDK_WINDOW_XDISPLAY(d),
-         GDK_WINDOW_XWINDOW(d),
-         GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(d)),
-         gfxIntSize(width, height));
+    // XXXvlad always create a new thebes surface for now,
+    // because the old clip doesn't get cleared otherwise.
+    // we should fix this at some point, and just reset
+    // the clip.
+    mThebesSurface = nsnull;
+
+    if (!mThebesSurface) {
+        GdkDrawable* d;
+        gint x_offset, y_offset;
+        gdk_window_get_internal_paint_info(mDrawingarea->inner_window,
+                &d, &x_offset, &y_offset);
+
+        gint width, height;
+        gdk_drawable_get_size(d, &width, &height);
+        // Owen Taylor says this is the right thing to do!
+        width = PR_MIN(32767, width);
+        height = PR_MIN(32767, height);
+
+        if (!gfxPlatform::UseGlitz()) {
+            mThebesSurface = new gfxXlibSurface
+                (GDK_WINDOW_XDISPLAY(d),
+                 GDK_WINDOW_XWINDOW(d),
+                 GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(d)),
+                 gfxIntSize(width, height));
+
+            // if the surface creation is reporting an error, then
+            // we don't have a surface to give back
+            if (mThebesSurface && mThebesSurface->CairoStatus() != 0)
+                mThebesSurface = nsnull;
+        } else {
+#ifdef MOZ_ENABLE_GLITZ
+            glitz_surface_t *gsurf;
+            glitz_drawable_t *gdraw;
+
+            glitz_drawable_format_t *gdformat = glitz_glx_find_window_format (GDK_DISPLAY(),
+                                                                              gdk_x11_get_default_screen(),
+                                                                              0, NULL, 0);
+            if (!gdformat)
+                NS_ERROR("Failed to find glitz drawable format");
+
+            Display* dpy = GDK_WINDOW_XDISPLAY(d);
+            Window wnd = GDK_WINDOW_XWINDOW(d);
+            
+            gdraw =
+                glitz_glx_create_drawable_for_window (dpy,
+                                                      DefaultScreen(dpy),
+                                                      gdformat,
+                                                      wnd,
+                                                      width,
+                                                      height);
+            glitz_format_t *gformat =
+                glitz_find_standard_format (gdraw, GLITZ_STANDARD_RGB24);
+            gsurf =
+                glitz_surface_create (gdraw,
+                                      gformat,
+                                      width,
+                                      height,
+                                      0,
+                                      NULL);
+            glitz_surface_attach (gsurf, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
+
+
+            //fprintf (stderr, "## nsThebesDrawingSurface::Init Glitz DRAWABLE %p (DC: %p)\n", aWidget, aDC);
+            mThebesSurface = new gfxGlitzSurface (gdraw, gsurf, PR_TRUE);
 #endif
-#ifdef MOZ_DFB
-    mThebesSurface = new gfxDirectFBSurface(gdk_directfb_surface_lookup(d));
-#endif
-
-    // if the surface creation is reporting an error, then
-    // we don't have a surface to give back
-    if (mThebesSurface && mThebesSurface->CairoStatus() != 0) {
-        mThebesSurface = nsnull;
-    } else {
-        mThebesSurface->SetDeviceOffset(gfxPoint(-x_offset, -y_offset));
+        }
+
+        if (mThebesSurface) {
+            mThebesSurface->SetDeviceOffset(gfxPoint(-x_offset, -y_offset));
+        }
     }
 
     return mThebesSurface;
 }
 
 NS_IMETHODIMP
 nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
 {
--- a/widget/src/gtk2/nsWindow.h
+++ b/widget/src/gtk2/nsWindow.h
@@ -51,23 +51,17 @@
 #include "nsIDragService.h"
 #include "nsITimer.h"
 #include "nsWidgetAtoms.h"
 
 #include "gfxASurface.h"
 
 #include <gtk/gtk.h>
 
-#ifdef MOZ_DFB
-#include <gdk/gdkdirectfb.h>
-#endif /* MOZ_DFB */
-
-#ifdef MOZ_X11
 #include <gdk/gdkx.h>
-#endif /* MOZ_X11 */
 #include <gtk/gtkwindow.h>
 
 #ifdef ACCESSIBILITY
 #include "nsIAccessNode.h"
 #include "nsIAccessible.h"
 #endif
 
 #ifdef USE_XIM
@@ -257,26 +251,22 @@ public:
 
     enum PluginType {
         PluginType_NONE = 0,   /* do not have any plugin */
         PluginType_XEMBED,     /* the plugin support xembed */
         PluginType_NONXEMBED   /* the plugin does not support xembed */
     };
 
     void               SetPluginType(PluginType aPluginType);
-#ifdef MOZ_X11
     void               SetNonXEmbedPluginFocus(void);
     void               LoseNonXEmbedPluginFocus(void);
-#endif /* MOZ_X11 */
 
     void               ThemeChanged(void);
 
-#ifdef MOZ_X11
     Window             mOldFocusWindow;
-#endif /* MOZ_X11 */
 
     static guint32     mLastButtonPressTime;
     static guint32     mLastButtonReleaseTime;
 
     NS_IMETHOD         BeginResizeDrag   (nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
 
 #ifdef USE_XIM
     void               IMEInitData       (void);
@@ -407,24 +397,16 @@ private:
     PRInt32             mSizeState;
     PluginType          mPluginType;
 
     PRInt32             mTransparencyBitmapWidth;
     PRInt32             mTransparencyBitmapHeight;
 
     nsRefPtr<gfxASurface> mThebesSurface;
 
-#ifdef MOZ_DFB
-    int                    mDFBCursorX;
-    int                    mDFBCursorY;
-    PRUint32               mDFBCursorCount;
-    IDirectFB             *mDFB;
-    IDirectFBDisplayLayer *mDFBLayer;
-#endif
-
 #ifdef ACCESSIBILITY
     nsCOMPtr<nsIAccessible> mRootAccessible;
     void                CreateRootAccessible();
     void                GetRootAccessible(nsIAccessible** aAccessible);
     void                DispatchActivateEvent(void);
     void                DispatchDeactivateEvent(void);
     NS_IMETHOD_(PRBool) DispatchAccessibleEvent(nsIAccessible** aAccessible);
 #endif