Bug 552315 - Improve Qt show functionality. r=dougt
authorOleg Romashin <romaxa@gmail.com>
Mon, 15 Mar 2010 08:08:15 +0200
changeset 39446 17a3e86d5ec51e0a45f07991d63c5e291757430d
parent 39445 d9e13024740cea51fd551df990f45e931a058424
child 39447 8ff6056308bd78e85aa67777cdcc4a7149e1bc4e
push idunknown
push userunknown
push dateunknown
reviewersdougt
bugs552315
milestone1.9.3a3pre
Bug 552315 - Improve Qt show functionality. r=dougt
widget/src/qt/nsWindow.cpp
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -533,30 +533,33 @@ nsWindow::SetSizeMode(PRInt32 aMode)
     rv = nsBaseWidget::SetSizeMode(aMode);
 
     // return if there's no shell or our current state is the same as
     // the mode we were just set to.
     if (!mWidget || mSizeState == mSizeMode) {
         return rv;
     }
 
+    QWidget *widget = GetViewWidget();
+    NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
+
     switch (aMode) {
     case nsSizeMode_Maximized:
-        GetViewWidget()->showMaximized();
+        widget->showMaximized();
         break;
     case nsSizeMode_Minimized:
-        GetViewWidget()->showMinimized();
+        widget->showMinimized();
         break;
     case nsSizeMode_Fullscreen:
-        GetViewWidget()->showFullScreen();
+        widget->showFullScreen();
         break;
 
     default:
         // nsSizeMode_Normal, really.
-        GetViewWidget()->showNormal();
+        widget->showNormal();
         break;
     }
 
     mSizeState = mSizeMode;
 
     return rv;
 }
 
@@ -593,17 +596,19 @@ nsWindow::SetFocus(PRBool aRaise)
     QGraphicsItem* realFocusItem = nsnull;
     find_first_visible_parent(mWidget, realFocusItem);
 
     if (!realFocusItem || realFocusItem->hasFocus())
         return NS_OK;
 
     if (aRaise) {
         // the raising has to happen on the view widget
-        GetViewWidget()->raise();
+        QWidget *widget = GetViewWidget();
+        if (widget)
+            widget->raise();
         realFocusItem->setFocus(Qt::ActiveWindowFocusReason);
     }
     else
         realFocusItem->setFocus(Qt::OtherFocusReason);
 
     DispatchActivateEvent();
 
     return NS_OK;
@@ -656,18 +661,21 @@ nsWindow::Invalidate(const nsIntRect &aR
              (void*)mWidget,aRect.x, aRect.y, aRect.width, aRect.height, aIsSynchronous));
 
     if (!mWidget)
         return NS_OK;
 
     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()->repaint();
