mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 552011 - Dialog crash fix + Qt widget cleanup. r=dougt. Landed on CLOSED TREE.
This commit is contained in:
parent
6e17d06ad8
commit
4576a188fa
@ -139,11 +139,13 @@ void MozQWidget::closeEvent(QCloseEvent* aEvent)
|
||||
void MozQWidget::hideEvent(QHideEvent* aEvent)
|
||||
{
|
||||
mReceiver->hideEvent(aEvent);
|
||||
QGraphicsWidget::hideEvent(aEvent);
|
||||
}
|
||||
|
||||
void MozQWidget::showEvent(QShowEvent* aEvent)
|
||||
{
|
||||
mReceiver->showEvent(aEvent);
|
||||
QGraphicsWidget::showEvent(aEvent);
|
||||
}
|
||||
|
||||
bool MozQWidget::SetCursor(nsCursor aCursor)
|
||||
@ -219,3 +221,9 @@ void MozQWidget::setModal(bool modal)
|
||||
LOG(("Modal QGraphicsWidgets not supported in Qt < 4.6\n"));
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariant MozQWidget::inputMethodQuery(Qt::InputMethodQuery aQuery) const
|
||||
{
|
||||
return QGraphicsWidget::inputMethodQuery(aQuery);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
QVariant inputMethodQuery(Qt::InputMethodQuery aQuery) const;
|
||||
|
||||
protected:
|
||||
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* aEvent);
|
||||
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* aEvent);
|
||||
@ -49,20 +51,80 @@ protected:
|
||||
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);
|
||||
|
||||
|
||||
bool SetCursor(const QPixmap& aPixmap, int, int);
|
||||
|
||||
private:
|
||||
nsWindow *mReceiver;
|
||||
};
|
||||
|
||||
class MozQGraphicsViewEvents
|
||||
{
|
||||
public:
|
||||
|
||||
MozQGraphicsViewEvents(QGraphicsView* aView, MozQWidget* aTopLevel)
|
||||
: mTopLevelWidget(aTopLevel)
|
||||
, mView(aView)
|
||||
{ }
|
||||
|
||||
void handleEvent(QEvent* aEvent)
|
||||
{
|
||||
if (!aEvent)
|
||||
return;
|
||||
if (aEvent->type() == QEvent::WindowActivate) {
|
||||
if (mTopLevelWidget)
|
||||
mTopLevelWidget->activate();
|
||||
}
|
||||
|
||||
if (aEvent->type() == QEvent::WindowDeactivate) {
|
||||
if (mTopLevelWidget)
|
||||
mTopLevelWidget->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void handleResizeEvent(QResizeEvent* aEvent)
|
||||
{
|
||||
if (!aEvent)
|
||||
return;
|
||||
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()));
|
||||
// resize scene rect to vieport size,
|
||||
// to avoid extra scrolling from QAbstractScrollable
|
||||
if (mView)
|
||||
mView->setSceneRect(mView->viewport()->rect());
|
||||
}
|
||||
}
|
||||
|
||||
bool handleCloseEvent(QCloseEvent* aEvent)
|
||||
{
|
||||
if (!aEvent)
|
||||
return false;
|
||||
if (mTopLevelWidget) {
|
||||
// close graphics widget instead, this view will be discarded
|
||||
// automatically
|
||||
QApplication::postEvent(mTopLevelWidget, new QCloseEvent(*aEvent));
|
||||
aEvent->ignore();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
MozQWidget* mTopLevelWidget;
|
||||
QGraphicsView* mView;
|
||||
};
|
||||
|
||||
/**
|
||||
This is a helper class to synchronize the QGraphicsView window with
|
||||
its contained QGraphicsWidget for things like resizing and closing
|
||||
@ -73,62 +135,35 @@ class MozQGraphicsView : public QGraphicsView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MozQGraphicsView(QGraphicsScene* aScene, QWidget * aParent = nsnull)
|
||||
: QGraphicsView (aScene, aParent)
|
||||
, mTopLevelWidget(0)
|
||||
{ }
|
||||
|
||||
void setTopLevel(MozQWidget* aTopLevel)
|
||||
MozQGraphicsView(MozQWidget* aTopLevel, QWidget * aParent = nsnull)
|
||||
: QGraphicsView (new QGraphicsScene(), aParent)
|
||||
, mEventHandler(this, aTopLevel)
|
||||
{
|
||||
mTopLevelWidget = aTopLevel;
|
||||
scene()->addItem(aTopLevel);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool event(QEvent* aEvent)
|
||||
{
|
||||
if (aEvent->type() == QEvent::WindowActivate) {
|
||||
if (mTopLevelWidget)
|
||||
mTopLevelWidget->activate();
|
||||
}
|
||||
|
||||
if (aEvent->type() == QEvent::WindowDeactivate) {
|
||||
if (mTopLevelWidget)
|
||||
mTopLevelWidget->deactivate();
|
||||
}
|
||||
|
||||
mEventHandler.handleEvent(aEvent);
|
||||
return QGraphicsView::event(aEvent);
|
||||
}
|
||||
|
||||
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()));
|
||||
// resize scene rect to vieport size,
|
||||
// to avoid extra scrolling from QAbstractScrollable
|
||||
setSceneRect(viewport()->rect());
|
||||
|
||||
}
|
||||
mEventHandler.handleResizeEvent(aEvent);
|
||||
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 {
|
||||
if (!mEventHandler.handleCloseEvent(aEvent))
|
||||
QGraphicsView::closeEvent(aEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MozQWidget* mTopLevelWidget;
|
||||
MozQGraphicsViewEvents mEventHandler;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1941,7 +1941,8 @@ nsWindow::createQWidget(MozQWidget *parent, nsWidgetInitData *aInitData)
|
||||
switch (mWindowType) {
|
||||
case eWindowType_dialog:
|
||||
windowName = "topLevelDialog";
|
||||
mIsTopLevel = PR_TRUE;
|
||||
if (!parent)
|
||||
mIsTopLevel = PR_TRUE;
|
||||
break;
|
||||
case eWindowType_popup:
|
||||
windowName = "topLevelPopup";
|
||||
@ -1972,35 +1973,24 @@ nsWindow::createQWidget(MozQWidget *parent, nsWidgetInitData *aInitData)
|
||||
|
||||
// create a QGraphicsView if this is a new toplevel window
|
||||
|
||||
if (eWindowType_dialog == mWindowType ||
|
||||
eWindowType_toplevel == mWindowType)
|
||||
{
|
||||
MozQGraphicsView* newView = 0;
|
||||
QGraphicsScene *scene = new QGraphicsScene();
|
||||
if (!scene) {
|
||||
delete widget;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
newView = new MozQGraphicsView(scene);
|
||||
if (mIsTopLevel) {
|
||||
QGraphicsView* newView = nsnull;
|
||||
newView = new MozQGraphicsView(widget);
|
||||
if (!newView) {
|
||||
delete scene;
|
||||
delete widget;
|
||||
return nsnull;
|
||||
}
|
||||
newView->setTopLevel(widget);
|
||||
|
||||
newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
newView->show();
|
||||
newView->raise();
|
||||
newView->showNormal();
|
||||
|
||||
scene->addItem(widget);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
|
||||
// Top level widget is just container, and should not be painted
|
||||
widget->setFlag(QGraphicsItem::ItemHasNoContents);
|
||||
#endif
|
||||
}
|
||||
} else if (eWindowType_dialog == mWindowType && parent)
|
||||
parent->scene()->addItem(widget);
|
||||
|
||||
if (mWindowType == eWindowType_popup) {
|
||||
widget->setZValue(100);
|
||||
|
Loading…
Reference in New Issue
Block a user