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
3 // found in the LICENSE file.
7 #include "core/frame/RootFrameViewport.h"
9 #include "core/layout/ScrollAlignment.h"
10 #include "platform/geometry/DoubleRect.h"
11 #include "platform/geometry/LayoutRect.h"
12 #include "platform/scroll/ScrollableArea.h"
14 #include <gtest/gtest.h>
16 #define EXPECT_POINT_EQ(expected, actual) \
18 EXPECT_EQ((expected).x(), (actual).x()); \
19 EXPECT_EQ((expected).y(), (actual).y()); \
21 #define EXPECT_SIZE_EQ(expected, actual) \
23 EXPECT_EQ((expected).width(), (actual).width()); \
24 EXPECT_EQ((expected).height(), (actual).height()); \
29 class ScrollableAreaStub
: public NoBaseWillBeGarbageCollectedFinalized
<ScrollableAreaStub
>, public ScrollableArea
{
30 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ScrollableAreaStub
);
32 static PassOwnPtrWillBeRawPtr
<ScrollableAreaStub
> create(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
34 return adoptPtrWillBeNoop(new ScrollableAreaStub(viewportSize
, contentsSize
));
37 void setViewportSize(const IntSize
& viewportSize
)
39 m_viewportSize
= viewportSize
;
42 IntSize
viewportSize() const { return m_viewportSize
; }
44 // ScrollableArea Impl
45 int scrollSize(ScrollbarOrientation orientation
) const override
47 IntSize scrollDimensions
= maximumScrollPosition() - minimumScrollPosition();
48 return (orientation
== HorizontalScrollbar
) ? scrollDimensions
.width() : scrollDimensions
.height();
51 void setUserInputScrollable(bool x
, bool y
)
53 m_userInputScrollableX
= x
;
54 m_userInputScrollableY
= y
;
57 IntPoint
scrollPosition() const override
{ return flooredIntPoint(m_scrollPosition
); }
58 DoublePoint
scrollPositionDouble() const override
{ return m_scrollPosition
; }
59 IntPoint
minimumScrollPosition() const override
{ return IntPoint(); }
60 DoublePoint
minimumScrollPositionDouble() const override
{ return DoublePoint(); }
61 IntPoint
maximumScrollPosition() const override
{ return flooredIntPoint(maximumScrollPositionDouble()); }
63 IntSize
contentsSize() const override
{ return m_contentsSize
; }
64 void setContentSize(const IntSize
& contentsSize
)
66 m_contentsSize
= contentsSize
;
69 DEFINE_INLINE_VIRTUAL_TRACE()
71 ScrollableArea::trace(visitor
);
75 ScrollableAreaStub(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
76 : m_userInputScrollableX(true)
77 , m_userInputScrollableY(true)
78 , m_viewportSize(viewportSize
)
79 , m_contentsSize(contentsSize
)
83 void setScrollOffset(const IntPoint
& offset
, ScrollType
) override
{ m_scrollPosition
= offset
; }
84 void setScrollOffset(const DoublePoint
& offset
, ScrollType
) override
{ m_scrollPosition
= offset
; }
85 bool shouldUseIntegerScrollOffset() const override
{ return true; }
86 bool isActive() const override
{ return true; }
87 bool isScrollCornerVisible() const override
{ return true; }
88 IntRect
scrollCornerRect() const override
{ return IntRect(); }
89 bool scrollbarsCanBeActive() const override
{ return true; }
90 IntRect
scrollableAreaBoundingBox() const override
{ return IntRect(); }
91 bool shouldPlaceVerticalScrollbarOnLeft() const override
{ return true; }
92 void invalidateScrollbarRect(Scrollbar
*, const IntRect
&) override
{ }
93 void invalidateScrollCornerRect(const IntRect
&) override
{ }
94 GraphicsLayer
* layerForContainer() const override
{ return nullptr; }
95 GraphicsLayer
* layerForScrolling() const override
{ return nullptr; }
96 GraphicsLayer
* layerForHorizontalScrollbar() const override
{ return nullptr; }
97 GraphicsLayer
* layerForVerticalScrollbar() const override
{ return nullptr; }
98 bool userInputScrollable(ScrollbarOrientation orientation
) const override
100 return orientation
== HorizontalScrollbar
? m_userInputScrollableX
: m_userInputScrollableY
;
103 DoublePoint
clampedScrollOffset(const DoublePoint
& offset
)
105 DoublePoint
clampedOffset(offset
);
106 clampedOffset
= clampedOffset
.shrunkTo(FloatPoint(maximumScrollPositionDouble()));
107 clampedOffset
= clampedOffset
.expandedTo(FloatPoint(minimumScrollPositionDouble()));
108 return clampedOffset
;
111 bool m_userInputScrollableX
;
112 bool m_userInputScrollableY
;
113 DoublePoint m_scrollPosition
;
114 IntSize m_viewportSize
;
115 IntSize m_contentsSize
;
118 class RootFrameViewStub
: public ScrollableAreaStub
{
120 static PassOwnPtrWillBeRawPtr
<RootFrameViewStub
> create(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
122 return adoptPtrWillBeNoop(new RootFrameViewStub(viewportSize
, contentsSize
));
125 DoublePoint
maximumScrollPositionDouble() const override
127 return IntPoint(contentsSize() - viewportSize());
131 RootFrameViewStub(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
132 : ScrollableAreaStub(viewportSize
, contentsSize
)
136 int visibleWidth() const override
{ return m_viewportSize
.width(); }
137 int visibleHeight() const override
{ return m_viewportSize
.height(); }
140 class VisualViewportStub
: public ScrollableAreaStub
{
142 static PassOwnPtrWillBeRawPtr
<VisualViewportStub
> create(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
144 return adoptPtrWillBeNoop(new VisualViewportStub(viewportSize
, contentsSize
));
147 DoublePoint
maximumScrollPositionDouble() const override
149 DoubleSize visibleViewport
= viewportSize();
150 visibleViewport
.scale(1 / m_scale
);
152 DoubleSize maxPosition
= DoubleSize(contentsSize()) - visibleViewport
;
153 return DoublePoint(maxPosition
);
156 void setScale(float scale
) { m_scale
= scale
; }
159 VisualViewportStub(const IntSize
& viewportSize
, const IntSize
& contentsSize
)
160 : ScrollableAreaStub(viewportSize
, contentsSize
)
165 int visibleWidth() const override
{ return m_viewportSize
.width() / m_scale
; }
166 int visibleHeight() const override
{ return m_viewportSize
.height() / m_scale
; }
167 DoubleRect
visibleContentRectDouble(IncludeScrollbarsInRect
) const override
169 DoubleSize size
= m_viewportSize
;
170 size
.scale(1 / m_scale
);
171 DoubleRect
rect(scrollPositionDouble(), size
);
178 class RootFrameViewportTest
: public ::testing::Test
{
180 RootFrameViewportTest()
190 // Tests that scrolling the viewport when the layout viewport is
191 // !userInputScrollable (as happens when overflow:hidden is set) works
192 // correctly, that is, the visual viewport can scroll, but not the layout.
193 TEST_F(RootFrameViewportTest
, UserInputScrollable
)
195 IntSize
viewportSize(100, 150);
196 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(200, 300));
197 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
199 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
= RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get());
201 visualViewport
->setScale(2);
203 // Disable just the layout viewport's horizontal scrolling, the
204 // RootFrameViewport should remain scrollable overall.
205 layoutViewport
->setUserInputScrollable(false, true);
206 visualViewport
->setUserInputScrollable(true, true);
208 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(HorizontalScrollbar
));
209 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(VerticalScrollbar
));
211 // Layout viewport shouldn't scroll since it's not horizontally scrollable,
212 // but visual viewport should.
213 rootFrameViewport
->userScroll(ScrollRight
, ScrollByPixel
, 300);
214 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
215 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport
->scrollPositionDouble());
216 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport
->scrollPositionDouble());
218 // Disable just the visual viewport's horizontal scrolling, only the layout
219 // viewport should scroll.
220 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
221 layoutViewport
->setUserInputScrollable(true, true);
222 visualViewport
->setUserInputScrollable(false, true);
224 rootFrameViewport
->userScroll(ScrollRight
, ScrollByPixel
, 300);
225 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport
->scrollPositionDouble());
226 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
227 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport
->scrollPositionDouble());
229 // Disable both viewports' horizontal scrolling, all horizontal scrolling
230 // should now be blocked.
231 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
232 layoutViewport
->setUserInputScrollable(false, true);
233 visualViewport
->setUserInputScrollable(false, true);
235 rootFrameViewport
->userScroll(ScrollRight
, ScrollByPixel
, 300);
236 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
237 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
238 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport
->scrollPositionDouble());
240 EXPECT_FALSE(rootFrameViewport
->userInputScrollable(HorizontalScrollbar
));
241 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(VerticalScrollbar
));
243 // Vertical scrolling should be unaffected.
244 rootFrameViewport
->userScroll(ScrollDown
, ScrollByPixel
, 300);
245 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport
->scrollPositionDouble());
246 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport
->scrollPositionDouble());
247 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport
->scrollPositionDouble());
249 // Try the same checks as above but for the vertical direction.
250 // ===============================================
252 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
254 // Disable just the layout viewport's vertical scrolling, the
255 // RootFrameViewport should remain scrollable overall.
256 layoutViewport
->setUserInputScrollable(true, false);
257 visualViewport
->setUserInputScrollable(true, true);
259 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(HorizontalScrollbar
));
260 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(VerticalScrollbar
));
262 // Layout viewport shouldn't scroll since it's not vertically scrollable,
263 // but visual viewport should.
264 rootFrameViewport
->userScroll(ScrollDown
, ScrollByPixel
, 300);
265 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
266 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport
->scrollPositionDouble());
267 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport
->scrollPositionDouble());
269 // Disable just the visual viewport's vertical scrolling, only the layout
270 // viewport should scroll.
271 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
272 layoutViewport
->setUserInputScrollable(true, true);
273 visualViewport
->setUserInputScrollable(true, false);
275 rootFrameViewport
->userScroll(ScrollDown
, ScrollByPixel
, 300);
276 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport
->scrollPositionDouble());
277 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
278 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport
->scrollPositionDouble());
280 // Disable both viewports' horizontal scrolling, all vertical scrolling
281 // should now be blocked.
282 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
283 layoutViewport
->setUserInputScrollable(true, false);
284 visualViewport
->setUserInputScrollable(true, false);
286 rootFrameViewport
->userScroll(ScrollDown
, ScrollByPixel
, 300);
287 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
288 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
289 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport
->scrollPositionDouble());
291 EXPECT_TRUE(rootFrameViewport
->userInputScrollable(HorizontalScrollbar
));
292 EXPECT_FALSE(rootFrameViewport
->userInputScrollable(VerticalScrollbar
));
294 // Horizontal scrolling should be unaffected.
295 rootFrameViewport
->userScroll(ScrollRight
, ScrollByPixel
, 300);
296 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport
->scrollPositionDouble());
297 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport
->scrollPositionDouble());
298 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport
->scrollPositionDouble());
301 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition())
302 // work correctly when one of the subviewports is explicitly scrolled without using the
303 // RootFrameViewport interface.
304 TEST_F(RootFrameViewportTest
, TestScrollAnimatorUpdatedBeforeScroll
)
306 IntSize
viewportSize(100, 150);
307 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(200, 300));
308 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
310 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
= RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get());
312 visualViewport
->setScale(2);
314 visualViewport
->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll
);
315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport
->scrollPositionDouble());
317 // If the scroll animator doesn't update, it will still think it's at (0, 0) and so it
319 rootFrameViewport
->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll
);
320 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport
->scrollPositionDouble());
321 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
323 // Try again for userScroll()
324 visualViewport
->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll
);
325 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport
->scrollPositionDouble());
327 rootFrameViewport
->userScroll(ScrollLeft
, ScrollByPixel
, 50);
328 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport
->scrollPositionDouble());
329 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport
->scrollPositionDouble());
331 // Make sure the layout viewport is also accounted for.
332 rootFrameViewport
->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll
);
333 layoutViewport
->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll
);
334 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport
->scrollPositionDouble());
336 rootFrameViewport
->userScroll(ScrollLeft
, ScrollByPixel
, 100);
337 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport
->scrollPositionDouble());
338 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport
->scrollPositionDouble());
341 // Test that the scrollIntoView correctly scrolls the main frame
342 // and visual viewport such that the given rect is centered in the viewport.
343 TEST_F(RootFrameViewportTest
, ScrollIntoView
)
345 IntSize
viewportSize(100, 150);
346 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(200, 300));
347 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
349 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
= RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get());
351 // Test that the visual viewport is scrolled if the viewport has been
352 // resized (as is the case when the ChromeOS keyboard comes up) but not
354 visualViewport
->setViewportSize(IntSize(100, 100));
355 rootFrameViewport
->scrollIntoView(
356 LayoutRect(100, 250, 50, 50),
357 ScrollAlignment::alignToEdgeIfNeeded
,
358 ScrollAlignment::alignToEdgeIfNeeded
);
359 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport
->scrollPositionDouble());
360 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport
->scrollPositionDouble());
362 rootFrameViewport
->scrollIntoView(
363 LayoutRect(25, 75, 50, 50),
364 ScrollAlignment::alignToEdgeIfNeeded
,
365 ScrollAlignment::alignToEdgeIfNeeded
);
366 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport
->scrollPositionDouble());
367 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport
->scrollPositionDouble());
369 // Reset the visual viewport's size, scale the page and repeat the test
370 visualViewport
->setViewportSize(IntSize(100, 150));
371 visualViewport
->setScale(2);
372 rootFrameViewport
->setScrollPosition(DoublePoint(), ProgrammaticScroll
);
374 rootFrameViewport
->scrollIntoView(
375 LayoutRect(50, 75, 50, 75),
376 ScrollAlignment::alignToEdgeIfNeeded
,
377 ScrollAlignment::alignToEdgeIfNeeded
);
378 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport
->scrollPositionDouble());
379 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
381 rootFrameViewport
->scrollIntoView(
382 LayoutRect(190, 290, 10, 10),
383 ScrollAlignment::alignToEdgeIfNeeded
,
384 ScrollAlignment::alignToEdgeIfNeeded
);
385 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport
->scrollPositionDouble());
386 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport
->scrollPositionDouble());
388 // Scrolling into view the viewport rect itself should be a no-op.
389 visualViewport
->setViewportSize(IntSize(100, 100));
390 visualViewport
->setScale(1.5f
);
391 visualViewport
->setScrollPosition(DoublePoint(0, 10), ProgrammaticScroll
);
392 layoutViewport
->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll
);
393 rootFrameViewport
->setScrollPosition(rootFrameViewport
->scrollPositionDouble(), ProgrammaticScroll
);
395 rootFrameViewport
->scrollIntoView(
396 LayoutRect(rootFrameViewport
->visibleContentRectDouble(ExcludeScrollbars
)),
397 ScrollAlignment::alignToEdgeIfNeeded
,
398 ScrollAlignment::alignToEdgeIfNeeded
);
399 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport
->scrollPositionDouble());
400 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport
->scrollPositionDouble());
402 rootFrameViewport
->scrollIntoView(
403 LayoutRect(rootFrameViewport
->visibleContentRectDouble(ExcludeScrollbars
)),
404 ScrollAlignment::alignCenterAlways
,
405 ScrollAlignment::alignCenterAlways
);
406 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport
->scrollPositionDouble());
407 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport
->scrollPositionDouble());
409 rootFrameViewport
->scrollIntoView(
410 LayoutRect(rootFrameViewport
->visibleContentRectDouble(ExcludeScrollbars
)),
411 ScrollAlignment::alignTopAlways
,
412 ScrollAlignment::alignTopAlways
);
413 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport
->scrollPositionDouble());
414 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport
->scrollPositionDouble());
417 // Tests that the setScrollPosition method works correctly with both viewports.
418 TEST_F(RootFrameViewportTest
, SetScrollPosition
)
420 IntSize
viewportSize(500, 500);
421 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(1000, 2000));
422 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
424 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
= RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get());
426 visualViewport
->setScale(2);
428 // Ensure that the layout viewport scrolls first.
429 rootFrameViewport
->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll
);
430 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
431 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport
->scrollPositionDouble());
433 // Scroll to the layout viewport's extent, the visual viewport should scroll the
435 rootFrameViewport
->setScrollPosition(DoublePoint(700, 1700), ProgrammaticScroll
);
436 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport
->scrollPositionDouble());
437 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport
->scrollPositionDouble());
439 // Only the visual viewport should scroll further. Make sure it doesn't scroll
441 rootFrameViewport
->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScroll
);
442 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport
->scrollPositionDouble());
443 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport
->scrollPositionDouble());
445 // Scroll all the way back.
446 rootFrameViewport
->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll
);
447 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport
->scrollPositionDouble());
448 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
451 // Tests that the visible rect (i.e. visual viewport rect) is correctly
452 // calculated, taking into account both viewports and page scale.
453 TEST_F(RootFrameViewportTest
, VisibleContentRect
)
455 IntSize
viewportSize(500, 401);
456 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(1000, 2000));
457 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
459 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
= RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get());
461 rootFrameViewport
->setScrollPosition(DoublePoint(100, 75), ProgrammaticScroll
);
463 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport
->visibleContentRect().location());
464 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport
->visibleContentRectDouble().location());
465 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport
->visibleContentRect().size());
466 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport
->visibleContentRectDouble().size());
468 visualViewport
->setScale(2);
470 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport
->visibleContentRect().location());
471 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport
->visibleContentRectDouble().location());
472 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport
->visibleContentRect().size());
473 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport
->visibleContentRectDouble().size());
476 // Tests that the invert scroll order experiment scrolls the visual viewport
477 // before trying to scroll the layout viewport.
478 TEST_F(RootFrameViewportTest
, ViewportScrollOrder
)
480 IntSize
viewportSize(100, 100);
481 OwnPtrWillBeRawPtr
<RootFrameViewStub
> layoutViewport
= RootFrameViewStub::create(viewportSize
, IntSize(200, 300));
482 OwnPtrWillBeRawPtr
<VisualViewportStub
> visualViewport
= VisualViewportStub::create(viewportSize
, viewportSize
);
484 bool invertScrollOrder
= true;
485 OwnPtrWillBeRawPtr
<ScrollableArea
> rootFrameViewport
=
486 RootFrameViewport::create(*visualViewport
.get(), *layoutViewport
.get(), invertScrollOrder
);
488 visualViewport
->setScale(2);
490 rootFrameViewport
->setScrollPosition(DoublePoint(40, 40), UserScroll
);
491 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport
->scrollPositionDouble());
492 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport
->scrollPositionDouble());
494 rootFrameViewport
->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll
);
495 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport
->scrollPositionDouble());
496 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport
->scrollPositionDouble());