Bug 1288686 - Avoid X11's |#define None 0L| intruding on other parts of the code. r=jrmuizel
authorBotond Ballo <botond@mozilla.com>
Mon, 29 Aug 2016 16:51:43 -0400
changeset 353487 e760ad8231d667e777534dce301db6bee92acbbd
parent 353486 7eac2acb63a5b28940bb8801e02ccab5c83c078c
child 353488 ff74f7a0d29c29817e87e04abed391237458f6a8
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1288686
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1288686 - Avoid X11's |#define None 0L| intruding on other parts of the code. r=jrmuizel MozReview-Commit-ID: 9rD0KLTLg7l
dom/plugins/base/npapi.h
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/base/nsPluginNativeWindowGtk.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/test/testplugin/nptest_gtk2.cpp
gfx/2d/BorrowedContext.h
gfx/2d/DrawTargetCairo.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/layers/ipc/ShadowLayerUtilsX11.cpp
gfx/src/X11UndefineNone.h
gfx/src/X11Util.cpp
gfx/src/X11Util.h
gfx/src/moz.build
gfx/thebes/gfxXlibSurface.cpp
gfx/thebes/gfxXlibSurface.h
widget/gtk/nsClipboard.cpp
widget/gtk/nsWindow.cpp
--- a/dom/plugins/base/npapi.h
+++ b/dom/plugins/base/npapi.h
@@ -41,16 +41,17 @@
 #endif
 #endif
 
 #if defined(XP_UNIX)
 #include <stdio.h>
 #if defined(MOZ_X11)
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include "X11UndefineNone.h"
 #endif
 #endif
 
 #if defined(XP_SYMBIAN)
 #include <QEvent>
 #include <QRegion>
 #endif
 
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -2605,17 +2605,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
         // Get reference point relative to screen:
         LayoutDeviceIntPoint rootPoint(-1, -1);
         if (widget) {
           rootPoint = anEvent.mRefPoint + widget->WidgetToScreenOffset();
         }
 #ifdef MOZ_WIDGET_GTK
         Window root = GDK_ROOT_WINDOW();
 #else
-        Window root = None; // Could XQueryTree, but this is not important.
+        Window root = X11None; // Could XQueryTree, but this is not important.
 #endif
 
         switch (anEvent.mMessage) {
           case eMouseOver:
           case eMouseOut:
             {
               XCrossingEvent& event = pluginEvent.xcrossing;
               event.type = anEvent.mMessage == eMouseOver ?
@@ -2623,17 +2623,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
               event.root = root;
               event.time = anEvent.mTime;
               event.x = pluginPoint.x;
               event.y = pluginPoint.y;
               event.x_root = rootPoint.x;
               event.y_root = rootPoint.y;
               event.state = XInputEventState(mouseEvent);
               // information lost
-              event.subwindow = None;
+              event.subwindow = X11None;
               event.mode = -1;
               event.detail = NotifyDetailNone;
               event.same_screen = True;
               event.focus = mContentFocused;
             }
             break;
           case eMouseMove:
             {
@@ -2642,17 +2642,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
               event.root = root;
               event.time = anEvent.mTime;
               event.x = pluginPoint.x;
               event.y = pluginPoint.y;
               event.x_root = rootPoint.x;
               event.y_root = rootPoint.y;
               event.state = XInputEventState(mouseEvent);
               // information lost
-              event.subwindow = None;
+              event.subwindow = X11None;
               event.is_hint = NotifyNormal;
               event.same_screen = True;
             }
             break;
           case eMouseDown:
           case eMouseUp:
             {
               XButtonEvent& event = pluginEvent.xbutton;
@@ -2673,17 +2673,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
                 case WidgetMouseEvent::eRightButton:
                   event.button = 3;
                   break;
                 default: // WidgetMouseEvent::eLeftButton;
                   event.button = 1;
                   break;
                 }
               // information lost:
-              event.subwindow = None;
+              event.subwindow = X11None;
               event.same_screen = True;
             }
             break;
           default:
             break;
           }
       }
       break;
@@ -2717,17 +2717,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
               break;
             default:
               break;
             }
 #endif
 
           // Information that could be obtained from pluginEvent but we may not
           // want to promise to provide:
