Bug 703155 - Port Mozilla Qt to Qt5. r=mark.finkle,mh+mozilla,dougt
authorOleg Romashin <romaxa@gmail.com>
Thu, 22 Mar 2012 16:24:40 -0700
changeset 92181 82fe9c59db85fab8bc7a9c090f611ba62b90a8f8
parent 92180 f65ae1a9074dee9a64ec8ba9a1cf0a2af6f56b47
child 92182 00e08da6ff720301859232f5851a3dab14149169
push idunknown
push userunknown
push dateunknown
reviewersmark
bugs703155
milestone14.0a1
Bug 703155 - Port Mozilla Qt to Qt5. r=mark.finkle,mh+mozilla,dougt
configure.in
dom/plugins/base/nsNPAPIPlugin.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/test/testplugin/nptest_qt.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/src/X11Util.h
gfx/thebes/gfxQtPlatform.cpp
gfx/thebes/gfxQtPlatform.h
ipc/chromium/src/base/message_pump_qt.cc
mobile/xul/components/build/nsShellService.cpp
toolkit/components/remote/nsQtRemoteService.cpp
toolkit/xre/nsAppRunner.cpp
widget/qt/faststartupqt/nsFastStartupQt.cpp
widget/qt/moziqwidget.h
widget/qt/mozqwidget.cpp
widget/qt/nsIdleServiceQt.cpp
widget/qt/nsNativeThemeQt.cpp
widget/qt/nsNativeThemeQt.h
widget/qt/nsWindow.cpp
widget/qt/nsWindow.h
widget/shared/nsShmImage.cpp
widget/shared/nsShmImage.h
--- a/configure.in
+++ b/configure.in
@@ -4964,30 +4964,50 @@ dnl ====================================
 if test "$MOZ_ENABLE_QT"
 then
     MOZ_ARG_WITH_STRING(qtdir,
     [  --with-qtdir=\$dir       Specify Qt directory ],
     [ QTDIR=$withval])
 
     if test -z "$QTDIR"; then
         PKG_CHECK_MODULES(MOZ_QT, QtGui QtNetwork QtCore QtOpenGL)
+        PKG_CHECK_MODULES(MOZ_QT5, QtWidgets QtMultimedia QtPrintSupport QtQuick1,
+                      MOZ_ENABLE_QT5=1,
+                      MOZ_ENABLE_QT5=)
+        if test "$MOZ_ENABLE_QT5"; then
+            echo "Using qt5"
+            MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS $MOZ_QT5_CFLAGS"
+            MOZ_QT_LIBS="$MOZ_QT_LIBS $MOZ_QT5_LIBS"
+        fi
+
         AC_CHECK_PROGS(HOST_MOC, $MOC moc, "")
         AC_CHECK_PROGS(HOST_RCC, $RCC rcc, "")
     else
         MOZ_QT_LIBS="-L$QTDIR/lib/ -lQtGui -lQtNetwork -lQtCore -lQtXml -lQtOpenGL"
 
         MOZ_QT_CFLAGS="-DQT_SHARED"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/Qt"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtGui"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtCore"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtNetwork"
         MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtXml"
+        MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtDeclarative"
         HOST_MOC="$QTDIR/bin/moc"
         HOST_RCC="$QTDIR/bin/rcc"
+
+        # QtWidgets was introduced only in Qt5
+        if test -d $QTDIR/include/QtWidgets; then
+            echo "Using qt5"
+            MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtWidgets"
+            MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtMultimedia"
+            MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtPrintSupport"
+            MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I$QTDIR/include/QtQuick1"
+            MOZ_QT_LIBS="$MOZ_QT_LIBS -lQtWidgets -lQtMultimedia -lQtPrintSupport -lQtQuick1"
+        fi
     fi
     if test -z "$HOST_MOC"; then
         AC_MSG_ERROR([No acceptable moc preprocessor found. Qt SDK is not installed or --with-qt is
 incorrect])
     fi
     if test -z "$HOST_RCC"; then
         AC_MSG_ERROR([No acceptable rcc preprocessor found. Qt SDK is not installed or --with-qt is
 incorrect])
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -31,20 +31,16 @@
  * 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 ***** */
 
-#ifdef MOZ_WIDGET_QT
-#include <QX11Info>
-#endif
-
 #include "base/basictypes.h"
 
 /* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
 #include "mozilla/Util.h"
 
 #include "prtypes.h"
 #include "prmem.h"
 #include "prenv.h"
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -42,18 +42,22 @@
  * 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 ***** */
 
 #ifdef MOZ_WIDGET_QT
 #include <QWidget>
 #include <QKeyEvent>
-#ifdef MOZ_X11
+#if defined(MOZ_X11)
+#if defined(Q_WS_X11)
 #include <QX11Info>
+#else
+#include "gfxQtPlatform.h"
+#endif
 #endif
 #undef slots
 #endif
 
 #ifdef MOZ_X11
 #include <cairo-xlib.h>
 #include "gfxXlibSurface.h"
 /* X headers suck */
@@ -2426,17 +2430,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
           static_cast<const nsMouseEvent&>(anEvent);
         // Get reference point relative to screen:
         nsIntPoint rootPoint(-1,-1);
         if (widget)
           rootPoint = anEvent.refPoint + widget->WidgetToScreenOffset();
 #ifdef MOZ_WIDGET_GTK2
         Window root = GDK_ROOT_WINDOW();
 #elif defined(MOZ_WIDGET_QT)
