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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); | 517 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); |
518 | 518 |
519 initializeWithAndroidSettings(); | 519 initializeWithAndroidSettings(); |
520 webViewImpl()->resize(IntSize(200, 250)); | 520 webViewImpl()->resize(IntSize(200, 250)); |
521 | 521 |
522 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 522 registerMockedHttpURLLoad("200-by-800-viewport.html"); |
523 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 523 navigateTo(m_baseURL + "200-by-800-viewport.html"); |
524 | 524 |
525 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 525 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
526 frameView.layoutViewportScrollableArea()->setScrollPosition(DoublePoint(0, 1
0.5), ProgrammaticScroll); | 526 frameView.layoutViewportScrollableArea()->setScrollPosition(DoublePoint(0, 1
0.5), ProgrammaticScroll); |
527 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(10, 20), Web
FloatSize(), 1, 0); | 527 frameView.layoutViewportScrollableArea()->ScrollableArea::setScrollPosition( |
| 528 DoublePoint(10, 30.5), CompositorScroll); |
528 | 529 |
529 EXPECT_EQ(30.5, frameView.layoutViewportScrollableArea()->scrollPositionDoub
le().y()); | 530 EXPECT_EQ(30.5, frameView.layoutViewportScrollableArea()->scrollPositionDoub
le().y()); |
530 | 531 |
531 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(origFractionalOffs
etsEnabled); | 532 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(origFractionalOffs
etsEnabled); |
532 } | 533 } |
533 | 534 |
534 // Test that the viewport's scroll offset is always appropriately bounded such t
hat the | 535 // Test that the viewport's scroll offset is always appropriately bounded such t
hat the |
535 // visual viewport always stays within the bounds of the main frame. | 536 // visual viewport always stays within the bounds of the main frame. |
536 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) | 537 TEST_P(ParameterizedVisualViewportTest, TestOffsetClamping) |
537 { | 538 { |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 | 1170 |
1170 // Both viewports with a 0.5 fraction. | 1171 // Both viewports with a 0.5 fraction. |
1171 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); | 1172 webViewImpl()->setVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); |
1172 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), Progr
ammaticScroll); | 1173 layoutViewportScrollableArea->setScrollPosition(DoublePoint(0, 900.5), Progr
ammaticScroll); |
1173 inputBox->scrollIntoViewIfNeeded(false); | 1174 inputBox->scrollIntoViewIfNeeded(false); |
1174 | 1175 |
1175 EXPECT_POINT_EQ(DoublePoint(0, 900), layoutViewportScrollableArea->scrollPos
itionDouble()); | 1176 EXPECT_POINT_EQ(DoublePoint(0, 900), layoutViewportScrollableArea->scrollPos
itionDouble()); |
1176 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); | 1177 EXPECT_POINT_EQ(FloatPoint(250.5f, 100.5f), visualViewport.location()); |
1177 } | 1178 } |
1178 | 1179 |
1179 // Top controls can make an unscrollable page temporarily scrollable, causing | |
1180 // a scroll clamp when the page is resized. Make sure this bug is fixed. | |
1181 // crbug.com/437620 | |
1182 TEST_F(VisualViewportTest, TestResizeDoesntChangeScrollOffset) | |
1183 { | |
1184 RuntimeEnabledFeatures::setInertTopControlsEnabled(false); | |
1185 initializeWithAndroidSettings(); | |
1186 webViewImpl()->resizeWithTopControls(IntSize(980, 650), 20, false); | |
1187 | |
1188 navigateTo("about:blank"); | |
1189 | |
1190 VisualViewport& visualViewport = frame()->page()->frameHost().visualViewport
(); | |
1191 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
1192 | |
1193 // Outer viewport isn't scrollable | |
1194 EXPECT_SIZE_EQ(IntSize(980, 650), frameView.visibleContentRect().size()); | |
1195 | |
1196 visualViewport.setScale(2); | |
1197 visualViewport.move(FloatPoint(0, 40)); | |
1198 | |
1199 // Simulate bringing down the top controls by 20px but counterscrolling the
outer viewport. | |
1200 webViewImpl()->applyViewportDeltas(WebFloatSize(), WebFloatSize(0, 20), WebF
loatSize(), 1, 1); | |
1201 | |
1202 EXPECT_EQ(20, frameView.layoutViewportScrollableArea()->scrollPosition().y()
); | |
1203 | |
1204 webViewImpl()->resizeWithTopControls(WebSize(980, 630), 20, true); | |
1205 | |
1206 EXPECT_EQ(0, frameView.layoutViewportScrollableArea()->scrollPosition().y())
; | |
1207 EXPECT_EQ(60, visualViewport.location().y()); | |
1208 } | |
1209 | |
1210 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport,
FrameView& frameView) | 1180 static IntPoint expectedMaxFrameViewScrollOffset(VisualViewport& visualViewport,
FrameView& frameView) |
1211 { | 1181 { |
1212 float aspectRatio = visualViewport.visibleRect().width() / visualViewport.vi
sibleRect().height(); | 1182 float aspectRatio = visualViewport.visibleRect().width() / visualViewport.vi
sibleRect().height(); |
1213 float newHeight = frameView.frameRect().width() / aspectRatio; | 1183 float newHeight = frameView.frameRect().width() / aspectRatio; |
1214 return IntPoint( | 1184 return IntPoint( |
1215 frameView.contentsSize().width() - frameView.frameRect().width(), | 1185 frameView.contentsSize().width() - frameView.frameRect().width(), |
1216 frameView.contentsSize().height() - newHeight); | 1186 frameView.contentsSize().height() - newHeight); |
1217 } | 1187 } |
1218 | 1188 |
1219 TEST_F(VisualViewportTest, TestTopControlsAdjustment) | 1189 TEST_F(VisualViewportTest, TestTopControlsAdjustment) |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 webViewImpl()->handleInputEvent(pinchUpdate); | 1829 webViewImpl()->handleInputEvent(pinchUpdate); |
1860 | 1830 |
1861 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); | 1831 VisualViewport& visualViewport = webViewImpl()->page()->frameHost().visualVi
ewport(); |
1862 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | 1832 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); |
1863 | 1833 |
1864 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); | 1834 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 50), visualViewport.location()); |
1865 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); | 1835 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), frameView.scrollPositionDouble()); |
1866 } | 1836 } |
1867 | 1837 |
1868 } // namespace | 1838 } // namespace |
OLD | NEW |