-          event.subwindow = None;
+          event.subwindow = X11None;
           event.x = 0;
           event.y = 0;
           event.x_root = -1;
           event.y_root = -1;
           event.same_screen = False;
         }
       else
         {
@@ -2759,17 +2759,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
   if (!pluginEvent.type) {
     return rv;
   }
 
   // Fill in (useless) generic event information.
   XAnyEvent& event = pluginEvent.xany;
   event.display = widget ?
     static_cast<Display*>(widget->GetNativeData(NS_NATIVE_DISPLAY)) : nullptr;
-  event.window = None; // not a real window
+  event.window = X11None; // not a real window
   // information lost:
   event.serial = 0;
   event.send_event = False;
 
   int16_t response = kNPEventNotHandled;
   mInstance->HandleEvent(&pluginEvent, &response, NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO);
   if (response == kNPEventHandled)
     rv = nsEventStatus_eConsumeNoDefault;
--- a/dom/plugins/base/nsPluginNativeWindowGtk.cpp
+++ b/dom/plugins/base/nsPluginNativeWindowGtk.cpp
@@ -212,17 +212,17 @@ nsresult nsPluginNativeWindowGtk::Create
     return NS_ERROR_FAILURE;
 
   mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
 #if (MOZ_WIDGET_GTK == 2)
   mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
   GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
   mWsInfo.depth = gdkVisual->depth;
 #else
-  mWsInfo.colormap = None;
+  mWsInfo.colormap = X11None;
   GdkVisual* gdkVisual = gdk_window_get_visual(gdkWindow);
   mWsInfo.depth = gdk_visual_get_depth(gdkVisual);
 #endif
   mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
     
   return NS_OK;
 }
 
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -1277,17 +1277,17 @@ PluginInstanceChild::AnswerNPP_SetWindow
                 // workaround https://bugzilla.gnome.org/show_bug.cgi?id=607061
                 // See wrap_gtk_plug_embedded in PluginModuleChild.cpp.
                 g_object_set_data(G_OBJECT(socket_window),
                                   "moz-existed-before-set-window",
                                   GUINT_TO_POINTER(1));
             }
         }
 
