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

Unified Diff: Source/web/WebViewImpl.cpp

Issue 23461009: Scale to legibleScale if double tap would barely zoom in from zoomed out state. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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/web/WebViewImpl.h ('k') | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebViewImpl.cpp
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index 9c7f9baa726108aa84e977ab7fd54c5e872ebff1..ef1de65c5843d04855f3cd0e8c496e1e37663ddc 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -1124,26 +1124,26 @@ WebRect WebViewImpl::widenRectWithinPageBounds(const WebRect& source, int target
return WebRect(newX, source.y, newWidth, source.height);
}
-void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, float padding, float& scale, WebPoint& scroll, bool& doubleTapShouldZoomOut)
+float WebViewImpl::legibleScale() const
+{
+ // Pages should be as legible as on desktop when at dpi scale, so no
+ // need to zoom in further when automatically determining zoom level
+ // (after double tap, find in page, etc), though the user should still
+ // be allowed to manually pinch zoom in further if they desire.
+ float legibleScale = 1;
+ if (page() && page()->settings().textAutosizingEnabled())
+ legibleScale *= page()->settings().textAutosizingFontScaleFactor();
+ return legibleScale;
+}
+
+void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, float padding, float defaultScaleWhenAlreadyLegible, float& scale, WebPoint& scroll)
{
scale = pageScaleFactor();
scroll.x = scroll.y = 0;
WebRect rect = blockRect;
- bool scaleUnchanged = true;
if (!rect.isEmpty()) {
- // Pages should be as legible as on desktop when at dpi scale, so no
- // need to zoom in further when automatically determining zoom level
- // (after double tap, find in page, etc), though the user should still
- // be allowed to manually pinch zoom in further if they desire.
- const float defaultScaleWhenAlreadyLegible = minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
- float legibleScale = 1;
- if (page())
- legibleScale *= page()->settings().textAutosizingFontScaleFactor();
- if (legibleScale < defaultScaleWhenAlreadyLegible)
- legibleScale = (scale == minimumPageScaleFactor()) ? defaultScaleWhenAlreadyLegible : minimumPageScaleFactor();
-
float defaultMargin = doubleTapZoomContentDefaultMargin;
float minimumMargin = doubleTapZoomContentMinimumMargin;
// We want the margins to have the same physical size, which means we
@@ -1157,18 +1157,12 @@ void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, fl
static_cast<int>(minimumMargin * rect.width / m_size.width));
// Fit block to screen, respecting limits.
scale = static_cast<float>(m_size.width) / rect.width;
- scale = min(scale, legibleScale);
+ scale = min(scale, legibleScale());
+ if (pageScaleFactor() < defaultScaleWhenAlreadyLegible)
+ scale = max(scale, defaultScaleWhenAlreadyLegible);
scale = clampPageScaleFactorToLimits(scale);
-
- scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference;
}
- bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPageScaleFactor
- && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor())
- || m_doubleTapZoomPending;
-
- doubleTapShouldZoomOut = rect.isEmpty() || scaleUnchanged || stillAtPreviousDoubleTapScale;
-
// FIXME: If this is being called for auto zoom during find in page,
// then if the user manually zooms in it'd be nice to preserve the
// relative increase in zoom they caused (if they zoom out then it's ok
@@ -1268,13 +1262,19 @@ void WebViewImpl::animateDoubleTapZoom(const IntPoint& point)
float scale;
WebPoint scroll;
- bool doubleTapShouldZoomOut;
- computeScaleAndScrollForBlockRect(blockBounds, touchPointPadding, scale, scroll, doubleTapShouldZoomOut);
+ computeScaleAndScrollForBlockRect(blockBounds, touchPointPadding, minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio, scale, scroll);
+
+ bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPageScaleFactor
+ && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor())
+ || m_doubleTapZoomPending;
+
+ bool scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference;
+ bool shouldZoomOut = blockBounds.isEmpty() || scaleUnchanged || stillAtPreviousDoubleTapScale;
bool isAnimating;
- if (doubleTapShouldZoomOut) {
+ if (shouldZoomOut) {
scale = minimumPageScaleFactor();
isAnimating = startPageScaleAnimation(mainFrameImpl()->frameView()->windowToContents(point), true, scale, doubleTapZoomAnimationDurationInSeconds);
} else {
@@ -1302,9 +1302,8 @@ void WebViewImpl::zoomToFindInPageRect(const WebRect& rect)
float scale;
WebPoint scroll;
- bool doubleTapShouldZoomOut;
- computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding, scale, scroll, doubleTapShouldZoomOut);
+ computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding, minimumPageScaleFactor(), scale, scroll);
startPageScaleAnimation(scroll, false, scale, findInPageAnimationDurationInSeconds);
}
@@ -1316,9 +1315,8 @@ bool WebViewImpl::zoomToMultipleTargetsRect(const WebRect& rect)
float scale;
WebPoint scroll;
- bool doubleTapShouldZoomOut;
- computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, scale, scroll, doubleTapShouldZoomOut);
+ computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, minimumPageScaleFactor(), scale, scroll);
if (scale <= pageScaleFactor())
return false;
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698