| 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/PinchViewport.h" | 7 #include "core/frame/PinchViewport.h" |
| 8 | 8 |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 pinchViewport.setLocation(FloatPoint(200, 200)); | 515 pinchViewport.setLocation(FloatPoint(200, 200)); |
| 516 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), pinchViewport.visibleRect().loca
tion()); | 516 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), pinchViewport.visibleRect().loca
tion()); |
| 517 | 517 |
| 518 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by
2X it should | 518 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by
2X it should |
| 519 // allow us to scroll by 5px more. | 519 // allow us to scroll by 5px more. |
| 520 pinchViewport.setSize(IntSize(310, 230)); | 520 pinchViewport.setSize(IntSize(310, 230)); |
| 521 pinchViewport.setLocation(FloatPoint(200, 200)); | 521 pinchViewport.setLocation(FloatPoint(200, 200)); |
| 522 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), pinchViewport.visibleRect().loca
tion()); | 522 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), pinchViewport.visibleRect().loca
tion()); |
| 523 | 523 |
| 524 // The viewport can be larger than the main frame (currently 320, 240) thoug
h typically | 524 // The viewport can be larger than the main frame (currently 320, 240) thoug
h typically |
| 525 // the scale will be clamped to prevent it from actually being larger. | 525 // the scale will be clamped to prevent it from actually being larger. Make
sure size |
| 526 // changes clamp the offset so the inner remains within the outer. |
| 526 pinchViewport.setSize(IntSize(330, 250)); | 527 pinchViewport.setSize(IntSize(330, 250)); |
| 527 EXPECT_SIZE_EQ(IntSize(330, 250), pinchViewport.size()); | 528 EXPECT_SIZE_EQ(IntSize(330, 250), pinchViewport.size()); |
| 529 EXPECT_FLOAT_POINT_EQ(FloatPoint(155, 115), pinchViewport.visibleRect().loca
tion()); |
| 530 pinchViewport.setLocation(FloatPoint(200, 200)); |
| 531 EXPECT_FLOAT_POINT_EQ(FloatPoint(155, 115), pinchViewport.visibleRect().loca
tion()); |
| 528 | 532 |
| 529 // Resize both the viewport and the frame to be larger. | 533 // Resize both the viewport and the frame to be larger. |
| 530 webViewImpl()->resize(IntSize(640, 480)); | 534 webViewImpl()->resize(IntSize(640, 480)); |
| 531 webViewImpl()->layout(); | 535 webViewImpl()->layout(); |
| 532 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), pinchViewport.size()); | 536 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), pinchViewport.size()); |
| 533 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), frame()->view()->frameRect().
size()); | 537 EXPECT_SIZE_EQ(IntSize(webViewImpl()->size()), frame()->view()->frameRect().
size()); |
| 534 pinchViewport.setLocation(FloatPoint(1000, 1000)); | 538 pinchViewport.setLocation(FloatPoint(1000, 1000)); |
| 535 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), pinchViewport.visibleRect().loca
tion()); | 539 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), pinchViewport.visibleRect().loca
tion()); |
| 536 | 540 |
| 537 // Make sure resizing the viewport doesn't change its offset if the resize d
oesn't make | 541 // Make sure resizing the viewport doesn't change its offset if the resize d
oesn't make |
| 538 // the viewport go out of bounds. | 542 // the viewport go out of bounds. |
| 539 pinchViewport.setLocation(FloatPoint(200, 200)); | 543 pinchViewport.setLocation(FloatPoint(200, 200)); |
| 540 pinchViewport.setSize(IntSize(880, 560)); | 544 pinchViewport.setSize(IntSize(880, 560)); |
| 541 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), pinchViewport.visibleRect().loca
tion()); | 545 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), pinchViewport.visibleRect().loca
tion()); |
| 546 |
| 547 // Resizing the viewport such that the viewport is out of bounds should move
the |
| 548 // viewport. |
| 549 pinchViewport.setSize(IntSize(920, 640)); |
| 550 EXPECT_FLOAT_POINT_EQ(FloatPoint(180, 160), pinchViewport.visibleRect().loca
tion()); |
| 542 } | 551 } |
| 543 | 552 |
| 544 // The main FrameView's size should be set such that its the size of the pinch v
iewport | 553 // The main FrameView's size should be set such that its the size of the pinch v
iewport |
| 545 // at minimum scale. If there's no explicit minimum scale set, the FrameView sho
uld be | 554 // at minimum scale. If there's no explicit minimum scale set, the FrameView sho
uld be |
| 546 // set to the content width and height derived by the aspect ratio. | 555 // set to the content width and height derived by the aspect ratio. |
| 547 TEST_F(PinchViewportTest, TestFrameViewSizedToContent) | 556 TEST_F(PinchViewportTest, TestFrameViewSizedToContent) |
| 548 { | 557 { |
| 549 initializeWithAndroidSettings(); | 558 initializeWithAndroidSettings(); |
| 550 webViewImpl()->resize(IntSize(320, 240)); | 559 webViewImpl()->resize(IntSize(320, 240)); |
| 551 | 560 |
| 552 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 561 registerMockedHttpURLLoad("200-by-300-viewport.html"); |
| 553 navigateTo(m_baseURL + "200-by-300-viewport.html"); | 562 navigateTo(m_baseURL + "200-by-300-viewport.html"); |
| 554 | 563 |
| 555 webViewImpl()->resize(IntSize(600, 800)); | 564 webViewImpl()->resize(IntSize(600, 800)); |
| 556 webViewImpl()->layout(); | 565 webViewImpl()->layout(); |
| 557 | 566 |
| 558 // Note: the size is ceiled and should match the behavior in CC's LayerImpl:
:bounds(). | 567 EXPECT_SIZE_EQ(IntSize(200, 266), |
| 559 EXPECT_SIZE_EQ(IntSize(200, 267), | |
| 560 webViewImpl()->mainFrameImpl()->frameView()->frameRect().size()); | 568 webViewImpl()->mainFrameImpl()->frameView()->frameRect().size()); |
| 561 } | 569 } |
| 562 | 570 |
| 563 // The main FrameView's size should be set such that its the size of the pinch v
iewport | 571 // The main FrameView's size should be set such that its the size of the pinch v
iewport |
| 564 // at minimum scale. On Desktop, the minimum scale is set at 1 so make sure the
FrameView | 572 // at minimum scale. On Desktop, the minimum scale is set at 1 so make sure the
FrameView |
| 565 // is sized to the viewport. | 573 // is sized to the viewport. |
| 566 TEST_F(PinchViewportTest, TestFrameViewSizedToMinimumScale) | 574 TEST_F(PinchViewportTest, TestFrameViewSizedToMinimumScale) |
| 567 { | 575 { |
| 568 initializeWithDesktopSettings(); | 576 initializeWithDesktopSettings(); |
| 569 webViewImpl()->resize(IntSize(320, 240)); | 577 webViewImpl()->resize(IntSize(320, 240)); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 960 |
| 953 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); | 961 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); |
| 954 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); | 962 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); |
| 955 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); | 963 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); |
| 956 | 964 |
| 957 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); | 965 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); |
| 958 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 966 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
| 959 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); | 967 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati
on()); |
| 960 } | 968 } |
| 961 | 969 |
| 962 static IntPoint expectedMaxFrameViewScrollOffset(PinchViewport& pinchViewport, F
rameView& frameView) | |
| 963 { | |
| 964 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewport.visi
bleRect().height(); | |
| 965 float newHeight = frameView.frameRect().width() / aspectRatio; | |
| 966 return IntPoint( | |
| 967 frameView.contentsSize().width() - frameView.frameRect().width(), | |
| 968 frameView.contentsSize().height() - newHeight); | |
| 969 } | |
| 970 | |
| 971 TEST_F(PinchViewportTest, TestTopControlsAdjustment) | |
| 972 { | |
| 973 initializeWithAndroidSettings(); | |
| 974 webViewImpl()->resize(IntSize(100, 150)); | |
| 975 | |
| 976 registerMockedHttpURLLoad("content-width-1000.html"); | |
| 977 navigateTo(m_baseURL + "content-width-1000.html"); | |
| 978 | |
| 979 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
| 980 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
| 981 | |
| 982 pinchViewport.setScale(1); | |
| 983 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.visibleRect().size()); | |
| 984 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | |
| 985 | |
| 986 // Simulate bringing down the top controls by 20px. | |
| 987 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | |
| 988 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.visibleRect().size()); | |
| 989 | |
| 990 // Test that the scroll bounds are adjusted appropriately: the pinch viewpor
t | |
| 991 // should be shrunk by 20px to 130px. The outer viewport was shrunk to maint
ain the | |
| 992 // aspect ratio so it's height is 1300px. | |
| 993 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 994 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | |
| 995 | |
| 996 // The outer viewport (FrameView) should be affected as well. | |
| 997 frameView.scrollBy(IntSize(10000, 10000)); | |
| 998 EXPECT_POINT_EQ( | |
| 999 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | |
| 1000 frameView.scrollPosition()); | |
| 1001 | |
| 1002 // Simulate bringing up the top controls by 10.5px. | |
| 1003 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, -10.5f); | |
| 1004 EXPECT_SIZE_EQ(FloatSize(100, 140.5f), pinchViewport.visibleRect().size()); | |
| 1005 | |
| 1006 // maximumScrollPosition floors the final values. | |
| 1007 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 1008 EXPECT_POINT_EQ(FloatPoint(900, floor(1405 - 140.5f)), pinchViewport.locatio
n()); | |
| 1009 | |
| 1010 // The outer viewport (FrameView) should be affected as well. | |
| 1011 frameView.scrollBy(IntSize(10000, 10000)); | |
| 1012 EXPECT_POINT_EQ( | |
| 1013 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | |
| 1014 frameView.scrollPosition()); | |
| 1015 } | |
| 1016 | |
| 1017 TEST_F(PinchViewportTest, TestTopControlsAdjustmentWithScale) | |
| 1018 { | |
| 1019 initializeWithAndroidSettings(); | |
| 1020 webViewImpl()->resize(IntSize(100, 150)); | |
| 1021 | |
| 1022 registerMockedHttpURLLoad("content-width-1000.html"); | |
| 1023 navigateTo(m_baseURL + "content-width-1000.html"); | |
| 1024 | |
| 1025 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
| 1026 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
| 1027 | |
| 1028 pinchViewport.setScale(2); | |
| 1029 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); | |
| 1030 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | |
| 1031 | |
| 1032 // Simulate bringing down the top controls by 20px. Since we're zoomed in, | |
| 1033 // the top controls take up half as much space (in document-space) than | |
| 1034 // they do at an unzoomed level. | |
| 1035 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | |
| 1036 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); | |
| 1037 | |
| 1038 // Test that the scroll bounds are adjusted appropriately. | |
| 1039 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 1040 EXPECT_POINT_EQ(FloatPoint(950, 1300 - 65), pinchViewport.location()); | |
| 1041 | |
| 1042 // The outer viewport (FrameView) should be affected as well. | |
| 1043 frameView.scrollBy(IntSize(10000, 10000)); | |
| 1044 IntPoint expected = expectedMaxFrameViewScrollOffset(pinchViewport, frameVie
w); | |
| 1045 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | |
| 1046 | |
| 1047 // Scale back out, FrameView max scroll shouldn't have changed. Pinch | |
| 1048 // viewport should be moved up to accomodate larger view. | |
| 1049 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.5f, 0); | |
| 1050 EXPECT_EQ(1, pinchViewport.scale()); | |
| 1051 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | |
| 1052 frameView.scrollBy(IntSize(10000, 10000)); | |
| 1053 EXPECT_POINT_EQ(expected, frameView.scrollPosition()); | |
| 1054 | |
| 1055 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | |
| 1056 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 1057 EXPECT_POINT_EQ(FloatPoint(900, 1300 - 130), pinchViewport.location()); | |
| 1058 | |
| 1059 // Scale out, use a scale that causes fractional rects. | |
| 1060 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 0.8f, -20); | |
| 1061 EXPECT_SIZE_EQ(FloatSize(125, 187.5), pinchViewport.visibleRect().size()); | |
| 1062 | |
| 1063 // Bring out the top controls by 11px. | |
| 1064 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 11); | |
| 1065 EXPECT_SIZE_EQ(FloatSize(125, 173.75), pinchViewport.visibleRect().size()); | |
| 1066 | |
| 1067 // Ensure max scroll offsets are updated properly. | |
| 1068 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 1069 EXPECT_POINT_EQ(FloatPoint(875, floor(1390 - 173.75)), pinchViewport.locatio
n()); | |
| 1070 | |
| 1071 frameView.scrollBy(IntSize(10000, 10000)); | |
| 1072 EXPECT_POINT_EQ( | |
| 1073 expectedMaxFrameViewScrollOffset(pinchViewport, frameView), | |
| 1074 frameView.scrollPosition()); | |
| 1075 | |
| 1076 } | |
| 1077 | |
| 1078 TEST_F(PinchViewportTest, TestTopControlsAdjustmentAndResize) | |
| 1079 { | |
| 1080 initializeWithAndroidSettings(); | |
| 1081 webViewImpl()->resize(IntSize(100, 150)); | |
| 1082 | |
| 1083 registerMockedHttpURLLoad("content-width-1000.html"); | |
| 1084 navigateTo(m_baseURL + "content-width-1000.html"); | |
| 1085 | |
| 1086 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
| 1087 FrameView& frameView = *webViewImpl()->mainFrameImpl()->frameView(); | |
| 1088 | |
| 1089 pinchViewport.setScale(2); | |
| 1090 EXPECT_SIZE_EQ(IntSize(50, 75), pinchViewport.visibleRect().size()); | |
| 1091 EXPECT_SIZE_EQ(IntSize(1000, 1500), frameView.frameRect().size()); | |
| 1092 | |
| 1093 webViewImpl()->applyViewportDeltas(WebSize(), WebSize(), 1, 20); | |
| 1094 EXPECT_SIZE_EQ(IntSize(100, 150), pinchViewport.size()); | |
| 1095 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); | |
| 1096 | |
| 1097 // Scroll all the way to the bottom. | |
| 1098 pinchViewport.move(FloatPoint(10000, 10000)); | |
| 1099 frameView.scrollBy(IntSize(10000, 10000)); | |
| 1100 IntPoint frameViewExpected = expectedMaxFrameViewScrollOffset(pinchViewport,
frameView); | |
| 1101 FloatPoint pinchViewportExpected = FloatPoint(950, 1300 - 65); | |
| 1102 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); | |
| 1103 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | |
| 1104 | |
| 1105 // Resize the widget to match the top controls adjustment. Ensure that scrol
l | |
| 1106 // offsets don't get clamped in the the process. | |
| 1107 webViewImpl()->setTopControlsLayoutHeight(20); | |
| 1108 webViewImpl()->resize(WebSize(100, 130)); | |
| 1109 | |
| 1110 EXPECT_SIZE_EQ(IntSize(100, 130), pinchViewport.size()); | |
| 1111 EXPECT_SIZE_EQ(IntSize(50, 65), pinchViewport.visibleRect().size()); | |
| 1112 EXPECT_SIZE_EQ(IntSize(1000, 1300), frameView.frameRect().size()); | |
| 1113 | |
| 1114 EXPECT_POINT_EQ(frameViewExpected, frameView.scrollPosition()); | |
| 1115 EXPECT_POINT_EQ(pinchViewportExpected, pinchViewport.location()); | |
| 1116 } | |
| 1117 | |
| 1118 } // namespace | 970 } // namespace |
| OLD | NEW |