[iOS][WK2] When a page relayout on dynamic resize, keep the same relative width in...
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 May 2014 21:42:38 +0000 (21:42 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 May 2014 21:42:38 +0000 (21:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133026
<rdar://problem/16833971>

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-05-19
Reviewed by Simon Fraser.

When a page does not relayout, we keep the same width in view.
When a page relayout, we should keep the same relative width in view.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::isResponsiveDesignWithContentLargerThanLayout):
(WebKit::WebPage::dynamicViewportSizeUpdate):

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 65b83fd05e0f9495a46135d075a9dfec58b86170..f4a940053727ba5b2e411ac820da5cb2e627777a 100644 (file)
@@ -1,3 +1,18 @@
+2014-05-19  Benjamin Poulain  <bpoulain@apple.com>
+
+        [iOS][WK2] When a page relayout on dynamic resize, keep the same relative width in view
+        https://bugs.webkit.org/show_bug.cgi?id=133026
+        <rdar://problem/16833971>
+
+        Reviewed by Simon Fraser.
+
+        When a page does not relayout, we keep the same width in view.
+        When a page relayout, we should keep the same relative width in view.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::isResponsiveDesignWithContentLargerThanLayout):
+        (WebKit::WebPage::dynamicViewportSizeUpdate):
+
 2014-05-19  Benjamin Poulain  <benjamin@webkit.org>
 
         [WK2] Add some missing state reset on crash
 2014-05-19  Benjamin Poulain  <benjamin@webkit.org>
 
         [WK2] Add some missing state reset on crash
index 3eaa8f3a8bc1d243190d3e0fcc1ef8680d812e8e..634c3f953ea83cece6907e2425b4214f24381d8a 100644 (file)
@@ -1941,10 +1941,12 @@ void WebPage::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, cons
     m_dynamicSizeUpdateHistory.add(std::make_pair(oldContentSize, oldPageScaleFactor), IntPoint(frameView.scrollOffset()));
 
     RefPtr<Node> oldNodeAtCenter;
     m_dynamicSizeUpdateHistory.add(std::make_pair(oldContentSize, oldPageScaleFactor), IntPoint(frameView.scrollOffset()));
 
     RefPtr<Node> oldNodeAtCenter;
+    double visibleHorizontalFraction = 1;
     float relativeHorizontalPositionInNodeAtCenter = 0;
     float relativeVerticalPositionInNodeAtCenter = 0;
     {
         IntRect unobscuredContentRect = frameView.unobscuredContentRect();
     float relativeHorizontalPositionInNodeAtCenter = 0;
     float relativeVerticalPositionInNodeAtCenter = 0;
     {
         IntRect unobscuredContentRect = frameView.unobscuredContentRect();
+        visibleHorizontalFraction = static_cast<float>(unobscuredContentRect.width()) / oldContentSize.width();
         IntPoint unobscuredContentRectCenter = unobscuredContentRect.center();
 
         HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
         IntPoint unobscuredContentRectCenter = unobscuredContentRect.center();
 
         HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
@@ -1978,6 +1980,14 @@ void WebPage::dynamicViewportSizeUpdate(const FloatSize& minimumLayoutSize, cons
     else
         scale = std::max(std::min(targetScale, m_viewportConfiguration.maximumScale()), m_viewportConfiguration.minimumScale());
 
     else
         scale = std::max(std::min(targetScale, m_viewportConfiguration.maximumScale()), m_viewportConfiguration.minimumScale());
 
+    if (m_userHasChangedPageScaleFactor && newContentSize.width() != oldContentSize.width()) {
+        // When the content size change, we keep the same relative horizontal content width in view, otherwise we would
+        // end up zoom to far in landscape->portrait, and too close in portrait->landscape.
+        float widthToKeepInView = visibleHorizontalFraction * newContentSize.width();
+        double newScale = targetUnobscuredRectInScrollViewCoordinates.width() / widthToKeepInView;
+        scale = std::max(std::min(newScale, m_viewportConfiguration.maximumScale()), m_viewportConfiguration.minimumScale());
+    }
+
     FloatRect newUnobscuredContentRect = targetUnobscuredRect;
     FloatRect newExposedContentRect = targetExposedContentRect;
 
     FloatRect newUnobscuredContentRect = targetUnobscuredRect;
     FloatRect newExposedContentRect = targetExposedContentRect;