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

Unified Diff: Source/web/tests/WebFrameTest.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 | « Source/web/WebViewImpl.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/tests/WebFrameTest.cpp
diff --git a/Source/web/tests/WebFrameTest.cpp b/Source/web/tests/WebFrameTest.cpp
index 5a07739bca5fa37141c2a6de3287e96a0ab60a76..495821d2ba701bfcf4c32573d6da8525c067c090 100644
--- a/Source/web/tests/WebFrameTest.cpp
+++ b/Source/web/tests/WebFrameTest.cpp
@@ -2871,13 +2871,14 @@ TEST_F(WebFrameTest, DivScrollIntoEditableTest)
int viewportHeight = 300;
float leftBoxRatio = 0.3f;
int caretPadding = 10;
- float minReadableCaretHeight = 18.0f;
+ float minReadableCaretHeight = 16.0f;
FrameTestHelpers::WebViewHelper webViewHelper;
webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editable_test.html");
+ webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(false);
webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
- webViewHelper.webView()->setPageScaleFactorLimits(1, 4);
- webViewHelper.webView()->layout();
+ webViewHelper.webView()->setPageScaleFactorLimits(0.25f, 4);
webViewHelper.webView()->setDeviceScaleFactor(1.5f);
+ webViewHelper.webView()->layout();
webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(true);
webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
@@ -2894,6 +2895,10 @@ TEST_F(WebFrameTest, DivScrollIntoEditableTest)
WebRect rect, caret;
webViewHelper.webViewImpl()->selectionBounds(caret, rect);
+ // Set the page scale to be smaller than the minimal readable scale.
+ float initialScale = minReadableCaretHeight / caret.height * 0.5f;
+ setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialScale);
+
float scale;
IntPoint scroll;
bool needAnimation;
@@ -2901,43 +2906,44 @@ TEST_F(WebFrameTest, DivScrollIntoEditableTest)
EXPECT_TRUE(needAnimation);
// The edit box should be left aligned with a margin for possible label.
int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale;
- EXPECT_NEAR(hScroll, scroll.x(), 5);
+ EXPECT_NEAR(hScroll, scroll.x(), 2);
int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText.height) / 2;
- EXPECT_NEAR(vScroll, scroll.y(), 1);
+ EXPECT_NEAR(vScroll, scroll.y(), 2);
EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
// The edit box is wider than the viewport when legible.
viewportWidth = 200;
viewportHeight = 150;
webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
- setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1);
- webViewHelper.webViewImpl()->selectionBounds(caret, rect);
+ setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialScale);
webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelper.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
EXPECT_TRUE(needAnimation);
// The caret should be right aligned since the caret would be offscreen when the edit box is left aligned.
hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale;
- EXPECT_NEAR(hScroll, scroll.x(), 1);
+ EXPECT_NEAR(hScroll, scroll.x(), 2);
EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
- setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1);
+ setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialScale);
// Move focus to edit box with text.
webViewHelper.webView()->advanceFocus(false);
- webViewHelper.webViewImpl()->selectionBounds(caret, rect);
webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelper.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
EXPECT_TRUE(needAnimation);
// The edit box should be left aligned.
hScroll = editBoxWithNoText.x;
- EXPECT_NEAR(hScroll, scroll.x(), 1);
+ EXPECT_NEAR(hScroll, scroll.x(), 2);
vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText.height) / 2;
- EXPECT_NEAR(vScroll, scroll.y(), 1);
+ EXPECT_NEAR(vScroll, scroll.y(), 2);
EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1);
- setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale);
-
// Move focus back to the first edit box.
webViewHelper.webView()->advanceFocus(true);
+ // Zoom out slightly.
+ const float withinToleranceScale = scale * 0.9f;
+ setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, withinToleranceScale);
+ // Move focus back to the second edit box.
+ webViewHelper.webView()->advanceFocus(false);
webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelper.webViewImpl()->focusedElement(), scale, scroll, needAnimation);
- // The position should have stayed the same since this box was already on screen with the right scale.
+ // The scale should not be adjusted as the zoomed out scale was sufficiently close to the previously focused scale.
EXPECT_FALSE(needAnimation);
}
@@ -2947,13 +2953,14 @@ TEST_F(WebFrameTest, DivScrollIntoEditablePreservePageScaleTest)
const int viewportWidth = 450;
const int viewportHeight = 300;
- const float minReadableCaretHeight = 18.0f;
+ const float minReadableCaretHeight = 16.0f;
FrameTestHelpers::WebViewHelper webViewHelper;
webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editable_test.html");
+ webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(false);
webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
- webViewHelper.webView()->setPageScaleFactorLimits(1, 4);
- webViewHelper.webView()->layout();
+ webViewHelper.webView()->setPageScaleFactorLimits(1.f, 4);
webViewHelper.webView()->setDeviceScaleFactor(1.5f);
+ webViewHelper.webView()->layout();
webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(true);
webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true);
@@ -2966,7 +2973,7 @@ TEST_F(WebFrameTest, DivScrollIntoEditablePreservePageScaleTest)
WebRect rect, caret;
webViewHelper.webViewImpl()->selectionBounds(caret, rect);
- // Set page scale twice larger then minimal readable scale
+ // Set the page scale to be twice as large as the minimal readable scale.
float newScale = minReadableCaretHeight / caret.height * 2.0;
setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), newScale);
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698