OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "core/page/scrolling/ScrollingCoordinator.h" | 25 #include "core/page/scrolling/ScrollingCoordinator.h" |
26 | 26 |
27 #include "core/css/CSSStyleSheet.h" | 27 #include "core/css/CSSStyleSheet.h" |
28 #include "core/css/StyleSheetList.h" | 28 #include "core/css/StyleSheetList.h" |
29 #include "core/frame/FrameHost.h" | 29 #include "core/frame/FrameHost.h" |
30 #include "core/frame/FrameView.h" | 30 #include "core/frame/FrameView.h" |
31 #include "core/frame/VisualViewport.h" | 31 #include "core/frame/VisualViewport.h" |
| 32 #include "core/html/HTMLIFrameElement.h" |
32 #include "core/layout/LayoutPart.h" | 33 #include "core/layout/LayoutPart.h" |
33 #include "core/layout/api/LayoutViewItem.h" | 34 #include "core/layout/api/LayoutViewItem.h" |
34 #include "core/layout/compositing/CompositedLayerMapping.h" | 35 #include "core/layout/compositing/CompositedLayerMapping.h" |
35 #include "core/layout/compositing/PaintLayerCompositor.h" | 36 #include "core/layout/compositing/PaintLayerCompositor.h" |
36 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
37 #include "platform/geometry/IntPoint.h" | 38 #include "platform/geometry/IntPoint.h" |
38 #include "platform/geometry/IntRect.h" | 39 #include "platform/geometry/IntRect.h" |
39 #include "platform/graphics/GraphicsLayer.h" | 40 #include "platform/graphics/GraphicsLayer.h" |
40 #include "platform/testing/URLTestHelpers.h" | 41 #include "platform/testing/URLTestHelpers.h" |
41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 container->removeAttribute("class"); | 843 container->removeAttribute("class"); |
843 forceFullCompositingUpdate(); | 844 forceFullCompositingUpdate(); |
844 scrollbarGraphicsLayer = compositedLayerMapping->layerForVerticalScrollbar(); | 845 scrollbarGraphicsLayer = compositedLayerMapping->layerForVerticalScrollbar(); |
845 ASSERT_FALSE( | 846 ASSERT_FALSE( |
846 scrollbarGraphicsLayer->platformLayer()->shouldScrollOnMainThread()); | 847 scrollbarGraphicsLayer->platformLayer()->shouldScrollOnMainThread()); |
847 ASSERT_FALSE( | 848 ASSERT_FALSE( |
848 scrollbarGraphicsLayer->platformLayer()->mainThreadScrollingReasons() & | 849 scrollbarGraphicsLayer->platformLayer()->mainThreadScrollingReasons() & |
849 MainThreadScrollingReason::kCustomScrollbarScrolling); | 850 MainThreadScrollingReason::kCustomScrollbarScrolling); |
850 } | 851 } |
851 | 852 |
| 853 TEST_F(ScrollingCoordinatorTest, |
| 854 BackgroundAttachmentFixedShouldTriggerMainThreadScroll) { |
| 855 registerMockedHttpURLLoad("iframe-background-attachment-fixed.html"); |
| 856 registerMockedHttpURLLoad("iframe-background-attachment-fixed-inner.html"); |
| 857 registerMockedHttpURLLoad("white-1x1.png"); |
| 858 navigateTo(m_baseURL + "iframe-background-attachment-fixed.html"); |
| 859 forceFullCompositingUpdate(); |
| 860 |
| 861 Element* iframe = frame()->document()->getElementById("iframe"); |
| 862 ASSERT_TRUE(iframe); |
| 863 |
| 864 LayoutObject* layoutObject = iframe->layoutObject(); |
| 865 ASSERT_TRUE(layoutObject); |
| 866 ASSERT_TRUE(layoutObject->isLayoutPart()); |
| 867 |
| 868 LayoutPart* layoutPart = toLayoutPart(layoutObject); |
| 869 ASSERT_TRUE(layoutPart); |
| 870 ASSERT_TRUE(layoutPart->widget()); |
| 871 ASSERT_TRUE(layoutPart->widget()->isFrameView()); |
| 872 |
| 873 FrameView* innerFrameView = toFrameView(layoutPart->widget()); |
| 874 LayoutViewItem innerLayoutViewItem = innerFrameView->layoutViewItem(); |
| 875 ASSERT_FALSE(innerLayoutViewItem.isNull()); |
| 876 |
| 877 PaintLayerCompositor* innerCompositor = innerLayoutViewItem.compositor(); |
| 878 ASSERT_TRUE(innerCompositor->inCompositingMode()); |
| 879 ASSERT_TRUE(innerCompositor->scrollLayer()); |
| 880 |
| 881 GraphicsLayer* scrollLayer = innerCompositor->scrollLayer(); |
| 882 ASSERT_EQ(innerFrameView, scrollLayer->getScrollableArea()); |
| 883 |
| 884 WebLayer* webScrollLayer = scrollLayer->platformLayer(); |
| 885 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 886 ASSERT_TRUE(webScrollLayer->mainThreadScrollingReasons() & |
| 887 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 888 |
| 889 // Remove fixed background-attachment should make the iframe |
| 890 // scroll on cc. |
| 891 auto* iframeDoc = toHTMLIFrameElement(iframe)->contentDocument(); |
| 892 iframe = iframeDoc->getElementById("scrollable"); |
| 893 ASSERT_TRUE(iframe); |
| 894 |
| 895 iframe->removeAttribute("class"); |
| 896 forceFullCompositingUpdate(); |
| 897 |
| 898 layoutObject = iframe->layoutObject(); |
| 899 ASSERT_TRUE(layoutObject); |
| 900 |
| 901 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 902 ASSERT_TRUE(scrollLayer); |
| 903 |
| 904 webScrollLayer = scrollLayer->platformLayer(); |
| 905 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 906 ASSERT_FALSE(webScrollLayer->mainThreadScrollingReasons() & |
| 907 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 908 |
| 909 // Force main frame to scroll on main thread. All its descendants |
| 910 // should scroll on main thread as well. |
| 911 Element* element = frame()->document()->getElementById("scrollable"); |
| 912 element->setAttribute( |
| 913 "style", |
| 914 "background-image: url('white-1x1.png'); background-attachment: fixed;", |
| 915 ASSERT_NO_EXCEPTION); |
| 916 |
| 917 forceFullCompositingUpdate(); |
| 918 |
| 919 layoutObject = iframe->layoutObject(); |
| 920 ASSERT_TRUE(layoutObject); |
| 921 |
| 922 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 923 ASSERT_TRUE(scrollLayer); |
| 924 |
| 925 webScrollLayer = scrollLayer->platformLayer(); |
| 926 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 927 ASSERT_TRUE(webScrollLayer->mainThreadScrollingReasons() & |
| 928 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 929 } |
| 930 |
| 931 // Upon resizing the content size, the main thread scrolling reason |
| 932 // kHasNonLayerViewportConstrainedObject should be updated on all frames |
| 933 TEST_F(ScrollingCoordinatorTest, |
| 934 RecalculateMainThreadScrollingReasonsUponResize) { |
| 935 webViewImpl()->settings()->setPreferCompositingToLCDTextEnabled(false); |
| 936 registerMockedHttpURLLoad("has-non-layer-viewport-constrained-objects.html"); |
| 937 navigateTo(m_baseURL + "has-non-layer-viewport-constrained-objects.html"); |
| 938 forceFullCompositingUpdate(); |
| 939 |
| 940 LOG(ERROR) << frame()->view()->mainThreadScrollingReasons(); |
| 941 Element* element = frame()->document()->getElementById("scrollable"); |
| 942 ASSERT_TRUE(element); |
| 943 |
| 944 LayoutObject* layoutObject = element->layoutObject(); |
| 945 ASSERT_TRUE(layoutObject); |
| 946 |
| 947 GraphicsLayer* scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 948 ASSERT_TRUE(scrollLayer); |
| 949 |
| 950 WebLayer* webScrollLayer = scrollLayer->platformLayer(); |
| 951 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 952 ASSERT_FALSE( |
| 953 webScrollLayer->mainThreadScrollingReasons() & |
| 954 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 955 |
| 956 Element* iframe = frame()->document()->getElementById("iframe"); |
| 957 ASSERT_TRUE(iframe); |
| 958 |
| 959 layoutObject = iframe->layoutObject(); |
| 960 ASSERT_TRUE(layoutObject); |
| 961 |
| 962 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 963 ASSERT_TRUE(scrollLayer); |
| 964 |
| 965 webScrollLayer = scrollLayer->platformLayer(); |
| 966 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 967 ASSERT_FALSE( |
| 968 webScrollLayer->mainThreadScrollingReasons() & |
| 969 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 970 |
| 971 // When the div becomes to scrollable it should scroll on main thread |
| 972 element->setAttribute("style", |
| 973 "overflow:scroll;height:2000px;will-change:transform;", |
| 974 ASSERT_NO_EXCEPTION); |
| 975 forceFullCompositingUpdate(); |
| 976 |
| 977 layoutObject = element->layoutObject(); |
| 978 ASSERT_TRUE(layoutObject); |
| 979 |
| 980 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 981 ASSERT_TRUE(scrollLayer); |
| 982 |
| 983 webScrollLayer = scrollLayer->platformLayer(); |
| 984 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 985 ASSERT_TRUE( |
| 986 webScrollLayer->mainThreadScrollingReasons() & |
| 987 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 988 |
| 989 layoutObject = iframe->layoutObject(); |
| 990 ASSERT_TRUE(layoutObject); |
| 991 |
| 992 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 993 ASSERT_TRUE(scrollLayer); |
| 994 |
| 995 webScrollLayer = scrollLayer->platformLayer(); |
| 996 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 997 ASSERT_TRUE( |
| 998 webScrollLayer->mainThreadScrollingReasons() & |
| 999 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 1000 |
| 1001 // The main thread scrolling reason should be reset upon the following change |
| 1002 element->setAttribute("style", |
| 1003 "overflow:scroll;height:200px;will-change:transform;", |
| 1004 ASSERT_NO_EXCEPTION); |
| 1005 forceFullCompositingUpdate(); |
| 1006 |
| 1007 layoutObject = element->layoutObject(); |
| 1008 ASSERT_TRUE(layoutObject); |
| 1009 |
| 1010 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 1011 ASSERT_TRUE(scrollLayer); |
| 1012 |
| 1013 webScrollLayer = scrollLayer->platformLayer(); |
| 1014 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 1015 ASSERT_FALSE( |
| 1016 webScrollLayer->mainThreadScrollingReasons() & |
| 1017 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 1018 |
| 1019 layoutObject = iframe->layoutObject(); |
| 1020 ASSERT_TRUE(layoutObject); |
| 1021 |
| 1022 scrollLayer = layoutObject->frameView()->layerForScrolling(); |
| 1023 ASSERT_TRUE(scrollLayer); |
| 1024 |
| 1025 webScrollLayer = scrollLayer->platformLayer(); |
| 1026 ASSERT_TRUE(webScrollLayer->scrollable()); |
| 1027 ASSERT_FALSE( |
| 1028 webScrollLayer->mainThreadScrollingReasons() & |
| 1029 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
| 1030 } |
| 1031 |
852 } // namespace blink | 1032 } // namespace blink |
OLD | NEW |