Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: Source/WebKit/chromium/src/WebViewImpl.cpp

Issue 13704012: Improve mobile device rotation behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: git cl upload with --similarity=70 Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebKit/chromium/src/ViewportAnchor.cpp ('k') | Source/WebKit/chromium/tests/WebFrameTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebKit/chromium/src/WebViewImpl.cpp
diff --git a/Source/WebKit/chromium/src/WebViewImpl.cpp b/Source/WebKit/chromium/src/WebViewImpl.cpp
index b3b3e4f8df162f56252a75ff255bab0623c2f276..ab1038dd149d34a808941457f35c3dcdd76b1393 100644
--- a/Source/WebKit/chromium/src/WebViewImpl.cpp
+++ b/Source/WebKit/chromium/src/WebViewImpl.cpp
@@ -72,7 +72,6 @@
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "HTMLTextAreaElement.h"
-#include "HitTestResult.h"
#include "Image.h"
#include "ImageBuffer.h"
#include "InspectorController.h"
@@ -118,6 +117,7 @@
#include "TouchDisambiguation.h"
#include "TraceEvent.h"
#include "ValidationMessageClientImpl.h"
+#include "ViewportAnchor.h"
#include "WebAccessibilityObject.h"
#include "WebActiveWheelFlingParameters.h"
#include "WebAutofillClient.h"
@@ -196,6 +196,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;
@@ -1651,12 +1655,18 @@ void WebViewImpl::resize(const WebSize& newSize)
WebSize oldSize = m_size;
float oldPageScaleFactor = pageScaleFactor();
- IntSize oldScrollOffset = view->scrollOffset();
- int oldFixedLayoutWidth = fixedLayoutSize().width;
+ int oldContentsWidth = contentsSize().width();
m_size = newSize;
#if ENABLE(VIEWPORT)
+ bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSize.width && oldContentsWidth;
+ ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
+ if (shouldAnchorAndRescaleViewport) {
+ viewportAnchor.setAnchor(view->visibleContentRect(),
+ FloatSize(viewportAnchorXCoord, viewportAnchorYCoord));
+ }
+
ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()->viewportArguments();
m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArguments);
#endif
@@ -1676,21 +1686,22 @@ 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.
- 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()));
+ if (shouldAnchorAndRescaleViewport) {
+ float viewportWidthRatio = static_cast<float>(newSize.width) / oldSize.width;
+ float contentsWidthRatio = static_cast<float>(contentsSize().width()) / oldContentsWidth;
+ float scaleMultiplier = viewportWidthRatio / contentsWidthRatio;
+
+ 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
« no previous file with comments | « Source/WebKit/chromium/src/ViewportAnchor.cpp ('k') | Source/WebKit/chromium/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698