-        Window root = QX11Info::appRootWindow();
+        Window root = RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay()));
 #else
         Window root = None; // Could XQueryTree, but this is not important.
 #endif
 
         switch (anEvent.message)
           {
           case NS_MOUSE_ENTER_SYNTH:
           case NS_MOUSE_EXIT_SYNTH:
@@ -2542,18 +2546,23 @@ nsEventStatus nsPluginInstanceOwner::Pro
 
 #ifdef MOZ_WIDGET_QT
           const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent);
 
           memset( &event, 0, sizeof(event) );
           event.time = anEvent.time;
 
           QWidget* qWidget = static_cast<QWidget*>(widget->GetNativeData(NS_NATIVE_WINDOW));
+
           if (qWidget)
+#if defined(Q_WS_X11)
             event.root = qWidget->x11Info().appRootWindow();
+#else
+            event.root = RootWindowOfScreen(DefaultScreenOfDisplay(gfxQtPlatform::GetXDisplay(qWidget)));
+#endif
 
           // deduce keycode from the information in the attached QKeyEvent
           const QKeyEvent* qtEvent = static_cast<const QKeyEvent*>(anEvent.pluginEvent);
           if (qtEvent) {
 
             if (qtEvent->nativeModifiers())
               event.state = qtEvent->nativeModifiers();
             else // fallback
@@ -3060,19 +3069,19 @@ void nsPluginInstanceOwner::Paint(gfxCon
 #ifdef MOZ_WIDGET_GTK2
   // This is the visual used by the widgets, 24-bit if available.
   GdkVisual* gdkVisual = gdk_rgb_get_visual();
   Visual* visual = gdk_x11_visual_get_xvisual(gdkVisual);
   Screen* screen =
     gdk_x11_screen_get_xscreen(gdk_visual_get_screen(gdkVisual));
 #endif
 #ifdef MOZ_WIDGET_QT
-  Display* dpy = QX11Info().display();
-  Screen* screen = ScreenOfDisplay(dpy, QX11Info().screen());
-  Visual* visual = static_cast<Visual*>(QX11Info().visual());
+  Display* dpy = mozilla::DefaultXDisplay();
+  Screen* screen = DefaultScreenOfDisplay(dpy);
+  Visual* visual = DefaultVisualOfScreen(screen);
 #endif
   renderer.Draw(aContext, nsIntSize(window->width, window->height),
                 rendererFlags, screen, visual, nsnull);
 }
 nsresult
 nsPluginInstanceOwner::Renderer::DrawWithXlib(gfxXlibSurface* xsurface, 
                                               nsIntPoint offset,
                                               nsIntRect *clipRects, 
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -80,17 +80,16 @@ using namespace std;
 #ifdef MOZ_WIDGET_GTK2
 
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdk.h>
 #include "gtk2xtbin.h"
 
 #elif defined(MOZ_WIDGET_QT)
-#include <QX11Info>
 #undef KeyPress
 #undef KeyRelease
 #elif defined(OS_WIN)
 #ifndef WM_MOUSEHWHEEL
 #define WM_MOUSEHWHEEL     0x020E
 #endif
 
 #include "nsWindowsDllInterceptor.h"
--- a/dom/plugins/test/testplugin/nptest_qt.cpp
+++ b/dom/plugins/test/testplugin/nptest_qt.cpp
@@ -116,52 +116,56 @@ pluginDrawWindow(InstanceData* instanceD
   int width = window.width;
   int height = window.height;
 
 #ifdef MOZ_X11
   XEvent* nsEvent = (XEvent*)event;
   const XGraphicsExposeEvent& expose = nsEvent->xgraphicsexpose;
 
   QColor drawColor((QColor)instanceData->scriptableObject->drawColor);//QRgb qRgba ( int r, int g, int b, int a )
+#ifdef Q_WS_X11
   QPixmap pixmap = QPixmap::fromX11Pixmap(expose.drawable, QPixmap::ExplicitlyShared);
 
   QRect exposeRect(expose.x, expose.y, expose.width, expose.height);
   if (instanceData->scriptableObject->drawMode == DM_SOLID_COLOR) {
     //printf("Drawing Solid\n");
     // drawing a solid color for reftests
     QPainter painter(&pixmap);
     painter.fillRect(exposeRect, drawColor);
     notifyDidPaint(instanceData);
     return;
 
   }
 #endif
+#endif
 
   NPP npp = instanceData->npp;
   if (!npp)
     return;
 
   QString text (NPN_UserAgent(npp));
   if (text.isEmpty())
     return;
 
 #ifdef MOZ_X11
+#ifdef Q_WS_X11
   //printf("Drawing Default\n");
   // drawing a solid color for reftests
   QColor color;
   QPainter painter(&pixmap);
   QRect theRect(x, y, width, height);
   QRect clipRect(QPoint(window.clipRect.left, window.clipRect.top),
                  QPoint(window.clipRect.right, window.clipRect.bottom));
   painter.setClipRect(clipRect);
   painter.fillRect(theRect, QColor(128,128,128,255));
   painter.drawRect(theRect);
   painter.drawText(QRect(theRect), Qt::AlignCenter, text);
   notifyDidPaint(instanceData);
 #endif
+#endif
   return;
 }
 
 int16_t
 pluginHandleEvent(InstanceData* instanceData, void* event)
 {
 #ifdef MOZ_X11
   XEvent* nsEvent = (XEvent*)event;
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -35,18 +35,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #define GET_NATIVE_WINDOW(aWidget) GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
 #elif defined(MOZ_WIDGET_QT)
 #include <QWidget>
-#include <QX11Info>
-#define GET_NATIVE_WINDOW(aWidget) static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->handle()
+#define GET_NATIVE_WINDOW(aWidget) static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
 #endif
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
 #include "mozilla/X11Util.h"
 
 #include "prenv.h"
--- a/gfx/src/X11Util.h
+++ b/gfx/src/X11Util.h
@@ -40,20 +40,18 @@
 #ifndef mozilla_X11Util_h
 #define mozilla_X11Util_h
 
 // Utilities common to all X clients, regardless of UI toolkit.
 
 #if defined(MOZ_WIDGET_GTK2)
 #  include <gdk/gdkx.h>
 #elif defined(MOZ_WIDGET_QT)
-// X11/X.h has #define CursorShape 0, but Qt's qnamespace.h defines
-//   enum CursorShape { ... }.  Good times!
+#include "gfxQtPlatform.h"
 #undef CursorShape
-#  include <QX11Info>
 #  include <X11/Xlib.h>
 #else
 #  error Unknown toolkit
 #endif 
 
 #include "gfxCore.h"
 #include "nsDebug.h"
 
@@ -63,17 +61,17 @@ namespace mozilla {
  * Return the default X Display created and used by the UI toolkit.
  */
 inline Display*
 DefaultXDisplay()
 {
 #if defined(MOZ_WIDGET_GTK2)
   return GDK_DISPLAY();
 #elif defined(MOZ_WIDGET_QT)
-  return QX11Info::display();
+  return gfxQtPlatform::GetXDisplay();
 #endif
 }
 
 /**
  * Sets *aVisual to point to aDisplay's Visual struct corresponding to
  * aVisualID, and *aDepth to its depth.  When aVisualID is None, these are set
  * to NULL and 0 respectively.  Both out-parameter pointers are assumed
  * non-NULL.  Returns true in both of these situations, but false if aVisualID
--- a/gfx/thebes/gfxQtPlatform.cpp
+++ b/gfx/thebes/gfxQtPlatform.cpp
@@ -32,17 +32,22 @@
  * 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 <QPixmap>
-#include <QX11Info>
+#include <qglobal.h>
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
+#  include <QX11Info>
+#else
+#  include <QPlatformNativeInterface>
+#endif
 #include <QApplication>
 #include <QDesktopWidget>
 #include <QPaintEngine>
 
 #include "gfxQtPlatform.h"
 
 #include "gfxFontconfigUtils.h"
 
@@ -80,17 +85,21 @@
 #endif
 
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 using namespace mozilla::unicode;
 using namespace mozilla::gfx;
 
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
 #define DEFAULT_RENDER_MODE RENDER_DIRECT
+#else
+#define DEFAULT_RENDER_MODE RENDER_BUFFERED
+#endif
 
 static QPaintEngine::Type sDefaultQtPaintEngineType = QPaintEngine::Raster;
 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull;
 static cairo_user_data_key_t cairo_qt_pixmap_key;
 static void do_qt_pixmap_unref (void *data)
 {
     QPixmap *pmap = (QPixmap*)data;
     delete pmap;
@@ -192,16 +201,50 @@ gfxQtPlatform::~gfxQtPlatform()
     // It would be nice to do this (although it might need to be after
     // the cairo shutdown that happens in ~gfxPlatform).  It even looks
     // idempotent.  But it has fatal assertions that fire if stuff is
     // leaked, and we hit them.
     FcFini();
 #endif
 }
 
+#ifdef MOZ_X11
+Display*
+gfxQtPlatform::GetXDisplay(QWidget* aWindow)
+{
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
+#ifdef Q_WS_X11
+  return aWindow ? aWindow->x11Info().display() : QX11Info::display();
+#else
+  return nsnull;
+#endif
+#else
+  return (Display*)(qApp->platformNativeInterface()->
+    nativeResourceForWindow("display", aWindow ? aWindow->windowHandle() : nsnull));
+#endif
+}
+
+Screen*
+gfxQtPlatform::GetXScreen(QWidget* aWindow)
+{
+#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
+#ifdef Q_WS_X11
+  return ScreenOfDisplay(GetXDisplay(aWindow), aWindow ? aWindow->x11Info().screen() : QX11Info().screen());
+#else
+  return nsnull;
+#endif
+#else
+  return ScreenOfDisplay(GetXDisplay(aWindow),
+                         (int)qApp->platformNativeInterface()->
+                           nativeResourceForWindow("screen",
+                             aWindow ? aWindow->windowHandle() : nsnull));
+#endif
+}
+#endif
+
 already_AddRefed<gfxASurface>
 gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
                                       gfxASurface::gfxContentType contentType)
 {
     nsRefPtr<gfxASurface> newSurface = nsnull;
 
     // try to optimize it for 16bpp screen
     gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
@@ -219,19 +262,19 @@ gfxQtPlatform::CreateOffscreenSurface(co
     if ((mRenderMode == RENDER_BUFFERED || mRenderMode == RENDER_DIRECT) &&
         sDefaultQtPaintEngineType != QPaintEngine::X11) {
       newSurface = new gfxImageSurface(size, imageFormat);
       return newSurface.forget();
     }
 
 #ifdef MOZ_X11
     XRenderPictFormat* xrenderFormat =
-        gfxXlibSurface::FindRenderFormat(QX11Info().display(), imageFormat);
+        gfxXlibSurface::FindRenderFormat(GetXDisplay(), imageFormat);
 
-    Screen* screen = ScreenOfDisplay(QX11Info().display(), QX11Info().screen());
+    Screen* screen = GetXScreen();
     newSurface = gfxXlibSurface::Create(screen, xrenderFormat, size);
 #endif
 
     if (newSurface) {
         gfxContext ctx(newSurface);
         ctx.SetOperator(gfxContext::OPERATOR_CLEAR);
         ctx.Paint();
     }
--- a/gfx/thebes/gfxQtPlatform.h
+++ b/gfx/thebes/gfxQtPlatform.h
@@ -38,18 +38,22 @@
 
 #ifndef GFX_PLATFORM_QT_H
 #define GFX_PLATFORM_QT_H
 
 #include "gfxPlatform.h"
 #include "nsAutoRef.h"
 #include "nsDataHashtable.h"
 #include "nsTArray.h"
+#ifdef MOZ_X11
+#include "X11/Xlib.h"
+#endif
 
 class gfxFontconfigUtils;
+class QWidget;
 #ifndef MOZ_PANGO
 typedef struct FT_LibraryRec_ *FT_Library;
 
 class FontFamily;
 class FontEntry;
 #endif
 
 class THEBES_API gfxQtPlatform : public gfxPlatform {
@@ -133,16 +137,20 @@ public:
 #endif
 
     RenderMode GetRenderMode() { return mRenderMode; }
     void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
 
     static PRInt32 GetDPI();
 
     virtual gfxImageFormat GetOffscreenFormat();
+#ifdef MOZ_X11
+    static Display* GetXDisplay(QWidget* aWindow = 0);
+    static Screen* GetXScreen(QWidget* aWindow = 0);
+#endif
 
 protected:
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 
     // TODO: unify this with mPrefFonts (NB: holds families, not fonts) in gfxPlatformFontList
--- a/ipc/chromium/src/base/message_pump_qt.cc
+++ b/ipc/chromium/src/base/message_pump_qt.cc
@@ -1,19 +1,19 @@
 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_pump_qt.h"
-
 #include <qabstracteventdispatcher.h>
 #include <qevent.h>
-#include <qapplication.h>
+#include <QApplication>
 #include <qtimer.h>
 
+#include "base/message_pump_qt.h"
+
 #include <fcntl.h>
 #include <limits>
 #include <math.h>
 
 #include "base/eintr_wrapper.h"
 #include "base/lazy_instance.h"
 #include "base/logging.h"
 #include "base/platform_thread.h"
--- a/mobile/xul/components/build/nsShellService.cpp
+++ b/mobile/xul/components/build/nsShellService.cpp
@@ -39,18 +39,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #if (MOZ_PLATFORM_MAEMO == 5)
 #include <dbus/dbus.h>
 #endif
 
 #ifdef MOZ_WIDGET_QT
-#include <QtGui/QApplication>
-#include <QtGui/QWidget>
+#include <QApplication>
+#include <QWidget>
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "AndroidBridge.h"
 #endif
 
 #include "nsShellService.h"
 #include "nsString.h"
--- a/toolkit/components/remote/nsQtRemoteService.cpp
+++ b/toolkit/components/remote/nsQtRemoteService.cpp
@@ -35,20 +35,20 @@
  * 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 <QWidget>
-#include <QX11Info>
 #include "nsQtRemoteService.h"
 
 #include "mozilla/ModuleUtils.h"
+#include "mozilla/X11Util.h"
 #include "nsIServiceManager.h"
 #include "nsIAppShellService.h"
 
 #include "nsCOMPtr.h"
 
 /**
   Helper class which is used to receive notification about property changes
 */
@@ -132,17 +132,17 @@ nsQtRemoteService::Shutdown()
 
   return NS_OK;
 }
 
 void
 nsQtRemoteService::PropertyNotifyEvent(XEvent *aEvt)
 {
   HandleNewProperty(aEvt->xproperty.window,
-                    QX11Info::display(),
+                    mozilla::DefaultXDisplay(),
                     aEvt->xproperty.time,
                     aEvt->xproperty.atom,
                     0);
 }
 
 void
 nsQtRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID,
                                                   PRUint32 aTimestamp)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -44,20 +44,23 @@
 #if defined(XP_OS2) && defined(MOZ_OS2_HIGH_MEMORY)
 // os2safe.h has to be included before os2.h, needed for high mem
 #include <os2safe.h>
 #endif
 
 #define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
 
 #if defined(MOZ_WIDGET_QT)
-#include <QtGui/QApplication>
+#include <QApplication>
+#include <QStringList>
 #include "nsQAppInstance.h"
-#include <QtGui/QInputContextFactory>
-#include <QtGui/QInputContext>
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+#include <QInputContextFactory>
+#include <QInputContext>
+#endif
 #endif // MOZ_WIDGET_QT
 
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentChild.h"
 
 #include "mozilla/Util.h"
 
 #include "nsAppRunner.h"
--- a/widget/qt/faststartupqt/nsFastStartupQt.cpp
+++ b/widget/qt/faststartupqt/nsFastStartupQt.cpp
@@ -31,17 +31,17 @@
  * 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 <QtGui/QApplication>
+#include <QApplication>
 #include "nsQAppInstance.h"
 #include <QtOpenGL/QGLWidget>
 #include <QThread>
 #if defined MOZ_ENABLE_MEEGOTOUCH
 #include <MScene>
 #endif
 #include "moziqwidget.h"
 #include "mozqwidgetfast.h"
--- a/widget/qt/moziqwidget.h
+++ b/widget/qt/moziqwidget.h
@@ -33,19 +33,19 @@
  * 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 MOZIQWIDGET_H
 #define MOZIQWIDGET_H
 
-#include <QtGui/QApplication>
-#include <QtGui/QGraphicsWidget>
-#include <QtGui/QGraphicsView>
+#include <QApplication>
+#include <QGraphicsWidget>
+#include <QGraphicsView>
 
 #include "nsCOMPtr.h"
 
 #ifdef MOZ_ENABLE_MEEGOTOUCH
 #include <MSceneWindow>
 #include <MInputMethodState>
 #include <QtGui/QGraphicsSceneResizeEvent>
 #include <QTimer>
--- a/widget/qt/mozqwidget.cpp
+++ b/widget/qt/mozqwidget.cpp
@@ -30,19 +30,21 @@
  * 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 <QtGui/QInputContext>
-#include <QtGui/QGraphicsSceneHoverEvent>
-#include <QtGui/QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneHoverEvent>
+#include <QGraphicsSceneMouseEvent>
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+#include <QInputContext>
+#endif
 #include <QtCore/QTimer>
 
 #include "mozqwidget.h"
 #include "nsWindow.h"
 
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 
@@ -579,17 +581,17 @@ void MozQWidget::showVKB()
 {
     // skip showing of keyboard if not pending
     if (!gPendingVKBOpen) {
         return;
     }
 
     gPendingVKBOpen = false;
 
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) && (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QWidget* focusWidget = qApp->focusWidget();
 
     if (focusWidget) {
         QInputContext *inputContext = qApp->inputContext();
         if (!inputContext) {
             NS_WARNING("Requesting SIP: but no input context");
             return;
         }
@@ -617,17 +619,17 @@ void MozQWidget::hideVKB()
         // do not really open
         gPendingVKBOpen = false;
     }
 
     if (!gKeyboardOpen) {
         return;
     }
 
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
+#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) && (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QInputContext *inputContext = qApp->inputContext();
     if (!inputContext) {
         NS_WARNING("Closing SIP: but no input context");
         return;
     }
 
     QEvent request(QEvent::CloseSoftwareInputPanel);
     inputContext->filterEvent(&request);
--- a/widget/qt/nsIdleServiceQt.cpp
+++ b/widget/qt/nsIdleServiceQt.cpp
@@ -32,20 +32,19 @@
  * 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 ***** */
 
-#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
-#include <QX11Info>
+#ifdef MOZ_X11
+#include "mozilla/X11Util.h"
 #endif
-
 #include "nsIdleServiceQt.h"
 #include "nsIServiceManager.h"
 #include "nsDebug.h"
 #include "prlink.h"
 
 #if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
 typedef bool (*_XScreenSaverQueryExtension_fn)(Display* dpy, int* event_base,
                                                  int* error_base);
@@ -112,17 +111,17 @@ nsIdleServiceQt::~nsIdleServiceQt()
 bool
 nsIdleServiceQt::PollIdleTime(PRUint32 *aIdleTime)
 {
 #if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
     // Ask xscreensaver about idle time:
     *aIdleTime = 0;
 
     // We might not have a display (cf. in xpcshell)
-    Display *dplay = QX11Info::display();
+    Display *dplay = mozilla::DefaultXDisplay();
     if (!dplay) {
         return false;
     }
 
     if (!sInitialized) {
         Initialize();
     }
     if (!_XSSQueryExtension || !_XSSAllocInfo || !_XSSQueryInfo) {
@@ -131,17 +130,17 @@ nsIdleServiceQt::PollIdleTime(PRUint32 *
 
     int event_base, error_base;
     if (_XSSQueryExtension(dplay, &event_base, &error_base)) {
         if (!mXssInfo)
             mXssInfo = _XSSAllocInfo();
         if (!mXssInfo)
             return false;
 
-        _XSSQueryInfo(dplay, QX11Info::appRootWindow(), mXssInfo);
+        _XSSQueryInfo(dplay, RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay())), mXssInfo);
         *aIdleTime = mXssInfo->idle;
         return true;
     }
 #endif
 
     return false;
 }
 
--- a/widget/qt/nsNativeThemeQt.cpp
+++ b/widget/qt/nsNativeThemeQt.cpp
@@ -148,17 +148,17 @@ nsNativeThemeQt::DrawWidgetBackground(ns
                           qSurface->Height(),
                           qSurface->Stride(),
                           _qimage_from_gfximage_format(qSurface->Format()));
         QPainter painter(&tempQImage);
         return DrawWidgetBackground(&painter, aContext,
                                     aFrame, aWidgetType,
                                     aRect, aClipRect);
     }
-#ifdef MOZ_X11
+#if defined(MOZ_X11) && defined(Q_WS_X11)
     else if (surface->GetType() == gfxASurface::SurfaceTypeXlib) {
         gfxXlibSurface* qSurface = (gfxXlibSurface*) (surface.get());
         QPixmap pixmap(QPixmap::fromX11Pixmap(qSurface->XDrawable()));
         QPainter painter(&pixmap);
         return DrawWidgetBackground(&painter, aContext,
                                     aFrame, aWidgetType,
                                     aRect, aClipRect);
     }
--- a/widget/qt/nsNativeThemeQt.h
+++ b/widget/qt/nsNativeThemeQt.h
@@ -44,17 +44,16 @@
 
 #include "nsITheme.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsNativeTheme.h"
 
 class QComboBox;
 class QStyleOptionButton;
-class QStyleOptionFrameV2;
 class QStyleOptionComboBox;
 class QRect;
 class nsIFrame;
 class nsDeviceContext;
 
 class nsNativeThemeQt : private nsNativeTheme,
                         public nsITheme
 {
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -40,31 +40,31 @@
  * 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 "mozilla/Util.h"
 
-#include <QtGui/QApplication>
-#include <QtGui/QDesktopWidget>
+#include <QApplication>
+#include <QDesktopWidget>
 #include <QtGui/QCursor>
-#include <QtGui/QIcon>
-#include <QtGui/QX11Info>
-#include <QtGui/QGraphicsScene>
-#include <QtGui/QGraphicsView>
-#include <QtGui/QGraphicsSceneContextMenuEvent>
-#include <QtGui/QGraphicsSceneDragDropEvent>
-#include <QtGui/QGraphicsSceneMouseEvent>
-#include <QtGui/QGraphicsSceneHoverEvent>
-#include <QtGui/QGraphicsSceneWheelEvent>
-#include <QtGui/QGraphicsSceneResizeEvent>
-#include <QtGui/QStyleOptionGraphicsItem>
+#include <QIcon>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QGraphicsSceneContextMenuEvent>
+#include <QGraphicsSceneDragDropEvent>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneHoverEvent>
+#include <QGraphicsSceneWheelEvent>
+#include <QGraphicsSceneResizeEvent>
+#include <QStyleOptionGraphicsItem>
 #include <QPaintEngine>
+#include <QMimeData>
 
 #include <QtCore/QDebug>
 #include <QtCore/QEvent>
 #include <QtCore/QVariant>
 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
 #include <QPinchGesture>
 #include <QGestureRecognizer>
 #include "mozSwipeGesture.h"
@@ -75,17 +75,16 @@ static Qt::GestureType gSwipeGestureId =
 static const float GESTURES_BLOCK_MOUSE_FOR = 200;
 #ifdef MOZ_ENABLE_QTMOBILITY
 #include <QtSensors/QOrientationSensor>
 using namespace QtMobility;
 #endif // MOZ_ENABLE_QTMOBILITY
 #endif // QT version check 4.6
 
 #ifdef MOZ_X11
-#include <QX11Info>
 #include <X11/Xlib.h>
 #endif //MOZ_X11
 
 #include "nsXULAppAPI.h"
 
 #include "prlink.h"
 
 #include "nsWindow.h"
@@ -259,17 +258,17 @@ nsWindow::nsWindow()
     
     if (!gGlobalsInitialized) {
         gfxPlatform::GetPlatform();
         gGlobalsInitialized = true;
 
 #if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
         // This cannot be called on non-main thread
         if (QThread::currentThread() == qApp->thread()) {
-            sPluginIMEAtom = XInternAtom(QX11Info::display(), PLUGIN_VKB_REQUEST_PROP, False);
+            sPluginIMEAtom = XInternAtom(mozilla::DefaultXDisplay(), PLUGIN_VKB_REQUEST_PROP, False);
         }
 #endif
         // It's OK if either of these fail, but it may not be one day.
         initialize_prefs();
     }
 
     memset(mKeyDownFlags, 0, sizeof(mKeyDownFlags));
 
@@ -340,18 +339,19 @@ UpdateOffScreenBuffers(int aDepth, QSize
     // Use fallback RGB24 format, Qt will do conversion for us
     if (format == gfxASurface::ImageFormatUnknown)
         format = gfxASurface::ImageFormatRGB24;
 
 #ifdef MOZ_HAVE_SHMIMAGE
     if (aWidget) {
         if (gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType() ==
             gfxASurface::SurfaceTypeImage) {
+            Display* dpy = mozilla::DefaultXDisplay();
             gShmImage = nsShmImage::Create(gBufferMaxSize,
-                                           (Visual*)aWidget->x11Info().visual(),
+                                           DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aWidget)),
                                            aDepth);
             gBufferSurface = gShmImage->AsSurface();
             return true;
         }
     }
 #endif
 
     gBufferSurface = gfxPlatform::GetPlatform()->
@@ -796,18 +796,17 @@ nsWindow::GetNativeData(PRUint32 aDataTy
 
     case NS_NATIVE_PLUGIN_PORT:
         return SetupPluginPort();
         break;
 
     case NS_NATIVE_DISPLAY:
         {
 #ifdef MOZ_X11
-            QWidget *widget = GetViewWidget();
-            return widget ? widget->x11Info().display() : nsnull;
+            return gfxQtPlatform::GetXDisplay(GetViewWidget());
 #else
             return nsnull;
 #endif
         }
         break;
 
     case NS_NATIVE_GRAPHIC: {
         return nsnull;
@@ -1014,19 +1013,19 @@ nsWindow::GetAttention(PRInt32 aCycleCou
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 #ifdef MOZ_X11
 static already_AddRefed<gfxASurface>
 GetSurfaceForQWidget(QWidget* aDrawable)
 {
     gfxASurface* result =
-        new gfxXlibSurface(aDrawable->x11Info().display(),
-                           aDrawable->handle(),
-                           (Visual*)aDrawable->x11Info().visual(),
+        new gfxXlibSurface(gfxQtPlatform::GetXDisplay(aDrawable),
+                           aDrawable->winId(),
+                           DefaultVisualOfScreen(gfxQtPlatform::GetXScreen(aDrawable)),
                            gfxIntSize(aDrawable->size().width(),
                            aDrawable->size().height()));
     NS_IF_ADDREF(result);
     return result;
 }
 #endif
 
 static void
@@ -1168,17 +1167,17 @@ nsWindow::DoPaint(QPainter* aPainter, co
 
     if (status == nsEventStatus_eIgnore)
         return status;
 
     LOGDRAW(("[%p] draw done\n", this));
 
     // Handle buffered painting mode
     if (renderMode == gfxQtPlatform::RENDER_BUFFERED) {
-#ifdef MOZ_X11
+#if defined(MOZ_X11) && defined(Q_WS_X11)
         if (gBufferSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
             // Paint offscreen pixmap to QPainter
             static QPixmap gBufferPixmap;
             Drawable draw = static_cast<gfxXlibSurface*>(gBufferSurface.get())->XDrawable();
             if (gBufferPixmap.handle() != draw)
                 gBufferPixmap = QPixmap::fromX11Pixmap(draw, QPixmap::ExplicitlyShared);
             XSync(static_cast<gfxXlibSurface*>(gBufferSurface.get())->XDisplay(), False);
             aPainter->drawPixmap(QPoint(rect.x, rect.y), gBufferPixmap,
@@ -1570,17 +1569,17 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
         //keyEventToContextMenuEvent(&event, &contextMenuEvent);
         return DispatchEvent(&contextMenuEvent);
     }
 
     PRUint32 domCharCode = 0;
     PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
 
     // get keymap and modifier map from the Xserver
-    Display *display = QX11Info::display();
+    Display *display = mozilla::DefaultXDisplay();
     int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
     XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
     XModifierKeymap *xmodmap = XGetModifierMapping(display);
     if (!xmodmap)
         return nsEventStatus_eIgnore;
 
     KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
                                           &xkeysyms_per_keycode);
@@ -1928,17 +1927,17 @@ nsWindow::OnKeyReleaseEvent(QKeyEvent *a
         return nsEventStatus_eConsumeDoDefault;
     }
 
     PRUint32 domKeyCode = QtKeyCodeToDOMKeyCode(aEvent->key());
 
 #ifdef MOZ_X11
     if (!domKeyCode) {
         // get keymap from the Xserver
-        Display *display = QX11Info::display();
+        Display *display = mozilla::DefaultXDisplay();
         int x_min_keycode = 0, x_max_keycode = 0, xkeysyms_per_keycode;
         XDisplayKeycodes(display, &x_min_keycode, &x_max_keycode);
         KeySym *xkeymap = XGetKeyboardMapping(display, x_min_keycode, x_max_keycode - x_min_keycode,
                                               &xkeysyms_per_keycode);
 
         if (aEvent->nativeScanCode() >= (quint32)x_min_keycode &&
             aEvent->nativeScanCode() <= (quint32)x_max_keycode) {
             int index = (aEvent->nativeScanCode() - x_min_keycode) * xkeysyms_per_keycode;
@@ -2366,19 +2365,19 @@ nsWindow::SetWindowClass(const nsAString
       else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c)))
         *c = '_';
     }
     class_hint->res_name[0] = toupper(class_hint->res_name[0]);
     if (!role) role = class_hint->res_name;
 
     QWidget *widget = GetViewWidget();
     // If widget not show, handle might be null
-    if (widget && widget->handle())
-        XSetClassHint(widget->x11Info().display(),
-                      widget->handle(),
+    if (widget && widget->winId())
+        XSetClassHint(gfxQtPlatform::GetXDisplay(widget),
+                      widget->winId(),
                       class_hint);
 
     nsMemory::Free(class_hint->res_class);
     nsMemory::Free(class_hint->res_name);
     XFree(class_hint);
 #endif
 
     return NS_OK;
@@ -2566,17 +2565,17 @@ nsWindow::HideWindowChrome(bool aShouldH
     // 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)
     QWidget *widget = GetViewWidget();
     NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
 #ifdef MOZ_X11
-    XSync(widget->x11Info().display(), False);
+    XSync(gfxQtPlatform::GetXDisplay(widget), False);
 #endif
 
     return NS_OK;
 }
 
 //////////////////////////////////////////////////////////////////////
 // These are all of our drag and drop operations
 
@@ -2716,17 +2715,17 @@ nsWindow::createQWidget(MozQWidget *pare
             if (!glWidget) {
                 newView->setViewport(new QGLWidget());
             }
         }
 #endif
 
         if (gfxQtPlatform::GetPlatform()->GetRenderMode() == gfxQtPlatform::RENDER_DIRECT) {
             // Disable double buffer and system background rendering
-#ifdef MOZ_X11
+#if defined(MOZ_X11) && (QT_VERSION < QT_VERSION_CHECK(5,0,0))
             newView->viewport()->setAttribute(Qt::WA_PaintOnScreen, true);
 #endif
             newView->viewport()->setAttribute(Qt::WA_NoSystemBackground, true);
         }
         // Enable gestures:
 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
 #if defined MOZ_ENABLE_MEEGOTOUCH
         // Disable default Gesture filters (speedup filtering)
@@ -2745,17 +2744,17 @@ nsWindow::createQWidget(MozQWidget *pare
 
 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
         // Top level widget is just container, and should not be painted
         widget->setFlag(QGraphicsItem::ItemHasNoContents);
 #endif
 
 #ifdef MOZ_X11
         if (newView->effectiveWinId()) {
-            XSetWindowBackgroundPixmap(QX11Info::display(),
+            XSetWindowBackgroundPixmap(mozilla::DefaultXDisplay(),
                                        newView->effectiveWinId(), None);
         }
 #endif
     }
 
     if (mWindowType == eWindowType_popup) {
         widget->setZValue(100);
 
@@ -3166,17 +3165,17 @@ typedef enum {
 
 static QCoreApplication::EventFilter previousEventFilter = NULL;
 
 static PluginVKBState
 GetPluginVKBState(Window aWinId)
 {
     // Set default value as unexpected error
     PluginVKBState imeState = VKBUndefined;
-    Display *display = QX11Info::display();
+    Display *display = mozilla::DefaultXDisplay();
 
     Atom actualType;
     int actualFormat;
     unsigned long nitems;
     unsigned long bytes;
     union {
         unsigned char* asUChar;
         unsigned long* asLong;
@@ -3196,17 +3195,17 @@ GetPluginVKBState(Window aWinId)
     }
 
     return imeState;
 }
 
 static void
 SetVKBState(Window aWinId, PluginVKBState aState)
 {
-    Display *display = QX11Info::display();
+    Display *display = mozilla::DefaultXDisplay();
     if (aState != VKBUndefined) {
         unsigned long isOpen = aState == VKBOpen ? 1 : 0;
         XChangeProperty(display, aWinId, sPluginIMEAtom, XA_CARDINAL, 32,
                         PropModeReplace, (unsigned char *) &isOpen, 1);
     } else {
         XDeleteProperty(display, aWinId, sPluginIMEAtom);
     }
     XSync(display, False);
--- a/widget/qt/nsWindow.h
+++ b/widget/qt/nsWindow.h
@@ -37,16 +37,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __nsWindow_h__
 #define __nsWindow_h__
 
 #include <QKeyEvent>
+#include <QGestureEvent>
 #include <qgraphicswidget.h>
 #include <QTime>
 
 #include "nsAutoPtr.h"
 
 #include "nsBaseWidget.h"
 #include "nsGUIEvent.h"
 
--- a/widget/shared/nsShmImage.cpp
+++ b/widget/shared/nsShmImage.cpp
@@ -200,18 +200,18 @@ nsShmImage::Put(GdkWindow* aWindow, cair
     // other options.
     XSync(dpy, False);
 }
 
 #elif defined(MOZ_WIDGET_QT)
 void
 nsShmImage::Put(QWidget* aWindow, QRect& aRect)
 {
-    Display* dpy = aWindow->x11Info().display();
-    Drawable d = aWindow->handle();
+    Display* dpy = gfxQtPlatform::GetXDisplay(aWindow);
+    Drawable d = aWindow->winId();
 
     GC gc = XCreateGC(dpy, d, 0, nsnull);
     // Avoid out of bounds painting
     QRect inter = aRect.intersected(aWindow->rect());
     XShmPutImage(dpy, d, gc, mImage,
                  inter.x(), inter.y(),
                  inter.x(), inter.y(),
                  inter.width(), inter.height(),
--- a/widget/shared/nsShmImage.h
+++ b/widget/shared/nsShmImage.h
@@ -47,25 +47,25 @@
 #  define MOZ_HAVE_SHMIMAGE
 #endif
 
 #ifdef MOZ_HAVE_SHMIMAGE
 
 #include "nsIWidget.h"
 #include "gfxASurface.h"
 
+#include "mozilla/X11Util.h"
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/XShm.h>
 
 #if defined(MOZ_WIDGET_GTK2) || defined(MOZ_WIDGET_GTK3)
 #define DISPLAY gdk_x11_get_default_xdisplay
 #elif defined(MOZ_WIDGET_QT)
-#include "QX11Info"
-#define DISPLAY QX11Info().display
+#define DISPLAY mozilla::DefaultXDisplay
 #endif
 
 class QRect;
 class QWidget;
 
 class nsShmImage {
     NS_INLINE_DECL_REFCOUNTING(nsShmImage)