OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/frame/VisualViewport.h" | 7 #include "core/frame/VisualViewport.h" |
8 | 8 |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1112 Mock::VerifyAndClearExpectations(&mockWebFrameClient); |
1113 | 1113 |
1114 // Scroll horizontally. | 1114 // Scroll horizontally. |
1115 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_)); | 1115 EXPECT_CALL(mockWebFrameClient, didChangeScrollOffset(_)); |
1116 visualViewport.setLocation(FloatPoint(70, 90)); | 1116 visualViewport.setLocation(FloatPoint(70, 90)); |
1117 | 1117 |
1118 // Reset the old client so destruction can occur naturally. | 1118 // Reset the old client so destruction can occur naturally. |
1119 webViewImpl()->mainFrameImpl()->setClient(oldClient); | 1119 webViewImpl()->mainFrameImpl()->setClient(oldClient); |
1120 } | 1120 } |
1121 | 1121 |
1122 // Tests that calling scroll into view on a visible element doesn cause | |
1123 // a scroll due to a fractional offset. Bug crbug.com/463356. | |
1124 TEST_P(ParameterizedVisualViewportTest, ScrollIntoViewFractionalOffset) | |
1125 { | |
1126 initializeWithAndroidSettings(); | |
1127 | |
1128 webViewImpl()->resize(IntSize(1000, 1000)); | |
1129 | |
1130 registerMockedHttpURLLoad("scroll-into-view.html"); | |
1131 navigateTo(m_baseURL + "scroll-into-view.html"); | |
1132 | |
1133 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
1134 ScrollableArea* layoutViewportScrollableArea = frameView.layoutViewportScrol
lableArea(); | |
1135 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | |
1136 Element* inputBox = frame()->document()->getElementById("box"); | |
1137 | |
1138 webViewImpl()->setPageScaleFactor(2); | |
1139 | |
1140 // The element is already in the view so the scrollIntoView shouldn't move | |
1141 // the viewport at all. | |
1142 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); | |
1143 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), Prog
rammaticScroll); | |
1144 inputBox->scrollIntoViewIfNeeded(false); | |
1145 | |
1146 EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scroll
PositionDouble()); | |
1147 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); | |
1148 | |
1149 // Change the fractional part of the frameview to one that would round down. | |
1150 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), Pro
grammaticScroll); | |
1151 inputBox->scrollIntoViewIfNeeded(false); | |
1152 | |
1153 EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrol
lPositionDouble()); | |
1154 EXPECT_POINT_EQ(FloatPoint(250.25f, 100.25f), visualViewport.location()); | |
1155 | |
1156 // Repeat both tests above with the visual viewport at a high fractional. | |
1157 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); | |
1158 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.75), Prog
rammaticScroll); | |
1159 inputBox->scrollIntoViewIfNeeded(false); | |
1160 | |
1161 EXPECT_POINT_EQ(DoublePoint(0, 900.75), layoutViewportScrollableArea->scroll
PositionDouble()); | |
1162 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); | |
1163 | |
1164 // Change the fractional part of the frameview to one that would round down. | |
1165 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.125), Pro
grammaticScroll); | |
1166 inputBox->scrollIntoViewIfNeeded(false); | |
1167 | |
1168 EXPECT_POINT_EQ(DoublePoint(0, 900.125), layoutViewportScrollableArea->scrol
lPositionDouble()); | |
1169 EXPECT_POINT_EQ(FloatPoint(250.875f, 100.875f), visualViewport.location()); | |
1170 | |
1171 // Both viewports with a 0.5 fraction. | |
1172 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); | |
1173 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), Progr
ammaticScroll); | |
1174 inputBox->scrollIntoViewIfNeeded(false); | |
1175 | |
1176 EXPECT_POINT_EQ(DoublePoint(0, 900.5), layoutViewportScrollableArea->scrollP
ositionDouble()); | |
1177 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); | |
1178 } | |
1179 | |
1180 // Top controls can make an unscrollable page temporarily scrollable, causing | 1122 // Top controls can make an unscrollable page temporarily scrollable, causing |
1181 // a scroll clamp when the page is resized. Make sure this bug is fixed. | 1123 // a scroll clamp when the page is resized. Make sure this bug is fixed. |
1182 // crbug.com/437620 | 1124 // crbug.com/437620 |
1183 TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) | 1125 TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) |
1184 { | 1126 { |
1185 initializeWithAndroidSettings(); | 1127 initializeWithAndroidSettings(); |
1186 webViewImpl()->resize(IntSize(980, 650)); | 1128 webViewImpl()->resize(IntSize(980, 650)); |
1187 | 1129 |
1188 navigateTo("about:blank"); | 1130 navigateTo("about:blank"); |
1189 | 1131 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 visualViewport.setScale(2); | 1404 visualViewport.setScale(2); |
1463 visualViewport.setLocation(scrollDelta); | 1405 visualViewport.setLocation(scrollDelta); |
1464 | 1406 |
1465 IntRect boundsInViewport = inputElement->boundsInViewportSpace(); | 1407 IntRect boundsInViewport = inputElement->boundsInViewportSpace(); |
1466 | 1408 |
1467 EXPECT_POINT_EQ(IntPoint(bounds.location() - scrollDelta), | 1409 EXPECT_POINT_EQ(IntPoint(bounds.location() - scrollDelta), |
1468 boundsInViewport.location()); | 1410 boundsInViewport.location()); |
1469 EXPECT_SIZE_EQ(bounds.size(), boundsInViewport.size()); | 1411 EXPECT_SIZE_EQ(bounds.size(), boundsInViewport.size()); |
1470 } | 1412 } |
1471 | 1413 |
1472 // Test that the various window.scroll and document.body.scroll properties and | |
1473 // methods work unchanged from the pre-virtual viewport mode. | |
1474 TEST_P(ParameterizedVisualViewportTest, bodyAndWindowScrollPropertiesAccountForV
iewport) | |
1475 { | |
1476 initializeWithAndroidSettings(); | |
1477 | |
1478 webViewImpl()->resize(IntSize(200, 300)); | |
1479 | |
1480 // Load page with no main frame scrolling. | |
1481 registerMockedHttpURLLoad("200-by-300-viewport.html"); | |
1482 navigateTo(m_baseURL + "200-by-300-viewport.html"); | |
1483 | |
1484 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | |
1485 visualViewport.setScale(2); | |
1486 | |
1487 // Chrome's quirky behavior regarding viewport scrolling means we treat the | |
1488 // body element as the viewport and don't apply scrolling to the HTML | |
1489 // element. | |
1490 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); | |
1491 | |
1492 LocalDOMWindow* window = webViewImpl()->mainFrameImpl()->frame()->localDOMWi
ndow(); | |
1493 window->scrollTo(100, 150); | |
1494 EXPECT_EQ(100, window->scrollX()); | |
1495 EXPECT_EQ(150, window->scrollY()); | |
1496 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | |
1497 | |
1498 HTMLElement* body = toHTMLBodyElement(window->document()->body()); | |
1499 body->setScrollLeft(50); | |
1500 body->setScrollTop(130); | |
1501 EXPECT_EQ(50, body->scrollLeft()); | |
1502 EXPECT_EQ(130, body->scrollTop()); | |
1503 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); | |
1504 | |
1505 HTMLElement* documentElement = toHTMLElement(window->document()->documentEle
ment()); | |
1506 documentElement->setScrollLeft(40); | |
1507 documentElement->setScrollTop(50); | |
1508 EXPECT_EQ(0, documentElement->scrollLeft()); | |
1509 EXPECT_EQ(0, documentElement->scrollTop()); | |
1510 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 130), visualViewport.location()); | |
1511 | |
1512 visualViewport.setLocation(FloatPoint(10, 20)); | |
1513 EXPECT_EQ(10, body->scrollLeft()); | |
1514 EXPECT_EQ(20, body->scrollTop()); | |
1515 EXPECT_EQ(0, documentElement->scrollLeft()); | |
1516 EXPECT_EQ(0, documentElement->scrollTop()); | |
1517 EXPECT_EQ(10, window->scrollX()); | |
1518 EXPECT_EQ(20, window->scrollY()); | |
1519 | |
1520 // Turning on the standards-compliant viewport scrolling impl should make | |
1521 // the document element the viewport and not body. | |
1522 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); | |
1523 | |
1524 window->scrollTo(100, 150); | |
1525 EXPECT_EQ(100, window->scrollX()); | |
1526 EXPECT_EQ(150, window->scrollY()); | |
1527 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | |
1528 | |
1529 body->setScrollLeft(50); | |
1530 body->setScrollTop(130); | |
1531 EXPECT_EQ(0, body->scrollLeft()); | |
1532 EXPECT_EQ(0, body->scrollTop()); | |
1533 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 150), visualViewport.location()); | |
1534 | |
1535 documentElement->setScrollLeft(40); | |
1536 documentElement->setScrollTop(50); | |
1537 EXPECT_EQ(40, documentElement->scrollLeft()); | |
1538 EXPECT_EQ(50, documentElement->scrollTop()); | |
1539 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 50), visualViewport.location()); | |
1540 | |
1541 visualViewport.setLocation(FloatPoint(10, 20)); | |
1542 EXPECT_EQ(0, body->scrollLeft()); | |
1543 EXPECT_EQ(0, body->scrollTop()); | |
1544 EXPECT_EQ(10, documentElement->scrollLeft()); | |
1545 EXPECT_EQ(20, documentElement->scrollTop()); | |
1546 EXPECT_EQ(10, window->scrollX()); | |
1547 EXPECT_EQ(20, window->scrollY()); | |
1548 } | |
1549 | |
1550 // Tests that when a new frame is created, it is created with the intended | 1414 // Tests that when a new frame is created, it is created with the intended |
1551 // size (i.e. viewport at minimum scale, 100x200 / 0.5). | 1415 // size (i.e. viewport at minimum scale, 100x200 / 0.5). |
1552 TEST_P(ParameterizedVisualViewportTest, TestMainFrameInitializationSizing) | 1416 TEST_P(ParameterizedVisualViewportTest, TestMainFrameInitializationSizing) |
1553 { | 1417 { |
1554 initializeWithAndroidSettings(); | 1418 initializeWithAndroidSettings(); |
1555 | 1419 |
1556 webViewImpl()->resize(IntSize(100, 200)); | 1420 webViewImpl()->resize(IntSize(100, 200)); |
1557 | 1421 |
1558 registerMockedHttpURLLoad("content-width-1000-min-scale.html"); | 1422 registerMockedHttpURLLoad("content-width-1000-min-scale.html"); |
1559 navigateTo(m_baseURL + "content-width-1000-min-scale.html"); | 1423 navigateTo(m_baseURL + "content-width-1000-min-scale.html"); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 webViewImpl()->handleInputEvent(pinchUpdate); | 1612 webViewImpl()->handleInputEvent(pinchUpdate); |
1749 | 1613 |
1750 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); | 1614 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); |
1751 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1615 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1752 | 1616 |
1753 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1617 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); |
1754 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1618 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); |
1755 } | 1619 } |
1756 | 1620 |
1757 } // namespace | 1621 } // namespace |
OLD | NEW |