[Webkit-unassigned] [Bug 37163] [Qt] inputMethodQuery returns coordinates in web page coordinates rather than in item coordinates.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Apr 19 12:09:33 PDT 2010


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





--- Comment #4 from John Pavan <john.pavan at nokia.com>  2010-04-19 12:09:33 PST ---
(From update of attachment 53372)
>Index: WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp
>===================================================================
>--- WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp	(revision 57531)
>+++ WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp	(working copy)
>@@ -31,6 +31,7 @@
> private slots:
>     void qgraphicswebview();
>     void crashOnViewlessWebPages();
>+    void inputMethodQueryItemCoordinates();
> };
> 
> void tst_QGraphicsWebView::qgraphicswebview()
>@@ -102,6 +103,43 @@
>     QVERIFY(waitForSignal(page, SIGNAL(loadFinished(bool))));
> }
> 
>+void tst_QGraphicsWebView::inputMethodQueryItemCoordinates()
>+{
>+    QGraphicsScene scene;
>+    QGraphicsView view(&scene);
>+
>+    QGraphicsWebView* webView = new QGraphicsWebView;
>+    QWebPage* page = new QWebPage;
>+    webView->setPage(page);
>+
>+    // set the size of the view to a known size
>+    scene.addItem(webView);
>+    webView->setGeometry(QRect(0, 0, 500, 500));
>+
>+    // set up a web page that's bigger than the size of the view
>+    page->mainFrame()->setHtml(QString("data:text/html,"
>+        "<canvas id=\"testCanvas\" width=\"1000\" height=\"1000\">"
>+        "This is a test canvas"
>+        "</canvas>"));
>+    page->mainFrame()->setFocus();
>+
>+    QTest::qWait(200);
>+    view.show();
>+    
>+    // get the initial microfocus
>+    QVariant initialMicroFocus = webView->inputMethodQuery(Qt::ImMicroFocus);
>+    QVERIFY(initialMicroFocus.isValid());
>+
>+    page->mainFrame()->scroll(300,300);
>+
>+    QVariant currentMicroFocus = webView->inputMethodQuery(Qt::ImMicroFocus);
>+    QVERIFY(currentMicroFocus.isValid());
>+
>+    QCOMPARE(initialMicroFocus.toRect().translated(-300,-300),currentMicroFocus.toRect());
>+
>+    delete webView;
>+}
>+
> QTEST_MAIN(tst_QGraphicsWebView)
> 
> #include "tst_qgraphicswebview.moc"
>Index: WebKit/qt/ChangeLog
>===================================================================
>--- WebKit/qt/ChangeLog	(revision 57608)
>+++ WebKit/qt/ChangeLog	(working copy)
>@@ -1,3 +1,17 @@
>+2010-04-14  John Pavan  <john.pavan at nokia.com>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        inputMethodQuery returns coordinates in web page coordinates rather than in item coordinates.
>+        To fix this problem if the inputMethodQuery to the underlying QWebPage returns a QPoint, QPointF, QRect, or QRectF it is transformed to reflect the difference between the web page coordinates and the widget coordinates.
>+        Added a unit test to reflect this as well.
>+        https://bugs.webkit.org/show_bug.cgi?id=37163
>+
>+        * Api/qgraphicswebview.cpp:
>+        (QGraphicsWebView::inputMethodQuery):
>+        * tests/qgraphicswebview/tst_qgraphicswebview.cpp:
>+        (tst_QGraphicsWebView::inputMethodQueryItemCoordinates):
>+
> 2010-04-14  Aaron Boodman  <aa at chromium.org>
> 
>         Reviewed by David Levin.
>Index: WebKit/qt/Api/qgraphicswebview.cpp
>===================================================================
>--- WebKit/qt/Api/qgraphicswebview.cpp	(revision 57531)
>+++ WebKit/qt/Api/qgraphicswebview.cpp	(working copy)
>@@ -668,9 +668,55 @@
> */
> QVariant QGraphicsWebView::inputMethodQuery(Qt::InputMethodQuery query) const
> {
>-    if (d->page)
>-        return d->page->inputMethodQuery(query);
>-    return QVariant();
>+    // john.pavan at nokia.com:
>+    // in cases of coordinates the QGraphicsWebView (as a QGraphicsWidget)
>+    // should be returning coordinates in the reference frame of the
>+    // item (qgraphicswebview), not the coordinates on the web page.
>+    // To do this we need the viewport.
>+
>+    QVariant retVal;
>+    if (d->page) {
>+        retVal = d->page->inputMethodQuery(query);
>+        if (retVal.type() == QVariant::RectF
>+            || retVal.type() == QVariant::PointF
>+            || retVal.type() == QVariant::Rect
>+            || retVal.type() == QVariant::Point) {
>+            // get the scroll position of the current frame.
>+                QPoint scrollPosition;
>+                if (d->page->currentFrame())
>+                    scrollPosition = d->page->currentFrame()->scrollPosition();
>+                else
>+                    scrollPosition = d->page->mainFrame()->scrollPosition();
>+                
>+
>+            // now apply the appropriate transform
>+                switch (retVal.type()) {
>+                case QVariant::RectF:
>+                    retVal = retVal.toRectF().translated(-scrollPosition);
>+                    break;
>+
>+                case QVariant::PointF:
>+                    retVal = retVal.toPointF() - scrollPosition;
>+                    break;
>+
>+                case QVariant::Rect:
>+                    retVal = retVal.toRect().translated(-scrollPosition);
>+                    break;
>+
>+                case QVariant::Point:
>+                    retVal = retVal.toPoint() - scrollPosition;
>+                    break;
>+
>+                default:
>+                    // do nothing
>+                    qt_noop();
>+                    break;
>+                };
>+        }
>+
>+
>+    }
>+    return retVal;
> }
> 
> /*! \reimp

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list