Title: [134796] trunk/Source/WebKit/chromium
Revision
134796
Author
[email protected]
Date
2012-11-15 10:41:52 -0800 (Thu, 15 Nov 2012)

Log Message

Use correct unscaled document size when calculating scale limits
https://bugs.webkit.org/show_bug.cgi?id=102028

Patch by Tien-Ren Chen <[email protected]> on 2012-11-15
Reviewed by Adam Barth.

Fixes bug http://crbug.com/160581
Using contentsSize / pageScaleFactor as unscaled contents size results
in rounding errors. This can cause scale factor to oscillate indefinitely.

* src/WebViewImpl.cpp:
(WebKit::unscaledContentsSize):
(WebKit):
(WebKit::WebViewImpl::computePageScaleFactorLimits):
* tests/WebFrameTest.cpp:
* tests/data/scale_oscillate.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (134795 => 134796)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-11-15 18:40:35 UTC (rev 134795)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-11-15 18:41:52 UTC (rev 134796)
@@ -1,3 +1,21 @@
+2012-11-15  Tien-Ren Chen  <[email protected]>
+
+        Use correct unscaled document size when calculating scale limits
+        https://bugs.webkit.org/show_bug.cgi?id=102028
+
+        Reviewed by Adam Barth.
+
+        Fixes bug http://crbug.com/160581
+        Using contentsSize / pageScaleFactor as unscaled contents size results
+        in rounding errors. This can cause scale factor to oscillate indefinitely.
+
+        * src/WebViewImpl.cpp:
+        (WebKit::unscaledContentsSize):
+        (WebKit):
+        (WebKit::WebViewImpl::computePageScaleFactorLimits):
+        * tests/WebFrameTest.cpp:
+        * tests/data/scale_oscillate.html: Added.
+
 2012-11-15  Kenneth Russell  <[email protected]>
 
         [chromium] Move allowWebGL query to WebFrameClient

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (134795 => 134796)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-11-15 18:40:35 UTC (rev 134795)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-11-15 18:41:52 UTC (rev 134796)
@@ -2999,6 +2999,14 @@
     m_page->chrome()->client()->dispatchViewportPropertiesDidChange(page()->mainFrame()->document()->viewportArguments());
 }
 
+static IntSize unscaledContentsSize(Frame* frame)
+{
+    RenderView* root = frame->contentRenderer();
+    if (!root)
+        return IntSize();
+    return root->unscaledDocumentRect().size();
+}
+
 bool WebViewImpl::computePageScaleFactorLimits()
 {
     if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageScaleFactor == -1)
@@ -3011,11 +3019,10 @@
     m_maximumPageScaleFactor = max(min(m_pageDefinedMaximumPageScaleFactor, maxPageScaleFactor), minPageScaleFactor) * (deviceScaleFactor() / m_deviceScaleInCompositor);
 
     int viewWidthNotIncludingScrollbars = page()->mainFrame()->view()->visibleContentRect(false).width();
-    int contentsWidth = mainFrame()->contentsSize().width;
-    if (viewWidthNotIncludingScrollbars && contentsWidth) {
+    int unscaledContentsWidth = unscaledContentsSize(page()->mainFrame()).width();
+    if (viewWidthNotIncludingScrollbars && unscaledContentsWidth) {
         // Limit page scaling down to the document width.
-        int unscaledContentWidth = contentsWidth / pageScaleFactor();
-        m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / unscaledContentWidth);
+        m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / unscaledContentsWidth);
         m_maximumPageScaleFactor = max(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
     }
     ASSERT(m_minimumPageScaleFactor <= m_maximumPageScaleFactor);

Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (134795 => 134796)


--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-11-15 18:40:35 UTC (rev 134795)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-11-15 18:41:52 UTC (rev 134796)
@@ -291,6 +291,24 @@
     webViewImpl->resize(WebSize(viewportWidth, viewportHeight + 100));
     EXPECT_EQ(userPinchPageScaleFactor, webViewImpl->pageScaleFactor());
 }
+
+TEST_F(WebFrameTest, ScaleFactorShouldNotOscillate)
+{
+    registerMockedHttpURLLoad("scale_oscillate.html");
+
+    FixedLayoutTestWebViewClient client;
+    client.m_screenInfo.horizontalDPI = 212;
+    int viewportWidth = 800;
+    int viewportHeight = 1057;
+    client.m_windowRect = WebRect(0, 0, viewportWidth, viewportHeight);
+
+    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "scale_oscillate.html", true, 0, &client));
+    webViewImpl->enableFixedLayoutMode(true);
+    webViewImpl->settings()->setViewportEnabled(true);
+    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
+    webViewImpl->layout();
+}
+
 #endif
 
 TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor)

Added: trunk/Source/WebKit/chromium/tests/data/scale_oscillate.html (0 => 134796)


--- trunk/Source/WebKit/chromium/tests/data/scale_oscillate.html	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/scale_oscillate.html	2012-11-15 18:41:52 UTC (rev 134796)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html style="width:100%;height:100%;">
+<head>
+<title>Test</title>
+<style>
+::-webkit-scrollbar {
+    width: 1px;
+}
+</style>
+<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
+</head>
+<body>
+This test passes if it doesn't cause oscillating scale factor due to content size rounding errors and creating/destroying of custom scrollbars.
+An example of parameter that reproduce the crash is viewport size (800, 1057) with device scale factor 1.325
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to