-        if (aWindow.visualID != None
+        if (aWindow.visualID != X11None
             && gtk_check_version(2, 12, 10) != nullptr) { // older
             // Workaround for a bug in Gtk+ (prior to 2.12.10) where deleting
             // a foreign GdkColormap will also free the XColormap.
             // http://git.gnome.org/browse/gtk+/log/gdk/x11/gdkcolor-x11.c?id=GTK_2_12_10
             GdkVisual *gdkvisual = gdkx_visual_get(aWindow.visualID);
             GdkColormap *gdkcolor =
                 gdk_x11_colormap_foreign_new(gdkvisual, aWindow.colormap);
 
--- a/dom/plugins/test/testplugin/nptest_gtk2.cpp
+++ b/dom/plugins/test/testplugin/nptest_gtk2.cpp
@@ -76,33 +76,33 @@ pluginInstanceInit(InstanceData* instanc
 #ifdef MOZ_X11
   instanceData->platformData = static_cast<PlatformData*>
     (NPN_MemAlloc(sizeof(PlatformData)));
   if (!instanceData->platformData)
     return NPERR_OUT_OF_MEMORY_ERROR;
 
   instanceData->platformData->display = nullptr;
   instanceData->platformData->visual = nullptr;
-  instanceData->platformData->colormap = None;  
+  instanceData->platformData->colormap = X11None;
   instanceData->platformData->plug = nullptr;
 
   return NPERR_NO_ERROR;
 #else
   // we only support X11 here, since thats what the plugin system uses
   return NPERR_INCOMPATIBLE_VERSION_ERROR;
 #endif
 }
 
 void
 pluginInstanceShutdown(InstanceData* instanceData)
 {
   if (instanceData->hasWidget) {
     Window window = reinterpret_cast<XID>(instanceData->window.window);
 
-    if (window != None) {
+    if (window != X11None) {
       // This window XID should still be valid.
       // See bug 429604 and bug 454756.
       XWindowAttributes attributes;
       if (!XGetWindowAttributes(instanceData->platformData->display, window,
                                 &attributes))
         g_error("XGetWindowAttributes failed at plugin instance shutdown");
     }
   }
--- a/gfx/2d/BorrowedContext.h
+++ b/gfx/2d/BorrowedContext.h
@@ -6,16 +6,17 @@
 #ifndef _MOZILLA_GFX_BORROWED_CONTEXT_H
 #define _MOZILLA_GFX_BORROWED_CONTEXT_H
 
 #include "2D.h"
 
 #ifdef MOZ_X11
 #include <X11/extensions/Xrender.h>
 #include <X11/Xlib.h>
+#include "X11UndefineNone.h"
 #endif
 
 struct _cairo;
 typedef struct _cairo cairo_t;
 
 namespace mozilla {
 
 namespace gfx {
@@ -82,26 +83,26 @@ private:
  * to see if it succeeded. The DrawTarget should not be used while
  * the drawable is borrowed. */
 class BorrowedXlibDrawable
 {
 public:
   BorrowedXlibDrawable()
     : mDT(nullptr),
       mDisplay(nullptr),
-      mDrawable(None),
+      mDrawable(X11None),
       mScreen(nullptr),
       mVisual(nullptr),
       mXRenderFormat(nullptr)
   {}
 
   explicit BorrowedXlibDrawable(DrawTarget *aDT)
     : mDT(nullptr),
       mDisplay(nullptr),
-      mDrawable(None),
+      mDrawable(X11None),
       mScreen(nullptr),
       mVisual(nullptr),
       mXRenderFormat(nullptr)
   {
     Init(aDT);
   }
 
   // We can optionally Init after construction in
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -2158,17 +2158,17 @@ DrawTargetCairo::Draw3DTransformedSurfac
   XRenderSetPictureTransform(display, srcPict, (XTransform*)&xform);
 
   Picture dstPict = XRenderCreatePicture(display,
                                          cairo_xlib_surface_get_drawable(xformSurf),
                                          cairo_xlib_surface_get_xrender_format(xformSurf),
                                          0, nullptr);
 
   XRenderComposite(display, PictOpSrc,
-                   srcPict, None, dstPict,
+                   srcPict, X11None, dstPict,
                    0, 0, 0, 0, 0, 0,
                    xformBounds.width, xformBounds.height);
 
   XRenderFreePicture(display, srcPict);
   XRenderFreePicture(display, dstPict);
 
   cairo_device_release(device);
   cairo_surface_mark_dirty(xformSurf);
@@ -2308,17 +2308,17 @@ BorrowedCairoContext::ReturnCairoContext
 
 #ifdef MOZ_X11
 bool
 BorrowedXlibDrawable::Init(DrawTarget* aDT)
 {
   MOZ_ASSERT(aDT, "Caller should check for nullptr");
   MOZ_ASSERT(!mDT, "Can't initialize twice!");
   mDT = aDT;
-  mDrawable = None;
+  mDrawable = X11None;
 
 #ifdef CAIRO_HAS_XLIB_SURFACE
   if (aDT->GetBackendType() != BackendType::CAIRO ||
       aDT->IsDualDrawTarget() ||
       aDT->IsTiledDrawTarget()) {
     return false;
   }
 
@@ -2351,15 +2351,15 @@ BorrowedXlibDrawable::Init(DrawTarget* a
 
 void
 BorrowedXlibDrawable::Finish()
 {
   DrawTargetCairo* cairoDT = static_cast<DrawTargetCairo*>(mDT);
   cairo_surface_t* surf = cairo_get_group_target(cairoDT->mContext);
   cairo_surface_mark_dirty(surf);
   if (mDrawable) {
-    mDrawable = None;
+    mDrawable = X11None;
   }
 }
 #endif
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -6,16 +6,17 @@
 #ifdef MOZ_WIDGET_GTK
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #define GET_NATIVE_WINDOW(aWidget) GDK_WINDOW_XID((GdkWindow*) aWidget->GetNativeData(NS_NATIVE_WINDOW))
 #endif
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include "X11UndefineNone.h"
 
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/widget/CompositorWidget.h"
 #include "mozilla/Unused.h"
 
 #include "prenv.h"
 #include "GLContextProvider.h"
@@ -303,36 +304,36 @@ GLXLibrary::SupportsVideoSync()
 
     return mHasVideoSync;
 }
 
 GLXPixmap
 GLXLibrary::CreatePixmap(gfxASurface* aSurface)
 {
     if (!SupportsTextureFromPixmap(aSurface)) {
-        return None;
+        return X11None;
     }
 
     gfxXlibSurface* xs = static_cast<gfxXlibSurface*>(aSurface);
     const XRenderPictFormat* format = xs->XRenderFormat();
     if (!format || format->type != PictTypeDirect) {
-        return None;
+        return X11None;
     }
     const XRenderDirectFormat& direct = format->direct;
     int alphaSize = FloorLog2(direct.alphaMask + 1);
     NS_ASSERTION((1 << alphaSize) - 1 == direct.alphaMask,
                  "Unexpected render format with non-adjacent alpha bits");
 
     int attribs[] = { LOCAL_GLX_DOUBLEBUFFER, False,
                       LOCAL_GLX_DRAWABLE_TYPE, LOCAL_GLX_PIXMAP_BIT,
                       LOCAL_GLX_ALPHA_SIZE, alphaSize,
                       (alphaSize ? LOCAL_GLX_BIND_TO_TEXTURE_RGBA_EXT
                        : LOCAL_GLX_BIND_TO_TEXTURE_RGB_EXT), True,
                       LOCAL_GLX_RENDER_TYPE, LOCAL_GLX_RGBA_BIT,
-                      None };
+                      X11None };
 
     int numConfigs = 0;
     Display* display = xs->XDisplay();
     int xscreen = DefaultScreen(display);
 
     ScopedXFree<GLXFBConfig> cfgs(xChooseFBConfig(display,
                                                   xscreen,
                                                   attribs,
@@ -346,17 +347,17 @@ GLXLibrary::CreatePixmap(gfxASurface* aS
         static_cast<unsigned long>(direct.greenMask) << direct.green;
     unsigned long blueMask =
         static_cast<unsigned long>(direct.blueMask) << direct.blue;
     // This is true if the Pixmap has bits for alpha or unused bits.
     bool haveNonColorBits =
         ~(redMask | greenMask | blueMask) != -1UL << format->depth;
 
     for (int i = 0; i < numConfigs; i++) {
-        int id = None;
+        int id = X11None;
         sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &id);
         Visual* visual;
         int depth;
         FindVisualAndDepth(display, id, &visual, &depth);
         if (!visual ||
             visual->c_class != TrueColor ||
             visual->red_mask != redMask ||
             visual->green_mask != greenMask ||
@@ -419,24 +420,24 @@ GLXLibrary::CreatePixmap(gfxASurface* aS
         matchIndex = i;
         break;
     }
     if (matchIndex == -1) {
         // GLX can't handle A8 surfaces, so this is not really unexpected. The
         // caller should deal with this situation.
         NS_WARN_IF_FALSE(format->depth == 8,
                          "[GLX] Couldn't find a FBConfig matching Pixmap format");
-        return None;
+        return X11None;
     }
 
     int pixmapAttribs[] = { LOCAL_GLX_TEXTURE_TARGET_EXT, LOCAL_GLX_TEXTURE_2D_EXT,
                             LOCAL_GLX_TEXTURE_FORMAT_EXT,
                             (alphaSize ? LOCAL_GLX_TEXTURE_FORMAT_RGBA_EXT
                              : LOCAL_GLX_TEXTURE_FORMAT_RGB_EXT),
-                            None};
+                            X11None};
 
     GLXPixmap glxpixmap = xCreatePixmap(display,
                                         cfgs[matchIndex],
                                         xs->XDrawable(),
                                         pixmapAttribs);
 
     return glxpixmap;
 }
@@ -895,17 +896,17 @@ GLContextGLX::~GLContextGLX()
     if (!mOwnsContext) {
         return;
     }
 
     // see bug 659842 comment 76
 #ifdef DEBUG
     bool success =
 #endif
-    mGLX->xMakeCurrent(mDisplay, None, nullptr);
+    mGLX->xMakeCurrent(mDisplay, X11None, nullptr);
     MOZ_ASSERT(success,
                "glXMakeCurrent failed to release GL context before we call "
                "glXDestroyContext!");
 
     mGLX->xDestroyContext(mDisplay, mContext);
 
     if (mDeleteDrawable) {
         mGLX->xDestroyPixmap(mDisplay, mDrawable);
@@ -1237,17 +1238,17 @@ GLContextGLX::FindFBConfigForWindow(Disp
         return false;
     }
     const VisualID windowVisualID = XVisualIDFromVisual(windowAttrs.visual);
 #ifdef DEBUG
     printf("[GLX] window %lx has VisualID 0x%lx\n", window, windowVisualID);
 #endif
 
     for (int i = 0; i < numConfigs; i++) {
-        int visid = None;
+        int visid = X11None;
         sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid);
         if (!visid) {
             continue;
         }
         if (sGLXLibrary.IsATI()) {
             int depth;
             Visual* visual;
             FindVisualAndDepth(display, visid, &visual, &depth);
--- a/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
+++ b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp
@@ -6,16 +6,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ShadowLayerUtilsX11.h"
 #include <X11/X.h>                      // for Drawable, XID
 #include <X11/Xlib.h>                   // for Display, Visual, etc
 #include <X11/extensions/Xrender.h>     // for XRenderPictFormat, etc
 #include <X11/extensions/render.h>      // for PictFormat
 #include "cairo-xlib.h"
+#include "X11UndefineNone.h"
 #include <stdint.h>                     // for uint32_t
 #include "GLDefs.h"                     // for GLenum
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "gfxXlibSurface.h"             // for gfxXlibSurface
 #include "gfx2DGlue.h"                  // for Moz2D transistion helpers
 #include "mozilla/X11Util.h"            // for DefaultXDisplay, FinishX, etc
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositableForwarder.h"
@@ -60,17 +61,17 @@ GetXRenderPictFormatFromId(Display* aDis
   tmplate.id = aFormatId;
   return XRenderFindFormat(aDisplay, PictFormatID, &tmplate, 0);
 }
 
 SurfaceDescriptorX11::SurfaceDescriptorX11(gfxXlibSurface* aSurf,
                                            bool aForwardGLX)
   : mId(aSurf->XDrawable())
   , mSize(aSurf->GetSize())
-  , mGLXPixmap(None)
+  , mGLXPixmap(X11None)
 {
   const XRenderPictFormat *pictFormat = aSurf->XRenderFormat();
   if (pictFormat) {
     mFormat = pictFormat->id;
   } else {
     mFormat = cairo_xlib_surface_get_visual(aSurf->CairoSurface())->visualid;
   }
 
@@ -81,17 +82,17 @@ SurfaceDescriptorX11::SurfaceDescriptorX
 #endif
 }
 
 SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID,
                                            const gfx::IntSize& aSize)
   : mId(aDrawable)
   , mFormat(aFormatID)
   , mSize(aSize)
-  , mGLXPixmap(None)
+  , mGLXPixmap(X11None)
 { }
 
 already_AddRefed<gfxXlibSurface>
 SurfaceDescriptorX11::OpenForeign() const
 {
   Display* display = DefaultXDisplay();
   Screen* screen = DefaultScreenOfDisplay(display);
 
new file mode 100644
--- /dev/null
+++ b/gfx/src/X11UndefineNone.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef MOZILLA_GFX_X11UNDEFINENONE_H_
+#define MOZILLA_GFX_X11UNDEFINENONE_H_
+
+// The header <X11/X.h> defines "None" as a macro that expands to "0L".
+// This is terrible because many enumerations have an enumerator named "None".
+// To work around this, we undefine the macro "None", and define a replacement
+// macro named "X11None".
+// Include this header after including X11 headers, where necessary.
+#ifdef None
+#  undef None
+#  define X11None 0L
+// <X11/X.h> also defines "RevertToNone" as a macro that expands to "(int)None".
+// Since we are undefining "None", that stops working. To keep it working,
+// we undefine "RevertToNone" and redefine it in terms of "X11None".
+#  ifdef RevertToNone
+#    undef RevertToNone
+#    define RevertToNone (int)X11None
+#  endif
+#endif
+
+#endif /* MOZILLA_GFX_X11UNDEFINENONE_H_ */
--- a/gfx/src/X11Util.cpp
+++ b/gfx/src/X11Util.cpp
@@ -24,17 +24,17 @@ FindVisualAndDepth(Display* aDisplay, Vi
             if (visual->visualid == aVisualID) {
                 *aVisual = visual;
                 *aDepth = d_info->depth;
                 return;
             }
         }
     }
 
-    NS_ASSERTION(aVisualID == None, "VisualID not on Screen.");
+    NS_ASSERTION(aVisualID == X11None, "VisualID not on Screen.");
     *aVisual = nullptr;
     *aDepth = 0;
     return;
 }
 
 void
 FinishX(Display* aDisplay)
 {
--- a/gfx/src/X11Util.h
+++ b/gfx/src/X11Util.h
@@ -8,16 +8,17 @@
 #ifndef mozilla_X11Util_h
 #define mozilla_X11Util_h
 
 // Utilities common to all X clients, regardless of UI toolkit.
 
 #if defined(MOZ_WIDGET_GTK)
 #  include <gdk/gdk.h>
 #  include <gdk/gdkx.h>
+#  include "X11UndefineNone.h"
 #else
 #  error Unknown toolkit
 #endif
 
 #include <string.h>                     // for memset
 #include "mozilla/Scoped.h"             // for SCOPED_TEMPLATE
 
 namespace mozilla {
--- a/gfx/src/moz.build
+++ b/gfx/src/moz.build
@@ -34,16 +34,17 @@ EXPORTS += [
     'nsRegion.h',
     'nsRegionFwd.h',
     'nsRenderingContext.h',
     'nsSize.h',
     'nsThemeConstants.h',
     'nsTransform2D.h',
     'PingPongRegion.h',
     'RegionBuilder.h',
+    'X11UndefineNone.h'
 ]
 
 EXPORTS.mozilla += [
     'AppUnits.h',
     'ArrayView.h',
 ]
 
 EXPORTS.mozilla.gfx += [
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -20,59 +20,59 @@
 #include "mozilla/CheckedInt.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
-    , mGLXPixmap(None)
+    , mGLXPixmap(X11None)
 #endif
 {
     const gfx::IntSize size = DoSizeQuery();
     cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfx::IntSize& size)
     : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
-    , mGLXPixmap(None)
+    , mGLXPixmap(X11None)
 #endif
 {
     NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad size");
 
     cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format,
                                const gfx::IntSize& size)
     : mPixmapTaken(false), mDisplay(DisplayOfScreen(screen)),
       mDrawable(drawable)
 #if defined(GL_PROVIDER_GLX)
-      , mGLXPixmap(None)
+      , mGLXPixmap(X11None)
 #endif
 {
     NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
                  "Bad Size");
 
     cairo_surface_t *surf =
         cairo_xlib_surface_create_with_xrender_format(mDisplay, drawable,
                                                       screen, format,
                                                       size.width, size.height);
     Init(surf);
 }
 
 gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf)
     : mPixmapTaken(false)
 #if defined(GL_PROVIDER_GLX)
-      , mGLXPixmap(None)
+      , mGLXPixmap(X11None)
 #endif
 {
     NS_PRECONDITION(cairo_surface_status(csurf) == 0,
                     "Not expecting an error surface");
 
     mDrawable = cairo_xlib_surface_get_drawable(csurf);
     mDisplay = cairo_xlib_surface_get_display(csurf);
 
@@ -92,19 +92,19 @@ gfxXlibSurface::~gfxXlibSurface()
     }
 }
 
 static Drawable
 CreatePixmap(Screen *screen, const gfx::IntSize& size, unsigned int depth,
              Drawable relatedDrawable)
 {
     if (!Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT))
-        return None;
+        return X11None;
 
-    if (relatedDrawable == None) {
+    if (relatedDrawable == X11None) {
         relatedDrawable = RootWindowOfScreen(screen);
     }
     Display *dpy = DisplayOfScreen(screen);
     // X gives us a fatal error if we try to create a pixmap of width
     // or height 0
     return XCreatePixmap(dpy, relatedDrawable,
                          std::max(1, size.width), std::max(1, size.height),
                          depth);
@@ -269,17 +269,17 @@ gfxXlibSurface::CreateSimilarSurface(gfx
 }
 
 void
 gfxXlibSurface::Finish()
 {
 #if defined(GL_PROVIDER_GLX)
     if (mPixmapTaken && mGLXPixmap) {
         gl::sGLXLibrary.DestroyPixmap(mDisplay, mGLXPixmap);
-        mGLXPixmap = None;
+        mGLXPixmap = X11None;
     }
 #endif
     gfxASurface::Finish();
 }
 
 const gfx::IntSize
 gfxXlibSurface::GetSize() const
 {
--- a/gfx/thebes/gfxXlibSurface.h
+++ b/gfx/thebes/gfxXlibSurface.h
@@ -5,16 +5,17 @@
 
 #ifndef GFX_XLIBSURFACE_H
 #define GFX_XLIBSURFACE_H
 
 #include "gfxASurface.h"
 
 #include <X11/extensions/Xrender.h>
 #include <X11/Xlib.h>
+#include "X11UndefineNone.h"
 
 #if defined(GL_PROVIDER_GLX)
 #include "GLXLibrary.h"
 #endif
 
 #include "nsSize.h"
 
 // Although the dimension parameters in the xCreatePixmapReq wire protocol are
@@ -41,23 +42,23 @@ public:
     explicit gfxXlibSurface(cairo_surface_t *csurf);
 
     // create a new Pixmap and wrapper surface.
     // |relatedDrawable| provides a hint to the server for determining whether
     // the pixmap should be in video or system memory.  It must be on
     // |screen| (if specified).
     static already_AddRefed<gfxXlibSurface>
     Create(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size,
-           Drawable relatedDrawable = None);
+           Drawable relatedDrawable = X11None);
     static cairo_surface_t *
     CreateCairoSurface(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size,
-                       Drawable relatedDrawable = None);
+                       Drawable relatedDrawable = X11None);
     static already_AddRefed<gfxXlibSurface>
     Create(Screen* screen, XRenderPictFormat *format, const mozilla::gfx::IntSize& size,
-           Drawable relatedDrawable = None);
+           Drawable relatedDrawable = X11None);
 
     virtual ~gfxXlibSurface();
 
     virtual already_AddRefed<gfxASurface>
     CreateSimilarSurface(gfxContentType aType,
                          const mozilla::gfx::IntSize& aSize) override;
     virtual void Finish() override;
 
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -1025,17 +1025,17 @@ wait_for_text(GtkClipboard *clipboard)
     return static_cast<gchar*>(context->Wait());
 }
 
 static GdkFilterReturn
 selection_request_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
 {
     XEvent *xevent = static_cast<XEvent*>(gdk_xevent);
     if (xevent->xany.type == SelectionRequest) {
-        if (xevent->xselectionrequest.requestor == None)
+        if (xevent->xselectionrequest.requestor == X11None)
             return GDK_FILTER_REMOVE;
 
         GdkDisplay *display = gdk_x11_lookup_xdisplay(
                 xevent->xselectionrequest.display);
         if (!display)
             return GDK_FILTER_REMOVE;
 
         GdkWindow *window = gdk_x11_window_foreign_new_for_display(display,
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -447,17 +447,17 @@ nsWindow::nsWindow()
     mSizeState           = nsSizeMode_Normal;
     mLastSizeMode        = nsSizeMode_Normal;
     mSizeConstraints.mMaxSize = GetSafeWindowSize(mSizeConstraints.mMaxSize);
 
 #ifdef MOZ_X11
     mOldFocusWindow      = 0;
 
     mXDisplay = nullptr;
-    mXWindow  = None;
+    mXWindow  = X11None;
     mXVisual  = nullptr;
     mXDepth   = 0;
 #endif /* MOZ_X11 */
     mPluginType          = PluginType_NONE;
 
     if (!gGlobalsInitialized) {
         gGlobalsInitialized = true;
 
@@ -4582,17 +4582,17 @@ nsWindow::ClearTransparencyBitmap()
 
 #ifdef MOZ_X11
     if (!mGdkWindow)
         return;
 
     Display* xDisplay = GDK_WINDOW_XDISPLAY(mGdkWindow);
     Window xWindow = gdk_x11_window_get_xid(mGdkWindow);
 
-    XShapeCombineMask(xDisplay, xWindow, ShapeBounding, 0, 0, None, ShapeSet);
+    XShapeCombineMask(xDisplay, xWindow, ShapeBounding, 0, 0, X11None, ShapeSet);
 #endif
 }
 
 nsresult
 nsWindow::UpdateTranslucentWindowAlphaInternal(const nsIntRect& aRect,
                                                uint8_t* aAlphas, int32_t aStride)
 {
     if (!mShell) {