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

Unified Diff: Source/web/tests/WebFrameTest.cpp

Issue 19281007: Allow zoom-in to a target rect when tapping multiple targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 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.cpp ('k') | public/web/WebView.h » ('j') | 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 a9e9a3c76aba8cc68ca45eeeb93d0c77bb501ba7..f7cadc04343ecbd92f9c27232e26bf0e65ee4df9 100644
--- a/Source/web/tests/WebFrameTest.cpp
+++ b/Source/web/tests/WebFrameTest.cpp
@@ -96,6 +96,8 @@ using WebKit::FrameTestHelpers::runPendingTasks;
namespace {
+const int touchPointPadding = 32;
+
#define EXPECT_EQ_RECT(a, b) \
EXPECT_EQ(a.x(), b.x()); \
EXPECT_EQ(a.y(), b.y()); \
@@ -1170,55 +1172,71 @@ TEST_F(WebFrameTest, DivAutoZoomParamsTest)
WebRect wideDiv(200, 100, 400, 150);
WebRect tallDiv(200, 300, 400, 800);
- WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, 0, 0);
- WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, 0, 0);
+ WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding, touchPointPadding);
+ WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding, touchPointPadding);
+ WebRect wideBlockBounds;
+ WebRect tallBlockBounds;
float scale;
WebPoint scroll;
- bool isAnchor;
+ bool doubleTapShouldZoomOut;
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
// Test double-tap zooming into wide div.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
+ wideBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointWide, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPointPadding, scale, scroll, doubleTapShouldZoomOut);
// The div should horizontally fill the screen (modulo margins), and
// vertically centered (modulo integer rounding).
EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
EXPECT_NEAR(wideDiv.x, scroll.x, 20);
EXPECT_EQ(0, scroll.y);
- EXPECT_FALSE(isAnchor);
+ EXPECT_FALSE(doubleTapShouldZoomOut);
setScaleAndScrollAndLayout(webViewImpl, scroll, scale);
// Test zoom out back to minimum scale.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointWide, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
- EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
- EXPECT_TRUE(isAnchor);
+ wideBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointWide, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPointPadding, scale, scroll, doubleTapShouldZoomOut);
+ EXPECT_TRUE(doubleTapShouldZoomOut);
+ scale = webViewImpl->minimumPageScaleFactor();
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), scale);
// Test double-tap zooming into tall div.
- webViewImpl->computeScaleAndScrollForHitRect(doubleTapPointTall, WebViewImpl::DoubleTap, scale, scroll, isAnchor);
+ tallBlockBounds = webViewImpl->computeBlockBounds(doubleTapPointTall, false);
+ webViewImpl->computeScaleAndScrollForBlockRect(tallBlockBounds, touchPointPadding, scale, scroll, doubleTapShouldZoomOut);
// The div should start at the top left of the viewport.
EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1);
EXPECT_NEAR(tallDiv.x, scroll.x, 20);
EXPECT_NEAR(tallDiv.y, scroll.y, 20);
- EXPECT_FALSE(isAnchor);
+ EXPECT_FALSE(doubleTapShouldZoomOut);
// Test for Non-doubletap scaling
// Test zooming into div.
- webViewImpl->computeScaleAndScrollForHitRect(WebRect(250, 250, 10, 10), WebViewImpl::FindInPage, scale, scroll, isAnchor);
+ webViewImpl->computeScaleAndScrollForBlockRect(webViewImpl->computeBlockBounds(WebRect(250, 250, 10, 10), true), 0, scale, scroll, doubleTapShouldZoomOut);
EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1);
}
-void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
+void simulatePageScale(WebViewImpl* webViewImpl, float& scale)
{
- webViewImpl->animateZoomAroundPoint(point, WebViewImpl::DoubleTap);
- EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
- WebCore::IntSize scrollDelta = webViewImpl->fakeDoubleTapTargetPositionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
- float scaleDelta = webViewImpl->fakeDoubleTapPageScaleFactorForTesting() / webViewImpl->pageScaleFactor();
+ WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPositionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition();
+ float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / webViewImpl->pageScaleFactor();
webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta);
scale = webViewImpl->pageScaleFactor();
}
+void simulateMultiTargetZoom(WebViewImpl* webViewImpl, const WebRect& rect, float& scale)
+{
+ if (webViewImpl->zoomToMultipleTargetsRect(rect))
+ simulatePageScale(webViewImpl, scale);
+}
+
+void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
+{
+ webViewImpl->animateDoubleTapZoom(point);
+ EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
+ simulatePageScale(webViewImpl, scale);
+}
+
TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
{
registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
@@ -1236,7 +1254,7 @@ TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect topDiv(200, 100, 200, 150);
WebRect bottomDiv(200, 300, 200, 150);
@@ -1263,7 +1281,7 @@ TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest)
// If we didn't yet get an auto-zoom update and a second double-tap arrives, should go back to minimum scale.
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
- webViewImpl->animateZoomAroundPoint(topPoint, WebViewImpl::DoubleTap);
+ webViewImpl->animateDoubleTapZoom(topPoint);
EXPECT_TRUE(webViewImpl->fakeDoubleTapAnimationPendingForTesting());
simulateDoubleTap(webViewImpl, bottomPoint, scale);
EXPECT_FLOAT_EQ(webViewImpl->minimumPageScaleFactor(), scale);
@@ -1283,7 +1301,7 @@ TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect div(200, 100, 200, 150);
WebPoint doubleTapPoint(div.x + 50, div.y + 50);
@@ -1345,7 +1363,7 @@ TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest)
m_webView->layout();
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
webViewImpl->page()->settings()->setTextAutosizingFontScaleFactor(textAutosizingFontScaleFactor);
WebRect div(200, 100, 200, 150);
@@ -1409,6 +1427,42 @@ TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest)
EXPECT_FLOAT_EQ(legibleScale, scale);
}
+TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest)
+{
+ registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html");
+
+ const float deviceScaleFactor = 2.0f;
+ int viewportWidth = 640 / deviceScaleFactor;
+ int viewportHeight = 1280 / deviceScaleFactor;
+ float doubleTapZoomAlreadyLegibleRatio = 1.2f;
+ m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple_divs_for_auto_zoom_test.html");
+ m_webView->enableFixedLayoutMode(true);
+ m_webView->resize(WebSize(viewportWidth, viewportHeight));
+ m_webView->setPageScaleFactorLimits(0.5f, 4);
+ m_webView->setDeviceScaleFactor(deviceScaleFactor);
+ m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0));
+ m_webView->layout();
+
+ WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
+
+ WebRect viewportRect(0, 0, viewportWidth, viewportHeight);
+ WebRect topDiv(200, 100, 200, 150);
+ WebRect bottomDiv(200, 300, 200, 150);
+ float scale;
+ setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
+
+ simulateMultiTargetZoom(webViewImpl, topDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ simulateMultiTargetZoom(webViewImpl, bottomDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ simulateMultiTargetZoom(webViewImpl, viewportRect, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+ webViewImpl->setPageScaleFactor(webViewImpl->minimumPageScaleFactor(), WebPoint(0, 0));
+ simulateMultiTargetZoom(webViewImpl, topDiv, scale);
+ EXPECT_FLOAT_EQ(1, scale);
+}
+
TEST_F(WebFrameTest, DivScrollIntoEditableTest)
{
registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html");
@@ -1427,7 +1481,7 @@ TEST_F(WebFrameTest, DivScrollIntoEditableTest)
m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true);
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
- webViewImpl->enableFakeDoubleTapAnimationForTesting(true);
+ webViewImpl->enableFakePageScaleAnimationForTesting(true);
WebRect editBoxWithText(200, 200, 250, 20);
WebRect editBoxWithNoText(200, 250, 250, 20);
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | public/web/WebView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698