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 "core/paint/PaintLayerScrollableArea.h" | 5 #include "core/paint/PaintLayerScrollableArea.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "core/layout/LayoutBoxModelObject.h" | 8 #include "core/layout/LayoutBoxModelObject.h" |
9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
10 #include "core/paint/PaintLayer.h" | 10 #include "core/paint/PaintLayer.h" |
11 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
12 #include "platform/scroll/ScrollTypes.h" | 12 #include "platform/scroll/ScrollTypes.h" |
13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class PaintLayerScrollableAreaTest : public RenderingTest { | 17 class PaintLayerScrollableAreaTest : public RenderingTest { |
18 public: | 18 public: |
19 PaintLayerScrollableAreaTest() | 19 PaintLayerScrollableAreaTest() |
20 : RenderingTest(EmptyFrameLoaderClient::create()) {} | 20 : RenderingTest(EmptyFrameLoaderClient::create()) {} |
21 | 21 |
22 bool canPaintBackgroundOntoScrollingContentsLayer(const char* elementId) { | 22 BackgroundPaintLocation backgroundPaintLocation(const char* elementId) { |
23 PaintLayer* paintLayer = | 23 PaintLayer* paintLayer = |
24 toLayoutBoxModelObject(getLayoutObjectByElementId(elementId))->layer(); | 24 toLayoutBoxModelObject(getLayoutObjectByElementId(elementId))->layer(); |
25 return paintLayer->canPaintBackgroundOntoScrollingContentsLayer(); | 25 return paintLayer->backgroundPaintLocation(); |
26 } | 26 } |
27 | 27 |
28 private: | 28 private: |
29 void SetUp() override { | 29 void SetUp() override { |
30 RenderingTest::SetUp(); | 30 RenderingTest::SetUp(); |
31 enableCompositing(); | 31 enableCompositing(); |
32 } | 32 } |
33 }; | 33 }; |
34 | 34 |
35 TEST_F(PaintLayerScrollableAreaTest, | 35 TEST_F(PaintLayerScrollableAreaTest, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 "content-box; padding: 10px;'><div class='spacer'></div></div>" | 76 "content-box; padding: 10px;'><div class='spacer'></div></div>" |
77 "<div id='scroller13' class='scroller' style='background: white " | 77 "<div id='scroller13' class='scroller' style='background: white " |
78 "border-box;'><div class='spacer'></div></div>" | 78 "border-box;'><div class='spacer'></div></div>" |
79 "<div id='scroller14' class='scroller' style='background: white; border: " | 79 "<div id='scroller14' class='scroller' style='background: white; border: " |
80 "1px solid black; outline: 1px solid blue; outline-offset: -1px;'><div " | 80 "1px solid black; outline: 1px solid blue; outline-offset: -1px;'><div " |
81 "class='spacer'></div></div>" | 81 "class='spacer'></div></div>" |
82 "<div id='scroller15' class='scroller' style='background: white; border: " | 82 "<div id='scroller15' class='scroller' style='background: white; border: " |
83 "1px solid black; outline: 1px solid blue; outline-offset: -2px;'><div " | 83 "1px solid black; outline: 1px solid blue; outline-offset: -2px;'><div " |
84 "class='spacer'></div></div>" | 84 "class='spacer'></div></div>" |
85 "<div id='scroller16' class='scroller' style='background: white; clip: " | 85 "<div id='scroller16' class='scroller' style='background: white; clip: " |
86 "rect(0px,10px,10px,0px);'><div class='spacer'></div></div>"); | 86 "rect(0px,10px,10px,0px);'><div class='spacer'></div></div>" |
| 87 "<div id='scroller17' class='scroller' style='background:" |
| 88 "rgba(255, 255, 255, 0.5) border-box; border: 5px solid " |
| 89 "rgba(0, 0, 0, 0.5);'><div class='spacer'></div></div>"); |
87 | 90 |
88 // #scroller1 cannot paint background into scrolling contents layer because it | 91 // #scroller1 cannot paint background into scrolling contents layer because it |
89 // has a negative z-index child. | 92 // has a negative z-index child. |
90 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller1")); | 93 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 94 backgroundPaintLocation("scroller1")); |
91 | 95 |
92 // #scroller2 cannot paint background into scrolling contents layer because it | 96 // #scroller2 cannot paint background into scrolling contents layer because it |
93 // has a content-box clip without local attachment. | 97 // has a content-box clip without local attachment. |
94 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller2")); | 98 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 99 backgroundPaintLocation("scroller2")); |
95 | 100 |
96 // #scroller3 can paint background into scrolling contents layer. | 101 // #scroller3 can paint background into scrolling contents layer. |
97 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller3")); | 102 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 103 backgroundPaintLocation("scroller3")); |
98 | 104 |
99 // #scroller4 cannot paint background into scrolling contents layer because | 105 // #scroller4 cannot paint background into scrolling contents layer because |
100 // the background image is not locally attached. | 106 // the background image is not locally attached. |
101 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller4")); | 107 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 108 backgroundPaintLocation("scroller4")); |
102 | 109 |
103 // #scroller5 can paint background into scrolling contents layer because both | 110 // #scroller5 can paint background into scrolling contents layer because both |
104 // the image and color are locally attached. | 111 // the image and color are locally attached. |
105 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller5")); | 112 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 113 backgroundPaintLocation("scroller5")); |
106 | 114 |
107 // #scroller6 can paint background into scrolling contents layer because the | 115 // #scroller6 can paint background into scrolling contents layer because the |
108 // image is locally attached and even though the color is not, it is filled to | 116 // image is locally attached and even though the color is not, it is filled to |
109 // the padding box so it will be drawn the same as a locally attached | 117 // the padding box so it will be drawn the same as a locally attached |
110 // background. | 118 // background. |
111 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller6")); | 119 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 120 backgroundPaintLocation("scroller6")); |
112 | 121 |
113 // #scroller7 cannot paint background into scrolling contents layer because | 122 // #scroller7 cannot paint background into scrolling contents layer because |
114 // the color is filled to the content box and we have padding so it is not | 123 // the color is filled to the content box and we have padding so it is not |
115 // equivalent to a locally attached background. | 124 // equivalent to a locally attached background. |
116 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller7")); | 125 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 126 backgroundPaintLocation("scroller7")); |
117 | 127 |
118 // #scroller8 can paint background into scrolling contents layer because its | 128 // #scroller8 can paint background into scrolling contents layer because its |
119 // border-box is equivalent to its padding box since it has no border. | 129 // border-box is equivalent to its padding box since it has no border. |
120 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller8")); | 130 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 131 backgroundPaintLocation("scroller8")); |
121 | 132 |
122 // #scroller9 can paint background into scrolling contents layer because its | 133 // #scroller9 can paint background into scrolling contents layer because its |
123 // border is opaque so it completely covers the background outside of the | 134 // border is opaque so it completely covers the background outside of the |
124 // padding-box. | 135 // padding-box. |
125 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller9")); | 136 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 137 backgroundPaintLocation("scroller9")); |
126 | 138 |
127 // #scroller10 cannot paint background into scrolling contents layer because | 139 // #scroller10 paints the background into both layers because its border is |
128 // its border is partially transparent so the background must be drawn to the | 140 // partially transparent so the background must be drawn to the |
129 // border-box edges. | 141 // border-box edges. |
130 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller10")); | 142 EXPECT_EQ(BackgroundPaintInGraphicsLayer | BackgroundPaintInScrollingContents, |
| 143 backgroundPaintLocation("scroller10")); |
131 | 144 |
132 // #scroller11 can paint background into scrolling contents layer because its | 145 // #scroller11 can paint background into scrolling contents layer because its |
133 // content-box is equivalent to its padding box since it has no padding. | 146 // content-box is equivalent to its padding box since it has no padding. |
134 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller11")); | 147 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 148 backgroundPaintLocation("scroller11")); |
135 | 149 |
136 // #scroller12 cannot paint background into scrolling contents layer because | 150 // #scroller12 cannot paint background into scrolling contents layer because |
137 // it has padding so its content-box is not equivalent to its padding-box. | 151 // it has padding so its content-box is not equivalent to its padding-box. |
138 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller12")); | 152 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 153 backgroundPaintLocation("scroller12")); |
139 | 154 |
140 // #scroller13 cannot paint background into scrolling contents layer because | 155 // #scroller13 paints the background into both layers because it has a custom |
141 // it has a custom scrollbar which the background may need to draw under. | 156 // scrollbar which the background may need to draw under. |
142 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller13")); | 157 EXPECT_EQ(BackgroundPaintInGraphicsLayer | BackgroundPaintInScrollingContents, |
| 158 backgroundPaintLocation("scroller13")); |
143 | 159 |
144 // #scroller14 can paint background into scrolling contents layer because the | 160 // #scroller14 can paint background into scrolling contents layer because the |
145 // outline is drawn outside the padding box. | 161 // outline is drawn outside the padding box. |
146 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller14")); | 162 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 163 backgroundPaintLocation("scroller14")); |
147 | 164 |
148 // #scroller15 can paint background into scrolling contents layer because | 165 // #scroller15 can paint background into scrolling contents layer because |
149 // the outline is drawn into the decoration layer which will not be covered | 166 // the outline is drawn into the decoration layer which will not be covered |
150 // up. | 167 // up. |
151 EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller15")); | 168 EXPECT_EQ(BackgroundPaintInScrollingContents, |
| 169 backgroundPaintLocation("scroller15")); |
152 | 170 |
153 // #scroller16 cannot paint background into scrolling contents layer because | 171 // #scroller16 cannot paint background into scrolling contents layer because |
154 // the scroller has a clip which would not be respected by the scrolling | 172 // the scroller has a clip which would not be respected by the scrolling |
155 // contents layer. | 173 // contents layer. |
156 EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller16")); | 174 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 175 backgroundPaintLocation("scroller16")); |
| 176 |
| 177 // #scroller17 can only be painted once as it is translucent, and it must |
| 178 // be painted in the graphics layer to be under the translucent border. |
| 179 EXPECT_EQ(BackgroundPaintInGraphicsLayer, |
| 180 backgroundPaintLocation("scroller17")); |
157 } | 181 } |
158 | 182 |
159 TEST_F(PaintLayerScrollableAreaTest, OpaqueContainedLayersPromoted) { | 183 TEST_F(PaintLayerScrollableAreaTest, OpaqueContainedLayersPromoted) { |
160 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true); | 184 RuntimeEnabledFeatures::setCompositeOpaqueScrollersEnabled(true); |
161 | 185 |
162 setBodyInnerHTML( | 186 setBodyInnerHTML( |
163 "<style>" | 187 "<style>" |
164 "#scroller { overflow: scroll; height: 200px; width: 200px; " | 188 "#scroller { overflow: scroll; height: 200px; width: 200px; " |
165 "contain: paint; background: white local content-box; " | 189 "contain: paint; background: white local content-box; " |
166 "border: 10px solid rgba(0, 255, 0, 0.5); }" | 190 "border: 10px solid rgba(0, 255, 0, 0.5); }" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 ASSERT_TRUE(blackLayer); | 456 ASSERT_TRUE(blackLayer); |
433 | 457 |
434 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeDark, | 458 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeDark, |
435 noneLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); | 459 noneLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); |
436 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeDark, | 460 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeDark, |
437 whiteLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); | 461 whiteLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); |
438 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeLight, | 462 ASSERT_EQ(ScrollbarOverlayColorTheme::ScrollbarOverlayColorThemeLight, |
439 blackLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); | 463 blackLayer->getScrollableArea()->getScrollbarOverlayColorTheme()); |
440 } | 464 } |
441 } | 465 } |
OLD | NEW |