Bug 544216 - Switch from QWidgets to QGraphicsWidgets. r=dougt

This commit is contained in:
Steffen Imhof 2010-02-16 10:14:20 -08:00
Родитель 8aeabfc548
Коммит b852f5e354
5 изменённых файлов: 613 добавлений и 833 удалений

Просмотреть файл

@ -1,13 +1,26 @@
#include "mozqwidget.h"
#include "nsWindow.h"
#include <qevent.h>
MozQWidget::MozQWidget(nsWindow *receiver, QWidget *parent,
const char *name, int f)
: QWidget(parent, (Qt::WindowFlags)f),
mReceiver(receiver)
#include <QtGui/QApplication>
#include <QtGui/QCursor>
#include <QtGui/QInputContext>
#include <QtGui/QGraphicsSceneContextMenuEvent>
#include <QtGui/QGraphicsSceneDragDropEvent>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QGraphicsSceneHoverEvent>
#include <QtGui/QGraphicsSceneWheelEvent>
#include <QtCore/QEvent>
#include <QtCore/QVariant>
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
}

Просмотреть файл

@ -1,18 +1,23 @@
#ifndef MOZQWIDGET_H
#define MOZQWIDGET_H
#include <qwidget.h>
#include "nsIWidget.h"
#include <QtGui/QApplication>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsWidget>
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<qreal>(aEvent->size().width()),
static_cast<qreal>(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

Просмотреть файл

@ -50,6 +50,7 @@
#include <qfile.h>
#include <qstringlist.h>
#include <qapplication.h>
/* 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<QWidget*>(parent->GetNativeData(NS_NATIVE_SHELLWIDGET)):0;
nsAutoString str(title);
mDialog = new QFileDialog(parentWidget, QString::fromUtf16(str.get()));

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsWeakReference.h"
#include "nsWidgetAtoms.h"
#include <qgraphicswidget.h>
#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<nsCString> &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<gfxASurface> 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__ */