Bug 663393 - Maemo6/Meego VKB doues not work properly without meegotouch r=dougt
authorOleg Romashin <romaxa@gmail.com>
Sat, 25 Jun 2011 09:22:34 -0400
changeset 72260 a70f3a49de1785b5cd59ac387eeaad6934dab0fa
parent 72259 3878e0b60ff22531ba63ddd586b1e87b5ebcfcab
child 72280 82b9558a9eeb1011206f3a3abeaef370d1f5a061
push idunknown
push userunknown
push dateunknown
reviewersdougt
bugs663393
milestone7.0a1
Bug 663393 - Maemo6/Meego VKB doues not work properly without meegotouch r=dougt
configure.in
toolkit/xre/nsAppRunner.cpp
widget/src/qt/mozqorientationsensorfilter.cpp
widget/src/qt/mozqorientationsensorfilter.h
widget/src/qt/mozqwidget.h
widget/src/qt/nsWindow.cpp
--- a/configure.in
+++ b/configure.in
@@ -6850,16 +6850,32 @@ if test $MOZ_PLATFORM_MAEMO; then
          if test "$_LIB_FOUND"; then
             MOZ_PLATFORM_MAEMO_LIBS="$MOZ_PLATFORM_MAEMO_LIBS $LIBCONTENTACTION_LIBS"
             MOZ_PLATFORM_MAEMO_CFLAGS="$MOZ_PLATFORM_MAEMO_CFLAGS $LIBCONTENTACTION_CFLAGS"
             MOZ_ENABLE_CONTENTACTION=1
             AC_DEFINE(MOZ_ENABLE_CONTENTACTION)
             AC_SUBST(MOZ_ENABLE_CONTENTACTION)
          fi
       fi
+
+      MOZ_ARG_ENABLE_BOOL(meegotouch,
+      [  --enable-meegotouch  Enable meegotouch support],
+         MOZ_MEEGOTOUCHENABLED=1,
+         MOZ_MEEGOTOUCHENABLED=)
+
+      if test -n "$MOZ_MEEGOTOUCHENABLED"; then
+          PKG_CHECK_MODULES(MOZ_MEEGOTOUCH, meegotouchcore, _LIB_FOUND=1, _LIB_FOUND=)
+          if test "$_LIB_FOUND"; then
+              MOZ_QT_CFLAGS="$MOZ_MEEGOTOUCH_CFLAGS $MOZ_QT_CFLAGS"
+              MOZ_QT_LIBS="$MOZ_MEEGOTOUCH_LIBS $MOZ_QT_LIBS"
+              AC_DEFINE(MOZ_ENABLE_MEEGOTOUCH)
+          else
+              AC_MSG_WARN([Cannot meegotouchcore-dev. Disabling Meegotouch support.])
+          fi
+      fi
    fi
 
    PKG_CHECK_MODULES(LIBLOCATION,liblocation, _LIB_FOUND=1, _LIB_FOUND=)
    MOZ_PLATFORM_MAEMO_LIBS="$MOZ_PLATFORM_MAEMO_LIBS $LIBLOCATION_LIBS"
    MOZ_PLATFORM_MAEMO_CFLAGS="$MOZ_PLATFORM_MAEMO_CFLAGS $LIBLOCATION_CFLAGS"
    if test "$_LIB_FOUND"; then
       MOZ_MAEMO_LIBLOCATION=1
       AC_DEFINE(MOZ_MAEMO_LIBLOCATION)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -49,16 +49,19 @@
 #define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
 
 #if defined(MOZ_WIDGET_QT)
 #include <QtGui/QApplication>
 #include <QtCore/QScopedPointer>
 #include <QtGui/QApplication>
 #include <QtGui/QInputContextFactory>
 #include <QtGui/QInputContext>
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+#include <MComponentData>
+#endif // MOZ_ENABLE_MEEGOTOUCH
 #endif // MOZ_WIDGET_QT
 
 #include "mozilla/dom/ContentParent.h"
 using mozilla::dom::ContentParent;
 
 #include "nsAppRunner.h"
 #include "nsUpdateDriver.h"
 
