Resurect old widget-qt port on new mozilla trunk
authorromaxa@romaxa.research.nokia.com
Sat, 19 Apr 2008 18:31:50 +0300
changeset 16782 f100399cfb8b2e66331f3a45a8062c1a5ba787bd
parent 16781 bec5e1269d11b9e3166a31e18e0f8a7a2b91ae5d
child 16783 a5d53a9ce0257668f790716df757ea6af0dade01
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0a1pre
Resurect old widget-qt port on new mozilla trunk
widget/src/qt/mozqwidget.cpp
widget/src/qt/mozqwidget.h
widget/src/qt/nsAppShell.cpp
widget/src/qt/nsAppShell.h
widget/src/qt/nsCommonWidget.cpp
widget/src/qt/nsCommonWidget.h
widget/src/qt/nsLookAndFeel.cpp
widget/src/qt/nsLookAndFeel.h
widget/src/qt/nsScreenManagerQt.cpp
widget/src/qt/nsScreenManagerQt.h
widget/src/qt/nsScreenQt.cpp
widget/src/qt/nsScreenQt.h
widget/src/qt/nsWindow.cpp
widget/src/qt/nsWindow.h
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/mozqwidget.cpp
@@ -0,0 +1,191 @@
+#include "mozqwidget.h"
+#include "nsCommonWidget.h"
+#include <qevent.h>
+
+MozQWidget::MozQWidget(nsCommonWidget *receiver, QWidget *parent,
+                       const char *name, int f)
+    : QWidget(parent, (Qt::WindowFlags)f),
+      mReceiver(receiver)
+{
+}
+
+bool MozQWidget::event(QEvent *e)
+{
+    bool ignore = false;
+    if (!mReceiver) return !ignore;
+    switch(e->type()) {
+/*
+    case QEvent::Accessibility:
+    {
+        qDebug("accessibility event received");
+    }
+    break;
+*/
+    case QEvent::MouseButtonPress:
+    {
+        QMouseEvent *ms = (QMouseEvent*)(e);
+        ignore = mReceiver->mousePressEvent(ms);
+    }
+    break;
+    case QEvent::MouseButtonRelease:
+    {
+        QMouseEvent *ms = (QMouseEvent*)(e);
+        ignore = mReceiver->mouseReleaseEvent(ms);
+    }
+    break;
+    case QEvent::MouseButtonDblClick:
+    {
+        QMouseEvent *ms = (QMouseEvent*)(e);
+        ignore = mReceiver->mouseDoubleClickEvent(ms);
+    }
+    break;
+    case QEvent::MouseMove:
+    {
+        QMouseEvent *ms = (QMouseEvent*)(e);
+        ignore = mReceiver->mouseMoveEvent(ms);
+    }
+    break;
+    case QEvent::KeyPress:
+    {
+        QKeyEvent *kev = (QKeyEvent*)(e);
+        ignore = mReceiver->keyPressEvent(kev);
+    }
+    break;
+    case QEvent::KeyRelease:
+    {
+        QKeyEvent *kev = (QKeyEvent*)(e);
+        ignore = mReceiver->keyReleaseEvent(kev);
+    }
+    break;
+/*
+    case QEvent::IMStart:
+    {
+        QIMEvent *iev = (QIMEvent*)(e);
+        ignore = mReceiver->imStartEvent(iev);
+    }
+    break;
+    case QEvent::IMCompose:
+    {
+        QIMEvent *iev = (QIMEvent*)(e);
+        ignore = mReceiver->imComposeEvent(iev);
+    }
+    break;
+    case QEvent::IMEnd:
+    {
+        QIMEvent *iev = (QIMEvent*)(e);
+        ignore = mReceiver->imEndEvent(iev);
+    }
+    break;
+*/
+    case QEvent::FocusIn:
+    {
+        QFocusEvent *fev = (QFocusEvent*)(e);
+        mReceiver->focusInEvent(fev);
+        return TRUE;
+    }
+    break;
+    case QEvent::FocusOut:
+    {
+        QFocusEvent *fev = (QFocusEvent*)(e);
+        mReceiver->focusOutEvent(fev);
+        return TRUE;
+    }
+    break;
+    case QEvent::Enter:
+    {
+        ignore = mReceiver->enterEvent(e);
+    }
+    break;
+    case QEvent::Leave:
+    {
+        ignore = mReceiver->enterEvent(e);
+    }
+    break;
+    case QEvent::Paint:
+    {
+        QPaintEvent *ev = (QPaintEvent*)(e);
+        mReceiver->paintEvent(ev);
+    }
+    break;
+    case QEvent::Move:
+    {
+        QMoveEvent *mev = (QMoveEvent*)(e);
+        ignore = mReceiver->moveEvent(mev);
+    }
+    break;
+    case QEvent::Resize:
+    {
+        QResizeEvent *rev = (QResizeEvent*)(e);
+        ignore = mReceiver->resizeEvent(rev);
+    }
+        break;
+    case QEvent::Show:
+    {
+        QShowEvent *sev = (QShowEvent*)(e);
+        mReceiver->showEvent(sev);
+    }
+    break;
+    case QEvent::Hide:
+    {
+        QHideEvent *hev = (QHideEvent*)(e);
+        ignore = mReceiver->hideEvent(hev);
+    }
+        break;
+    case QEvent::Close:
+    {
+        QCloseEvent *cev = (QCloseEvent*)(e);
+        ignore = mReceiver->closeEvent(cev);
+    }
+    break;
+    case QEvent::Wheel:
+    {
+        QWheelEvent *wev = (QWheelEvent*)(e);
+        ignore = mReceiver->wheelEvent(wev);
+    }
+    break;
+    case QEvent::ContextMenu:
+    {
+        QContextMenuEvent *cev = (QContextMenuEvent*)(e);
+        ignore = mReceiver->contextMenuEvent(cev);
+    }
+    break;
+    case QEvent::DragEnter:
+    {
+        QDragEnterEvent *dev = (QDragEnterEvent*)(e);
+        ignore = mReceiver->dragEnterEvent(dev);
+    }
+        break;
+    case QEvent::DragMove:
+    {
+        QDragMoveEvent *dev = (QDragMoveEvent*)(e);
+        ignore = mReceiver->dragMoveEvent(dev);
+    }
+    break;
+    case QEvent::DragLeave:
+    {
+        QDragLeaveEvent *dev = (QDragLeaveEvent*)(e);
+        ignore = mReceiver->dragLeaveEvent(dev);
+    }
+    break;
+    case QEvent::Drop:
+    {
+        QDropEvent *dev = (QDropEvent*)(e);
+        ignore = mReceiver->dropEvent(dev);
+    }
+    break;
+    default:
+        break;
+    }
+
+    QWidget::event(e);
+
+    return !ignore;
+}
+
+void MozQWidget::setModal(bool modal)
+{
+    if (modal)
+        setWindowModality(Qt::ApplicationModal);
+    else
+        setWindowModality(Qt::NonModal);
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/mozqwidget.h
@@ -0,0 +1,28 @@
+#ifndef MOZQWIDGET_H
+#define MOZQWIDGET_H
+
+#include <qwidget.h>
+
+class QEvent;
+class nsCommonWidget;
+
+class MozQWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    MozQWidget(nsCommonWidget *receiver, QWidget *parent,
+               const char *name, int f);
+
+    /**
+     * Mozilla helper.
+     */
+    void setModal(bool);
+    void dropReciever() { mReceiver = 0x0; };
+
+protected:
+    virtual bool event(QEvent *ev);
+private:
+    nsCommonWidget *mReceiver;
+};
+
+#endif
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsAppShell.cpp
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim:expandtab:shiftwidth=4:tabstop=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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is Christopher Blizzard
+ * <blizzard@mozilla.org>.  Portions created by the Initial Developer
+ * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 "nsAppShell.h"
+#include <qapplication.h>
+
+#define NOTIFY_TOKEN 0xFA
+
+void nsAppShell::EventNativeCallback(qint64 numBytes)
+{
+    char c;
+    mBuff.read(&c, 1);
+    //NS_ASSERTION(c == (char) NOTIFY_TOKEN, "wrong token");
+
+    NativeEventCallback();
+    return;
+}
+
+nsAppShell::~nsAppShell()
+{
+    mBuff.close();
+}
+
+nsresult
+nsAppShell::Init()
+{
+    while (!tcpServer.isListening() && !tcpServer.listen()) {}
+    mBuff.connectToHost(QHostAddress::LocalHost, tcpServer.serverPort());
+    connect(&mBuff, SIGNAL(bytesWritten(qint64)), this, SLOT(EventNativeCallback(qint64)));
+
+    return nsBaseAppShell::Init();
+}
+
+void
+nsAppShell::ScheduleNativeEventCallback()
+{
+  char buf [] = { NOTIFY_TOKEN };
+  mBuff.write(buf, 1);
+}
+
+PRBool
+nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
+{
+  qApp->processEvents();
+  return PR_TRUE;
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsAppShell.h
@@ -0,0 +1,75 @@
+/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *   Oleg Romashin <romaxa@gmail.com>
+ * Portions created by the Initial Developer are Copyright (C) 2003
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Oleg Romashin <romaxa@gmail.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 nsAppShell_h__
+#define nsAppShell_h__
+
+#include "nsBaseAppShell.h"
+#include "nsCOMPtr.h"
+#include <QtNetwork>
+
+/**
+ * Native QT Application shell wrapper
+ */
+
+#define SOCK_IMPL 1
+
+class nsAppShell : public QObject, public nsBaseAppShell
+{
+  Q_OBJECT
+public:
+  nsAppShell() { };
+
+  nsresult Init();
+
+private slots:
+  void EventNativeCallback(qint64 numBytes);
+
+protected:
+  virtual void ScheduleNativeEventCallback();
+  virtual PRBool ProcessNextNativeEvent(PRBool mayWait);
+  virtual ~nsAppShell();
+
+private:
+  QTcpSocket mBuff;
+  QTcpServer tcpServer;
+};
+
+
+#endif // nsAppShell_h__
+
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsCommonWidget.cpp
@@ -0,0 +1,1598 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *  Zack Rusin <zack@kde.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *
+ * 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 "nsCommonWidget.h"
+
+#include "nsGUIEvent.h"
+//#include "nsQtEventDispatcher.h"
+#include "nsIRenderingContext.h"
+#include "nsIServiceManager.h"
+#include "nsGfxCIID.h"
+#include "nsIPrefBranch.h"
+#include "nsIPrefService.h"
+
+#include "mozqwidget.h"
+
+#include <qapplication.h>
+#include <qdesktopwidget.h>
+#include <qwidget.h>
+#include "qx11info_x11.h"
+#include <qcursor.h>
+#include <qevent.h>
+#include <qobject.h>
+#include <execinfo.h>
+#include <stdlib.h>
+
+#include <execinfo.h>
+#include <stdlib.h>
+
+static const int WHEEL_DELTA = 120;
+static const int kWindowPositionSlop = 20;
+
+struct nsKeyConverter
+{
+    int vkCode; // Platform independent key code
+    int keysym; // Qt key code
+};
+
+static void backTrace()
+{
+    int levels = -1;
+    QString s;
+    void* trace[256];
+    int n = backtrace(trace, 256);
+    if (!n)
+    return;
+    char** strings = backtrace_symbols (trace, n);
+
+    if ( levels != -1 )
+        n = qMin( n, levels );
+    s = "[\n";
+
+    for (int i = 0; i < n; ++i)
+        s += QString::number(i) +
+             QString::fromLatin1(": ") +
+             QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
+    s += "]\n";
+    if (strings)
+        free (strings);
+//    qDebug("stacktrace:\n%s", s.latin1());
+}
+
+static struct nsKeyConverter nsKeycodes[] =
+{
+//  { NS_VK_CANCEL,        Qt::Key_Cancel },
+    { NS_VK_BACK,          Qt::Key_Backspace },
+    { NS_VK_TAB,           Qt::Key_Tab },
+//  { NS_VK_CLEAR,         Qt::Key_Clear },
+    { NS_VK_RETURN,        Qt::Key_Return },
+    { NS_VK_RETURN,        Qt::Key_Enter },
+    { NS_VK_SHIFT,         Qt::Key_Shift },
+    { NS_VK_CONTROL,       Qt::Key_Control },
+    { NS_VK_ALT,           Qt::Key_Alt },
+    { NS_VK_PAUSE,         Qt::Key_Pause },
+    { NS_VK_CAPS_LOCK,     Qt::Key_CapsLock },
+    { NS_VK_ESCAPE,        Qt::Key_Escape },
+    { NS_VK_SPACE,         Qt::Key_Space },
+    { NS_VK_PAGE_UP,       Qt::Key_PageUp },
+    { NS_VK_PAGE_DOWN,     Qt::Key_PageDown },
+    { NS_VK_END,           Qt::Key_End },
+    { NS_VK_HOME,          Qt::Key_Home },
+    { NS_VK_LEFT,          Qt::Key_Left },
+    { NS_VK_UP,            Qt::Key_Up },
+    { NS_VK_RIGHT,         Qt::Key_Right },
+    { NS_VK_DOWN,          Qt::Key_Down },
+    { NS_VK_PRINTSCREEN,   Qt::Key_Print },
+    { NS_VK_INSERT,        Qt::Key_Insert },
+    { NS_VK_DELETE,        Qt::Key_Delete },
+
+    { NS_VK_0,             Qt::Key_0 },
+    { NS_VK_1,             Qt::Key_1 },
+    { NS_VK_2,             Qt::Key_2 },
+    { NS_VK_3,             Qt::Key_3 },
+    { NS_VK_4,             Qt::Key_4 },
+    { NS_VK_5,             Qt::Key_5 },
+    { NS_VK_6,             Qt::Key_6 },
+    { NS_VK_7,             Qt::Key_7 },
+    { NS_VK_8,             Qt::Key_8 },
+    { NS_VK_9,             Qt::Key_9 },
+
+    { NS_VK_SEMICOLON,     Qt::Key_Semicolon },
+    { NS_VK_EQUALS,        Qt::Key_Equal },
+
+    { NS_VK_A,             Qt::Key_A },
+    { NS_VK_B,             Qt::Key_B },
+    { NS_VK_C,             Qt::Key_C },
+    { NS_VK_D,             Qt::Key_D },
+    { NS_VK_E,             Qt::Key_E },
+    { NS_VK_F,             Qt::Key_F },
+    { NS_VK_G,             Qt::Key_G },
+    { NS_VK_H,             Qt::Key_H },
+    { NS_VK_I,             Qt::Key_I },
+    { NS_VK_J,             Qt::Key_J },
+    { NS_VK_K,             Qt::Key_K },
+    { NS_VK_L,             Qt::Key_L },
+    { NS_VK_M,             Qt::Key_M },
+    { NS_VK_N,             Qt::Key_N },
+    { NS_VK_O,             Qt::Key_O },
+    { NS_VK_P,             Qt::Key_P },
+    { NS_VK_Q,             Qt::Key_Q },
+    { NS_VK_R,             Qt::Key_R },
+    { NS_VK_S,             Qt::Key_S },
+    { NS_VK_T,             Qt::Key_T },
+    { NS_VK_U,             Qt::Key_U },
+    { NS_VK_V,             Qt::Key_V },
+    { NS_VK_W,             Qt::Key_W },
+    { NS_VK_X,             Qt::Key_X },
+    { NS_VK_Y,             Qt::Key_Y },
+    { NS_VK_Z,             Qt::Key_Z },
+
+    { NS_VK_NUMPAD0,       Qt::Key_0 },
+    { NS_VK_NUMPAD1,       Qt::Key_1 },
+    { NS_VK_NUMPAD2,       Qt::Key_2 },
+    { NS_VK_NUMPAD3,       Qt::Key_3 },
+    { NS_VK_NUMPAD4,       Qt::Key_4 },
+    { NS_VK_NUMPAD5,       Qt::Key_5 },
+    { NS_VK_NUMPAD6,       Qt::Key_6 },
+    { NS_VK_NUMPAD7,       Qt::Key_7 },
+    { NS_VK_NUMPAD8,       Qt::Key_8 },
+    { NS_VK_NUMPAD9,       Qt::Key_9 },
+    { NS_VK_MULTIPLY,      Qt::Key_Asterisk },
+    { NS_VK_ADD,           Qt::Key_Plus },
+//  { NS_VK_SEPARATOR,     Qt::Key_Separator },
+    { NS_VK_SUBTRACT,      Qt::Key_Minus },
+    { NS_VK_DECIMAL,       Qt::Key_Period },
+    { NS_VK_DIVIDE,        Qt::Key_Slash },
+    { NS_VK_F1,            Qt::Key_F1 },
+    { NS_VK_F2,            Qt::Key_F2 },
+    { NS_VK_F3,            Qt::Key_F3 },
+    { NS_VK_F4,            Qt::Key_F4 },
+    { NS_VK_F5,            Qt::Key_F5 },
+    { NS_VK_F6,            Qt::Key_F6 },
+    { NS_VK_F7,            Qt::Key_F7 },
+    { NS_VK_F8,            Qt::Key_F8 },
+    { NS_VK_F9,            Qt::Key_F9 },
+    { NS_VK_F10,           Qt::Key_F10 },
+    { NS_VK_F11,           Qt::Key_F11 },
+    { NS_VK_F12,           Qt::Key_F12 },
+    { NS_VK_F13,           Qt::Key_F13 },
+    { NS_VK_F14,           Qt::Key_F14 },
+    { NS_VK_F15,           Qt::Key_F15 },
+    { NS_VK_F16,           Qt::Key_F16 },
+    { NS_VK_F17,           Qt::Key_F17 },
+    { NS_VK_F18,           Qt::Key_F18 },
+    { NS_VK_F19,           Qt::Key_F19 },
+    { NS_VK_F20,           Qt::Key_F20 },
+    { NS_VK_F21,           Qt::Key_F21 },
+    { NS_VK_F22,           Qt::Key_F22 },
+    { NS_VK_F23,           Qt::Key_F23 },
+    { NS_VK_F24,           Qt::Key_F24 },
+
+    { NS_VK_NUM_LOCK,      Qt::Key_NumLock },
+    { NS_VK_SCROLL_LOCK,   Qt::Key_ScrollLock },
+
+    { NS_VK_COMMA,         Qt::Key_Comma },
+    { NS_VK_PERIOD,        Qt::Key_Period },
+    { NS_VK_SLASH,         Qt::Key_Slash },
+    { NS_VK_BACK_QUOTE,    Qt::Key_QuoteLeft },
+    { NS_VK_OPEN_BRACKET,  Qt::Key_ParenLeft },
+    { NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight },
+    { NS_VK_QUOTE,         Qt::Key_QuoteDbl },
+
+    { NS_VK_META,          Qt::Key_Meta }
+};
+
+static PRInt32 NS_GetKey(PRInt32 aKey)
+{
+    PRInt32 length = sizeof(nsKeycodes) / sizeof(nsKeyConverter);
+
+    for (PRInt32 i = 0; i < length; i++) {
+        if (nsKeycodes[i].keysym == aKey) {
+            return nsKeycodes[i].vkCode;
+        }
+    }
+    return 0;
+}
+
+static PRBool
+isContextMenuKey(const nsKeyEvent &aKeyEvent)
+{
+    return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.isShift &&
+             !aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt) ||
+            (aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.isShift &&
+             !aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt));
+}
+
+static void
+keyEventToContextMenuEvent(const nsKeyEvent* aKeyEvent,
+                           nsMouseEvent* aCMEvent)
+{
+    memcpy(aCMEvent, aKeyEvent, sizeof(nsInputEvent));
+//    aCMEvent->message = NS_CONTEXTMENU_KEY;
+    aCMEvent->isShift = aCMEvent->isControl = PR_FALSE;
+    aCMEvent->isControl = PR_FALSE;
+    aCMEvent->isAlt = aCMEvent->isMeta = PR_FALSE;
+    aCMEvent->isMeta = PR_FALSE;
+    aCMEvent->clickCount = 0;
+    aCMEvent->acceptActivation = PR_FALSE;
+}
+
+nsCommonWidget::nsCommonWidget()
+    : mContainer(0),
+      mWidget(0),
+      mListenForResizes(PR_FALSE),
+      mNeedsResize(PR_FALSE),
+      mNeedsShow(PR_FALSE),
+      mIsShown(PR_FALSE)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(nsCommonWidget,nsBaseWidget)
+nsCommonWidget::~nsCommonWidget()
+{
+    MozQWidget *mozWidget = static_cast<MozQWidget*>(mWidget);
+    if (mozWidget)
+        mozWidget->dropReciever();
+    mWidget->deleteLater();
+    mWidget = 0;
+}
+
+void
+nsCommonWidget::Initialize(QWidget *widget)
+{
+    Q_ASSERT(widget);
+
+    mWidget = widget;
+    mWidget->setMouseTracking(PR_TRUE);
+    mWidget->setFocusPolicy(Qt::WheelFocus);
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Show(PRBool aState)
+{
+    mIsShown = aState;
+
+    // Ok, someone called show on a window that isn't sized to a sane
+    // value.  Mark this window as needing to have Show() called on it
+    // and return.
+    if ((aState && !AreBoundsSane()) || !mWidget) {
+#ifdef DEBUG_WIDGETS
+        qWarning("XX Bounds are insane or window hasn't been created yet");
+#endif
+        mNeedsShow = PR_TRUE;
+        return NS_OK;
+    }
+
+    // If someone is hiding this widget, clear any needing show flag.
+    if (!aState)
+        mNeedsShow = PR_FALSE;
+
+    // If someone is showing this window and it needs a resize then
+    // resize the widget.
+    if (aState && mNeedsResize) {
+#ifdef DEBUG_WIDGETS
+        qDebug("\tresizing [%d, %d, %d, %d]", mBounds.x, mBounds.y,
+               mBounds.width, mBounds.height);
+#endif
+        NativeResize(mBounds.x, mBounds.y, mBounds.width, mBounds.height,
+                     PR_FALSE);
+    }
+
+    NativeShow(aState);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::IsVisible(PRBool &visible)
+{
+    if (mWidget)
+        visible = mWidget->isVisible();
+    else
+        visible = PR_FALSE;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY)
+{
+    if (mContainer) {
+        PRInt32 screenWidth  = QApplication::desktop()->width();
+        PRInt32 screenHeight = QApplication::desktop()->height();
+        if (aAllowSlop) {
+            if (*aX < (kWindowPositionSlop - mBounds.width))
+                *aX = kWindowPositionSlop - mBounds.width;
+            if (*aX > (screenWidth - kWindowPositionSlop))
+                *aX = screenWidth - kWindowPositionSlop;
+            if (*aY < (kWindowPositionSlop - mBounds.height))
+                *aY = kWindowPositionSlop - mBounds.height;
+            if (*aY > (screenHeight - kWindowPositionSlop))
+                *aY = screenHeight - kWindowPositionSlop;
+        } else {
+            if (*aX < 0)
+                *aX = 0;
+            if (*aX > (screenWidth - mBounds.width))
+                *aX = screenWidth - mBounds.width;
+            if (*aY < 0)
+                *aY = 0;
+            if (*aY > (screenHeight - mBounds.height))
+                *aY = screenHeight - mBounds.height;
+        }
+    }
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Move(PRInt32 x, PRInt32 y)
+{
+    bool popup = mWidget ? mWidget->windowType() == Qt::Popup : false;
+
+    if (!mWidget || (x == mBounds.x && y == mBounds.y &&
+                     !popup))
+        return NS_OK;
+
+#ifdef DEBUG_WIDGETS
+    qDebug("Move [%d,%d] (%s)", x, y, popup?"popup":"widget");
+#endif
+
+    if (!mWidget)
+        return NS_OK;
+
+    QPoint pos(x, y);
+    if (mContainer) {
+        if (mParent && mWidget->windowType() == Qt::Popup) {
+            nsRect oldrect, newrect;
+            oldrect.x = x;
+            oldrect.y = y;
+
+            mParent->WidgetToScreen(oldrect, newrect);
+
+            pos = QPoint(newrect.x, newrect.y);
+#ifdef DEBUG_WIDGETS
+            qDebug("pos is [%d,%d]", pos.x(), pos.y());
+#endif
+        } else {
+            qDebug("Widget within another? (%p)", (void*)mWidget);
+        }
+    }
+
+    mBounds.x = pos.x();
+    mBounds.y = pos.y();
+
+    mWidget->move(pos);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Resize(PRInt32 aWidth,
+                       PRInt32 aHeight,
+                       PRBool  aRepaint)
+{
+    mBounds.width = aWidth;
+    mBounds.height = aHeight;
+
+    if (!mWidget || (mWidget->width() == aWidth &&
+                     mWidget->height() == aHeight))
+        return NS_OK;
+
+    // There are several cases here that we need to handle, based on a
+    // matrix of the visibility of the widget, the sanity of this resize
+    // and whether or not the widget was previously sane.
+
+    // Has this widget been set to visible?
+    if (mIsShown) {
+        // Are the bounds sane?
+        if (AreBoundsSane()) {
+            // Yep?  Resize the window
+            //Maybe, the toplevel has moved
+            if (mContainer || mNeedsShow)
+                NativeResize(mBounds.x, mBounds.y,
+                             mBounds.width, mBounds.height, aRepaint);
+            else
+                NativeResize(mBounds.width, mBounds.height, aRepaint);
+
+            // Does it need to be shown because it was previously insane?
+            if (mNeedsShow)
+                NativeShow(PR_TRUE);
+        }
+        else {
+            // If someone has set this so that the needs show flag is false
+            // and it needs to be hidden, update the flag and hide the
+            // window.  This flag will be cleared the next time someone
+            // hides the window or shows it.  It also prevents us from
+            // calling NativeShow(PR_FALSE) excessively on the window which
+            // causes unneeded X traffic.
+            if (!mNeedsShow) {
+                mNeedsShow = PR_TRUE;
+                NativeShow(PR_FALSE);
+            }
+        }
+    }
+    // If the widget hasn't been shown, mark the widget as needing to be
+    // resized before it is shown.
+    else {
+        if (AreBoundsSane() && mListenForResizes) {
+            // For widgets that we listen for resizes for (widgets created
+            // with native parents) we apparently _always_ have to resize.  I
+            // dunno why, but apparently we're lame like that.
+            NativeResize(aWidth, aHeight, aRepaint);
+        }
+        else {
+            mNeedsResize = PR_TRUE;
+        }
+    }
+
+    // synthesize a resize event if this isn't a toplevel
+    if (mContainer || mListenForResizes) {
+        nsRect rect(mBounds.x, mBounds.y, aWidth, aHeight);
+        nsEventStatus status;
+        DispatchResizeEvent(rect, status);
+    }
+
+    return NS_OK;
+}
+
+/*
+ * XXXX: This sucks because it basically hardcore duplicates the
+ *       code from the above function.
+ */
+NS_IMETHODIMP
+nsCommonWidget::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
+                       PRBool aRepaint)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("Resize : [%d,%d,%d,%d]", aX, aY, aWidth, aHeight);
+#endif
+    if (!mWidget || (mWidget->x() == aX &&
+                     mWidget->y() == aY &&
+                     mWidget->height() == aHeight &&
+                     mWidget->width() == aWidth))
+        return NS_OK;
+
+    mBounds.x = aX;
+    mBounds.y = aY;
+    mBounds.width = aWidth;
+    mBounds.height = aHeight;
+
+    // There are several cases here that we need to handle, based on a
+    // matrix of the visibility of the widget, the sanity of this resize
+    // and whether or not the widget was previously sane.
+
+    // Has this widget been set to visible?
+    if (mIsShown) {
+        // Are the bounds sane?
+        if (AreBoundsSane()) {
+            // Yep?  Resize the window
+            NativeResize(aX, aY, aWidth, aHeight, aRepaint);
+
+            // Does it need to be shown because it was previously insane?
+            if (mNeedsShow)
+                NativeShow(PR_TRUE);
+        }
+        else {
+            // If someone has set this so that the needs show flag is false
+            // and it needs to be hidden, update the flag and hide the
+            // window.  This flag will be cleared the next time someone
+            // hides the window or shows it.  It also prevents us from
+            // calling NativeShow(PR_FALSE) excessively on the window which
+            // causes unneeded X traffic.
+            if (!mNeedsShow) {
+                mNeedsShow = PR_TRUE;
+                NativeShow(PR_FALSE);
+            }
+        }
+    }
+    // If the widget hasn't been shown, mark the widget as needing to be
+    // resized before it is shown
+    else {
+        if (AreBoundsSane() && mListenForResizes){
+            // For widgets that we listen for resizes for (widgets created
+            // with native parents) we apparently _always_ have to resize.  I
+            // dunno why, but apparently we're lame like that.
+            NativeResize(aX, aY, aWidth, aHeight, aRepaint);
+        }
+        else {
+            mNeedsResize = PR_TRUE;
+        }
+    }
+
+    // synthesize a resize event if this isn't a toplevel
+    if (mContainer || mListenForResizes) {
+        nsRect rect(mBounds.x, mBounds.y, mBounds.width, mBounds.height);
+        nsEventStatus status;
+        DispatchResizeEvent(rect, status);
+    }
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Enable(PRBool aState)
+{
+    if (mWidget)
+        mWidget->setEnabled(aState);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::IsEnabled(PRBool *aState)
+{
+    if (mWidget)
+        *aState = mWidget->isEnabled();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetFocus(PRBool aRaise)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("SetFocus mWidget=%p, mContainer=%p, focuswidget=%p (%d)",
+           (void*)mWidget, (void*)mContainer, (void*)mWidget->focusWidget());
+#endif
+    if (mWidget) {
+        if (aRaise)
+            mWidget->raise();
+        mWidget->setFocus();
+
+        DispatchGotFocusEvent();
+    }
+
+    return NS_OK;
+}
+
+nsIFontMetrics*
+nsCommonWidget::GetFont()
+{
+#ifdef DEBUG_WIDGETS
+    qWarning("nsCommonWidget.cpp: GetFont not implemented");
+#endif
+    return nsnull;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetFont(const nsFont&)
+{
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Invalidate(PRBool aIsSynchronous)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("nsCommonWidget::Invalidate1 container=%p widget=%p", (void*)mContainer, (void*)mWidget);
+#endif
+    if (!mWidget)
+        return NS_OK;
+
+    if (aIsSynchronous)
+        mWidget->repaint();
+    else
+        mWidget->update();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Invalidate(const nsRect & aRect, PRBool aIsSynchronous)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("nsCommonWidget::Invalidate2 container=%p widget=%p", (void*)mContainer, (void*)mWidget);
+#endif
+    if (!mWidget)
+        return NS_OK;
+
+    if (aIsSynchronous)
+        mWidget->repaint(aRect.x, aRect.y, aRect.width, aRect.height);
+    else
+        mWidget->update(aRect.x, aRect.y, aRect.width, aRect.height);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Update()
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("nsCommonWidget::Update container=%p widget=%p", (void*)mContainer, (void*)mWidget);
+#endif
+    if (!mWidget)
+        return NS_OK;
+    mWidget->update();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetColorMap(nsColorMap*)
+{
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Scroll(int aDx, int aDy, nsRect *aClipRect)
+{
+    if (mWidget)
+        mWidget->scroll(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;
+        static_cast<nsBaseWidget*>(kid)->SetBounds(bounds);
+    }
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::ScrollWidgets(PRInt32 aDx,
+                              PRInt32 aDy)
+{
+    if (mWidget)
+        mWidget->scroll(aDx, aDy);
+
+    return NS_OK;
+}
+
+void*
+nsCommonWidget::GetNativeData(PRUint32 aDataType)
+{
+    switch(aDataType) {
+    case NS_NATIVE_WINDOW:
+        return mWidget;
+        break;
+
+    case NS_NATIVE_DISPLAY:
+        if (mWidget)
+            return mWidget->x11Info().display();
+        break;
+
+    case NS_NATIVE_WIDGET:
+        return mWidget;
+        break;
+
+    case NS_NATIVE_PLUGIN_PORT:
+        if (mWidget)
+            return (void*)mWidget->winId();
+        break;
+
+    default:
+        break;
+    }
+
+    return nsnull;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetTitle(const nsAString &str)
+{
+    nsAString::const_iterator it;
+    QString qStr((QChar*)str.BeginReading(it).get(), -1);
+
+    if (mContainer)
+        mContainer->setWindowTitle(qStr);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetMenuBar(nsIMenuBar*)
+{
+    qWarning("XXXXX SetMenuBar");
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::ShowMenuBar(int)
+{
+
+    qWarning("XXXXX ShowMenuBar");
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect)
+{
+    aNewRect.width = aOldRect.width;
+    aNewRect.height = aOldRect.height;
+
+    if (mWidget) {
+        PRInt32 x,y;
+
+        QPoint offset(0,0);
+        offset = mWidget->mapToGlobal(offset);
+        x = offset.x();
+        y = offset.y();
+
+        aNewRect.x = aOldRect.x + x;
+        aNewRect.y = aOldRect.y + y;
+    }
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::ScreenToWidget(const nsRect &aOldRect, nsRect &aNewRect)
+{
+    if (mWidget) {
+        PRInt32 X,Y;
+
+        QPoint offset(0,0);
+        offset = mWidget->mapFromGlobal(offset);
+        X = offset.x();
+        Y = offset.y();
+
+        aNewRect.x = aOldRect.x + X;
+        aNewRect.y = aOldRect.y + Y;
+    }
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::BeginResizingChildren()
+{
+    qWarning("XXXXXX BeginResizingChildren");
+    return  NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::EndResizingChildren()
+{
+    qWarning("XXXXXXX EndResizingChildren");
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::GetPreferredSize(PRInt32 &aWidth, PRInt32 &aHeight)
+{
+    if (!mWidget)
+        return NS_ERROR_FAILURE;
+
+    QSize sh = mWidget->sizeHint();
+    aWidth = qMax(0, sh.width());
+    aHeight = qMax(0, sh.height());
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::SetPreferredSize(int w, int h)
+{
+    qWarning("XXX SetPreferredSize %d %d", w, h);
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus)
+{
+    aStatus = nsEventStatus_eIgnore;
+
+    // hold a widget reference while we dispatch this event
+    NS_ADDREF(aEvent->widget);
+
+    if (mEventCallback)
+        aStatus = (*mEventCallback)(aEvent);
+
+    // dispatch to event listener if event was not consumed
+    if ((aStatus != nsEventStatus_eIgnore) && mEventListener)
+        aStatus = mEventListener->ProcessEvent(*aEvent);
+
+    NS_IF_RELEASE(aEvent->widget);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::CaptureRollupEvents(nsIRollupListener*, PRBool, PRBool)
+{
+    return NS_OK;
+}
+
+void
+nsCommonWidget::DispatchGotFocusEvent(void)
+{
+    nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, this);
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+}
+
+void
+nsCommonWidget::DispatchLostFocusEvent(void)
+{
+    nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, this);
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+}
+
+void
+nsCommonWidget::DispatchActivateEvent(void)
+{
+    nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this);
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+}
+
+void
+nsCommonWidget::DispatchDeactivateEvent(void)
+{
+    nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this);
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+}
+
+void
+nsCommonWidget::DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus)
+{
+    nsSizeEvent event(PR_TRUE, NS_SIZE, this);
+
+    event.windowSize = &aRect;
+    event.refPoint.x = aRect.x;
+    event.refPoint.y = aRect.y;
+    event.mWinWidth = aRect.width;
+    event.mWinHeight = aRect.height;
+
+    DispatchEvent(&event, aStatus);
+}
+
+bool
+nsCommonWidget::mousePressEvent(QMouseEvent *e)
+{
+    //qDebug("mousePressEvent mWidget=%p", (void*)mWidget);
+//     backTrace();
+    PRUint32      eventType;
+
+    switch (e->button()) {
+    case Qt::MidButton:
+        eventType = nsMouseEvent::eMiddleButton;
+        break;
+    case Qt::RightButton:
+        eventType = nsMouseEvent::eRightButton;
+        break;
+    default:
+        eventType = nsMouseEvent::eLeftButton;
+        break;
+    }
+
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal);
+    event.button = eventType;
+
+    InitMouseEvent(&event, e, 1);
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+
+    // right menu click on linux should also pop up a context menu
+    if (eventType == nsMouseEvent::eRightButton) {
+        nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this,
+                                      nsMouseEvent::eReal);
+        InitMouseEvent(&contextMenuEvent, e, 1);
+        DispatchEvent(&contextMenuEvent, status);
+    }
+
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::mouseReleaseEvent(QMouseEvent *e)
+{
+    //qDebug("mouseReleaseEvent mWidget=%p", (void*)mWidget);
+    PRUint32      eventType;
+
+    switch (e->button()) {
+    case Qt::MidButton:
+        eventType = nsMouseEvent::eMiddleButton;
+        break;
+    case Qt::RightButton:
+        eventType = nsMouseEvent::eRightButton;
+        break;
+    default:
+        eventType = nsMouseEvent::eLeftButton;
+        break;
+    }
+
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal);
+    event.button = eventType;
+
+    InitMouseEvent(&event, e, 1);
+
+    //not pressed
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::mouseDoubleClickEvent(QMouseEvent *e)
+{
+    PRUint32      eventType;
+
+    switch (e->button()) {
+    case Qt::MidButton:
+        eventType = nsMouseEvent::eMiddleButton;
+        break;
+    case Qt::RightButton:
+        eventType = nsMouseEvent::eRightButton;
+        break;
+    default:
+        eventType = nsMouseEvent::eLeftButton;
+        break;
+    }
+
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_DOUBLECLICK, this, nsMouseEvent::eReal);
+    event.button = eventType;
+
+    InitMouseEvent(&event, e, 2);
+    //pressed
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::mouseMoveEvent(QMouseEvent *e)
+{
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal);
+
+    InitMouseEvent(&event, e, 0);
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::wheelEvent(QWheelEvent *e)
+{
+    nsMouseScrollEvent nsEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
+
+    InitMouseWheelEvent(&nsEvent, e);
+
+    nsEventStatus status;
+    DispatchEvent(&nsEvent, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::keyPressEvent(QKeyEvent *e)
+{
+    //qDebug("keyPressEvent");
+
+    nsEventStatus status;
+
+    // If the key repeat flag isn't set then set it so we don't send
+    // another key down event on the next key press -- DOM events are
+    // key down, key press and key up.  X only has key press and key
+    // release.  gtk2 already filters the extra key release events for
+    // us.
+
+    nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, this);
+    InitKeyEvent(&pressEvent, e);
+    pressEvent.charCode = (PRInt32)e->text()[0].unicode();
+
+    if (!e->isAutoRepeat()) {
+
+        // send the key down event
+        nsKeyEvent downEvent(PR_TRUE, NS_KEY_DOWN, this);
+        InitKeyEvent(&downEvent, e);
+        DispatchEvent(&downEvent, status);
+        if (ignoreEvent(status)) { // If prevent default on keydown, do same for keypress
+          pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
+        }
+    }
+
+    // before we dispatch a key, check if it's the context menu key.
+    // If so, send a context menu key event instead.
+    if (isContextMenuKey(pressEvent)) {
+        nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal);
+        keyEventToContextMenuEvent(&pressEvent, &contextMenuEvent);
+        DispatchEvent(&contextMenuEvent, status);
+    }
+    else {
+        // send the key press event
+        DispatchEvent(&pressEvent, status);
+    }
+
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::keyReleaseEvent(QKeyEvent *e)
+{
+    nsKeyEvent event(PR_TRUE, NS_KEY_UP, this);
+
+    InitKeyEvent(&event, e);
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::focusInEvent(QFocusEvent *)
+{
+    if (!mWidget)
+        return FALSE;
+
+#ifdef DEBUG_WIDGETS
+    qDebug("focusInEvent mWidget=%p, mContainer=%p", (void*)mWidget, (void*)mContainer);
+#endif
+
+    DispatchGotFocusEvent();
+
+    DispatchActivateEvent();
+
+    return FALSE;
+}
+
+bool
+nsCommonWidget::focusOutEvent(QFocusEvent *)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("focusOutEvent mWidget=%p,mContainer = %p", (void*)mWidget, (void*)mContainer);
+#endif
+
+    DispatchLostFocusEvent();
+    if (mContainer)
+        DispatchDeactivateEvent();
+
+    return FALSE;
+}
+
+bool
+nsCommonWidget::enterEvent(QEvent *)
+{
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this, nsMouseEvent::eReal);
+
+    QPoint pt = QCursor::pos();
+
+    event.refPoint.x = nscoord(pt.x());
+    event.refPoint.y = nscoord(pt.y());
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return FALSE;
+}
+
+bool
+nsCommonWidget::leaveEvent(QEvent *aEvent)
+{
+    nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this, nsMouseEvent::eReal);
+
+    QPoint pt = QCursor::pos();
+
+    event.refPoint.x = nscoord(pt.x());
+    event.refPoint.y = nscoord(pt.y());
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return FALSE;
+}
+
+bool
+nsCommonWidget::paintEvent(QPaintEvent *e)
+{
+    //qDebug("paintEvent: mWidget=%p x = %d, y = %d, width =  %d, height = %d", (void*)mWidget,
+    //e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height());
+//     qDebug("paintEvent: Widgetrect %d %d %d %d", mWidget->x(), mWidget->y(),
+//            mWidget->width(), mWidget->height());
+
+    QRect r = e->rect();
+    if (!r.isValid())
+        r = mWidget->rect();
+    nsRect rect(r.x(), r.y(), r.width(), r.height());
+
+    nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
+
+    // Generate XPFE paint event
+    nsPaintEvent event(PR_TRUE, NS_PAINT, this);
+    event.refPoint.x = 0;
+    event.refPoint.y = 0;
+    event.rect = &rect;
+    // XXX fix this!
+    event.region = nsnull;
+    // XXX fix this!
+    event.renderingContext = rc;
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::moveEvent(QMoveEvent *e)
+{
+    // can we shortcut?
+    if (!mWidget || (mBounds.x == e->pos().x() &&
+                     mBounds.y == e->pos().y()))
+        return FALSE;
+
+#ifdef DEBUG_WIDGETS
+    bool shown = mWidget ? !mWidget->isHidden() : false;
+    bool popup = mWidget ? mWidget->windowType() == Qt::Popup : false;
+
+    qDebug("moveEvent mWidget=%p %d %d (%s, %s)", (void*)mWidget, e->pos().x(), e->pos().y(),
+           shown? "shown": "hidden", popup ? "popup": "widget");
+#endif
+
+    // Toplevel windows need to have their bounds set so that we can
+    // keep track of our location.  It's not often that the x,y is set
+    // by the layout engine.  Width and height are set elsewhere.
+    QPoint pos = e->pos();
+
+    if (mContainer) {
+        // Need to translate this into the right coordinates
+        nsRect oldrect, newrect;
+        WidgetToScreen(oldrect, newrect);
+        mBounds.x = newrect.x;
+        mBounds.y = newrect.y;
+#ifdef DEBUG_WIDGETS
+        qDebug("BOUNDS are [%d, %d]", mBounds.x, mBounds.y);
+#endif
+    }
+
+    nsGUIEvent event(PR_TRUE, NS_MOVE, this);
+    event.refPoint.x = pos.x();
+    event.refPoint.y = pos.y();
+
+    // XXX mozilla will invalidate the entire window after this move
+    // complete.  wtf?
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::resizeEvent(QResizeEvent *e)
+{
+    nsRect rect;
+
+    // Generate XPFE resize event
+    GetBounds(rect);
+    rect.width = e->size().width();
+    rect.height = e->size().height();
+
+    mBounds.width = rect.width;
+    mBounds.height = rect.height;
+
+#ifdef DEBUG_WIDGETS
+    qDebug("resizeEvent: mWidget=%p, aWidth=%d, aHeight=%d, aX = %d, aY = %d", (void*)mWidget,
+           rect.width, rect.height, rect.x, rect.y);
+#endif
+
+    nsEventStatus status;
+    DispatchResizeEvent(rect, status);
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::closeEvent(QCloseEvent *)
+{
+    nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, this);
+
+    event.refPoint.x = 0;
+    event.refPoint.y = 0;
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+
+    return ignoreEvent(status);
+}
+
+bool
+nsCommonWidget::contextMenuEvent(QContextMenuEvent *)
+{
+    //qDebug("context menu");
+    return false;
+}
+
+bool
+nsCommonWidget::imStartEvent(QEvent *)
+{
+    qWarning("XXX imStartEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::imComposeEvent(QEvent *)
+{
+    qWarning("XXX imComposeEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::imEndEvent(QEvent * )
+{
+    qWarning("XXX imComposeEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::dragEnterEvent(QDragEnterEvent *)
+{
+    qDebug("XXX dragEnterEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::dragMoveEvent(QDragMoveEvent *)
+{
+    qDebug("XXX dragMoveEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::dragLeaveEvent(QDragLeaveEvent *)
+{
+    qDebug("XXX dragLeaveEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::dropEvent(QDropEvent *)
+{
+    qDebug("XXX dropEvent");
+    return false;
+}
+
+bool
+nsCommonWidget::showEvent(QShowEvent *)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("showEvent mWidget=%p", (void*)mWidget);
+#endif
+
+    QRect r = mWidget->rect();
+    nsRect rect(r.x(), r.y(), r.width(), r.height());
+
+    nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
+       // Generate XPFE paint event
+    nsPaintEvent event(PR_TRUE, NS_PAINT, this);
+    event.refPoint.x = 0;
+    event.refPoint.y = 0;
+    event.rect = &rect;
+    // XXX fix this!
+    event.region = nsnull;
+    // XXX fix this!
+    event.renderingContext = rc;
+
+    nsEventStatus status;
+    DispatchEvent(&event, status);
+
+    return false;
+}
+
+bool
+nsCommonWidget::hideEvent(QHideEvent *)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("hideEvent mWidget=%p", (void*)mWidget);
+#endif
+    return false;
+}
+
+void
+nsCommonWidget::InitKeyEvent(nsKeyEvent *nsEvent, QKeyEvent *qEvent)
+{
+    nsEvent->isShift   = qEvent->modifiers() & Qt::ShiftModifier;
+    nsEvent->isControl = qEvent->modifiers() & Qt::ControlModifier;
+    nsEvent->isAlt     = qEvent->modifiers() & Qt::AltModifier;
+    nsEvent->isMeta    = qEvent->modifiers() & Qt::MetaModifier;
+    nsEvent->time      = 0;
+
+    if (qEvent->text().length() && qEvent->text()[0].isPrint()) {
+        nsEvent->charCode = (PRInt32)qEvent->text()[0].unicode();
+    }
+    else {
+        nsEvent->charCode = 0;
+    }
+
+    if (nsEvent->charCode) {
+        nsEvent->keyCode = 0;
+    }
+    else {
+        nsEvent->keyCode = NS_GetKey(qEvent->key());
+    }
+}
+
+void
+nsCommonWidget::InitMouseEvent(nsMouseEvent *nsEvent, QMouseEvent *qEvent, int aClickCount)
+{
+    nsEvent->refPoint.x = nscoord(qEvent->x());
+    nsEvent->refPoint.y = nscoord(qEvent->y());
+
+    nsEvent->isShift         = qEvent->modifiers() & Qt::ShiftModifier;
+    nsEvent->isControl       = qEvent->modifiers() & Qt::ControlModifier;
+    nsEvent->isAlt           = qEvent->modifiers() & Qt::AltModifier;
+    nsEvent->isMeta          = qEvent->modifiers() & Qt::MetaModifier;
+    nsEvent->clickCount      = aClickCount;
+}
+
+void
+nsCommonWidget::InitMouseWheelEvent(nsMouseScrollEvent *aEvent,
+                                    QWheelEvent *qEvent)
+{
+    switch (qEvent->orientation()) {
+    case Qt::Vertical:
+        aEvent->scrollFlags = nsMouseScrollEvent::kIsVertical;
+        break;
+    case Qt::Horizontal:
+        aEvent->scrollFlags = nsMouseScrollEvent::kIsHorizontal;
+        break;
+    default:
+        Q_ASSERT(0);
+        break;
+    }
+    aEvent->delta = (int)((qEvent->delta() / WHEEL_DELTA) * -3);
+
+    aEvent->refPoint.x = nscoord(qEvent->x());
+    aEvent->refPoint.y = nscoord(qEvent->y());
+
+    aEvent->isShift         = qEvent->modifiers() & Qt::ShiftModifier;
+    aEvent->isControl       = qEvent->modifiers() & Qt::ControlModifier;
+    aEvent->isAlt           = qEvent->modifiers() & Qt::AltModifier;
+    aEvent->isMeta          = qEvent->modifiers() & Qt::MetaModifier;
+    aEvent->time            = 0;
+}
+
+void
+nsCommonWidget::CommonCreate(nsIWidget *aParent, PRBool aListenForResizes)
+{
+    mParent = aParent;
+    mListenForResizes = aListenForResizes;
+}
+
+PRBool
+nsCommonWidget::AreBoundsSane() const
+{
+    if (mBounds.width > 0 && mBounds.height > 0)
+        return PR_TRUE;
+
+    return PR_FALSE;
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Create(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction,
+                       nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsIToolkit *aToolkit,
+                       nsWidgetInitData *aInitData)
+{
+    return NativeCreate(aParent, nsnull, aRect, aHandleEventFunction, aContext, aAppShell,
+                        aToolkit, aInitData);
+}
+
+NS_IMETHODIMP
+nsCommonWidget::Create(nsNativeWidget aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction,
+                       nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsIToolkit *aToolkit,
+                       nsWidgetInitData *aInitData)
+{
+    return NativeCreate(nsnull, (QWidget*)aParent, aRect, aHandleEventFunction, aContext, aAppShell,
+                        aToolkit, aInitData);
+}
+
+nsresult
+nsCommonWidget::NativeCreate(nsIWidget        *aParent,
+                             QWidget          *aNativeParent,
+                             const nsRect     &aRect,
+                             EVENT_CALLBACK    aHandleEventFunction,
+                             nsIDeviceContext *aContext,
+                             nsIAppShell      *aAppShell,
+                             nsIToolkit       *aToolkit,
+                             nsWidgetInitData *aInitData)
+{
+    // only set the base parent if we're going to be a dialog or a
+    // toplevel
+    nsIWidget *baseParent = aInitData &&
+                            (aInitData->mWindowType == eWindowType_dialog ||
+                             aInitData->mWindowType == eWindowType_toplevel ||
+                             aInitData->mWindowType == eWindowType_invisible) ?
+                            nsnull : aParent;
+
+    // initialize all the common bits of this class
+    BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
+               aAppShell, aToolkit, aInitData);
+
+    // Do we need to listen for resizes?
+    PRBool listenForResizes = PR_FALSE;;
+    if (aNativeParent || (aInitData && aInitData->mListenForResizes))
+        listenForResizes = PR_TRUE;
+
+    // and do our common creation
+    CommonCreate(aParent, listenForResizes);
+
+    // save our bounds
+    mBounds = aRect;
+
+    QWidget *parent = 0;
+    if (aParent != nsnull)
+        parent = (QWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET);
+    else
+        parent = aNativeParent;
+
+    mWidget = createQWidget(parent, aInitData);
+
+    Initialize(mWidget);
+
+    Resize(mBounds.width, mBounds.height, PR_FALSE);
+
+    return NS_OK;
+}
+
+nsCursor nsCommonWidget::GetCursor()
+{
+    return mCursor;
+}
+
+NS_METHOD nsCommonWidget::SetCursor(nsCursor aCursor)
+{
+    mCursor = aCursor;
+    Qt::CursorShape cursor = Qt::ArrowCursor;
+    switch(mCursor) {
+    case eCursor_standard:
+	cursor = Qt::ArrowCursor;
+        break;
+    case eCursor_wait:
+        cursor = Qt::WaitCursor;
+        break;
+    case eCursor_select:
+        cursor = Qt::IBeamCursor;
+        break;
+    case eCursor_hyperlink:
+        cursor = Qt::PointingHandCursor;
+        break;
+    case eCursor_ew_resize:
+        cursor = Qt::SplitHCursor;
+        break;
+    case eCursor_ns_resize:
+        cursor = Qt::SplitVCursor;
+        break;
+    case eCursor_nw_resize:
+    case eCursor_se_resize:
+	cursor = Qt::SizeBDiagCursor;
+        break;
+    case eCursor_ne_resize:
+    case eCursor_sw_resize:
+	cursor = Qt::SizeFDiagCursor;
+        break;
+    case eCursor_crosshair:
+    case eCursor_move:
+	cursor = Qt::SizeAllCursor;
+        break;
+    case eCursor_help:
+	cursor = Qt::WhatsThisCursor;
+        break;
+    case eCursor_copy:
+    case eCursor_alias:
+        break;
+    case eCursor_context_menu:
+    case eCursor_cell:
+    case eCursor_grab:
+    case eCursor_grabbing:
+    case eCursor_spinning:
+    case eCursor_zoom_in:
+    case eCursor_zoom_out:
+
+    default:
+        break;
+    }
+    mWidget->setCursor(cursor);
+    return NS_OK;
+}
+
+NS_METHOD nsCommonWidget::SetModal(PRBool aModal)
+{
+#ifdef DEBUG_WIDGETS
+    qDebug("------------> SetModal mWidget=%p",(void*) mWidget);
+#endif
+
+    MozQWidget *mozWidget = static_cast<MozQWidget*>(mWidget);
+    if (mozWidget)
+        mozWidget->setModal(aModal);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP nsCommonWidget::GetScreenBounds(nsRect &aRect)
+{
+	nsRect origin(0,0,mBounds.width,mBounds.height);
+	WidgetToScreen(origin, aRect);
+	return NS_OK;
+}
+
+void
+nsCommonWidget::NativeShow(PRBool aState)
+{
+    mNeedsShow = PR_FALSE;
+
+    if (!mWidget) {
+         //XXX: apperently can be null during the printing, check whether
+         //     that's true
+         qDebug("nsCommon::Show : widget empty");
+         return;
+    }
+    mWidget->setShown(aState);
+}
+
+void
+nsCommonWidget::NativeResize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
+{
+    mNeedsResize = PR_FALSE;
+
+    mWidget->resize( aWidth, aHeight);
+
+    if (aRepaint) {
+        if (mWidget->isVisible())
+            mWidget->repaint();
+    }
+}
+
+void
+nsCommonWidget::NativeResize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
+                             PRBool aRepaint)
+{
+    mNeedsResize = PR_FALSE;
+
+    QPoint pos(aX, aY);
+    if (mContainer)
+    {
+        if (mParent && mWidget->windowType() == Qt::Popup) {
+            nsRect oldrect, newrect;
+            oldrect.x = aX;
+            oldrect.y = aY;
+
+            mParent->WidgetToScreen(oldrect, newrect);
+
+            pos = QPoint(newrect.x, newrect.y);
+#ifdef DEBUG_WIDGETS
+            qDebug("pos is [%d,%d]", pos.x(), pos.y());
+#endif
+        } else {
+#ifdef DEBUG_WIDGETS
+            qDebug("Widget with original position? (%p)", mWidget);
+#endif
+        }
+    }
+
+    mWidget->setGeometry(pos.x(), pos.y(), aWidth, aHeight);
+
+    if (aRepaint) {
+        if (mWidget->isVisible())
+            mWidget->repaint();
+    }
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsCommonWidget.h
@@ -0,0 +1,215 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *  Zack Rusin <zack@kde.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *
+ * 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 NSCOMMONWIDGET_H
+#define NSCOMMONWIDGET_H
+
+#include "nsBaseWidget.h"
+
+#include "nsEvent.h"
+
+#include <qevent.h> //XXX switch for forward-decl
+
+class nsIToolkit;
+class nsWidgetInitData;
+class nsIDeviceContext;
+class nsIAppShell;
+class nsIFontMetrics;
+class nsColorMap;
+class nsFont;
+class nsRect;
+class nsAString;
+class nsIMenuBar;
+class nsGUIEvent;
+class nsIRollupListener;
+class QWidget;
+class nsQtEventDispatcher;
+
+class nsCommonWidget : public nsBaseWidget
+{
+public:
+    nsCommonWidget();
+    ~nsCommonWidget();
+
+    NS_DECL_ISUPPORTS_INHERITED
+
+    NS_IMETHOD Show(PRBool);
+    NS_IMETHOD IsVisible(PRBool&);
+
+    NS_IMETHOD ConstrainPosition(PRBool, PRInt32*, PRInt32*);
+    NS_IMETHOD Move(PRInt32, PRInt32);
+    NS_IMETHOD Resize(PRInt32, PRInt32, PRBool);
+    NS_IMETHOD Resize(PRInt32, PRInt32, PRInt32, PRInt32, PRBool);
+    NS_IMETHOD Enable(PRBool);
+    NS_IMETHOD IsEnabled(PRBool*);
+    NS_IMETHOD SetFocus(PRBool araise = PR_FALSE);
+
+    virtual nsIFontMetrics* GetFont();
+
+    NS_IMETHOD SetFont(const nsFont&);
+    NS_IMETHOD Invalidate(PRBool);
+    NS_IMETHOD Invalidate(const nsRect&, int);
+    NS_IMETHOD Update();
+    NS_IMETHOD SetColorMap(nsColorMap*);
+    NS_IMETHOD Scroll(PRInt32, PRInt32, nsRect*);
+    NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy);
+
+    NS_IMETHOD SetModal(PRBool aModal);
+
+    virtual void* GetNativeData(PRUint32);
+
+    NS_IMETHOD SetTitle(const nsAString&);
+    NS_IMETHOD SetMenuBar(nsIMenuBar*);
+    NS_IMETHOD ShowMenuBar(PRBool);
+    NS_IMETHOD GetScreenBounds(nsRect &aRect);
+    NS_IMETHOD WidgetToScreen(const nsRect&, nsRect&);
+    NS_IMETHOD ScreenToWidget(const nsRect&, nsRect&);
+    NS_IMETHOD BeginResizingChildren();
+    NS_IMETHOD EndResizingChildren();
+    NS_IMETHOD GetPreferredSize(PRInt32&, PRInt32&);
+    NS_IMETHOD SetPreferredSize(PRInt32, PRInt32);
+    NS_IMETHOD DispatchEvent(nsGUIEvent*, nsEventStatus&);
+    NS_IMETHOD CaptureRollupEvents(nsIRollupListener*, PRBool, PRBool);
+
+    // nsIWidget
+    NS_IMETHOD         Create(nsIWidget        *aParent,
+                              const nsRect     &aRect,
+                              EVENT_CALLBACK   aHandleEventFunction,
+                              nsIDeviceContext *aContext,
+                              nsIAppShell      *aAppShell,
+                              nsIToolkit       *aToolkit,
+                              nsWidgetInitData *aInitData);
+    NS_IMETHOD         Create(nsNativeWidget aParent,
+                              const nsRect     &aRect,
+                              EVENT_CALLBACK   aHandleEventFunction,
+                              nsIDeviceContext *aContext,
+                              nsIAppShell      *aAppShell,
+                              nsIToolkit       *aToolkit,
+                              nsWidgetInitData *aInitData);
+
+    nsCursor GetCursor();
+    NS_METHOD SetCursor(nsCursor aCursor);
+
+protected:
+    /**
+     * Event handlers (proxied from the actual qwidget).
+     * They follow normal Qt widget semantics.
+     */
+    friend class nsQtEventDispatcher;
+    friend class InterceptContainer;
+    friend class MozQWidget;
+
+    virtual bool mousePressEvent(QMouseEvent *);
+    virtual bool mouseReleaseEvent(QMouseEvent *);
+    virtual bool mouseDoubleClickEvent(QMouseEvent *);
+    virtual bool mouseMoveEvent(QMouseEvent *);
+    virtual bool wheelEvent(QWheelEvent *);
+    virtual bool keyPressEvent(QKeyEvent *);
+    virtual bool keyReleaseEvent(QKeyEvent *);
+    virtual bool focusInEvent(QFocusEvent *);
+    virtual bool focusOutEvent(QFocusEvent *);
+    virtual bool enterEvent(QEvent *);
+    virtual bool leaveEvent(QEvent *);
+    virtual bool paintEvent(QPaintEvent *);
+    virtual bool moveEvent(QMoveEvent *);
+    virtual bool resizeEvent(QResizeEvent *);
+    virtual bool closeEvent(QCloseEvent *);
+    virtual bool contextMenuEvent(QContextMenuEvent *);
+    virtual bool imStartEvent(QEvent *);
+    virtual bool imComposeEvent(QEvent *);
+    virtual bool imEndEvent(QEvent *);
+    virtual bool dragEnterEvent(QDragEnterEvent *);
+    virtual bool dragMoveEvent(QDragMoveEvent *);
+    virtual bool dragLeaveEvent(QDragLeaveEvent *);
+    virtual bool dropEvent(QDropEvent *);
+    virtual bool showEvent(QShowEvent *);
+    virtual bool hideEvent(QHideEvent *);
+
+protected:
+    virtual QWidget  *createQWidget(QWidget *parent, nsWidgetInitData *aInitData) = 0;
+    virtual void NativeResize(PRInt32, PRInt32, PRInt32, PRInt32, PRBool);
+    virtual void NativeResize(PRInt32, PRInt32, PRBool);
+    virtual void NativeShow(PRBool);
+
+    static bool ignoreEvent(nsEventStatus aStatus)
+                { return aStatus == nsEventStatus_eConsumeNoDefault; }
+
+    /**
+     * Has to be called in subclasses after they created
+     * the actual QWidget if they overwrite the Create
+     * calls from the nsCommonWidget class.
+     */
+    void Initialize(QWidget *widget);
+
+    void DispatchGotFocusEvent(void);
+    void DispatchLostFocusEvent(void);
+    void DispatchActivateEvent(void);
+    void DispatchDeactivateEvent(void);
+    void DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus);
+
+    void InitKeyEvent(nsKeyEvent *nsEvent, QKeyEvent *qEvent);
+    void InitMouseEvent(nsMouseEvent *nsEvent, QMouseEvent *qEvent, int aClickCount);
+    void InitMouseWheelEvent(nsMouseScrollEvent *aEvent, QWheelEvent *qEvent);
+
+    void CommonCreate(nsIWidget *aParent, PRBool aListenForResizes);
+
+    PRBool AreBoundsSane() const;
+
+protected:
+    QWidget *mContainer;
+    QWidget *mWidget;
+    PRPackedBool   mListenForResizes;
+    PRPackedBool   mNeedsResize;
+    PRPackedBool   mNeedsShow;
+    PRPackedBool   mIsShown;
+    nsCOMPtr<nsIWidget> mParent;
+
+private:
+    nsresult NativeCreate(nsIWidget        *aParent,
+                          QWidget          *aNativeParent,
+                          const nsRect     &aRect,
+                          EVENT_CALLBACK    aHandleEventFunction,
+                          nsIDeviceContext *aContext,
+                          nsIAppShell      *aAppShell,
+                          nsIToolkit       *aToolkit,
+                          nsWidgetInitData *aInitData);
+
+};
+
+#endif
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsLookAndFeel.cpp
@@ -0,0 +1,498 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *   John C. Griggs <johng@corel.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 "nsLookAndFeel.h"
+
+#include <qpalette.h>
+#include <qapplication.h>
+
+#define QCOLOR_TO_NS_RGB(c) \
+    ((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
+
+//-------------------------------------------------------------------------
+//
+// Query interface implementation
+//
+//-------------------------------------------------------------------------
+nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
+{
+}
+
+nsLookAndFeel::~nsLookAndFeel()
+{
+}
+
+nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID,nscolor &aColor)
+{
+  nsresult res = NS_OK;
+
+  if (!qApp)
+    return NS_ERROR_FAILURE;
+
+  QPalette palette = qApp->palette();
+
+  switch (aID) {
+    case eColor_WindowBackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_WindowForeground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Foreground));
+      break;
+
+    case eColor_WidgetBackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_WidgetForeground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Foreground));
+      break;
+
+    case eColor_WidgetSelectBackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Background));
+      break;
+
+    case eColor_WidgetSelectForeground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Foreground));
+      break;
+
+    case eColor_Widget3DHighlight:
+      aColor = NS_RGB(0xa0,0xa0,0xa0);
+      break;
+
+    case eColor_Widget3DShadow:
+      aColor = NS_RGB(0x40,0x40,0x40);
+      break;
+
+    case eColor_TextBackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_TextForeground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+    case eColor_TextSelectBackground:
+    case eColor_IMESelectedRawTextBackground:
+    case eColor_IMESelectedConvertedTextBackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Highlight));
+      break;
+
+    case eColor_TextSelectForeground:
+    case eColor_IMESelectedRawTextForeground:
+    case eColor_IMESelectedConvertedTextForeground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::HighlightedText));
+      break;
+
+    case eColor_IMERawInputBackground:
+    case eColor_IMEConvertedTextBackground:
+      aColor = NS_TRANSPARENT;
+      break;
+
+    case eColor_IMERawInputForeground:
+    case eColor_IMEConvertedTextForeground:
+      aColor = NS_SAME_AS_FOREGROUND_COLOR;
+      break;
+
+    case eColor_IMERawInputUnderline:
+    case eColor_IMEConvertedTextUnderline:
+      aColor = NS_SAME_AS_FOREGROUND_COLOR;
+      break;
+
+    case eColor_IMESelectedRawTextUnderline:
+    case eColor_IMESelectedConvertedTextUnderline:
+      aColor = NS_TRANSPARENT;
+      break;
+
+    case eColor_activeborder:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_activecaption:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_appworkspace:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_background:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_captiontext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+    case eColor_graytext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Disabled, QPalette::Text));
+      break;
+
+    case eColor_highlight:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Highlight));
+      break;
+
+    case eColor_highlighttext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::HighlightedText));
+      break;
+
+    case eColor_inactiveborder:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_inactivecaption:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Disabled, QPalette::Background));
+      break;
+
+    case eColor_inactivecaptiontext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Disabled, QPalette::Text));
+      break;
+
+    case eColor_infobackground:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_infotext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+    case eColor_menu:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_menutext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+    case eColor_scrollbar:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Background));
+      break;
+
+    case eColor_threedface:
+    case eColor_buttonface:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_buttonhighlight:
+    case eColor_threedhighlight:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Light));
+      break;
+
+    case eColor_buttontext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+    case eColor_buttonshadow:
+    case eColor_threedshadow:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Shadow));
+      break;
+
+    case eColor_threeddarkshadow:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Dark));
+      break;
+
+    case eColor_threedlightshadow:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Light));
+      break;
+
+    case eColor_window:
+    case eColor_windowframe:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+      break;
+
+    case eColor_windowtext:
+      aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+      break;
+
+     // from the CSS3 working draft (not yet finalized)
+     // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
+     case eColor__moz_field:
+       aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Base));
+       break;
+
+     case eColor__moz_fieldtext:
+       aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+       break;
+
+     case eColor__moz_dialog:
+       aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Background));
+       break;
+
+     case eColor__moz_dialogtext:
+       aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Inactive, QPalette::Text));
+       break;
+
+     case eColor__moz_dragtargetzone:
+       aColor = QCOLOR_TO_NS_RGB(palette.color(QPalette::Active, QPalette::Background));
+       break;
+
+    default:
+      aColor = 0;
+      res    = NS_ERROR_FAILURE;
+      break;
+  }
+  return res;
+}
+
+static const char *metricToString[] = {
+    "eMetric_WindowTitleHeight",
+    "eMetric_WindowBorderWidth",
+    "eMetric_WindowBorderHeight",
+    "eMetric_Widget3DBorder",
+    "eMetric_TextFieldBorder"
+    "eMetric_TextFieldHeight",
+    "eMetric_TextVerticalInsidePadding",
+    "eMetric_TextShouldUseVerticalInsidePadding",
+    "eMetric_TextHorizontalInsideMinimumPadding",
+    "eMetric_TextShouldUseHorizontalInsideMinimumPadding",
+    "eMetric_ButtonHorizontalInsidePaddingNavQuirks",
+    "eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks",
+    "eMetric_CheckboxSize",
+    "eMetric_RadioboxSize",
+
+    "eMetric_ListShouldUseHorizontalInsideMinimumPadding",
+    "eMetric_ListHorizontalInsideMinimumPadding",
+
+    "eMetric_ListShouldUseVerticalInsidePadding",
+    "eMetric_ListVerticalInsidePadding",
+
+    "eMetric_CaretBlinkTime",
+    "eMetric_CaretWidth",
+    "eMetric_ShowCaretDuringSelection",
+    "eMetric_SelectTextfieldsOnKeyFocus",
+    "eMetric_SubmenuDelay",
+    "eMetric_MenusCanOverlapOSBar",
+    "eMetric_DragFullWindow",
+    "eMetric_DragThresholdX",
+    "eMetric_DragThresholdY",
+    "eMetric_UseAccessibilityTheme",
+    "eMetric_IsScreenReaderActive",
+
+    "eMetric_ScrollArrowStyle",
+    "eMetric_ScrollSliderStyle",
+
+    "eMetric_TreeOpenDelay",
+    "eMetric_TreeCloseDelay",
+    "eMetric_TreeLazyScrollDelay",
+    "eMetric_TreeScrollDelay",
+    "eMetric_TreeScrollLinesMax"
+    };
+
+
+NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric)
+{
+//     qDebug("nsLookAndFeel::GetMetric aID = %s", metricToString[aID]);
+  nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
+  if (NS_SUCCEEDED(res))
+      return res;
+//   qDebug("    checking ourselves");
+  res = NS_OK;
+
+  switch (aID) {
+    case eMetric_WindowTitleHeight:
+      aMetric = 0;
+      break;
+
+    case eMetric_WindowBorderWidth:
+      // There was once code in nsDeviceContextQt::GetSystemAttribute to
+      // use the border width obtained from a widget in its Init method.
+      break;
+
+    case eMetric_WindowBorderHeight:
+      // There was once code in nsDeviceContextQt::GetSystemAttribute to
+      // use the border width obtained from a widget in its Init method.
+      break;
+
+    case eMetric_Widget3DBorder:
+      aMetric = 4;
+      break;
+
+    case eMetric_TextFieldHeight:
+      aMetric = 15;
+      break;
+
+    case eMetric_TextFieldBorder:
+      aMetric = 2;
+      break;
+
+    case eMetric_TextVerticalInsidePadding:
+      aMetric = 0;
+      break;
+
+    case eMetric_TextShouldUseVerticalInsidePadding:
+      aMetric = 0;
+      break;
+
+    case eMetric_TextHorizontalInsideMinimumPadding:
+      aMetric = 15;
+      break;
+
+    case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
+      aMetric = 1;
+      break;
+
+    case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
+      aMetric = 10;
+      break;
+
+    case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
+      aMetric = 8;
+      break;
+
+    case eMetric_CheckboxSize:
+      aMetric = 15;
+      break;
+
+    case eMetric_RadioboxSize:
+      aMetric = 15;
+      break;
+
+    case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
+      aMetric = 15;
+      break;
+
+    case eMetric_ListHorizontalInsideMinimumPadding:
+      aMetric = 15;
+      break;
+
+    case eMetric_ListShouldUseVerticalInsidePadding:
+      aMetric = 1;
+      break;
+
+    case eMetric_ListVerticalInsidePadding:
+      aMetric = 1;
+      break;
+
+    case eMetric_CaretBlinkTime:
+      aMetric = 500;
+      break;
+
+    case eMetric_CaretWidth:
+      aMetric = 1;
+      break;
+
+    case eMetric_ShowCaretDuringSelection:
+      aMetric = 0;
+      break;
+
+    case eMetric_SelectTextfieldsOnKeyFocus:
+      // Select textfield content when focused by kbd
+      // used by nsEventStateManager::sTextfieldSelectModel
+      aMetric = 1;
+      break;
+
+    case eMetric_SubmenuDelay:
+      aMetric = 200;
+      break;
+
+    case eMetric_MenusCanOverlapOSBar:
+      // we want XUL popups to be able to overlap the task bar.
+      aMetric = 1;
+      break;
+
+    case eMetric_DragFullWindow:
+      aMetric = 1;
+      break;
+
+    case eMetric_ScrollArrowStyle:
+      aMetric = eMetric_ScrollArrowStyleSingle;
+      break;
+
+    case eMetric_ScrollSliderStyle:
+      aMetric = eMetric_ScrollThumbStyleProportional;
+      break;
+
+    default:
+      aMetric = 0;
+      res = NS_ERROR_FAILURE;
+  }
+  return res;
+}
+
+NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID,
+                                       float &aMetric)
+{
+  nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
+  if (NS_SUCCEEDED(res))
+      return res;
+  res = NS_OK;
+
+  switch (aID) {
+    case eMetricFloat_TextFieldVerticalInsidePadding:
+      aMetric = 0.25f;
+      break;
+
+    case eMetricFloat_TextFieldHorizontalInsidePadding:
+      aMetric = 0.95f; // large number on purpose so minimum padding is used
+      break;
+
+    case eMetricFloat_TextAreaVerticalInsidePadding:
+      aMetric = 0.40f;
+      break;
+
+    case eMetricFloat_TextAreaHorizontalInsidePadding:
+      aMetric = 0.40f; // large number on purpose so minimum padding is used
+      break;
+
+    case eMetricFloat_ListVerticalInsidePadding:
+      aMetric = 0.10f;
+      break;
+
+    case eMetricFloat_ListHorizontalInsidePadding:
+      aMetric = 0.40f;
+      break;
+
+    case eMetricFloat_ButtonVerticalInsidePadding:
+      aMetric = 0.25f;
+      break;
+
+    case eMetricFloat_ButtonHorizontalInsidePadding:
+      aMetric = 0.25f;
+      break;
+
+    case eMetricFloat_IMEUnderlineRelativeSize:
+      aMetric = 1.0f;
+      break;
+
+    default:
+      aMetric = -1.0;
+      res = NS_ERROR_FAILURE;
+  }
+  return res;
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsLookAndFeel.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   John C. Griggs <johng@corel.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 __nsLookAndFeel
+#define __nsLookAndFeel
+
+#include "nsXPLookAndFeel.h"
+
+class nsLookAndFeel: public nsXPLookAndFeel
+{
+public:
+    nsLookAndFeel();
+    virtual ~nsLookAndFeel();
+
+    nsresult NativeGetColor(const nsColorID aID, nscolor &aColor);
+    NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric);
+    NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric);
+};
+
+#endif
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsScreenManagerQt.cpp
@@ -0,0 +1,143 @@
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *   John C. Griggs <johng@corel.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 "nsScreenManagerQt.h"
+#include "nsScreenQt.h"
+
+#include "qdesktopwidget.h"
+#include "qapplication.h"
+
+nsScreenManagerQt::nsScreenManagerQt()
+{
+    desktop = 0;
+}
+
+
+nsScreenManagerQt::~nsScreenManagerQt()
+{
+    // nothing to see here.
+}
+
+// addref, release, QI
+NS_IMPL_ISUPPORTS1(nsScreenManagerQt, nsIScreenManager)
+
+void nsScreenManagerQt::init()
+{
+    if (desktop)
+        return;
+
+    desktop = QApplication::desktop();
+    nScreens = desktop->numScreens();
+    screens = new nsCOMPtr<nsIScreen>[nScreens];
+
+    for (int i = 0; i < nScreens; ++i)
+        screens[i] = new nsScreenQt(i);
+}
+
+//
+// ScreenForRect
+//
+// Returns the screen that contains the rectangle. If the rect overlaps
+// multiple screens, it picks the screen with the greatest area of intersection.
+//
+// The coordinates are in pixels (not twips) and in screen coordinates.
+//
+NS_IMETHODIMP
+nsScreenManagerQt::ScreenForRect(PRInt32 inLeft, PRInt32 inTop,
+				 PRInt32 inWidth, PRInt32 inHeight,
+				 nsIScreen **outScreen)
+{
+    if (!desktop)
+        init();
+
+    QRect r(inLeft, inTop, inWidth, inHeight);
+    int best = 0;
+    int area = 0;
+    for (int i = 0; i < nScreens; ++i) {
+        const QRect& rect = desktop->screenGeometry(i);
+        QRect intersection = r&rect;
+        int a = intersection.width()*intersection.height();
+        if (a > area) {
+            best = i;
+            area = a;
+        }
+    }
+    NS_IF_ADDREF(*outScreen = screens[best]);
+    return NS_OK;
+}
+
+//
+// GetPrimaryScreen
+//
+// The screen with the menubar/taskbar. This shouldn't be needed very
+// often.
+//
+NS_IMETHODIMP
+nsScreenManagerQt::GetPrimaryScreen(nsIScreen **aPrimaryScreen)
+{
+    if (!desktop)
+        init();
+
+    NS_IF_ADDREF(*aPrimaryScreen = screens[0]);
+    return NS_OK;
+}
+
+//
+// GetNumberOfScreens
+//
+// Returns how many physical screens are available.
+//
+NS_IMETHODIMP
+nsScreenManagerQt::GetNumberOfScreens(PRUint32 *aNumberOfScreens)
+{
+    if (!desktop)
+        init();
+
+    *aNumberOfScreens = desktop->numScreens();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScreenManagerQt :: ScreenForNativeWidget (void *aWidget, nsIScreen **outScreen)
+{
+    // I don't know how to go from GtkWindow to nsIScreen, especially
+    // given xinerama and stuff, so let's just do this
+    QRect rect = static_cast<QWidget*>(aWidget)->geometry();
+    return ScreenForRect(rect.x(), rect.y(), rect.width(), rect.height(), outScreen);
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsScreenManagerQt.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *   John C. Griggs <johng@corel.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 nsScreenManagerQt_h___
+#define nsScreenManagerQt_h___
+
+#include "nsIScreenManager.h"
+#include "nsIScreen.h"
+#include "nsCOMPtr.h"
+
+//------------------------------------------------------------------------
+class QDesktopWidget;
+
+class nsScreenManagerQt : public nsIScreenManager
+{
+public:
+  nsScreenManagerQt ( );
+  virtual ~nsScreenManagerQt();
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSISCREENMANAGER
+
+private:
+
+  void init ();
+
+  nsCOMPtr<nsIScreen> *screens;
+  QDesktopWidget *desktop;
+  int nScreens;
+};
+
+#endif  // nsScreenManagerQt_h___
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsScreenQt.cpp
@@ -0,0 +1,103 @@
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *   John C. Griggs <johng@corel.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 "nsScreenQt.h"
+
+#include <qcolor.h>
+#include <qcolormap.h>
+#include <qrect.h>
+#include <qdesktopwidget.h>
+#include <qapplication.h>
+
+nsScreenQt::nsScreenQt(int aScreen)
+{
+    screen = aScreen;
+    // nothing else to do. I guess we could cache a bunch of information
+    // here, but we want to ask the device at runtime in case anything
+    // has changed.
+}
+
+nsScreenQt::~nsScreenQt()
+{
+    // nothing to see here.
+}
+
+// addref, release, QI
+NS_IMPL_ISUPPORTS1(nsScreenQt, nsIScreen)
+
+    NS_IMETHODIMP
+nsScreenQt::GetRect(PRInt32 *outLeft,PRInt32 *outTop,
+                    PRInt32 *outWidth,PRInt32 *outHeight)
+{
+    QRect r = QApplication::desktop()->screenGeometry(screen);
+    *outTop = r.x();
+    *outLeft = r.y();
+    *outWidth = r.width();
+    *outHeight = r.height();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScreenQt::GetAvailRect(PRInt32 *outLeft,PRInt32 *outTop,
+                         PRInt32 *outWidth,PRInt32 *outHeight)
+{
+    QRect r = QApplication::desktop()->availableGeometry(screen);
+    *outTop = r.x();
+    *outLeft = r.y();
+    *outWidth = r.width();
+    *outHeight = r.height();
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScreenQt::GetPixelDepth(PRInt32 *aPixelDepth)
+{
+    // #############
+    *aPixelDepth = (PRInt32)QColormap::instance().depth();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScreenQt::GetColorDepth(PRInt32 *aColorDepth)
+{
+    // ###############
+    return GetPixelDepth(aColorDepth);
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsScreenQt.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *   John C. Griggs <johng@corel.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 nsScreenQt_h___
+#define nsScreenQt_h___
+
+#include "nsIScreen.h"
+
+//------------------------------------------------------------------------
+
+class nsScreenQt : public nsIScreen
+{
+public:
+  nsScreenQt (int aScreen);
+  virtual ~nsScreenQt();
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSISCREEN
+
+private:
+  int screen;
+};
+
+#endif  // nsScreenQt_h___
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsWindow.cpp
@@ -0,0 +1,227 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *  Zack Rusin <zack@kde.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *
+ * 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 "nsWindow.h"
+
+#include "mozqwidget.h"
+
+#include "gfxPlatform.h"
+#include "gfxXlibSurface.h"
+
+#include <qwidget.h>
+#include <qlayout.h>
+#include <QX11Info>
+
+NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsCommonWidget,
+                             nsISupportsWeakReference)
+
+nsWindow::nsWindow()
+{
+}
+
+nsWindow::~nsWindow()
+{
+}
+
+QWidget*
+nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData)
+{
+    Qt::WFlags flags = Qt::Widget;
+    Qt::WA_StaticContents;
+#ifdef DEBUG_WIDGETS
+    qDebug("NEW WIDGET\n\tparent is %p (%s)", (void*)parent,
+           parent ? qPrintable(parent->objectName()) : "null");
+#endif
+    // ok, create our windows
+    switch (mWindowType) {
+    case eWindowType_dialog:
+    case eWindowType_popup:
+    case eWindowType_toplevel:
+    case eWindowType_invisible: {
+        if (mWindowType == eWindowType_dialog) {
+            flags |= Qt::Dialog;
+            mContainer = new MozQWidget(this, parent, "topLevelDialog", flags);
+            qDebug("\t\t#### dialog (%p)", (void*)mContainer);
+            //SetDefaultIcon();
+        }
+        else if (mWindowType == eWindowType_popup) {
+            flags |= Qt::Popup;
+            mContainer = new MozQWidget(this, parent, "topLevelPopup", flags);
+            qDebug("\t\t#### popup (%p)", (void*)mContainer);
+            mContainer->setFocusPolicy(Qt::WheelFocus);
+        }
+        else { // must be eWindowType_toplevel
+            flags |= Qt::Window;
+            mContainer = new MozQWidget(this, parent, "topLevelWindow", flags);
+            qDebug("\t\t#### toplevel (%p)", (void*)mContainer);
+            //SetDefaultIcon();
+        }
+        mWidget = mContainer;
+    }
+        break;
+    case eWindowType_child: {
+        mWidget = new MozQWidget(this, parent, "paintArea", 0);
+        qDebug("\t\t#### child (%p)", (void*)mWidget);
+    }
+        break;
+    default:
+        break;
+    }
+
+    mWidget->setAttribute(Qt::WA_StaticContents);
+    mWidget->setAttribute(Qt::WA_OpaquePaintEvent); // Transparent Widget Background
+
+    //mWidget->setBackgroundMode(Qt::NoBackground);
+    //setAutoFillBackground(false)
+
+    return mWidget;
+}
+
+NS_IMETHODIMP
+nsWindow::PreCreateWidget(nsWidgetInitData *aWidgetInitData)
+{
+    if (nsnull != aWidgetInitData) {
+        mWindowType = aWidgetInitData->mWindowType;
+        mBorderStyle = aWidgetInitData->mBorderStyle;
+        return NS_OK;
+    }
+    return NS_ERROR_FAILURE;
+}
+
+gfxASurface*
+nsWindow::GetThebesSurface()
+{
+    // 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) {
+        PRInt32 x_offset = 0, y_offset = 0;
+        int width = mWidget->width(), height = mWidget->height();
+
+        // Owen Taylor says this is the right thing to do!
+        width = PR_MIN(32767, height);
+        height = PR_MIN(32767, width);
+
+        if (!gfxPlatform::UseGlitz()) {
+            qDebug("QT_WIDGET NOT SURE: Func:%s::%d, [%ix%i]\n", __PRETTY_FUNCTION__, __LINE__, width, height);
+            mThebesSurface = new gfxXlibSurface
+            (mWidget->x11Info().display(),
+             (Drawable)mWidget->x11Info().appRootWindow(),
+             static_cast<Visual*>(mWidget->x11Info().visual()),
+             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(),
+                                                mWidget->x11Info().appScreen(),
+                                                0, NULL, 0);
+            if (!gdformat)
+                NS_ERROR("Failed to find glitz drawable format");
+
+            Display* dpy = mWidget->x11Info().display(),;
+            Window wnd = (Window)mWidget->x11Info().appRootWindow();
+
+            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
+        }
+
+        if (mThebesSurface) {
+            mThebesSurface->SetDeviceOffset(gfxPoint(-x_offset, -y_offset));
+        }
+    }
+
+    return mThebesSurface;
+}
+
+//////////////////////////////////////////////////////////////////////
+ChildWindow::ChildWindow()
+{
+}
+
+ChildWindow::~ChildWindow()
+{
+}
+
+PRBool
+ChildWindow::IsChild() const
+{
+    return PR_TRUE;
+}
+
+PopupWindow::PopupWindow()
+{
+    qDebug("===================== popup!");
+}
+
+PopupWindow::~PopupWindow()
+{
+}
+
+
+
new file mode 100644
--- /dev/null
+++ b/widget/src/qt/nsWindow.h
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *  Zack Rusin <zack@kde.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Lars Knoll <knoll@kde.org>
+ *   Zack Rusin <zack@kde.org>
+ *
+ * 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 NSWINDOWNG_H
+#define NSWINDOWNG_H
+
+#include "nsCommonWidget.h"
+#include "nsWeakReference.h"
+#include "nsAutoPtr.h"
+
+class nsWindow : public nsCommonWidget,
+                 public nsSupportsWeakReference
+{
+public:
+    nsWindow();
+    virtual ~nsWindow();
+
+
+    NS_DECL_ISUPPORTS_INHERITED
+
+    NS_IMETHOD         PreCreateWidget(nsWidgetInitData *aWidgetInitData);
+
+    gfxASurface       *GetThebesSurface();
+
+protected:
+    QWidget  *createQWidget(QWidget *parent, nsWidgetInitData *aInitData);
+    nsRefPtr<gfxASurface> mThebesSurface;
+};
+
+class ChildWindow : public nsWindow
+{
+public:
+  ChildWindow();
+  ~ChildWindow();
+  virtual PRBool IsChild() const;
+
+  PRInt32 mChildID;
+};
+
+class PopupWindow : public nsWindow
+{
+public:
+    PopupWindow();
+    ~PopupWindow();
+
+  PRInt32 mChildID;
+};
+
+#endif