[Qt] Make sure WTR sizes the window and item correctly
authorvestbo@webkit.org <vestbo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Sep 2011 20:04:57 +0000 (20:04 +0000)
committervestbo@webkit.org <vestbo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Sep 2011 20:04:57 +0000 (20:04 +0000)
Revision 96345 changed the logic for how the view and
window was created, but missed a vital part, setting
the size.

We now use a QSGView for the window, that has a simple
item as its root object that is always resized to fit
within the window. The webview is then parented to the
root object and set to anchors.fill: parent. That way
any window geometry changes will propagate to the web
view.

https://bugs.webkit.org/show_bug.cgi?id=69134

Reviewed by Andreas Kling.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96416 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitTestRunner/PlatformWebView.h
Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp

index b6c87a1..f6365cb 100644 (file)
@@ -1,3 +1,25 @@
+2011-09-30  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
+
+        [Qt] Make sure WTR sizes the window and item correctly
+
+        Revision 96345 changed the logic for how the view and
+        window was created, but missed a vital part, setting
+        the size.
+
+        We now use a QSGView for the window, that has a simple
+        item as its root object that is always resized to fit
+        within the window. The webview is then parented to the
+        root object and set to anchors.fill: parent. That way
+        any window geometry changes will propagate to the web
+        view.
+
+        https://bugs.webkit.org/show_bug.cgi?id=69134
+
+        Reviewed by Andreas Kling.
+
+        * WebKitTestRunner/PlatformWebView.h:
+        * WebKitTestRunner/qt/PlatformWebViewQt.cpp:
+
 2011-09-30  Raphael Kubo da Costa  <kubo@profusion.mobi>
 
         [EFL] Only save the current viewport in PixelDumpSupportEfl.
index 5284e87..1cff688 100644 (file)
@@ -29,8 +29,8 @@
 #if defined(BUILDING_QT__)
 class QDesktopWebView;
 typedef QDesktopWebView* PlatformWKView;
-class QSGCanvas;
-typedef QSGCanvas* PlatformWindow;
+class QSGView;
+typedef QSGView* PlatformWindow;
 #elif defined(__APPLE__) && __APPLE__
 #if __OBJC__
 @class WKView;
index f1e0b69..93f06c7 100644 (file)
 #include "qdesktopwebview.h"
 
 #include <QApplication>
-#include <QtDeclarative/qsgcanvas.h>
+#include <QDeclarativeProperty>
+#include <QSGView>
 
 namespace WTR {
 
+class WrapperWindow : public QSGView {
+    Q_OBJECT
+public:
+    WrapperWindow(QSGItem* view)
+        : QSGView(QUrl("data:text/plain,import QtQuick 2.0\nItem { objectName: 'root' }"))
+        , m_view(view)
+    {
+        connect(this, SIGNAL(statusChanged(QSGView::Status)), SLOT(handleStatusChanged(QSGView::Status)));
+    }
+
+private slots:
+    void handleStatusChanged(QSGView::Status status)
+    {
+        if (status != QSGView::Ready)
+            return;
+
+        setGeometry(0, 0, 800, 600);
+        setResizeMode(QSGView::SizeRootObjectToView);
+
+        m_view->setParentItem(rootObject());
+        QDeclarativeProperty::write(m_view, "anchors.fill", qVariantFromValue(rootObject()));
+
+        QFocusEvent ev(QEvent::WindowActivate);
+        QApplication::sendEvent(m_view, &ev);
+        m_view->setFocus(Qt::OtherFocusReason);
+    }
+
+private:
+    QSGItem* m_view;
+};
+
 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
     : m_view(new QDesktopWebView(contextRef, pageGroupRef))
-    , m_window(new QSGCanvas)
+    , m_window(new WrapperWindow(m_view))
 {
-    m_view->setParent(m_window->rootItem());
-    m_window->setGeometry(0, 0, 800, 600);
-
-    QFocusEvent ev(QEvent::WindowActivate);
-    QApplication::sendEvent(m_view, &ev);
-    m_view->setFocus(Qt::OtherFocusReason);
 }
 
 PlatformWebView::~PlatformWebView()
@@ -93,3 +119,5 @@ void PlatformWebView::postEvent(QEvent* event)
 }
 
 } // namespace WTR
+
+#include "PlatformWebViewQt.moc"