| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "bindings/core/v8/NodeOrString.h" | 5 #include "bindings/core/v8/NodeOrString.h" |
| 6 #include "core/dom/ClientRect.h" | 6 #include "core/dom/ClientRect.h" |
| 7 #include "core/frame/BrowserControls.h" | 7 #include "core/frame/BrowserControls.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/RootFrameViewport.h" | 9 #include "core/frame/RootFrameViewport.h" |
| 10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 // ViewportScrollCallback removed. Keep the scrolls to guard crashes | 723 // ViewportScrollCallback removed. Keep the scrolls to guard crashes |
| 724 // but the expectations on when a ViewportScrollCallback have changed | 724 // but the expectations on when a ViewportScrollCallback have changed |
| 725 // and should be updated. | 725 // and should be updated. |
| 726 // EXPECT_EQ(200, container->scrollTop()); | 726 // EXPECT_EQ(200, container->scrollTop()); |
| 727 } | 727 } |
| 728 | 728 |
| 729 // Reset explicitly to prevent lifetime issues with the RemoteFrameClient. | 729 // Reset explicitly to prevent lifetime issues with the RemoteFrameClient. |
| 730 m_helper.reset(); | 730 m_helper.reset(); |
| 731 } | 731 } |
| 732 | 732 |
| 733 // Tests that the clipping layer is resized on the root scroller element even | |
| 734 // if the layout height doesn't change. | |
| 735 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayer) { | |
| 736 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled(); | |
| 737 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | |
| 738 | |
| 739 initialize("root-scroller.html"); | |
| 740 Element* container = mainFrame()->document()->getElementById("container"); | |
| 741 | |
| 742 { | |
| 743 mainFrame()->document()->setRootScroller(container); | |
| 744 | |
| 745 mainFrameView()->updateAllLifecyclePhases(); | |
| 746 ASSERT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400); | |
| 747 | |
| 748 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject()) | |
| 749 ->layer() | |
| 750 ->compositedLayerMapping() | |
| 751 ->scrollingLayer(); | |
| 752 ASSERT_EQ(clipLayer->size().height(), 400); | |
| 753 } | |
| 754 | |
| 755 { | |
| 756 webViewImpl()->handleInputEvent( | |
| 757 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | |
| 758 | |
| 759 // Scrolling over the #container DIV should cause the browser controls to | |
| 760 // hide. | |
| 761 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); | |
| 762 webViewImpl()->handleInputEvent(generateTouchGestureEvent( | |
| 763 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); | |
| 764 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); | |
| 765 | |
| 766 webViewImpl()->handleInputEvent( | |
| 767 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); | |
| 768 | |
| 769 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false); | |
| 770 | |
| 771 EXPECT_FALSE(container->layoutObject()->needsLayout()); | |
| 772 | |
| 773 mainFrameView()->updateAllLifecyclePhases(); | |
| 774 | |
| 775 // Since inert top controls are enabled, the container should not have | |
| 776 // resized, however, the clip layer should. | |
| 777 EXPECT_EQ(toLayoutBox(container->layoutObject())->clientHeight(), 400); | |
| 778 GraphicsLayer* clipLayer = toLayoutBox(container->layoutObject()) | |
| 779 ->layer() | |
| 780 ->compositedLayerMapping() | |
| 781 ->scrollingLayer(); | |
| 782 EXPECT_EQ(clipLayer->size().height(), 450); | |
| 783 } | |
| 784 | |
| 785 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls); | |
| 786 } | |
| 787 | |
| 788 // Tests that the clipping layer is resized on the root scroller element when | |
| 789 // it's an iframe and even if the layout height doesn't change. | |
| 790 TEST_F(RootScrollerTest, BrowserControlsResizeClippingLayerIFrame) { | |
| 791 bool oldInertTopControls = RuntimeEnabledFeatures::inertTopControlsEnabled(); | |
| 792 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | |
| 793 | |
| 794 initialize("root-scroller-iframe.html"); | |
| 795 | |
| 796 Element* iframe = mainFrame()->document()->getElementById("iframe"); | |
| 797 LocalFrame* childFrame = | |
| 798 toLocalFrame(toHTMLFrameOwnerElement(iframe)->contentFrame()); | |
| 799 | |
| 800 PaintLayerCompositor* childPLC = | |
| 801 childFrame->view()->layoutViewItem().compositor(); | |
| 802 | |
| 803 // Give the iframe itself scrollable content and make it the root scroller. | |
| 804 { | |
| 805 NonThrowableExceptionState nonThrow; | |
| 806 mainFrame()->document()->setRootScroller(iframe, nonThrow); | |
| 807 | |
| 808 WebLocalFrame* childWebFrame = | |
| 809 mainWebFrame()->firstChild()->toWebLocalFrame(); | |
| 810 executeScript( | |
| 811 "document.getElementById('container').style.width = '300%';" | |
| 812 "document.getElementById('container').style.height = '300%';", | |
| 813 *childWebFrame); | |
| 814 | |
| 815 mainFrameView()->updateAllLifecyclePhases(); | |
| 816 | |
| 817 // Some sanity checks to make sure the test is setup correctly. | |
| 818 ASSERT_EQ(childFrame->view()->visibleContentSize().height(), 400); | |
| 819 ASSERT_EQ(childPLC->containerLayer()->size().height(), 400); | |
| 820 ASSERT_EQ(childPLC->rootGraphicsLayer()->size().height(), 400); | |
| 821 } | |
| 822 | |
| 823 { | |
| 824 webViewImpl()->handleInputEvent( | |
| 825 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | |
| 826 | |
| 827 // Scrolling over the #container DIV should cause the browser controls to | |
| 828 // hide. | |
| 829 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); | |
| 830 webViewImpl()->handleInputEvent(generateTouchGestureEvent( | |
| 831 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); | |
| 832 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); | |
| 833 | |
| 834 webViewImpl()->handleInputEvent( | |
| 835 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); | |
| 836 | |
| 837 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false); | |
| 838 | |
| 839 EXPECT_FALSE(childFrame->view()->needsLayout()); | |
| 840 | |
| 841 mainFrameView()->updateAllLifecyclePhases(); | |
| 842 | |
| 843 // Since inert top controls are enabled, the iframe element should not have | |
| 844 // resized, however, its clip layer should resize to reveal content as the | |
| 845 // browser controls hide. | |
| 846 EXPECT_EQ(childFrame->view()->visibleContentSize().height(), 400); | |
| 847 EXPECT_EQ(childPLC->containerLayer()->size().height(), 450); | |
| 848 EXPECT_EQ(childPLC->rootGraphicsLayer()->size().height(), 450); | |
| 849 } | |
| 850 | |
| 851 RuntimeEnabledFeatures::setInertTopControlsEnabled(oldInertTopControls); | |
| 852 } | |
| 853 | |
| 854 // Tests that removing the root scroller element from the DOM resets the | 733 // Tests that removing the root scroller element from the DOM resets the |
| 855 // effective root scroller without waiting for any lifecycle events. | 734 // effective root scroller without waiting for any lifecycle events. |
| 856 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { | 735 TEST_F(RootScrollerTest, RemoveRootScrollerFromDom) { |
| 857 initialize("root-scroller-iframe.html"); | 736 initialize("root-scroller-iframe.html"); |
| 858 | 737 |
| 859 { | 738 { |
| 860 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( | 739 HTMLFrameOwnerElement* iframe = toHTMLFrameOwnerElement( |
| 861 mainFrame()->document()->getElementById("iframe")); | 740 mainFrame()->document()->getElementById("iframe")); |
| 862 Element* innerContainer = | 741 Element* innerContainer = |
| 863 iframe->contentDocument()->getElementById("container"); | 742 iframe->contentDocument()->getElementById("container"); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 // FrameView without a layout. | 985 // FrameView without a layout. |
| 1107 iframe->remove(); | 986 iframe->remove(); |
| 1108 | 987 |
| 1109 EXPECT_EQ(mainFrameView()->layoutViewportScrollableArea(), | 988 EXPECT_EQ(mainFrameView()->layoutViewportScrollableArea(), |
| 1110 &mainFrameView()->getRootFrameViewport()->layoutViewport()); | 989 &mainFrameView()->getRootFrameViewport()->layoutViewport()); |
| 1111 } | 990 } |
| 1112 | 991 |
| 1113 } // namespace | 992 } // namespace |
| 1114 | 993 |
| 1115 } // namespace blink | 994 } // namespace blink |
| OLD | NEW |