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

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: Avoid computing constraints for non-anchored sticky and add/update tests. 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 EXPECT_EQ( 122 EXPECT_EQ(
123 LayoutRect(90, 40, 110, 243), 123 LayoutRect(90, 40, 110, 243),
124 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0)); 124 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0));
125 } 125 }
126 126
127 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) { 127 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) {
128 setBodyInnerHTML("<div id='target' style='position: relative'></div>"); 128 setBodyInnerHTML("<div id='target' style='position: relative'></div>");
129 129
130 PaintLayer* layer = 130 PaintLayer* layer =
131 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 131 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
132 EXPECT_FALSE(layer->sticksToViewport()); 132 EXPECT_FALSE(layer->fixedToViewport());
133 } 133 }
134 134
135 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) { 135 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) {
136 setBodyInnerHTML("<div id='target' style='position: fixed'></div>"); 136 setBodyInnerHTML("<div id='target' style='position: fixed'></div>");
137 137
138 PaintLayer* layer = 138 PaintLayer* layer =
139 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 139 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
140 EXPECT_TRUE(layer->sticksToViewport()); 140 EXPECT_TRUE(layer->fixedToViewport());
141 } 141 }
142 142
143 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) { 143 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) {
144 // We don't intend to launch SPv2 without root layer scrolling, so skip this 144 // We don't intend to launch SPv2 without root layer scrolling, so skip this
145 // test in that configuration because it's broken. 145 // test in that configuration because it's broken.
146 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && 146 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() &&
147 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 147 !RuntimeEnabledFeatures::rootLayerScrollingEnabled())
148 return; 148 return;
149 setBodyInnerHTML( 149 setBodyInnerHTML(
150 "<div style='transform: translateZ(0)'>" 150 "<div style='transform: translateZ(0)'>"
151 " <div id='target' style='position: fixed'></div>" 151 " <div id='target' style='position: fixed'></div>"
152 "</div>" 152 "</div>"
153 "<div style='width: 10px; height: 1000px'></div>"); 153 "<div style='width: 10px; height: 1000px'></div>");
154 PaintLayer* layer = 154 PaintLayer* layer =
155 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 155 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
156 EXPECT_FALSE(layer->sticksToViewport()); 156 EXPECT_FALSE(layer->fixedToViewport());
157 } 157 }
158 158
159 TEST_P(PaintLayerTest, 159 TEST_P(PaintLayerTest,
160 ScrollsWithViewportFixedPositionInsideTransformNoScroll) { 160 ScrollsWithViewportFixedPositionInsideTransformNoScroll) {
161 setBodyInnerHTML( 161 setBodyInnerHTML(
162 "<div style='transform: translateZ(0)'>" 162 "<div style='transform: translateZ(0)'>"
163 " <div id='target' style='position: fixed'></div>" 163 " <div id='target' style='position: fixed'></div>"
164 "</div>"); 164 "</div>");
165 PaintLayer* layer = 165 PaintLayer* layer =
166 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 166 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
167 167
168 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all, 168 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all,
169 // and so return true. 169 // and so return true.
170 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 170 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
171 EXPECT_TRUE(layer->sticksToViewport()); 171 EXPECT_TRUE(layer->fixedToViewport());
172 else 172 else
173 EXPECT_FALSE(layer->sticksToViewport()); 173 EXPECT_FALSE(layer->fixedToViewport());
174 } 174 }
175 175
176 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPosition) { 176 TEST_P(PaintLayerTest, SticksToScrollerStickyPosition) {
177 setBodyInnerHTML(
178 "<div style='transform: translateZ(0)'>"
179 " <div id='target' style='position: sticky; top: 0;'></div>"
180 "</div>"
181 "<div style='width: 10px; height: 1000px'></div>");
182
183 PaintLayer* layer =
184 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
185 EXPECT_TRUE(layer->sticksToScroller());
186 }
187
188 TEST_P(PaintLayerTest, SticksToScrollerNoAnchor) {
177 setBodyInnerHTML( 189 setBodyInnerHTML(
178 "<div style='transform: translateZ(0)'>" 190 "<div style='transform: translateZ(0)'>"
179 " <div id='target' style='position: sticky'></div>" 191 " <div id='target' style='position: sticky'></div>"
180 "</div>" 192 "</div>"
181 "<div style='width: 10px; height: 1000px'></div>"); 193 "<div style='width: 10px; height: 1000px'></div>");
182 194
183 PaintLayer* layer = 195 PaintLayer* layer =
184 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 196 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
185 EXPECT_TRUE(layer->sticksToViewport()); 197 EXPECT_FALSE(layer->sticksToScroller());
186 } 198 }
187 199
188 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionNoScroll) { 200 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionNoScroll) {
189 setBodyInnerHTML( 201 setBodyInnerHTML(
190 "<div style='transform: translateZ(0)'>" 202 "<div style='transform: translateZ(0)'>"
191 " <div id='target' style='position: sticky'></div>" 203 " <div id='target' style='position: sticky; top: 0;'></div>"
192 "</div>"); 204 "</div>");
193 205
194 PaintLayer* layer = 206 PaintLayer* layer =
195 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 207 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
196 EXPECT_TRUE(layer->sticksToViewport()); 208 EXPECT_TRUE(layer->sticksToScroller());
197 } 209 }
198 210
199 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionInsideScroller) { 211 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionInsideScroller) {
200 setBodyInnerHTML( 212 setBodyInnerHTML(
201 "<div style='overflow:scroll; width: 100px; height: 100px;'>" 213 "<div style='overflow:scroll; width: 100px; height: 100px;'>"
202 " <div id='target' style='position: sticky'></div>" 214 " <div id='target' style='position: sticky; top: 0;'></div>"
203 " <div style='width: 50px; height: 1000px;'></div>" 215 " <div style='width: 50px; height: 1000px;'></div>"
204 "</div>"); 216 "</div>");
205 217
206 PaintLayer* layer = 218 PaintLayer* layer =
207 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 219 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
208 EXPECT_FALSE(layer->sticksToViewport()); 220 EXPECT_TRUE(layer->sticksToScroller());
209 } 221 }
210 222
211 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) { 223 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) {
212 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 224 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
213 return; 225 return;
214 226
215 enableCompositing(); 227 enableCompositing();
216 setBodyInnerHTML( 228 setBodyInnerHTML(
217 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;" 229 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;"
218 " will-change: transform'>" 230 " will-change: transform'>"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location()); 749 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location());
738 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location()); 750 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location());
739 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100) 751 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100)
740 // 20 = y-location(100) - column-height(80) 752 // 20 = y-location(100) - column-height(80)
741 EXPECT_EQ(LayoutPoint(-60, 20), 753 EXPECT_EQ(LayoutPoint(-60, 20),
742 extraLayer->visualOffsetFromAncestor(columns)); 754 extraLayer->visualOffsetFromAncestor(columns));
743 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns)); 755 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns));
744 } 756 }
745 757
746 } // namespace blink 758 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698