@@ -3002,16 +3005,21 @@ XRE_main(int argc, char* argv[], const n
 
 #if defined(MOZ_WIDGET_QT)
     const char* qgraphicssystemARG = NULL;
     ar = CheckArg("graphicssystem", PR_TRUE, &qgraphicssystemARG, PR_FALSE);
     if (ar == ARG_FOUND)
       PR_SetEnv(PR_smprintf("MOZ_QT_GRAPHICSSYSTEM=%s", qgraphicssystemARG));
 
     QScopedPointer<QApplication> app(new QApplication(gArgc, gArgv));
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+    gArgv[gArgc] = strdup("-software");
+    gArgc++;
+    QScopedPointer<MComponentData> meegotouch(new MComponentData(gArgc, gArgv));
+#endif
 
 #if MOZ_PLATFORM_MAEMO > 5
     if (XRE_GetProcessType() == GeckoProcessType_Default) {
       // try to get the MInputContext if possible to support the MeeGo VKB
       QInputContext* inputContext = app->inputContext();
       if (inputContext && inputContext->identifierName() != "MInputContext") {
           QInputContext* context = QInputContextFactory::create("MInputContext",
                                                                 app.data());
--- a/widget/src/qt/mozqorientationsensorfilter.cpp
+++ b/widget/src/qt/mozqorientationsensorfilter.cpp
@@ -31,16 +31,21 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozqorientationsensorfilter.h"
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+#include <MApplication>
+#include <MWindow>
+#endif
+#include "nsXULAppAPI.h"
 
 int MozQOrientationSensorFilter::mWindowRotationAngle = 0;
 QTransform MozQOrientationSensorFilter::mWindowRotationTransform;
 
 bool
 MozQOrientationSensorFilter::filter(QOrientationReading* reading)
 {
     switch (reading->orientation()) {
@@ -68,12 +73,48 @@ MozQOrientationSensorFilter::filter(QOri
     case QOrientationReading::Undefined:
     default:
         return true;
     }
 
     mWindowRotationTransform = QTransform();
     mWindowRotationTransform.rotate(mWindowRotationAngle);
 
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+    if (XRE_GetProcessType() == GeckoProcessType_Default) {
+        MWindow* window = MApplication::activeWindow();
+        if (window) {
+            window->setOrientationAngle((M::OrientationAngle)mWindowRotationAngle);
+        }
+    }
+#else
     emit orientationChanged();
+#endif
 
     return true; // don't store the reading in the sensor
 }
+
+int
+MozQOrientationSensorFilter::GetWindowRotationAngle()
+{
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+    if (XRE_GetProcessType() == GeckoProcessType_Default) {
+        MWindow* window = MApplication::activeWindow();
+        if (window) {
+            M::OrientationAngle angle = window->orientationAngle();
+            if (mWindowRotationAngle != angle) {
+                mWindowRotationAngle = angle;
+                mWindowRotationTransform = QTransform();
+                mWindowRotationTransform.rotate(mWindowRotationAngle);
+            }
+        }
+    }
+#endif
+    return mWindowRotationAngle;
+}
+
+QTransform&
+MozQOrientationSensorFilter::GetRotationTransform()
+{
+    GetWindowRotationAngle();
+    return mWindowRotationTransform;
+}
+
--- a/widget/src/qt/mozqorientationsensorfilter.h
+++ b/widget/src/qt/mozqorientationsensorfilter.h
@@ -54,18 +54,18 @@ public:
     {
         mWindowRotationAngle = 0;
     }
 
     virtual ~MozQOrientationSensorFilter(){}
 
     virtual bool filter(QOrientationReading* reading);
 
-    static int GetWindowRotationAngle() { return mWindowRotationAngle; }
-    static QTransform& GetRotationTransform() { return mWindowRotationTransform; }
+    static int GetWindowRotationAngle();
+    static QTransform& GetRotationTransform();
 
 signals:
     void orientationChanged();
 
 private:
     bool filter(QSensorReading *reading) { return filter(static_cast<QOrientationReading*>(reading)); }
 
     static int mWindowRotationAngle;
--- a/widget/src/qt/mozqwidget.h
+++ b/widget/src/qt/mozqwidget.h
@@ -47,16 +47,25 @@
 
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 
 #ifdef MOZ_ENABLE_QTMOBILITY
 #include "mozqorientationsensorfilter.h"
 #endif
 
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+#include <QtGui/QGraphicsSceneResizeEvent>
+#include <MSceneWindow>
+#include <MScene>
+#include <QTimer>
+#include <MInputMethodState>
+#include <MApplication>
+#endif
+
 class QEvent;
 class QPixmap;
 class QWidget;
 
 class nsWindow;
 
 class MozQWidget : public QGraphicsWidget
 {
@@ -225,10 +234,128 @@ protected:
             QGraphicsView::closeEvent(aEvent);
     }
 
 private:
     MozQGraphicsViewEvents mEventHandler;
     MozQWidget* mTopLevelWidget;
 };
 
+#ifdef MOZ_ENABLE_MEEGOTOUCH
+class MozMSceneWindow : public MSceneWindow
+{
+    Q_OBJECT
+public:
+    MozMSceneWindow(MozQWidget* aTopLevel)
+     : MSceneWindow(aTopLevel->parentItem())
+     , mTopLevelWidget(aTopLevel)
+    {
+        mTopLevelWidget->setParentItem(this);
+        mTopLevelWidget->installEventFilter(this);
+        MInputMethodState* inputMethodState = MInputMethodState::instance();
+        if (inputMethodState) {
+            connect(inputMethodState, SIGNAL(inputMethodAreaChanged(const QRect&)),
+                    this, SLOT(VisibleScreenAreaChanged(const QRect&)));
+        }
+    }
 
+protected:
+    virtual void resizeEvent(QGraphicsSceneResizeEvent* aEvent)
+    {
+        mCurrentSize = aEvent->newSize();
+        MSceneWindow::resizeEvent(aEvent);
+        CheckTopLevelSize();
+    }
+
+    virtual bool eventFilter(QObject* watched, QEvent* e)
+    {
+        if (e->type() == QEvent::GraphicsSceneResize ||
+            e->type() == QEvent::GraphicsSceneMove) {
+
+            //Do this in next event loop, or we are in recursion!
+            QTimer::singleShot(0, this, SLOT(CheckTopLevelSize()));
+        }
+
+        return false;
+    }
+
+private slots:
+    void CheckTopLevelSize()
+    {
+        if (mTopLevelWidget) {
+            qreal xpos = 0;
+            qreal ypos = 0;
+            qreal width = mCurrentSize.width();
+            qreal height = mCurrentSize.height();
+
+            // transfer new size to graphics widget if changed
+            QRectF r = mTopLevelWidget->geometry();
+            if (r != QRectF(xpos, ypos, width, height)) {
+                mTopLevelWidget->setGeometry(xpos, ypos, width, height);
+            }
+        }
+    }
+
+    void VisibleScreenAreaChanged(const QRect& rect) {
+        if (mTopLevelWidget) {
+            QRect r = mTopLevelWidget->geometry().toRect();
+            if (rect.height()) {
+                r.setHeight(rect.height());
+            }
+
+            nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
+            if (observerService) {
+                QString rect = QString("{\"left\": %1, \"top\": %2, \"right\": %3, \"bottom\": %4}")
+                                       .arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
+                observerService->NotifyObservers(nsnull, "softkb-change", rect.utf16());
+            }
+        }
+    }
+
+private:
+    MozQWidget* mTopLevelWidget;
+    QSizeF mCurrentSize;
+};
+
+/**
+  This is a helper class to synchronize the MWindow window with
+  its contained QGraphicsWidget for things like resizing and closing
+  by the user.
+*/
+class MozMGraphicsView : public MWindow
+{
+
+public:
+    MozMGraphicsView(MozQWidget* aTopLevel, QWidget* aParent = nsnull)
+     : MWindow(aParent)
+     , mEventHandler(this)
+     , mTopLevelWidget(aTopLevel)
+    {
+        MozMSceneWindow* page = new MozMSceneWindow(aTopLevel);
+        page->appear(this);
+    }
+
+protected:
+    virtual bool event(QEvent* aEvent) {
+        mEventHandler.handleEvent(aEvent, mTopLevelWidget);
+        return MWindow::event(aEvent);
+    }
+
+    virtual void resizeEvent(QResizeEvent* aEvent)
+    {
+        setSceneRect(viewport()->rect());
+        MWindow::resizeEvent(aEvent);
+    }
+
+    virtual void closeEvent (QCloseEvent* aEvent)
+    {
+        if (!mEventHandler.handleCloseEvent(aEvent, mTopLevelWidget)) {
+            MWindow::closeEvent(aEvent);
+        }
+    }
+
+private:
+    MozQGraphicsViewEvents mEventHandler;
+    MozQWidget* mTopLevelWidget;
+};
+
+#endif /* MOZ_ENABLE_MEEGOTOUCH */
 #endif
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -2591,17 +2591,22 @@ nsWindow::createQWidget(MozQWidget *pare
     if (eWindowType_child == mWindowType || eWindowType_plugin == mWindowType) {
         widget->setFlag(QGraphicsItem::ItemIsFocusable);
         widget->setFocusPolicy(Qt::WheelFocus);
     }
 
     // create a QGraphicsView if this is a new toplevel window
 
     if (mIsTopLevel) {
-        QGraphicsView* newView = new MozQGraphicsView(widget, parentWidget);
+        QGraphicsView* newView = nsnull;
+#if defined MOZ_ENABLE_MEEGOTOUCH
+        newView = new MozMGraphicsView(widget, parentWidget);
+#else
+        newView = new MozQGraphicsView(widget, parentWidget);
+#endif
 
         if (!newView) {
             delete widget;
             return nsnull;
         }
 
         newView->setWindowFlags(flags);
         if (mWindowType == eWindowType_dialog) {