Chromium Code Reviews| Index: Source/WebKit/chromium/src/WebViewImpl.cpp |
| diff --git a/Source/WebKit/chromium/src/WebViewImpl.cpp b/Source/WebKit/chromium/src/WebViewImpl.cpp |
| index 0a7b1f89494d0fbbcfd72c97ca7d33e6ddc9ec00..73a530167506f12991c4f63759c2e487a352f32d 100644 |
| --- a/Source/WebKit/chromium/src/WebViewImpl.cpp |
| +++ b/Source/WebKit/chromium/src/WebViewImpl.cpp |
| @@ -73,7 +73,6 @@ |
| #include "HTMLMediaElement.h" |
| #include "HTMLNames.h" |
| #include "HTMLTextAreaElement.h" |
| -#include "HitTestResult.h" |
| #include "Image.h" |
| #include "ImageBuffer.h" |
| #include "InspectorController.h" |
| @@ -119,6 +118,7 @@ |
| #include "TouchDisambiguation.h" |
| #include "TraceEvent.h" |
| #include "ValidationMessageClientImpl.h" |
| +#include "ViewportAnchor.h" |
| #include "WebAccessibilityObject.h" |
| #include "WebActiveWheelFlingParameters.h" |
| #include "WebAutofillClient.h" |
| @@ -197,6 +197,10 @@ static const float doubleTapZoomContentMinimumMargin = 2; |
| static const double doubleTapZoomAnimationDurationInSeconds = 0.25; |
| static const float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| +// Constants for viewport anchoring on resize. |
| +static const float viewportAnchorXCoord = 0.5f; |
| +static const float viewportAnchorYCoord = 0; |
| + |
| // Constants for zooming in on a focused text field. |
| static const double scrollAndScaleAnimationDurationInSeconds = 0.2; |
| static const int minReadableCaretHeight = 18; |
| @@ -1654,12 +1658,18 @@ void WebViewImpl::resize(const WebSize& newSize) |
| WebSize oldSize = m_size; |
| float oldPageScaleFactor = pageScaleFactor(); |
| - IntSize oldScrollOffset = view->scrollOffset(); |
| + float oldMinimumPageScaleFactor = m_minimumPageScaleFactor; |
| int oldFixedLayoutWidth = fixedLayoutSize().width; |
| + int oldContentsWidth = contentsSize().width(); |
| m_size = newSize; |
| #if ENABLE(VIEWPORT) |
| + ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); |
| + if (settings()->viewportEnabled()) |
| + viewportAnchor.setAnchor(view->visibleContentRect(), |
| + FloatSize(viewportAnchorXCoord, viewportAnchorYCoord)); |
| + |
| ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()->viewportArguments(); |
| m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArguments); |
| #endif |
| @@ -1679,21 +1689,29 @@ void WebViewImpl::resize(const WebSize& newSize) |
| if (view->needsLayout()) |
| view->layout(); |
| - // 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. |
| + // The minimum scale limit may change as a result of layout content |
| + // changes; in this case, scale relative to the change in content width. |
| + // Otherwise scale relative to the change in layout width. |
| + // Don't do any scaling if the old width was zero (i.e., first resize). |
| + float scalingWidthRatio = 1; |
| + if (oldSize.width && oldContentsWidth && m_minimumPageScaleFactor != oldMinimumPageScaleFactor) |
|
aelias_OOO_until_Jul13
2013/04/15 18:25:39
Could you delete the "&& m_minimumPageScaleFactor
jdduke (slow)
2013/04/16 15:40:26
Done.
|
| + scalingWidthRatio = contentsSize().width() / (float) oldContentsWidth; |
| + else if (oldFixedLayoutWidth) |
| + scalingWidthRatio = fixedLayoutSize().width / (float) oldFixedLayoutWidth; |
|
aelias_OOO_until_Jul13
2013/04/15 18:25:39
Could you try deleting this else block and see if
jdduke (slow)
2013/04/16 15:40:26
This initially caused some problems with fixed wid
|
| + |
| 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) |
| - setPageScaleFactor(oldPageScaleFactor * scaleMultiplier, WebPoint(oldScrollOffset.width(), oldScrollOffset.height())); |
| + float scaleMultiplier = viewportWidthRatio / scalingWidthRatio; |
| + |
| + IntSize viewportSize = view->visibleContentRect().size(); |
| + if (scaleMultiplier != 1) { |
| + float newPageScaleFactor = oldPageScaleFactor * scaleMultiplier; |
| + viewportSize.scale(pageScaleFactor() / newPageScaleFactor); |
| + IntPoint scrollOffsetAtNewScale = viewportAnchor.computeOrigin(viewportSize); |
| + setPageScaleFactor(newPageScaleFactor, scrollOffsetAtNewScale); |
| + } else { |
| + IntPoint scrollOffsetAtNewScale = clampOffsetAtScale(viewportAnchor.computeOrigin(viewportSize), pageScaleFactor()); |
| + updateMainFrameScrollPosition(scrollOffsetAtNewScale, false); |
| + } |
| } |
| #endif |