Title: [118461] trunk/Source/WebKit/chromium
Revision
118461
Author
[email protected]
Date
2012-05-24 18:56:09 -0700 (Thu, 24 May 2012)

Log Message

[chromium] Support mobile device rotation resizing
https://bugs.webkit.org/show_bug.cgi?id=86819

Patch by Alexandre Elias <[email protected]> on 2012-05-24
Reviewed by Adam Barth.

Resizes on a mobile device are caused either by rotation or
on-screen-keyboard bringup, and need different treatment to remain
naturally laid out, scaled and scrolled without disorienting the user.

* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::resize):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (118460 => 118461)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-05-25 01:55:45 UTC (rev 118460)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-05-25 01:56:09 UTC (rev 118461)
@@ -1,3 +1,17 @@
+2012-05-24  Alexandre Elias  <[email protected]>
+
+        [chromium] Support mobile device rotation resizing
+        https://bugs.webkit.org/show_bug.cgi?id=86819
+
+        Reviewed by Adam Barth.
+
+        Resizes on a mobile device are caused either by rotation or
+        on-screen-keyboard bringup, and need different treatment to remain
+        naturally laid out, scaled and scrolled without disorienting the user.
+
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::resize):
+
 2012-05-24  Antoine Labour  <[email protected]>
 
         [chromium] Add a setForceRenderSurface to WebLayer for test/bench purpose

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (118460 => 118461)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-05-25 01:55:45 UTC (rev 118460)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-05-25 01:56:09 UTC (rev 118461)
@@ -1326,8 +1326,28 @@
 {
     if (m_shouldAutoResize || m_size == newSize)
         return;
+
+    FrameView* view = mainFrameImpl()->frameView();
+    if (!view)
+        return;
+
+    WebSize oldSize = m_size;
+    float oldPageScaleFactor = pageScaleFactor();
+    IntSize oldScrollOffset = view->scrollOffset();
+    int oldFixedLayoutWidth = fixedLayoutSize().width;
+
     m_size = newSize;
 
+    if (isFixedLayoutModeEnabled()) {
+        // Fallback width is used to layout sites designed for desktop. The
+        // conventional size used by all mobile browsers is 980. When a mobile
+        // device has a particularly wide screen (such as a 10" tablet held in
+        // landscape), it can be larger.
+        const int standardFallbackWidth = 980;
+        int dpiIndependentViewportWidth = newSize.width / page()->settings()->defaultDeviceScaleFactor();
+        settings()->setLayoutFallbackWidth(std::max(standardFallbackWidth, dpiIndependentViewportWidth));
+    }
+
 #if ENABLE(VIEWPORT)
     if (settings()->viewportEnabled()) {
         ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()->viewportArguments();
@@ -1344,6 +1364,31 @@
             webFrame->frameView()->resize(newSize.width, newSize.height);
     }
 
+    if (isFixedLayoutModeEnabled()) {
+        // Relayout immediately to obtain the new content width, which is needed
+        // to calculate the minimum scale limit.
+        view->layout();
+        computePageScaleFactorLimits();
+        // When the device rotates:
+        // - If the page width is unchanged, then zoom by new width/old width
+        //   such as to keep the same content horizontally onscreen.
+        // - If the page width stretches proportionally to the change in
+        //   screen width, then don't zoom at all (assuming the content has
+        //   scaled uniformly, then the same content will be horizontally
+        //   onscreen).
+        //   - If the page width partially stretches, then zoom partially to
+        //   make up the difference.
+        // In all cases try to keep the same content at the top of the screen.
+        float viewportWidthRatio = !oldSize.width ? 1 : newSize.width / (float) oldSize.width;
+        float fixedLayoutWidthRatio = !oldFixedLayoutWidth ? 1 : fixedLayoutSize().width / (float) oldFixedLayoutWidth;
+        float scaleMultiplier = viewportWidthRatio / fixedLayoutWidthRatio;
+        if (scaleMultiplier != 1) {
+            IntSize scrollOffsetAtNewScale = oldScrollOffset;
+            scrollOffsetAtNewScale.scale(scaleMultiplier);
+            setPageScaleFactor(oldPageScaleFactor * scaleMultiplier, IntPoint(scrollOffsetAtNewScale));
+        }
+    }
+
     sendResizeEventAndRepaint();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to