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