diff --git a/widget/src/qt/mozqwidget.cpp b/widget/src/qt/mozqwidget.cpp index 8447558d42e8..7941053bbdda 100644 --- a/widget/src/qt/mozqwidget.cpp +++ b/widget/src/qt/mozqwidget.cpp @@ -1,13 +1,26 @@ #include "mozqwidget.h" #include "nsWindow.h" -#include -MozQWidget::MozQWidget(nsWindow *receiver, QWidget *parent, - const char *name, int f) - : QWidget(parent, (Qt::WindowFlags)f), - mReceiver(receiver) +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +MozQWidget::MozQWidget(nsWindow* aReceiver, QGraphicsItem* aParent) + : QGraphicsWidget(aParent), + mReceiver(aReceiver) { - setAttribute(Qt::WA_QuitOnClose, false); + setFlag(QGraphicsItem::ItemIsFocusable); + + setFocusPolicy(Qt::WheelFocus); } MozQWidget::~MozQWidget() @@ -16,206 +29,128 @@ MozQWidget::~MozQWidget() mReceiver->QWidgetDestroyed(); } -bool MozQWidget::event(QEvent *e) +void MozQWidget::paint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget /*= 0*/) { - nsEventStatus status = nsEventStatus_eIgnore; - bool handled = true; - - // always handle (delayed) delete requests triggered by - // calling deleteLater() on this widget: - if (e->type() == QEvent::DeferredDelete) - return QObject::event(e); - - if (!mReceiver) - return false; - - switch(e->type()) { -/* - case QEvent::Accessibility: - { - qDebug("accessibility event received"); - } - break; -*/ - case QEvent::MouseButtonPress: - { - QMouseEvent *ms = (QMouseEvent*)(e); - status = mReceiver->OnButtonPressEvent(ms); - } - break; - case QEvent::MouseButtonRelease: - { - QMouseEvent *ms = (QMouseEvent*)(e); - status = mReceiver->OnButtonReleaseEvent(ms); - } - break; - case QEvent::MouseButtonDblClick: - { - QMouseEvent *ms = (QMouseEvent*)(e); - status = mReceiver->mouseDoubleClickEvent(ms); - } - break; - case QEvent::MouseMove: - { - QMouseEvent *ms = (QMouseEvent*)(e); - status = mReceiver->OnMotionNotifyEvent(ms); - } - break; - case QEvent::KeyPress: - { - QKeyEvent *kev = (QKeyEvent*)(e); - status = mReceiver->OnKeyPressEvent(kev); - } - break; - case QEvent::KeyRelease: - { - QKeyEvent *kev = (QKeyEvent*)(e); - status = mReceiver->OnKeyReleaseEvent(kev); - } - break; -/* - case QEvent::IMStart: - { - QIMEvent *iev = (QIMEvent*)(e); - status = mReceiver->imStartEvent(iev); - } - break; - case QEvent::IMCompose: - { - QIMEvent *iev = (QIMEvent*)(e); - status = mReceiver->imComposeEvent(iev); - } - break; - case QEvent::IMEnd: - { - QIMEvent *iev = (QIMEvent*)(e); - status = mReceiver->imEndEvent(iev); - } - break; -*/ - case QEvent::WindowActivate: - { - QFocusEvent *fev = (QFocusEvent*)(e); - mReceiver->OnFocusInEvent(fev); - return TRUE; - } - break; - case QEvent::WindowDeactivate: - { - QFocusEvent *fev = (QFocusEvent*)(e); - mReceiver->OnFocusOutEvent(fev); - return TRUE; - } - break; - case QEvent::Enter: - { - status = mReceiver->OnEnterNotifyEvent(e); - } - break; - case QEvent::Leave: - { - status = mReceiver->OnLeaveNotifyEvent(e); - } - break; - case QEvent::Paint: - { - QPaintEvent *ev = (QPaintEvent*)(e); - status = mReceiver->OnPaintEvent(ev); - } - break; - case QEvent::Move: - { - QMoveEvent *mev = (QMoveEvent*)(e); - status = mReceiver->OnMoveEvent(mev); - } - break; - case QEvent::Resize: - { - QResizeEvent *rev = (QResizeEvent*)(e); - status = mReceiver->OnResizeEvent(rev); - } - break; - case QEvent::Show: - { - QShowEvent *sev = (QShowEvent*)(e); - mReceiver->showEvent(sev); - } - break; - case QEvent::Hide: - { - QHideEvent *hev = (QHideEvent*)(e); - status = mReceiver->hideEvent(hev); - } - break; - case QEvent::Close: - { - QCloseEvent *cev = (QCloseEvent*)(e); - status = mReceiver->OnCloseEvent(cev); - } - break; - case QEvent::Wheel: - { - QWheelEvent *wev = (QWheelEvent*)(e); - status = mReceiver->OnScrollEvent(wev); - } - break; - case QEvent::ContextMenu: - { - QContextMenuEvent *cev = (QContextMenuEvent*)(e); - status = mReceiver->contextMenuEvent(cev); - } - break; - case QEvent::DragEnter: - { - QDragEnterEvent *dev = (QDragEnterEvent*)(e); - status = mReceiver->OnDragEnter(dev); - } - break; - case QEvent::DragMove: - { - QDragMoveEvent *dev = (QDragMoveEvent*)(e); - status = mReceiver->OnDragMotionEvent(dev); - } - break; - case QEvent::DragLeave: - { - QDragLeaveEvent *dev = (QDragLeaveEvent*)(e); - status = mReceiver->OnDragLeaveEvent(dev); - } - break; - case QEvent::Drop: - { - QDropEvent *dev = (QDropEvent*)(e); - status = mReceiver->OnDragDropEvent(dev); - } - break; - default: - handled = false; - break; - } - - if (handled) - return true; - - return QWidget::event(e); - -#if 0 - // If we were going to ignore this event, pass it up to the parent - // and return its value - if (status == nsEventStatus_eIgnore) - return QWidget::event(e); - - // Otherwise, we know we already consumed it -- we just need to know - // whether we want default handling or not - if (status == nsEventStatus_eConsumeDoDefault) - QWidget::event(e); - - return true; -#endif + mReceiver->DoPaint(aPainter, aOption); } -bool -MozQWidget::SetCursor(nsCursor aCursor) +void MozQWidget::resizeEvent(QGraphicsSceneResizeEvent* aEvent) +{ + mReceiver->OnResizeEvent(aEvent); +} + +void MozQWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent* aEvent) +{ + mReceiver->contextMenuEvent(aEvent); +} + +void MozQWidget::dragEnterEvent(QGraphicsSceneDragDropEvent* aEvent) +{ + mReceiver->OnDragEnter(aEvent); +} + +void MozQWidget::dragLeaveEvent(QGraphicsSceneDragDropEvent* aEvent) +{ + mReceiver->OnDragLeaveEvent(aEvent); +} + +void MozQWidget::dragMoveEvent(QGraphicsSceneDragDropEvent* aEvent) +{ + mReceiver->OnDragMotionEvent(aEvent); +} + +void MozQWidget::dropEvent(QGraphicsSceneDragDropEvent* aEvent) +{ + mReceiver->OnDragDropEvent(aEvent); +} + +void MozQWidget::focusInEvent(QFocusEvent* aEvent) +{ + mReceiver->OnFocusInEvent(aEvent); +} + +void MozQWidget::focusOutEvent(QFocusEvent* aEvent) +{ + mReceiver->OnFocusOutEvent(aEvent); +} + +void MozQWidget::hoverEnterEvent(QGraphicsSceneHoverEvent* aEvent) +{ + mReceiver->OnEnterNotifyEvent(aEvent); +} + +void MozQWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent* aEvent) +{ + mReceiver->OnLeaveNotifyEvent(aEvent); +} + +void MozQWidget::hoverMoveEvent(QGraphicsSceneHoverEvent* aEvent) +{ + mReceiver->OnMoveEvent(aEvent); +} + +void MozQWidget::keyPressEvent(QKeyEvent* aEvent) +{ + mReceiver->OnKeyPressEvent(aEvent); +} + +void MozQWidget::keyReleaseEvent(QKeyEvent* aEvent) +{ + mReceiver->OnKeyReleaseEvent(aEvent); +} + +void MozQWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* aEvent) +{ + mReceiver->mouseDoubleClickEvent(aEvent); +} + +void MozQWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* aEvent) +{ + mReceiver->OnMotionNotifyEvent(aEvent); +} + +void MozQWidget::mousePressEvent(QGraphicsSceneMouseEvent* aEvent) +{ + mReceiver->OnButtonPressEvent(aEvent); +} + +void MozQWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* aEvent) +{ + mReceiver->OnButtonReleaseEvent(aEvent); +} + +bool MozQWidget::sceneEvent(QEvent* aEvent) +{ + if (QEvent::WindowActivate == aEvent->type()) { + mReceiver->OnFocusInEvent(aEvent); + } else if (QEvent::WindowDeactivate == aEvent->type()) { + mReceiver->OnFocusOutEvent(aEvent); + } + + return QGraphicsWidget::sceneEvent(aEvent); +} + +void MozQWidget::wheelEvent(QGraphicsSceneWheelEvent* aEvent) +{ + mReceiver->OnScrollEvent(aEvent); +} + +void MozQWidget::closeEvent(QCloseEvent* aEvent) +{ + mReceiver->OnCloseEvent(aEvent); +} + +void MozQWidget::hideEvent(QHideEvent* aEvent) +{ + mReceiver->hideEvent(aEvent); +} + +void MozQWidget::showEvent(QShowEvent* aEvent) +{ + mReceiver->showEvent(aEvent); +} + +bool MozQWidget::SetCursor(nsCursor aCursor) { Qt::CursorShape cursor = Qt::ArrowCursor; switch(aCursor) { @@ -267,18 +202,24 @@ MozQWidget::SetCursor(nsCursor aCursor) break; } - // qDebug("FIXME:>>>>>>Func:%s::%d, cursor:%i, aCursor:%i\n", __PRETTY_FUNCTION__, __LINE__, cursor, aCursor); - // FIXME after reimplementation of whole nsWindow SetCursor cause lot of errors setCursor(cursor); return NS_OK; } +bool MozQWidget::SetCursor(const QPixmap& aCursor, int aHotX, int aHotY) +{ + QCursor bitmapCursor(aCursor, aHotX, aHotY); + setCursor(bitmapCursor); + + return NS_OK; +} + void MozQWidget::setModal(bool modal) { - if (modal) - setWindowModality(Qt::ApplicationModal); - else - setWindowModality(Qt::NonModal); +#if QT_VERSION >= 0x040600 + setPanelModality(modal ? QGraphicsItem::SceneModal : QGraphicsItem::NonModal); +#else + LOG(("Modal QGraphicsWidgets not supported in Qt < 4.6\n")); +#endif } - diff --git a/widget/src/qt/mozqwidget.h b/widget/src/qt/mozqwidget.h index f7bab20136b0..7a31865714a0 100644 --- a/widget/src/qt/mozqwidget.h +++ b/widget/src/qt/mozqwidget.h @@ -1,18 +1,23 @@ #ifndef MOZQWIDGET_H #define MOZQWIDGET_H -#include #include "nsIWidget.h" +#include +#include +#include + class QEvent; +class QPixmap; +class QWidget; + class nsWindow; -class MozQWidget : public QWidget +class MozQWidget : public QGraphicsWidget { Q_OBJECT public: - MozQWidget(nsWindow* receiver, QWidget *parent, - const char *name, int f); + MozQWidget(nsWindow* aReceiver, QGraphicsItem *aParent); ~MozQWidget(); @@ -25,9 +30,83 @@ public: nsWindow* getReceiver() { return mReceiver; }; protected: - virtual bool event(QEvent *ev); + virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* aEvent); + virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* aEvent); + virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* aEvent); + virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* aEvent); + virtual void dropEvent(QGraphicsSceneDragDropEvent* aEvent); + virtual void focusInEvent(QFocusEvent* aEvent); + virtual void focusOutEvent(QFocusEvent* aEvent); + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* aEvent); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* aEvent); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* aEvent); + virtual void keyPressEvent(QKeyEvent* aEvent); + virtual void keyReleaseEvent(QKeyEvent* aEvent); + virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* aEvent); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* aEvent); + virtual void mousePressEvent(QGraphicsSceneMouseEvent* aEvent); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* aEvent); + + virtual void wheelEvent(QGraphicsSceneWheelEvent* aEvent); + virtual void paint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget = 0); + virtual void resizeEvent(QGraphicsSceneResizeEvent* aEvent); + virtual void closeEvent(QCloseEvent* aEvent); + virtual void hideEvent(QHideEvent* aEvent); + virtual void showEvent(QShowEvent* aEvent); + virtual bool sceneEvent(QEvent* aEvent); + + bool SetCursor(const QPixmap& aPixmap, int, int); + private: nsWindow *mReceiver; }; +/** + This is a helper class to synchronize the QGraphicsView window with + its contained QGraphicsWidget for things like resizing and closing + by the user. +*/ +class MozQGraphicsView : public QGraphicsView +{ + Q_OBJECT + +public: + MozQGraphicsView(QGraphicsScene* aScene, QWidget * aParent = nsnull) + : QGraphicsView (aScene, aParent) + , mTopLevelWidget(0) + { } + + void setTopLevel(MozQWidget* aTopLevel) + { + mTopLevelWidget = aTopLevel; + } + +protected: + virtual void resizeEvent(QResizeEvent* aEvent) + { + if (mTopLevelWidget) { + // transfer new size to graphics widget + mTopLevelWidget->setGeometry( 0.0, 0.0, + static_cast(aEvent->size().width()), + static_cast(aEvent->size().height())); + } + QGraphicsView::resizeEvent(aEvent); + } + + virtual void closeEvent (QCloseEvent* aEvent) + { + if (mTopLevelWidget) { + // close graphics widget instead, this view will be discarded + // automatically + QApplication::postEvent(mTopLevelWidget, new QCloseEvent(*aEvent)); + aEvent->ignore(); + } else { + QGraphicsView::closeEvent(aEvent); + } + } + +private: + MozQWidget* mTopLevelWidget; +}; + #endif diff --git a/widget/src/qt/nsFilePicker.cpp b/widget/src/qt/nsFilePicker.cpp index 3f1529baddc5..306323912a1f 100644 --- a/widget/src/qt/nsFilePicker.cpp +++ b/widget/src/qt/nsFilePicker.cpp @@ -50,6 +50,7 @@ #include #include +#include /* Implementation file */ NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker) @@ -241,7 +242,7 @@ nsFilePicker::Show(PRInt16 *aReturn) } QString path = QFile::encodeName(selected); - qDebug("path is '%s'", path.data()); + qDebug("path is '%s'", path.toAscii().data()); mFile.Assign(path.toUtf8().data()); *aReturn = nsIFilePicker::returnOK; if (mMode == modeSave) { @@ -273,7 +274,9 @@ nsFilePicker::Show(PRInt16 *aReturn) void nsFilePicker::InitNative(nsIWidget *parent, const nsAString &title, PRInt16 mode) { qDebug("nsFilePicker::InitNative()"); - QWidget *parentWidget = (parent)? (QWidget*)parent->GetNativeData(NS_NATIVE_WIDGET):0; + + QWidget *parentWidget = (parent)? + static_cast(parent->GetNativeData(NS_NATIVE_SHELLWIDGET)):0; nsAutoString str(title); mDialog = new QFileDialog(parentWidget, QString::fromUtf16(str.get())); diff --git a/widget/src/qt/nsWindow.cpp b/widget/src/qt/nsWindow.cpp index 836257bc83f0..ea1d56e38f01 100644 --- a/widget/src/qt/nsWindow.cpp +++ b/widget/src/qt/nsWindow.cpp @@ -25,6 +25,8 @@ * Masayuki Nakano * Romashin Oleg * Vladimir Vukicevic + * Jeremias Bosch + * Steffen Imhof * * 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 @@ -42,61 +44,52 @@ #include "prlink.h" -#include //XXX switch for forward-decl -#include -#include - #include "nsWindow.h" +#include "mozqwidget.h" + #include "nsToolkit.h" #include "nsIDeviceContext.h" #include "nsIRenderingContext.h" #include "nsIRegion.h" #include "nsIRollupListener.h" #include "nsIMenuRollup.h" -#include "nsIDOMNode.h" - #include "nsWidgetsCID.h" -#include "nsIDragService.h" - #include "nsQtKeyUtils.h" -#include "nsWidgetAtoms.h" - #include "nsIPrefService.h" #include "nsIPrefBranch.h" -#include "nsIServiceManager.h" #include "nsIStringBundle.h" #include "nsGfxCIID.h" -/* For SetIcon */ -#include "nsAppDirectoryServiceDefs.h" -#include "nsXPIDLString.h" -#include "nsIFile.h" -#include "nsILocalFile.h" - -/* SetCursor(imgIContainer*) */ #include "imgIContainer.h" #include "nsGfxCIID.h" #include "nsIInterfaceRequestorUtils.h" #include "nsAutoPtr.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + #include "gfxQtPlatform.h" #include "gfxXlibSurface.h" #include "gfxQPainterSurface.h" #include "gfxContext.h" -#include "gfxImageSurface.h" -#include "mozqwidget.h" - -#include -#include -#include -#include -#include - -#include - -#include /* For PrepareNativeWidget */ static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); @@ -110,7 +103,7 @@ static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); #define kWindowPositionSlop 20 -// QT +// Qt static const int WHEEL_DELTA = 120; static PRBool gGlobalsInitialized = PR_FALSE; @@ -119,12 +112,10 @@ static nsIMenuRollup* gMenuRollup; static nsWeakPtr gRollupWindow; static PRBool gConsumeRollupEvent; -//static nsWindow * get_window_for_qt_widget(QWidget *widget); - static PRBool check_for_rollup(double aMouseX, double aMouseY, PRBool aIsWheel); -static PRBool -is_mouse_in_window (QWidget* aWindow, double aMouseX, double aMouseY); +static bool +is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY); static PRBool isContextMenuKeyEvent(const QKeyEvent *qe) @@ -147,10 +138,10 @@ InitKeyEvent(nsKeyEvent &aEvent, QKeyEvent *aQEvent) aEvent.isMeta = (aQEvent->modifiers() & Qt::MetaModifier) ? PR_TRUE : PR_FALSE; aEvent.time = 0; - // The transformations above and in gdk for the keyval are not invertible - // so link to the GdkEvent (which will vanish soon after return from the + // The transformations above and in qt for the keyval are not invertible + // so link to the QKeyEvent (which will vanish soon after return from the // event callback) to give plugins access to hardware_keycode and state. - // (An XEvent would be nice but the GdkEvent is good enough.) + // (An XEvent would be nice but the QKeyEvent is good enough.) aEvent.pluginEvent = (void *)aQEvent; } @@ -163,14 +154,15 @@ nsWindow::nsWindow() mIsShown = PR_FALSE; mEnabled = PR_TRUE; - mWidget = nsnull; + mWidget = nsnull; mIsVisible = PR_FALSE; mActivatePending = PR_FALSE; mWindowType = eWindowType_child; mSizeState = nsSizeMode_Normal; mPluginType = PluginType_NONE; mQCursor = Qt::ArrowCursor; - + mScene = nsnull; + if (!gGlobalsInitialized) { gGlobalsInitialized = PR_TRUE; @@ -192,22 +184,6 @@ nsWindow::~nsWindow() Destroy(); } -/* XXX - this gets called right after CreateQWidget, which also - * sets mWidget. We probably want to always pass a MozQWidget - * here; things won't really work at all with any generic widget. - */ -void -nsWindow::Initialize(MozQWidget *widget) -{ - LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this)); - - Q_ASSERT(widget); - - mWidget = widget; - mWidget->setMouseTracking(PR_TRUE); - mWidget->setFocusPolicy(Qt::WheelFocus); -} - /* static */ void nsWindow::ReleaseGlobals() { @@ -277,11 +253,20 @@ nsWindow::Destroy(void) // also set WA_DeleteOnClose, but this gives us more control. mWidget->deleteLater(); } - mWidget = nsnull; OnDestroy(); + // tear down some infrastructure after all event handling is finished + if (mScene) { + QWidget* view = GetViewWidget(); + + delete mScene; + mScene = nsnull; + + delete view; + } + return NS_OK; } @@ -297,10 +282,10 @@ nsWindow::SetParent(nsIWidget *aNewParent) parent->RemoveChild(this); } - QWidget * newParent = static_cast(aNewParent->GetNativeData(NS_NATIVE_WINDOW)); + MozQWidget* newParent = static_cast(aNewParent->GetNativeData(NS_NATIVE_WINDOW)); NS_ASSERTION(newParent, "Parent widget has a null native window handle"); if (mWidget) { - mWidget->setParent(newParent); + mWidget->setParentItem(newParent); } aNewParent->AddChild(this); @@ -316,7 +301,7 @@ nsWindow::SetParent(nsIWidget *aNewParent) parent->RemoveChild(this); if (mWidget) - mWidget->setParent(0); + mWidget->setParentItem(0); return NS_OK; } @@ -325,10 +310,8 @@ NS_IMETHODIMP nsWindow::SetModal(PRBool aModal) { LOG(("nsWindow::SetModal [%p] %d, widget[%p]\n", (void *)this, aModal, mWidget)); - - MozQWidget *mozWidget = static_cast(mWidget); - if (mozWidget) - mozWidget->setModal(aModal); + if (mWidget) + mWidget->setModal(aModal); return NS_OK; } @@ -346,6 +329,7 @@ nsWindow::ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY) if (mWidget) { PRInt32 screenWidth = QApplication::desktop()->width(); PRInt32 screenHeight = QApplication::desktop()->height(); + if (aAllowSlop) { if (*aX < (kWindowPositionSlop - mBounds.width)) *aX = kWindowPositionSlop - mBounds.width; @@ -379,39 +363,31 @@ nsWindow::Move(PRInt32 aX, PRInt32 aY) if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog) { SetSizeMode(nsSizeMode_Normal); + + // the internal QGraphicsWidget is always in the top corner of + // the view if it is a toplevel one + aX = aY = 0; } - // Since a popup window's x/y coordinates are in relation to to - // the parent, the parent might have moved so we always move a - // popup window. - //bool popup = mWidget ? mWidget->windowType() == Qt::Popup : false; - if (aX == mBounds.x && aY == mBounds.y && - mWindowType != eWindowType_popup) + if (aX == mBounds.x && aY == mBounds.y) return NS_OK; - // XXX Should we do some AreBoundsSane check here? - - if (!mWidget) return NS_OK; - QPoint pos(aX, aY); + // update the bounds + QPointF pos( aX, aY ); if (mWidget) { - if (mParent && mWidget->windowType() == Qt::Popup) { - nsIntPoint screenPos = mParent->WidgetToScreenOffset(); - pos += QPoint(screenPos.x, screenPos.y); -#ifdef DEBUG_WIDGETS - qDebug("pos is [%d,%d]", pos.x(), pos.y()); -#endif - } else { - qDebug("Widget within another? (%p)", (void*)mWidget); - } + // the position of the widget is set relative to the parent + // so we map the coordinates accordingly + pos = mWidget->mapFromScene(pos); + pos = mWidget->mapToParent(pos); + mWidget->setPos(pos); } mBounds.x = pos.x(); mBounds.y = pos.y(); - mWidget->move(pos); return NS_OK; } @@ -424,41 +400,6 @@ nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsWindow::SetZIndex(PRInt32 aZIndex) -{ - nsIWidget* oldPrev = GetPrevSibling(); - - nsBaseWidget::SetZIndex(aZIndex); - - if (GetPrevSibling() == oldPrev) { - return NS_OK; - } - - NS_ASSERTION(!mWidget, "Expected Mozilla child widget"); - - // We skip the nsWindows that don't have mWidgets. - // These are probably in the process of being destroyed. - - if (!GetNextSibling()) { - // We're to be on top. - if (mWidget) { - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - // gdk_window_raise(mWidget->clip_window); - } - } else { - // All the siblings before us need to be below our widget. - for (nsWindow* w = this; w; - w = static_cast(w->GetPrevSibling())) { - if (w->mWidget) { - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - // gdk_window_lower(w->mWidget->clip_window); - } - } - } - return NS_OK; -} - NS_IMETHODIMP nsWindow::SetSizeMode(PRInt32 aMode) { @@ -477,18 +418,18 @@ nsWindow::SetSizeMode(PRInt32 aMode) switch (aMode) { case nsSizeMode_Maximized: - mWidget->showMaximized(); + GetViewWidget()->showMaximized(); break; case nsSizeMode_Minimized: - mWidget->showMinimized(); + GetViewWidget()->showMinimized(); break; case nsSizeMode_Fullscreen: - mWidget->showFullScreen(); + GetViewWidget()->showFullScreen(); break; default: // nsSizeMode_Normal, really. - mWidget->showNormal(); + GetViewWidget()->showNormal(); break; } @@ -497,22 +438,48 @@ nsWindow::SetSizeMode(PRInt32 aMode) return rv; } +// Helper function to recursively find the first parent item that +// is still visible (QGraphicsItem can be hidden even if they are +// set to visible if one of their ancestors is invisible) +static void find_first_visible_parent(QGraphicsItem* aItem, QGraphicsItem*& aVisibleItem) +{ + if (!aItem) + return; + + if (!aVisibleItem && aItem->isVisible()) + aVisibleItem = aItem; + else if (aVisibleItem && !aItem->isVisible()) + aVisibleItem = nsnull; + + // check further up the chain + find_first_visible_parent(aItem->parentItem(), aVisibleItem); +} + NS_IMETHODIMP nsWindow::SetFocus(PRBool aRaise) { // Make sure that our owning widget has focus. If it doesn't try to // grab it. Note that we don't set our focus flag in this case. - LOGFOCUS((" SetFocus [%p]\n", (void *)this)); if (!mWidget) return NS_ERROR_FAILURE; - if (mWidget->hasFocus()) + + // Because QGraphicsItem cannot get the focus if they are + // invisible, we look up the chain, for the lowest visible + // parent and focus that one + QGraphicsItem* realFocusItem = nsnull; + find_first_visible_parent(mWidget, realFocusItem); + + if (!realFocusItem || realFocusItem->hasFocus()) return NS_OK; if (aRaise) - mWidget->raise(); - mWidget->setFocus(); + realFocusItem->setFocus(Qt::ActiveWindowFocusReason); + else + realFocusItem->setFocus(Qt::OtherFocusReason); + + DispatchActivateEvent(); return NS_OK; } @@ -520,8 +487,8 @@ nsWindow::SetFocus(PRBool aRaise) NS_IMETHODIMP nsWindow::GetScreenBounds(nsIntRect &aRect) { - aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size()); - LOG(("GetScreenBounds %d %d | %d %d | %d %d\n", + aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size()); + LOG(("GetScreenBounds %d %d | %d %d | %d %d\n", aRect.x, aRect.y, mBounds.width, mBounds.height, aRect.width, aRect.height)); @@ -549,63 +516,11 @@ nsWindow::SetCursor(nsCursor aCursor) return NS_OK; } -/* -static -PRUint8* Data32BitTo1Bit(PRUint8* aImageData, - PRUint32 aImageBytesPerRow, - PRUint32 aWidth, PRUint32 aHeight) -{ - PRUint32 outBpr = (aWidth + 7) / 8; - - PRUint8* outData = new PRUint8[outBpr * aHeight]; - if (!outData) - return NULL; - - PRUint8 *outRow = outData, - *imageRow = aImageData; - - for (PRUint32 curRow = 0; curRow < aHeight; curRow++) { - PRUint8 *irow = imageRow; - PRUint8 *orow = outRow; - PRUint8 imagePixels = 0; - PRUint8 offset = 0; - - for (PRUint32 curCol = 0; curCol < aWidth; curCol++) { - PRUint8 r = *imageRow++, - g = *imageRow++, - b = *imageRow++; - imageRow++; - - if ((r + b + g) < 3 * 128) - imagePixels |= (1 << offset); - - if (offset == 7) { - *outRow++ = imagePixels; - offset = 0; - imagePixels = 0; - } else { - offset++; - } - } - if (offset != 0) - *outRow++ = imagePixels; - - imageRow = irow + aImageBytesPerRow; - outRow = orow + outBpr; - } - - return outData; -} -*/ - - NS_IMETHODIMP nsWindow::SetCursor(imgIContainer* aCursor, PRUint32 aHotspotX, PRUint32 aHotspotY) { - nsresult rv = NS_ERROR_OUT_OF_MEMORY; - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - return rv; + return NS_ERROR_NOT_AVAILABLE; } NS_IMETHODIMP @@ -618,11 +533,11 @@ nsWindow::Invalidate(const nsIntRect &aRect, 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); - } + mWidget->update(aRect.x, aRect.y, aRect.width, aRect.height); + + // QGraphicsItems cannot trigger a repaint themselves, so we start it on the view + if (aIsSynchronous && GetViewWidget()) + GetViewWidget()->repaint(); return NS_OK; } @@ -679,6 +594,23 @@ nsWindow::Scroll(const nsIntPoint& aDelta, } } +QWidget* nsWindow::GetViewWidget() +{ + QWidget* viewWidget = nsnull; + + if (!mScene) { + if (mParent) + return static_cast(mParent.get())->GetViewWidget(); + + return nsnull; + } + + NS_ASSERTION(mScene->views().size() == 1, "Not exactly one view for our scene!"); + viewWidget = mScene->views()[0]; + + return viewWidget; +} + void* nsWindow::GetNativeData(PRUint32 aDataType) { @@ -698,7 +630,7 @@ nsWindow::GetNativeData(PRUint32 aDataType) #ifdef Q_WS_X11 case NS_NATIVE_DISPLAY: - return mWidget->x11Info().display(); + return GetViewWidget()->x11Info().display(); break; #endif @@ -709,7 +641,7 @@ nsWindow::GetNativeData(PRUint32 aDataType) } case NS_NATIVE_SHELLWIDGET: - return (void *) mWidget; + return (void *) GetViewWidget(); default: NS_WARNING("nsWindow::GetNativeData called with bad value"); @@ -720,10 +652,11 @@ nsWindow::GetNativeData(PRUint32 aDataType) NS_IMETHODIMP nsWindow::SetTitle(const nsAString& aTitle) { - if (mWidget) { - QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length())); + QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length())); + if (mIsTopLevel) + GetViewWidget()->setWindowTitle(qStr); + else if (mWidget) mWidget->setWindowTitle(qStr); - } return NS_OK; } @@ -772,8 +705,8 @@ nsWindow::WidgetToScreenOffset() { NS_ENSURE_TRUE(mWidget, nsIntPoint(0,0)); - QPoint origin(0, 0); - origin = mWidget->mapToGlobal(origin); + QPointF origin(0, 0); + origin = mWidget->mapToScene(origin); return nsIntPoint(origin.x(), origin.y()); } @@ -792,11 +725,10 @@ nsWindow::CaptureMouse(PRBool aCapture) if (!mWidget) return NS_OK; - if (aCapture) - mWidget->grabMouse(); + GetViewWidget()->grabMouse(); else - mWidget->releaseMouse(); + GetViewWidget()->releaseMouse(); return NS_OK; } @@ -837,8 +769,8 @@ check_for_rollup(double aMouseX, double aMouseY, nsCOMPtr rollupWidget = do_QueryReferent(gRollupWindow); if (rollupWidget && gRollupListener) { - QWidget *currentPopup = - (QWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW); + MozQWidget *currentPopup = + (MozQWidget *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW); if (!is_mouse_in_window(currentPopup, aMouseX, aMouseY)) { PRBool rollup = PR_TRUE; @@ -855,8 +787,8 @@ check_for_rollup(double aMouseX, double aMouseY, PRUint32 sameTypeCount = gMenuRollup->GetSubmenuWidgetChain(&widgetChain); for (PRUint32 i=0; iGetNativeData(NS_NATIVE_WINDOW); + MozQWidget* currWindow = + (MozQWidget*) widget->GetNativeData(NS_NATIVE_WINDOW); if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) { if (i < sameTypeCount) { rollup = PR_FALSE; @@ -885,42 +817,22 @@ check_for_rollup(double aMouseX, double aMouseY, } /* static */ -PRBool -is_mouse_in_window (QWidget* aWindow, double aMouseX, double aMouseY) +bool +is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY) { - int x = 0; - int y = 0; - int w, h; - - x = aWindow->pos().x(); - y = aWindow->pos().y(); - w = aWindow->size().width(); - h = aWindow->size().height(); - - if (aMouseX > x && aMouseX < x + w && - aMouseY > y && aMouseY < y + h) - return PR_TRUE; - - return PR_FALSE; + return aWindow->geometry().contains( aMouseX, aMouseY ); } NS_IMETHODIMP nsWindow::GetAttention(PRInt32 aCycleCount) { LOG(("nsWindow::GetAttention [%p]\n", (void *)this)); - - SetUrgencyHint(mWidget, PR_TRUE); - - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } -static int gDoubleBuffering = -1; - nsEventStatus -nsWindow::OnPaintEvent(QPaintEvent *aEvent) +nsWindow::DoPaint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption) { - //fprintf (stderr, "===== Expose start\n"); - if (mIsDestroyed) { LOG(("Expose event on destroyed window [%p] window %p\n", (void *)this, mWidget)); @@ -936,27 +848,16 @@ nsWindow::OnPaintEvent(QPaintEvent *aEvent) if (!updateRegion) return nsEventStatus_eIgnore; - updateRegion->Init(); + QRectF r; - QVector rects = aEvent->region().rects(); + if (aOption) + r = aOption->exposedRect; + else + r = mWidget->boundingRect(); - LOGDRAW(("[%p] sending expose event %p 0x%lx (rects follow):\n", - (void *)this, (void *)aEvent, 0)); + updateRegion->SetTo( (int)r.x(), (int)r.y(), (int)r.width(), (int)r.height() ); - for (int i = 0; i < rects.size(); ++i) { - QRect r = rects.at(i); - updateRegion->Union(r.x(), r.y(), r.width(), r.height()); - LOGDRAW(("\t%d %d %d %d\n", r.x(), r.y(), r.width(), r.height())); - } - - QPainter painter; - - if (!painter.begin(mWidget)) { - fprintf (stderr, "*********** Failed to begin painting!\n"); - return nsEventStatus_eConsumeNoDefault; - } - - nsRefPtr targetSurface = new gfxQPainterSurface(&painter); + nsRefPtr targetSurface = new gfxQPainterSurface(aPainter); nsRefPtr ctx = new gfxContext(targetSurface); nsCOMPtr rc; @@ -966,24 +867,16 @@ nsWindow::OnPaintEvent(QPaintEvent *aEvent) rc->Init(GetDeviceContext(), ctx); - nsIntRect boundsRect; - - updateRegion->GetBoundingBox(&boundsRect.x, &boundsRect.y, - &boundsRect.width, &boundsRect.height); - nsPaintEvent event(PR_TRUE, NS_PAINT, this); - QRect r = aEvent->rect(); - if (!r.isValid()) - r = mWidget->rect(); + nsIntRect rect(r.x(), r.y(), r.width(), r.height()); - event.refPoint.x = aEvent->rect().x(); - event.refPoint.y = aEvent->rect().y(); - event.rect = ▭ // was null FIXME + event.refPoint.x = r.x(); + event.refPoint.y = r.y(); + event.rect = nsnull; event.region = updateRegion; event.renderingContext = rc; nsEventStatus status = DispatchEvent(&event); - //nsEventStatus status = nsEventStatus_eConsumeNoDefault; // DispatchEvent can Destroy us (bug 378273), avoid doing any paint // operations below if that happened - it will lead to XError and exit(). @@ -998,14 +891,12 @@ nsWindow::OnPaintEvent(QPaintEvent *aEvent) ctx = nsnull; targetSurface = nsnull; - //fprintf (stderr, "===== Expose end\n"); - // check the return value! return status; } nsEventStatus -nsWindow::OnMoveEvent(QMoveEvent *aEvent) +nsWindow::OnMoveEvent(QGraphicsSceneHoverEvent *aEvent) { LOG(("configure event [%p] %d %d\n", (void *)this, aEvent->pos().x(), aEvent->pos().y())); @@ -1020,19 +911,10 @@ nsWindow::OnMoveEvent(QMoveEvent *aEvent) return nsEventStatus_eIgnore; } - // 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 = aEvent->pos(); - if (mIsTopLevel) { - // Need to translate this into the right coordinates - mBounds.MoveTo(WidgetToScreenOffset()); - } - nsGUIEvent event(PR_TRUE, NS_MOVE, this); - event.refPoint.x = pos.x(); - event.refPoint.y = pos.y(); + event.refPoint.x = aEvent->pos().x(); + event.refPoint.y = aEvent->pos().y(); // XXX mozilla will invalidate the entire window after this move // complete. wtf? @@ -1040,30 +922,19 @@ nsWindow::OnMoveEvent(QMoveEvent *aEvent) } nsEventStatus -nsWindow::OnResizeEvent(QResizeEvent *e) +nsWindow::OnResizeEvent(QGraphicsSceneResizeEvent *aEvent) { nsIntRect rect; // Generate XPFE resize event GetBounds(rect); - rect.width = e->size().width(); - rect.height = e->size().height(); - - LOG(("size_allocate [%p] %d %d\n", - (void *)this, rect.width, rect.height)); + rect.width = aEvent->newSize().width(); + rect.height = aEvent->newSize().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 - - if (mWidget) - mWidget->resize(rect.width, rect.height); - nsEventStatus status; DispatchResizeEvent(rect, status); return status; @@ -1081,14 +952,12 @@ nsWindow::OnCloseEvent(QCloseEvent *aEvent) } nsEventStatus -nsWindow::OnEnterNotifyEvent(QEvent *aEvent) +nsWindow::OnEnterNotifyEvent(QGraphicsSceneHoverEvent *aEvent) { 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()); + event.refPoint.x = nscoord(aEvent->pos().x()); + event.refPoint.y = nscoord(aEvent->pos().y()); LOG(("OnEnterNotify: %p\n", (void *)this)); @@ -1096,14 +965,12 @@ nsWindow::OnEnterNotifyEvent(QEvent *aEvent) } nsEventStatus -nsWindow::OnLeaveNotifyEvent(QEvent *aEvent) +nsWindow::OnLeaveNotifyEvent(QGraphicsSceneHoverEvent *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()); + event.refPoint.x = nscoord(aEvent->pos().x()); + event.refPoint.y = nscoord(aEvent->pos().y()); LOG(("OnLeaveNotify: %p\n", (void *)this)); @@ -1111,50 +978,49 @@ nsWindow::OnLeaveNotifyEvent(QEvent *aEvent) } nsEventStatus -nsWindow::OnMotionNotifyEvent(QMouseEvent *aEvent) +nsWindow::OnMotionNotifyEvent(QGraphicsSceneMouseEvent *aEvent) { - // when we receive this, it must be that the gtk dragging is over, - // it is dropped either in or out of mozilla, clear the flag - //mWidget->setCursor(mQCursor); - nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal); + event.refPoint.x = nscoord(aEvent->pos().x()); + event.refPoint.y = nscoord(aEvent->pos().y()); - event.refPoint.x = nscoord(aEvent->x()); - event.refPoint.y = nscoord(aEvent->y()); - - event.isShift = aEvent->modifiers() & Qt::ShiftModifier; - event.isControl = aEvent->modifiers() & Qt::ControlModifier; - event.isAlt = aEvent->modifiers() & Qt::AltModifier; - event.isMeta = aEvent->modifiers() & Qt::MetaModifier; + event.isShift = ((aEvent->modifiers() & Qt::ShiftModifier) != 0); + event.isControl = ((aEvent->modifiers() & Qt::ControlModifier) != 0); + event.isAlt = ((aEvent->modifiers() & Qt::AltModifier) != 0); + event.isMeta = ((aEvent->modifiers() & Qt::MetaModifier) != 0); event.clickCount = 0; nsEventStatus status = DispatchEvent(&event); - //fprintf (stderr, "[%p] %p MotionNotify -> %d\n", this, mWidget, status); - return status; } void -nsWindow::InitButtonEvent(nsMouseEvent &event, - QMouseEvent *aEvent, int aClickCount) +nsWindow::InitButtonEvent(nsMouseEvent &aMoveEvent, + QGraphicsSceneMouseEvent *aEvent, int aClickCount) { - event.refPoint.x = nscoord(aEvent->x()); - event.refPoint.y = nscoord(aEvent->y()); + aMoveEvent.refPoint.x = nscoord(aEvent->pos().x()); + aMoveEvent.refPoint.y = nscoord(aEvent->pos().y()); - event.isShift = aEvent->modifiers() & Qt::ShiftModifier; - event.isControl = aEvent->modifiers() & Qt::ControlModifier; - event.isAlt = aEvent->modifiers() & Qt::AltModifier; - event.isMeta = aEvent->modifiers() & Qt::MetaModifier; - event.clickCount = aClickCount; + aMoveEvent.isShift = ((aEvent->modifiers() & Qt::ShiftModifier) != 0); + aMoveEvent.isControl = ((aEvent->modifiers() & Qt::ControlModifier) != 0); + aMoveEvent.isAlt = ((aEvent->modifiers() & Qt::AltModifier) != 0); + aMoveEvent.isMeta = ((aEvent->modifiers() & Qt::MetaModifier) != 0); + aMoveEvent.clickCount = aClickCount; } nsEventStatus -nsWindow::OnButtonPressEvent(QMouseEvent *aEvent) +nsWindow::OnButtonPressEvent(QGraphicsSceneMouseEvent *aEvent) { - PRBool rolledUp = check_for_rollup(aEvent->globalX(), - aEvent->globalY(), PR_FALSE); + QPointF pos = aEvent->pos(); + + // we check against the widgets geometry, so use parent coordinates + // for the check + if (mWidget) + pos = mWidget->mapToParent(pos); + + PRBool rolledUp = check_for_rollup( pos.x(), pos.y(), PR_FALSE); if (gConsumeRollupEvent && rolledUp) return nsEventStatus_eIgnore; @@ -1188,16 +1054,13 @@ nsWindow::OnButtonPressEvent(QMouseEvent *aEvent) DispatchEvent(&contextMenuEvent, status); } - //fprintf (stderr, "[%p] %p ButtonPress -> %d\n", this, mWidget, status); - return status; } nsEventStatus -nsWindow::OnButtonReleaseEvent(QMouseEvent *aEvent) +nsWindow::OnButtonReleaseEvent(QGraphicsSceneMouseEvent *aEvent) { PRUint16 domButton; -// mLastButtonReleaseTime = aEvent->time; switch (aEvent->button()) { case Qt::MidButton: @@ -1219,17 +1082,15 @@ nsWindow::OnButtonReleaseEvent(QMouseEvent *aEvent) nsEventStatus status = DispatchEvent(&event); - //fprintf (stderr, "[%p] %p ButtonRelease -> %d\n", this, mWidget, status); - return status; } nsEventStatus -nsWindow::mouseDoubleClickEvent(QMouseEvent *e) +nsWindow::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *aEvent) { - PRUint32 eventType; + PRUint32 eventType; - switch (e->button()) { + switch (aEvent->button()) { case Qt::MidButton: eventType = nsMouseEvent::eMiddleButton; break; @@ -1244,25 +1105,18 @@ nsWindow::mouseDoubleClickEvent(QMouseEvent *e) nsMouseEvent event(PR_TRUE, NS_MOUSE_DOUBLECLICK, this, nsMouseEvent::eReal); event.button = eventType; - InitButtonEvent(event, e, 2); + InitButtonEvent(event, aEvent, 2); //pressed return DispatchEvent(&event); } nsEventStatus -nsWindow::OnFocusInEvent(QFocusEvent *aEvent) +nsWindow::OnFocusInEvent(QEvent *aEvent) { LOGFOCUS(("OnFocusInEvent [%p]\n", (void *)this)); - // Return if someone has blocked events for this widget. This will - // happen if someone has called gtk_widget_grab_focus() from - // nsWindow::SetFocus() and will prevent recursion. - if (!mWidget) return nsEventStatus_eIgnore; - // Unset the urgency hint, if possible -// SetUrgencyHint(top_window, PR_FALSE); - DispatchActivateEvent(); LOGFOCUS(("Events sent from focus in event [%p]\n", (void *)this)); @@ -1270,7 +1124,7 @@ nsWindow::OnFocusInEvent(QFocusEvent *aEvent) } nsEventStatus -nsWindow::OnFocusOutEvent(QFocusEvent *aEvent) +nsWindow::OnFocusOutEvent(QEvent *aEvent) { LOGFOCUS(("OnFocusOutEvent [%p]\n", (void *)this)); @@ -1295,7 +1149,7 @@ nsWindow::DispatchCommandEvent(nsIAtom* aCommand) DispatchEvent(&event); - return TRUE; + return PR_TRUE; } nsEventStatus @@ -1383,7 +1237,7 @@ nsWindow::OnKeyReleaseEvent(QKeyEvent *aEvent) } nsEventStatus -nsWindow::OnScrollEvent(QWheelEvent *aEvent) +nsWindow::OnScrollEvent(QGraphicsSceneWheelEvent *aEvent) { // check to see if we should rollup nsMouseScrollEvent event(PR_TRUE, NS_MOUSE_SCROLL, this); @@ -1405,8 +1259,8 @@ nsWindow::OnScrollEvent(QWheelEvent *aEvent) event.delta = (int)(aEvent->delta() / WHEEL_DELTA) * -3; - event.refPoint.x = nscoord(aEvent->x()); - event.refPoint.y = nscoord(aEvent->y()); + event.refPoint.x = nscoord(aEvent->scenePos().x()); + event.refPoint.y = nscoord(aEvent->scenePos().y()); event.isShift = aEvent->modifiers() & Qt::ShiftModifier; event.isControl = aEvent->modifiers() & Qt::ControlModifier; @@ -1422,24 +1276,6 @@ nsEventStatus nsWindow::showEvent(QShowEvent *) { LOG(("%s [%p]\n", __PRETTY_FUNCTION__,(void *)this)); - // qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); -/* - QRect r = mWidget->rect(); - nsIntRect rect(r.x(), r.y(), r.width(), r.height()); - - nsCOMPtr 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 = ▭ - // XXX fix this! - event.region = nsnull; - // XXX fix this! - event.renderingContext = rc; - - return DispatchEvent(&event); -*/ mIsVisible = PR_TRUE; return nsEventStatus_eConsumeDoDefault; } @@ -1452,14 +1288,6 @@ nsWindow::hideEvent(QHideEvent *) return nsEventStatus_eConsumeDoDefault; } -nsEventStatus -nsWindow::OnWindowStateEvent(QEvent *aEvent) -{ - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - nsSizeModeEvent event(PR_TRUE, NS_SIZEMODE, this); - return DispatchEvent(&event); -} - void nsWindow::ThemeChanged() { @@ -1467,14 +1295,12 @@ nsWindow::ThemeChanged() DispatchEvent(&event); - if (!mWidget || NS_UNLIKELY(mIsDestroyed)) - return; - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); + // do nothing return; } nsEventStatus -nsWindow::OnDragMotionEvent(QDragMoveEvent *e) +nsWindow::OnDragMotionEvent(QGraphicsSceneDragDropEvent *aEvent) { LOG(("nsWindow::OnDragMotionSignal\n")); @@ -1484,7 +1310,7 @@ nsWindow::OnDragMotionEvent(QDragMoveEvent *e) } nsEventStatus -nsWindow::OnDragLeaveEvent(QDragLeaveEvent *e) +nsWindow::OnDragLeaveEvent(QGraphicsSceneDragDropEvent *aEvent) { // XXX Do we want to pass this on only if the event's subwindow is null? LOG(("nsWindow::OnDragLeaveSignal(%p)\n", this)); @@ -1494,7 +1320,7 @@ nsWindow::OnDragLeaveEvent(QDragLeaveEvent *e) } nsEventStatus -nsWindow::OnDragDropEvent(QDropEvent *aDropEvent) +nsWindow::OnDragDropEvent(QGraphicsSceneDragDropEvent *aDropEvent) { if (aDropEvent->proposedAction() == Qt::CopyAction) { @@ -1509,7 +1335,7 @@ nsWindow::OnDragDropEvent(QDropEvent *aDropEvent) } nsEventStatus -nsWindow::OnDragEnter(QDragEnterEvent *aDragEvent) +nsWindow::OnDragEnter(QGraphicsSceneDragDropEvent *aDragEvent) { // Is it some format we think we can support? if ( aDragEvent->mimeData()->hasFormat(kURLMime) @@ -1563,13 +1389,19 @@ nsWindow::Create(nsIWidget *aParent, nsIToolkit *aToolkit, nsWidgetInitData *aInitData) { - // only set the base parent if we're going to be a dialog or a + // only set the base parent if we're not going to be a dialog or a // toplevel - nsIWidget *baseParent = aInitData && + nsIWidget *baseParent = aParent; + + if (aInitData && (aInitData->mWindowType == eWindowType_dialog || aInitData->mWindowType == eWindowType_toplevel || - aInitData->mWindowType == eWindowType_invisible) ? - nsnull : aParent; + aInitData->mWindowType == eWindowType_invisible)) { + + baseParent = nsnull; + // also drop native parent for toplevel windows + aNativeParent = nsnull; + } // initialize all the common bits of this class BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, @@ -1581,23 +1413,19 @@ nsWindow::Create(nsIWidget *aParent, // save our bounds mBounds = aRect; - // figure out our parent window - QWidget *parent = nsnull; - if (aParent != nsnull) - parent = (QWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET); - else - parent = (QWidget*)aNativeParent; + // find native parent + MozQWidget *parent = nsnull; - // ok, create our windows + if (aParent != nsnull) + parent = static_cast(aParent->GetNativeData(NS_NATIVE_WIDGET)); + else + parent = static_cast(aNativeParent); + + // ok, create our QGraphicsWidget mWidget = createQWidget(parent, aInitData); - Initialize(mWidget); - - // disable focus handling for secondary windows (problems with mouse selection and NS_ACTIVATE) - if (aParent != nsnull) - { - mWidget->setFocusPolicy(Qt::NoFocus); - } + if (!mWidget) + return NS_ERROR_OUT_OF_MEMORY; LOG(("Create: nsWindow [%p] [%p]\n", (void *)this, (void *)mWidget)); @@ -1610,57 +1438,54 @@ nsWindow::Create(nsIWidget *aParent, NS_IMETHODIMP nsWindow::SetWindowClass(const nsAString &xulWinType) { - if (!mWidget) - return NS_ERROR_FAILURE; + if (!mWidget) + return NS_ERROR_FAILURE; - nsXPIDLString brandName; - GetBrandName(brandName); + nsXPIDLString brandName; + GetBrandName(brandName); #ifdef Q_WS_X11 - XClassHint *class_hint = XAllocClassHint(); - if (!class_hint) - return NS_ERROR_OUT_OF_MEMORY; - const char *role = NULL; - class_hint->res_name = ToNewCString(xulWinType); - if (!class_hint->res_name) { - XFree(class_hint); - return NS_ERROR_OUT_OF_MEMORY; - } - class_hint->res_class = ToNewCString(brandName); - if (!class_hint->res_class) { + XClassHint *class_hint = XAllocClassHint(); + if (!class_hint) + return NS_ERROR_OUT_OF_MEMORY; + const char *role = NULL; + class_hint->res_name = ToNewCString(xulWinType); + if (!class_hint->res_name) { + XFree(class_hint); + return NS_ERROR_OUT_OF_MEMORY; + } + class_hint->res_class = ToNewCString(brandName); + if (!class_hint->res_class) { + nsMemory::Free(class_hint->res_name); + XFree(class_hint); + return NS_ERROR_OUT_OF_MEMORY; + } + + // Parse res_name into a name and role. Characters other than + // [A-Za-z0-9_-] are converted to '_'. Anything after the first + // colon is assigned to role; if there's no colon, assign the + // whole thing to both role and res_name. + for (char *c = class_hint->res_name; *c; c++) { + if (':' == *c) { + *c = 0; + role = c + 1; + } + else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c))) + *c = '_'; + } + class_hint->res_name[0] = toupper(class_hint->res_name[0]); + if (!role) role = class_hint->res_name; + + XSetClassHint(GetViewWidget()->x11Info().display(), + GetViewWidget()->handle(), + class_hint); + + nsMemory::Free(class_hint->res_class); nsMemory::Free(class_hint->res_name); XFree(class_hint); - return NS_ERROR_OUT_OF_MEMORY; - } - - // Parse res_name into a name and role. Characters other than - // [A-Za-z0-9_-] are converted to '_'. Anything after the first - // colon is assigned to role; if there's no colon, assign the - // whole thing to both role and res_name. - for (char *c = class_hint->res_name; *c; c++) { - if (':' == *c) { - *c = 0; - role = c + 1; - } - else if (!isascii(*c) || (!isalnum(*c) && ('_' != *c) && ('-' != *c))) - *c = '_'; - } - class_hint->res_name[0] = toupper(class_hint->res_name[0]); - if (!role) role = class_hint->res_name; - - // gdk_window_set_role(GTK_WIDGET(mWidget)->window, role); - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - // Can't use gtk_window_set_wmclass() for this; it prints - // a warning & refuses to make the change. - XSetClassHint(mWidget->x11Info().display(), - mWidget->handle(), - class_hint); - nsMemory::Free(class_hint->res_class); - nsMemory::Free(class_hint->res_name); - XFree(class_hint); #endif - return NS_OK; + return NS_OK; } void @@ -1683,22 +1508,7 @@ nsWindow::NativeResize(PRInt32 aX, PRInt32 aY, LOG(("nsWindow::NativeResize [%p] %d %d %d %d\n", (void *)this, aX, aY, aWidth, aHeight)); - nsIntPoint pos(aX, aY); - if (mWidget) - { - if (mParent && mWidget->windowType() == Qt::Popup) { - pos += mParent->WidgetToScreenOffset(); -#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); + mWidget->setGeometry(aX, aY, aWidth, aHeight); if (aRepaint) mWidget->update(); @@ -1727,22 +1537,9 @@ nsWindow::GetHasTransparentBackground(PRBool& aTransparent) } void -nsWindow::GetToplevelWidget(QWidget **aWidget) +nsWindow::GetToplevelWidget(MozQWidget **aWidget) { - *aWidget = nsnull; - - if (mWidget) { - *aWidget = mWidget; - return; - } -} - -void -nsWindow::SetUrgencyHint(QWidget *top_window, PRBool state) -{ - if (!top_window) - return; - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); + *aWidget = mWidget; } void * @@ -1759,8 +1556,17 @@ nsWindow::SetupPluginPort(void) nsresult nsWindow::SetWindowIconList(const nsTArray &aIconList) { - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - return NS_OK; + QIcon icon; + + for (PRUint32 i = 0; i < aIconList.Length(); ++i) { + const char *path = aIconList[i].get(); + LOG(("window [%p] Loading icon from %s\n", (void *)this, path)); + icon.addFile(path); + } + + GetViewWidget()->setWindowIcon(icon); + + return NS_OK; } void @@ -1769,60 +1575,6 @@ nsWindow::SetDefaultIcon(void) SetIcon(NS_LITERAL_STRING("default")); } -void -nsWindow::SetPluginType(PluginType aPluginType) -{ - mPluginType = aPluginType; -} - -void -nsWindow::SetNonXEmbedPluginFocus() -{ - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); -} - -void -nsWindow::LoseNonXEmbedPluginFocus() -{ - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - LOGFOCUS(("nsWindow::LoseNonXEmbedPluginFocus\n")); - LOGFOCUS(("nsWindow::LoseNonXEmbedPluginFocus end\n")); -} - - -qint32 -nsWindow::ConvertBorderStyles(nsBorderStyle aStyle) -{ - qint32 w = 0; - - if (aStyle == eBorderStyle_default) - return -1; - - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); -/* - if (aStyle & eBorderStyle_all) - w |= Qt::Key_DECOR_ALL; - if (aStyle & eBorderStyle_border) - w |= Qt::Key_DECOR_BORDER; - if (aStyle & eBorderStyle_resizeh) - w |= Qt::Key_DECOR_RESIZEH; - if (aStyle & eBorderStyle_title) - w |= Qt::Key_DECOR_TITLE; - if (aStyle & eBorderStyle_menu) - w |= Qt::Key_DECOR_MENU; - if (aStyle & eBorderStyle_minimize) - w |= Qt::Key_DECOR_MINIMIZE; - if (aStyle & eBorderStyle_maximize) - w |= Qt::Key_DECOR_MAXIMIZE; - if (aStyle & eBorderStyle_close) { -#ifdef DEBUG - printf("we don't handle eBorderStyle_close yet... please fix me\n"); -#endif - } -*/ - return w; -} - void nsWindow::QWidgetDestroyed() { mWidget = nsnull; @@ -1834,22 +1586,22 @@ nsWindow::MakeFullScreen(PRBool aFullScreen) if (aFullScreen) { if (mSizeMode != nsSizeMode_Fullscreen) mLastSizeMode = mSizeMode; - + mSizeMode = nsSizeMode_Fullscreen; - mWidget->showFullScreen(); + GetViewWidget()->showFullScreen(); } else { mSizeMode = mLastSizeMode; switch (mSizeMode) { case nsSizeMode_Maximized: - mWidget->showMaximized(); + GetViewWidget()->showMaximized(); break; case nsSizeMode_Minimized: - mWidget->showMinimized(); + GetViewWidget()->showMinimized(); break; case nsSizeMode_Normal: - mWidget->showNormal(); + GetViewWidget()->showNormal(); break; } } @@ -1864,7 +1616,7 @@ nsWindow::HideWindowChrome(PRBool aShouldHide) { if (!mWidget) { // Pass the request to the toplevel window - QWidget *topWidget = nsnull; + MozQWidget *topWidget = nsnull; GetToplevelWidget(&topWidget); // return topWindow->HideWindowChrome(aShouldHide); return NS_ERROR_FAILURE; @@ -1879,12 +1631,6 @@ nsWindow::HideWindowChrome(PRBool aShouldHide) wasVisible = PR_TRUE; } - qint32 wmd; - if (aShouldHide) - wmd = 0; - else - wmd = ConvertBorderStyles(mBorderStyle); - if (wasVisible) { NativeShow(PR_TRUE); } @@ -1895,7 +1641,7 @@ nsWindow::HideWindowChrome(PRBool aShouldHide) // error later when this happens (when the persistence timer fires // and GetWindowPos is called) #ifdef Q_WS_X11 - XSync(mWidget->x11Info().display(), False); + XSync(GetViewWidget()->x11Info().display(), False); #endif return NS_OK; @@ -1911,8 +1657,7 @@ nsWindow::InitDragEvent(nsMouseEvent &aEvent) } // This will update the drag action based on the information in the -// drag context. Gtk gets this from a combination of the key settings -// and what the source is offering. +// drag context. /* static */ nsresult @@ -1972,18 +1717,10 @@ nsPopupWindow::~nsPopupWindow() } MozQWidget* -nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData) +nsWindow::createQWidget(MozQWidget *parent, nsWidgetInitData *aInitData) { - Qt::WFlags flags = Qt::Widget; const char *windowName = NULL; - if (gDoubleBuffering == -1) { - if (getenv("MOZ_NO_DOUBLEBUFFER")) - gDoubleBuffering = 0; - else - gDoubleBuffering = 1; - } - #ifdef DEBUG_WIDGETS qDebug("NEW WIDGET\n\tparent is %p (%s)", (void*)parent, parent ? qPrintable(parent->objectName()) : "null"); @@ -1993,17 +1730,16 @@ nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData) switch (mWindowType) { case eWindowType_dialog: windowName = "topLevelDialog"; + mIsTopLevel = PR_TRUE; break; case eWindowType_popup: - flags |= Qt::ToolTip; windowName = "topLevelPopup"; break; case eWindowType_toplevel: - flags |= Qt::Window; windowName = "topLevelWindow"; + mIsTopLevel = PR_TRUE; break; case eWindowType_invisible: - flags |= Qt::Window; windowName = "topLevelInvisible"; break; case eWindowType_child: @@ -2013,11 +1749,43 @@ nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData) break; } - MozQWidget * widget = new MozQWidget(this, parent, windowName, flags); + MozQWidget * widget = new MozQWidget(this, parent); + if (!widget) + return nsnull; + + // create a QGraphicsView if this is a new toplevel window + MozQGraphicsView* newView = 0; + + if (eWindowType_dialog == mWindowType || + eWindowType_toplevel == mWindowType) + { + mScene = new QGraphicsScene(); + if (!mScene) { + delete widget; + return nsnull; + } + + newView = new MozQGraphicsView(mScene); + if (!newView) { + delete mScene; + delete widget; + return nsnull; + } + + newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + newView->show(); + newView->raise(); + } + + if (mScene && newView) { + mScene->addItem(widget); + newView->setTopLevel(widget); + } if (mWindowType == eWindowType_popup) { - widget->setFocusPolicy(Qt::WheelFocus); - + widget->setZValue(100); + // XXX is this needed for Qt? // gdk does not automatically set the cursor for "temporary" // windows, which are what gtk uses for popups. @@ -2026,13 +1794,6 @@ nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData) SetDefaultIcon(); } - widget->setAttribute(Qt::WA_StaticContents); - widget->setAttribute(Qt::WA_OpaquePaintEvent); // Transparent Widget Background - widget->setAttribute(Qt::WA_NoSystemBackground); - - if (!gDoubleBuffering) - { widget->setAttribute(Qt::WA_PaintOnScreen); } - return widget; } @@ -2054,49 +1815,42 @@ nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVert { NS_ENSURE_ARG_POINTER(aEvent); - if (aEvent->eventStructType != NS_MOUSE_EVENT) { - // you can only begin a resize drag with a mouse event - return NS_ERROR_INVALID_ARG; + // you can only begin a resize drag with a mouse event + return NS_ERROR_INVALID_ARG; } nsMouseEvent* mouse_event = static_cast(aEvent); if (mouse_event->button != nsMouseEvent::eLeftButton) { - // you can only begin a resize drag with the left mouse button - return NS_ERROR_INVALID_ARG; + // you can only begin a resize drag with the left mouse button + return NS_ERROR_INVALID_ARG; } - qDebug("FIXME:>>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__); - return NS_OK; } nsEventStatus -nsWindow::contextMenuEvent(QContextMenuEvent *) +nsWindow::contextMenuEvent(QGraphicsSceneContextMenuEvent *) { - //qDebug("context menu"); return nsEventStatus_eIgnore; } nsEventStatus nsWindow::imStartEvent(QEvent *) { - qWarning("XXX imStartEvent"); return nsEventStatus_eIgnore; } nsEventStatus nsWindow::imComposeEvent(QEvent *) { - qWarning("XXX imComposeEvent"); return nsEventStatus_eIgnore; } nsEventStatus nsWindow::imEndEvent(QEvent * ) { - qWarning("XXX imComposeEvent"); return nsEventStatus_eIgnore; } @@ -2178,13 +1932,15 @@ nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) mBounds.width = aWidth; mBounds.height = aHeight; - qDebug() << "RESIZING NSWINDOW:" << (void*)(this) << aWidth << "x" << aHeight; - if (!mWidget) return NS_OK; mWidget->resize(aWidth, aHeight); + if (mIsTopLevel) { + GetViewWidget()->resize(aWidth,aHeight); + } + if (aRepaint) mWidget->update(); @@ -2207,6 +1963,10 @@ nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, mWidget->setGeometry(aX, aY, aWidth, aHeight); + if (mIsTopLevel) { + GetViewWidget()->resize(aWidth,aHeight); + } + if (aRepaint) mWidget->update(); diff --git a/widget/src/qt/nsWindow.h b/widget/src/qt/nsWindow.h index f5bbcbad95b5..5a42870ac9a0 100644 --- a/widget/src/qt/nsWindow.h +++ b/widget/src/qt/nsWindow.h @@ -50,6 +50,7 @@ #include "nsWeakReference.h" #include "nsWidgetAtoms.h" +#include #ifdef MOZ_LOGGING @@ -97,6 +98,7 @@ extern PRLogModuleInfo *gWidgetDrawLog; class QEvent; class MozQWidget; +class QGraphicsScene; class nsWindow : public nsBaseWidget, public nsSupportsWeakReference @@ -105,6 +107,8 @@ public: nsWindow(); virtual ~nsWindow(); + nsEventStatus DoPaint( QPainter* aPainter, const QStyleOptionGraphicsItem * aOption ); + static void ReleaseGlobals(); NS_DECL_ISUPPORTS_INHERITED @@ -142,7 +146,6 @@ public: PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint); - NS_IMETHOD SetZIndex(PRInt32 aZIndex); NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, PRBool aActivate); @@ -187,9 +190,6 @@ public: // // utility methods // - - qint32 ConvertBorderStyles(nsBorderStyle aStyle); - void QWidgetDestroyed(); /***** from CommonWidget *****/ @@ -243,35 +243,32 @@ protected: friend class InterceptContainer; friend class MozQWidget; - virtual nsEventStatus OnPaintEvent(QPaintEvent *); - virtual nsEventStatus OnMoveEvent(QMoveEvent *); - virtual nsEventStatus OnResizeEvent(QResizeEvent *); + virtual nsEventStatus OnMoveEvent(QGraphicsSceneHoverEvent *); + virtual nsEventStatus OnResizeEvent(QGraphicsSceneResizeEvent *); virtual nsEventStatus OnCloseEvent(QCloseEvent *); - virtual nsEventStatus OnEnterNotifyEvent(QEvent *); - virtual nsEventStatus OnLeaveNotifyEvent(QEvent *); - virtual nsEventStatus OnMotionNotifyEvent(QMouseEvent *); - virtual nsEventStatus OnButtonPressEvent(QMouseEvent *); - virtual nsEventStatus OnButtonReleaseEvent(QMouseEvent *); - virtual nsEventStatus mouseDoubleClickEvent(QMouseEvent *); - virtual nsEventStatus OnFocusInEvent(QFocusEvent *); - virtual nsEventStatus OnFocusOutEvent(QFocusEvent *); + virtual nsEventStatus OnEnterNotifyEvent(QGraphicsSceneHoverEvent *); + virtual nsEventStatus OnLeaveNotifyEvent(QGraphicsSceneHoverEvent *); + virtual nsEventStatus OnMotionNotifyEvent(QGraphicsSceneMouseEvent *); + virtual nsEventStatus OnButtonPressEvent(QGraphicsSceneMouseEvent *); + virtual nsEventStatus OnButtonReleaseEvent(QGraphicsSceneMouseEvent *); + virtual nsEventStatus mouseDoubleClickEvent(QGraphicsSceneMouseEvent *); + virtual nsEventStatus OnFocusInEvent(QEvent *); + virtual nsEventStatus OnFocusOutEvent(QEvent *); virtual nsEventStatus OnKeyPressEvent(QKeyEvent *); virtual nsEventStatus OnKeyReleaseEvent(QKeyEvent *); - virtual nsEventStatus OnScrollEvent(QWheelEvent *); + virtual nsEventStatus OnScrollEvent(QGraphicsSceneWheelEvent *); - virtual nsEventStatus contextMenuEvent(QContextMenuEvent *); + virtual nsEventStatus contextMenuEvent(QGraphicsSceneContextMenuEvent *); virtual nsEventStatus imStartEvent(QEvent *); virtual nsEventStatus imComposeEvent(QEvent *); virtual nsEventStatus imEndEvent(QEvent *); - virtual nsEventStatus OnDragEnter (QDragEnterEvent *); - virtual nsEventStatus OnDragMotionEvent(QDragMoveEvent *); - virtual nsEventStatus OnDragLeaveEvent(QDragLeaveEvent *); - virtual nsEventStatus OnDragDropEvent (QDropEvent *); + virtual nsEventStatus OnDragEnter (QGraphicsSceneDragDropEvent *); + virtual nsEventStatus OnDragMotionEvent(QGraphicsSceneDragDropEvent *); + virtual nsEventStatus OnDragLeaveEvent(QGraphicsSceneDragDropEvent *); + virtual nsEventStatus OnDragDropEvent (QGraphicsSceneDragDropEvent *); virtual nsEventStatus showEvent(QShowEvent *); virtual nsEventStatus hideEvent(QHideEvent *); - nsEventStatus OnWindowStateEvent(QEvent *aEvent); - void NativeResize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint); @@ -291,29 +288,29 @@ protected: }; void SetPluginType(PluginType aPluginType); - void SetNonXEmbedPluginFocus(void); - void LoseNonXEmbedPluginFocus(void); void ThemeChanged(void); - gfxASurface *GetThebesSurface(); + gfxASurface* GetThebesSurface(); private: - void GetToplevelWidget(QWidget **aWidget); - void SetUrgencyHint(QWidget *top_window, PRBool state); - void *SetupPluginPort(void); + void GetToplevelWidget(MozQWidget **aWidget); + void* SetupPluginPort(void); nsresult SetWindowIconList(const nsTArray &aIconList); void SetDefaultIcon(void); - void InitButtonEvent(nsMouseEvent &event, QMouseEvent *aEvent, int aClickCount = 1); + void InitButtonEvent(nsMouseEvent &event, QGraphicsSceneMouseEvent *aEvent, int aClickCount = 1); PRBool DispatchCommandEvent(nsIAtom* aCommand); - MozQWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData); + MozQWidget* createQWidget(MozQWidget *parent, nsWidgetInitData *aInitData); - MozQWidget * mWidget; + QWidget* GetViewWidget(); - PRUint32 mIsVisible : 1, - mActivatePending : 1; - PRInt32 mSizeState; - PluginType mPluginType; + MozQWidget* mWidget; + QGraphicsScene* mScene; + + PRUint32 mIsVisible : 1, + mActivatePending : 1; + PRInt32 mSizeState; + PluginType mPluginType; nsRefPtr mThebesSurface; @@ -365,16 +362,16 @@ public: nsChildWindow(); ~nsChildWindow(); - PRInt32 mChildID; + PRInt32 mChildID; }; class nsPopupWindow : public nsWindow { public: - nsPopupWindow (); - ~nsPopupWindow (); + nsPopupWindow (); + ~nsPopupWindow (); - PRInt32 mChildID; + PRInt32 mChildID; }; #endif /* __nsWindow_h__ */