Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintLayerTest.cpp

Issue 2716583005: Do not promote position sticky or fixed elements unless they move with scroll. (Closed)
Patch Set: Create a stacking context for sticky. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/PaintLayer.h" 5 #include "core/paint/PaintLayer.h"
6 6
7 #include "core/html/HTMLIFrameElement.h" 7 #include "core/html/HTMLIFrameElement.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/layout/LayoutView.h" 10 #include "core/layout/LayoutView.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 EXPECT_EQ( 109 EXPECT_EQ(
110 LayoutRect(90, 40, 110, 243), 110 LayoutRect(90, 40, 110, 243),
111 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0)); 111 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0));
112 } 112 }
113 113
114 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) { 114 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) {
115 setBodyInnerHTML("<div id='target' style='position: relative'></div>"); 115 setBodyInnerHTML("<div id='target' style='position: relative'></div>");
116 116
117 PaintLayer* layer = 117 PaintLayer* layer =
118 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 118 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
119 EXPECT_FALSE(layer->sticksToViewport()); 119 EXPECT_FALSE(layer->fixedToViewport());
120 } 120 }
121 121
122 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) { 122 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) {
123 setBodyInnerHTML("<div id='target' style='position: fixed'></div>"); 123 setBodyInnerHTML("<div id='target' style='position: fixed'></div>");
124 124
125 PaintLayer* layer = 125 PaintLayer* layer =
126 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 126 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
127 EXPECT_TRUE(layer->sticksToViewport()); 127 EXPECT_TRUE(layer->fixedToViewport());
128 } 128 }
129 129
130 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) { 130 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) {
131 // We don't intend to launch SPv2 without root layer scrolling, so skip this 131 // We don't intend to launch SPv2 without root layer scrolling, so skip this
132 // test in that configuration because it's broken. 132 // test in that configuration because it's broken.
133 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && 133 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() &&
134 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 134 !RuntimeEnabledFeatures::rootLayerScrollingEnabled())
135 return; 135 return;
136 setBodyInnerHTML( 136 setBodyInnerHTML(
137 "<div style='transform: translateZ(0)'>" 137 "<div style='transform: translateZ(0)'>"
138 " <div id='target' style='position: fixed'></div>" 138 " <div id='target' style='position: fixed'></div>"
139 "</div>" 139 "</div>"
140 "<div style='width: 10px; height: 1000px'></div>"); 140 "<div style='width: 10px; height: 1000px'></div>");
141 PaintLayer* layer = 141 PaintLayer* layer =
142 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 142 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
143 EXPECT_FALSE(layer->sticksToViewport()); 143 EXPECT_FALSE(layer->fixedToViewport());
144 } 144 }
145 145
146 TEST_P(PaintLayerTest, 146 TEST_P(PaintLayerTest,
147 ScrollsWithViewportFixedPositionInsideTransformNoScroll) { 147 ScrollsWithViewportFixedPositionInsideTransformNoScroll) {
148 setBodyInnerHTML( 148 setBodyInnerHTML(
149 "<div style='transform: translateZ(0)'>" 149 "<div style='transform: translateZ(0)'>"
150 " <div id='target' style='position: fixed'></div>" 150 " <div id='target' style='position: fixed'></div>"
151 "</div>"); 151 "</div>");
152 PaintLayer* layer = 152 PaintLayer* layer =
153 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 153 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
154 154
155 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all, 155 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all,
156 // and so return true. 156 // and so return true.
157 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 157 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
158 EXPECT_TRUE(layer->sticksToViewport()); 158 EXPECT_TRUE(layer->fixedToViewport());
159 else 159 else
160 EXPECT_FALSE(layer->sticksToViewport()); 160 EXPECT_FALSE(layer->fixedToViewport());
161 } 161 }
162 162
163 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPosition) { 163 TEST_P(PaintLayerTest, SticksToScrollerStickyPosition) {
164 setBodyInnerHTML(
165 "<div style='transform: translateZ(0)'>"
166 " <div id='target' style='position: sticky; top: 0;'></div>"
167 "</div>"
168 "<div style='width: 10px; height: 1000px'></div>");
169
170 PaintLayer* layer =
171 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
172 EXPECT_TRUE(layer->sticksToScroller());
173 }
174
175 TEST_P(PaintLayerTest, SticksToScrollerNoAnchor) {
164 setBodyInnerHTML( 176 setBodyInnerHTML(
165 "<div style='transform: translateZ(0)'>" 177 "<div style='transform: translateZ(0)'>"
166 " <div id='target' style='position: sticky'></div>" 178 " <div id='target' style='position: sticky'></div>"
167 "</div>" 179 "</div>"
168 "<div style='width: 10px; height: 1000px'></div>"); 180 "<div style='width: 10px; height: 1000px'></div>");
169 181
170 PaintLayer* layer = 182 PaintLayer* layer =
171 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 183 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
172 EXPECT_TRUE(layer->sticksToViewport()); 184 EXPECT_FALSE(layer->sticksToScroller());
173 } 185 }
174 186
175 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionNoScroll) { 187 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionNoScroll) {
176 setBodyInnerHTML( 188 setBodyInnerHTML(
177 "<div style='transform: translateZ(0)'>" 189 "<div style='transform: translateZ(0)'>"
178 " <div id='target' style='position: sticky'></div>" 190 " <div id='target' style='position: sticky; top: 0;'></div>"
179 "</div>"); 191 "</div>");
180 192
181 PaintLayer* layer = 193 PaintLayer* layer =
182 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 194 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
183 EXPECT_TRUE(layer->sticksToViewport()); 195 EXPECT_TRUE(layer->sticksToScroller());
184 } 196 }
185 197
186 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionInsideScroller) { 198 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionInsideScroller) {
187 setBodyInnerHTML( 199 setBodyInnerHTML(
188 "<div style='overflow:scroll; width: 100px; height: 100px;'>" 200 "<div style='overflow:scroll; width: 100px; height: 100px;'>"
189 " <div id='target' style='position: sticky'></div>" 201 " <div id='target' style='position: sticky; top: 0;'></div>"
190 " <div style='width: 50px; height: 1000px;'></div>" 202 " <div style='width: 50px; height: 1000px;'></div>"
191 "</div>"); 203 "</div>");
192 204
193 PaintLayer* layer = 205 PaintLayer* layer =
194 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 206 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
195 EXPECT_FALSE(layer->sticksToViewport()); 207 EXPECT_TRUE(layer->sticksToScroller());
196 } 208 }
197 209
198 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) { 210 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) {
199 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 211 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
200 return; 212 return;
201 213
202 enableCompositing(); 214 enableCompositing();
203 setBodyInnerHTML( 215 setBodyInnerHTML(
204 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;" 216 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;"
205 " will-change: transform'>" 217 " will-change: transform'>"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location()); 736 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location());
725 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location()); 737 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location());
726 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100) 738 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100)
727 // 20 = y-location(100) - column-height(80) 739 // 20 = y-location(100) - column-height(80)
728 EXPECT_EQ(LayoutPoint(-60, 20), 740 EXPECT_EQ(LayoutPoint(-60, 20),
729 extraLayer->visualOffsetFromAncestor(columns)); 741 extraLayer->visualOffsetFromAncestor(columns));
730 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns)); 742 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns));
731 } 743 }
732 744
733 } // namespace blink 745 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698