[Qt] resizeToContent seems to trigger infinite resize on some pages
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 10:41:11 +0000 (10:41 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 10:41:11 +0000 (10:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=43852

Patch by Adenilson Cavalcanti <adenilson.silva@openbossa.org> on 2011-09-20
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

InnerHeight and InnerWidth are now calculated using ScrollView::visibleContentRect
including the scrollbars (if any) instead of using ScrollView::frameRect as before.

This makes no behavior change while not using the tiled backing
store and is compliant with the W3C definition stated in the CSSOM
View Module.

Plus it will return the correct values for tiled backing store,
thus fixing the original bug report by avoiding infinite resize
events caused by wrong innerHeight and innerWidth values.

Test: innerWidth/Height are covered by existing tests. The
non-infinite resizing is covered by a new Qt autotest at
test_qgraphicswebview::windowResizeEvent()

* page/DOMWindow.cpp:
(WebCore::DOMWindow::innerHeight): using ScrollView::visibleContentRect.
(WebCore::DOMWindow::innerWidth): using ScrollView::visibleContentRect.

Source/WebKit/qt:

Test by Luiz Agostini.

* tests/qgraphicswebview/tst_qgraphicswebview.cpp:
(ResizeSpy::receiveResize):
(ResizeSpy::size):
(tst_QGraphicsWebView::windowResizeEvent):

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

Source/WebCore/ChangeLog
Source/WebCore/page/DOMWindow.cpp
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp

index 9bc6221..3e2bb66 100644 (file)
@@ -1,3 +1,29 @@
+2011-09-20  Adenilson Cavalcanti  <adenilson.silva@openbossa.org>
+
+        [Qt] resizeToContent seems to trigger infinite resize on some pages
+        https://bugs.webkit.org/show_bug.cgi?id=43852
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        InnerHeight and InnerWidth are now calculated using ScrollView::visibleContentRect
+        including the scrollbars (if any) instead of using ScrollView::frameRect as before.
+
+        This makes no behavior change while not using the tiled backing
+        store and is compliant with the W3C definition stated in the CSSOM
+        View Module.
+
+        Plus it will return the correct values for tiled backing store,
+        thus fixing the original bug report by avoiding infinite resize
+        events caused by wrong innerHeight and innerWidth values.
+
+        Test: innerWidth/Height are covered by existing tests. The
+        non-infinite resizing is covered by a new Qt autotest at
+        test_qgraphicswebview::windowResizeEvent()
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::innerHeight): using ScrollView::visibleContentRect.
+        (WebCore::DOMWindow::innerWidth): using ScrollView::visibleContentRect.
+
 2011-09-09  Pavel Podivilov  <podivilov@chromium.org>
 
         Web Inspector: implement reverse mapping for compiler source maps.
index b724941..2841fe7 100644 (file)
@@ -1093,7 +1093,7 @@ int DOMWindow::innerHeight() const
     if (!view)
         return 0;
     
-    return static_cast<int>(view->height() / m_frame->pageZoomFactor());
+    return static_cast<int>(view->visibleContentRect(/* includeScrollbars */ true).height() / m_frame->pageZoomFactor());
 }
 
 int DOMWindow::innerWidth() const
@@ -1105,7 +1105,7 @@ int DOMWindow::innerWidth() const
     if (!view)
         return 0;
 
-    return static_cast<int>(view->width() / m_frame->pageZoomFactor());
+    return static_cast<int>(view->visibleContentRect(/* includeScrollbars */ true).width() / m_frame->pageZoomFactor());
 }
 
 int DOMWindow::screenX() const
index e6e1aa5..2bfb809 100644 (file)
@@ -1,3 +1,17 @@
+2011-09-20  Adenilson Cavalcanti  <adenilson.silva@openbossa.org>
+
+        [Qt] resizeToContent seems to trigger infinite resize on some pages
+        https://bugs.webkit.org/show_bug.cgi?id=43852
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Test by Luiz Agostini.
+
+        * tests/qgraphicswebview/tst_qgraphicswebview.cpp:
+        (ResizeSpy::receiveResize):
+        (ResizeSpy::size):
+        (tst_QGraphicsWebView::windowResizeEvent):
+
 2011-09-17  Mihai Parparita  <mihaip@chromium.org>
 
         FrameLoaderClient BackForwardList-related methods are unsued
index d095361..b4a0521 100644 (file)
@@ -41,6 +41,8 @@ private slots:
     void focusInputTypes();
     void crashOnSetScaleBeforeSetUrl();
     void widgetsRenderingThroughCache();
+    void windowResizeEvent();
+
 #if !(defined(WTF_USE_QT_MOBILE_THEME) && WTF_USE_QT_MOBILE_THEME)
     void setPalette_data();
     void setPalette();
@@ -607,6 +609,53 @@ void tst_QGraphicsWebView::compareCanvasToImage(const QUrl& url, const QImage& r
 }
 #endif
 
+class ResizeSpy : public QObject {
+    Q_OBJECT
+public slots:
+    void receiveResize(int width, int height)
+    {
+        m_size = QSize(width, height);
+        emit resized();
+    }
+
+    QSize size() const
+    {
+        return m_size;
+    }
+
+signals:
+    void resized();
+
+private:
+    QSize m_size;
+};
+
+void tst_QGraphicsWebView::windowResizeEvent()
+{
+    QGraphicsWebView webView;
+    ResizeSpy resizeSpy;
+    resizeSpy.setProperty("resizeCount", 0);
+
+    QString html = "<html><body><script>"
+                   "function onResize() { window.resizeSpy.receiveResize(window.innerWidth, window.innerHeight); }"
+                   "window.addEventListener('resize', onResize , false);"
+                   "</script></body></html>";
+
+    webView.page()->mainFrame()->setHtml(html);
+    webView.page()->mainFrame()->addToJavaScriptWindowObject("resizeSpy",
+                                                             &resizeSpy);
+    webView.setGeometry(QRect(0, 0, 50, 50));
+    QVERIFY(::waitForSignal(&resizeSpy, SIGNAL(resized()), 1000));
+    QCOMPARE(resizeSpy.size(), QSize(50, 50));
+
+    webView.page()->setActualVisibleContentRect(QRect(10, 10, 60, 60));
+    webView.setGeometry(QRect(0, 0, 100, 100));
+    waitForSignal(&resizeSpy, SIGNAL(resized()), 1000);
+
+    // This will be triggered without the fix on DOMWindow::innerHeight/Width
+    QCOMPARE(resizeSpy.size(), QSize(60, 60));
+}
+
 QTEST_MAIN(tst_QGraphicsWebView)
 
 #include "tst_qgraphicswebview.moc"