+    if (aIsSynchronous) {
+        QWidget *widget = GetViewWidget();
+        if (widget)
+            widget->repaint();
+    }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::Update()
 {
     return NS_OK;
@@ -729,17 +737,17 @@ nsWindow::Scroll(const nsIntPoint& aDelt
 
 // Returns the graphics view widget for this nsWindow by iterating
 // the chain of parents until a toplevel window with a view/scene is found.
 // (This function always returns something or asserts if the precondition
 // is not met)
 QWidget* nsWindow::GetViewWidget()
 {
     NS_ASSERTION(mWidget, "Calling GetViewWidget without mWidget created");
-    if (!mWidget)
+    if (!mWidget || !mWidget->scene())
         return nsnull;
 
     NS_ASSERTION(mWidget->scene()->views().size() == 1, "Not exactly one view for our scene!");
     return mWidget->scene()->views()[0];
 }
 
 void*
 nsWindow::GetNativeData(PRUint32 aDataType)
@@ -755,17 +763,18 @@ nsWindow::GetNativeData(PRUint32 aDataTy
     }
 
     case NS_NATIVE_PLUGIN_PORT:
         return SetupPluginPort();
         break;
 
 #ifdef Q_WS_X11
     case NS_NATIVE_DISPLAY:
-        return GetViewWidget()->x11Info().display();
+        QWidget *widget = GetViewWidget();
+        return widget ? widget->x11Info().display() : nsnull;
         break;
 #endif
 
     case NS_NATIVE_GRAPHIC: {
         NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");
         return (void *)static_cast<nsToolkit *>(mToolkit)->GetSharedGC();
         break;
     }
@@ -778,18 +787,21 @@ nsWindow::GetNativeData(PRUint32 aDataTy
         return nsnull;
     }
 }
 
 NS_IMETHODIMP
 nsWindow::SetTitle(const nsAString& aTitle)
 {
     QString qStr(QString::fromUtf16(aTitle.BeginReading(), aTitle.Length()));
-    if (mIsTopLevel)
-        GetViewWidget()->setWindowTitle(qStr);
+    if (mIsTopLevel) {
+        QWidget *widget = GetViewWidget();
+        if (widget)
+            widget->setWindowTitle(qStr);
+    }
     else if (mWidget)
         mWidget->setWindowTitle(qStr);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::SetIcon(const nsAString& aIconSpec)
@@ -850,20 +862,24 @@ nsWindow::EnableDragDrop(PRBool aEnable)
 
 NS_IMETHODIMP
 nsWindow::CaptureMouse(PRBool aCapture)
 {
     LOG(("CaptureMouse %p\n", (void *)this));
 
     if (!mWidget)
         return NS_OK;
+
+    QWidget *widget = GetViewWidget();
+    NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
+
     if (aCapture)
-        GetViewWidget()->grabMouse();
+        widget->grabMouse();
     else
-        GetViewWidget()->releaseMouse();
+        widget->releaseMouse();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::CaptureRollupEvents(nsIRollupListener *aListener,
                               nsIMenuRollup     *aMenuRollup,
                               PRBool             aDoCapture,
@@ -1824,18 +1840,22 @@ nsWindow::NativeResize(PRInt32 aX, PRInt
 
     if (aRepaint)
         mWidget->update();
 }
 
 void
 nsWindow::NativeShow(PRBool aAction)
 {
-    if (aAction == PR_TRUE)
+    if (aAction) {
+        QWidget *widget = GetViewWidget();
+        if (widget && !widget->isVisible())
+            MakeFullScreen(mSizeMode == nsSizeMode_Fullscreen);
         mWidget->show();
+    }
     else
         mWidget->hide();
 }
 
 NS_IMETHODIMP
 nsWindow::SetHasTransparentBackground(PRBool aTransparent)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
@@ -1871,17 +1891,19 @@ nsWindow::SetWindowIconList(const nsTArr
     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);
+    QWidget *widget = GetViewWidget();
+    NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
+    widget->setWindowIcon(icon);
 
     return NS_OK;
 }
 
 void
 nsWindow::SetDefaultIcon(void)
 {
     SetIcon(NS_LITERAL_STRING("default"));
@@ -1890,35 +1912,40 @@ nsWindow::SetDefaultIcon(void)
 void nsWindow::QWidgetDestroyed()
 {
     mWidget = nsnull;
 }
 
 NS_IMETHODIMP
 nsWindow::MakeFullScreen(PRBool aFullScreen)
 {
+    QWidget *widget = GetViewWidget();
+    NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
     if (aFullScreen) {
         if (mSizeMode != nsSizeMode_Fullscreen)
             mLastSizeMode = mSizeMode;
 
         mSizeMode = nsSizeMode_Fullscreen;
-        GetViewWidget()->showFullScreen();
+        widget->showFullScreen();
     }
     else {
         mSizeMode = mLastSizeMode;
 
         switch (mSizeMode) {
         case nsSizeMode_Maximized:
-            GetViewWidget()->showMaximized();
+            widget->showMaximized();
             break;
         case nsSizeMode_Minimized:
-            GetViewWidget()->showMinimized();
+            widget->showMinimized();
             break;
         case nsSizeMode_Normal:
-            GetViewWidget()->showNormal();
+            widget->showNormal();
+            break;
+        default:
+            widget->showNormal();
             break;
         }
     }
     
     NS_ASSERTION(mLastSizeMode != nsSizeMode_Fullscreen,
                  "mLastSizeMode should never be fullscreen");
     return NS_OK;
 }
@@ -1948,17 +1975,19 @@ nsWindow::HideWindowChrome(PRBool aShoul
     }
 
     // For some window managers, adding or removing window decorations
     // requires unmapping and remapping our toplevel window.  Go ahead
     // and flush the queue here so that we don't end up with a BadWindow
     // error later when this happens (when the persistence timer fires
     // and GetWindowPos is called)
 #ifdef Q_WS_X11
-    XSync(GetViewWidget()->x11Info().display(), False);
+    QWidget *widget = GetViewWidget();
+    NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
+    XSync(widget->x11Info().display(), False);
 #endif
 
     return NS_OK;
 }
 
 //////////////////////////////////////////////////////////////////////
 // These are all of our drag and drop operations
 
@@ -2086,17 +2115,16 @@ nsWindow::createQWidget(MozQWidget *pare
 
         // Enable gestures:
 #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0))
         newView->grabGesture(Qt::PinchGesture);
         newView->viewport()->grabGesture(Qt::PinchGesture);
 #endif
         newView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
         newView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-        newView->showNormal();
 
 #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);
 
@@ -2263,17 +2291,19 @@ nsWindow::Resize(PRInt32 aWidth, PRInt32
     mBounds.height = aHeight;
 
     if (!mWidget)
         return NS_OK;
 
     mWidget->resize(aWidth, aHeight);
 
     if (mIsTopLevel) {
-        GetViewWidget()->resize(aWidth,aHeight);
+        QWidget *widget = GetViewWidget();
+        if (widget)
+            widget->resize(aWidth, aHeight);
     }
 
     if (aRepaint)
         mWidget->update();
 
     return NS_OK;
 }
 
@@ -2289,17 +2319,19 @@ nsWindow::Resize(PRInt32 aX, PRInt32 aY,
     mPlaced = PR_TRUE;
 
     if (!mWidget)
         return NS_OK;
 
     mWidget->setGeometry(aX, aY, aWidth, aHeight);
 
     if (mIsTopLevel) {
-        GetViewWidget()->resize(aWidth,aHeight);
+        QWidget *widget = GetViewWidget();
+        if (widget)
+            widget->resize(aWidth, aHeight);
     }
 
     if (aRepaint)
         mWidget->update();
 
     return NS_OK;
 }