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

Unified Diff: Source/web/WebViewImpl.cpp

Issue 196133011: Refine autozoom scaling constants and logic (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 1 month 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 | « no previous file | 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 f102142cb35dd03333fc261cc34421622ec83a47..12e302b8b53867edea66e1acfffc8f5c8f56f128 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -195,8 +195,9 @@ 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;
-static const float minScaleChangeToTriggerZoom = 1.05f;
+static const int minReadableCaretHeight = 16;
+static const int minReadableCaretHeightForTextArea = 13;
+static const float minScaleChangeToTriggerZoom = 1.5f;
static const float leftBoxRatio = 0.3f;
static const int caretPadding = 10;
@@ -2857,13 +2858,25 @@ void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, float&
unscaledCaret.scale(1 / pageScaleFactor());
caret = unscaledCaret;
- // Pick a scale which is reasonably readable. This is the scale at which
- // the caret height will become minReadableCaretHeight (adjusted for dpi
- // and font scale factor).
- newScale = clampPageScaleFactorToLimits(legibleScale() * minReadableCaretHeight / caret.height);
- newScale = std::max(newScale, pageScaleFactor());
+ if (shouldDisableDesktopWorkarounds()) {
+ newScale = pageScaleFactor();
+ } else {
+ // Pick a scale which is reasonably readable. This is the scale at which
+ // the caret height will become minReadableCaretHeightForNode (adjusted
+ // for dpi and font scale factor).
+ const int minReadableCaretHeightForNode = textboxRect.height() >= 2 * caret.height ? minReadableCaretHeightForTextArea : minReadableCaretHeight;
+ newScale = clampPageScaleFactorToLimits(legibleScale() * minReadableCaretHeightForNode / caret.height);
+ newScale = std::max(newScale, pageScaleFactor());
+ }
const float deltaScale = newScale / pageScaleFactor();
+ needAnimation = false;
+ // If we are at less than the target zoom level, zoom in.
+ if (deltaScale > minScaleChangeToTriggerZoom)
+ needAnimation = true;
+ else
+ newScale = pageScaleFactor();
+
// Convert the rects to absolute space in the new scale.
IntRect textboxRectInDocumentCoordinates = textboxRect;
textboxRectInDocumentCoordinates.move(mainFrame()->scrollOffset());
@@ -2873,6 +2886,20 @@ void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, float&
int viewWidth = m_size.width / newScale;
int viewHeight = m_size.height / newScale;
+ // If the caret is offscreen, then animate.
+ IntRect sizeRect(0, 0, viewWidth, viewHeight);
+ sizeRect.scale(newScale / pageScaleFactor());
+ if (!sizeRect.contains(caret))
+ needAnimation = true;
+
+ // If the box is partially offscreen and it's possible to bring it fully
+ // onscreen, then animate.
+ if (sizeRect.contains(textboxRectInDocumentCoordinates.width(), textboxRectInDocumentCoordinates.height()) && !sizeRect.contains(textboxRect))
+ needAnimation = true;
+
+ if (!needAnimation)
+ return;
+
if (textboxRectInDocumentCoordinates.width() <= viewWidth) {
// Field is narrower than screen. Try to leave padding on left so field's
// label is visible, but it's more important to ensure entire field is
@@ -2893,20 +2920,6 @@ void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, float&
// be offscreen, in which case bottom-align the caret.
newScroll.setY(std::max<int>(textboxRectInDocumentCoordinates.y(), caretInDocumentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding - viewHeight));
}
-
- needAnimation = false;
- // If we are at less than the target zoom level, zoom in.
- if (deltaScale > minScaleChangeToTriggerZoom)
- needAnimation = true;
- // If the caret is offscreen, then animate.
- IntRect sizeRect(0, 0, viewWidth, viewHeight);
- sizeRect.scale(newScale / pageScaleFactor());
- if (!sizeRect.contains(caret))
- needAnimation = true;
- // If the box is partially offscreen and it's possible to bring it fully
- // onscreen, then animate.
- if (sizeRect.contains(textboxRectInDocumentCoordinates.width(), textboxRectInDocumentCoordinates.height()) && !sizeRect.contains(textboxRect))
- needAnimation = true;
}
void WebViewImpl::advanceFocus(bool reverse)
« no previous file with comments | « no previous file | Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698