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