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

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: 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_EQ( 100 EXPECT_EQ(
101 LayoutRect(90, 40, 110, 243), 101 LayoutRect(90, 40, 110, 243),
102 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0)); 102 layer->paintingExtent(document().layoutView()->layer(), LayoutSize(), 0));
103 } 103 }
104 104
105 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) { 105 TEST_P(PaintLayerTest, ScrollsWithViewportRelativePosition) {
106 setBodyInnerHTML("<div id='target' style='position: relative'></div>"); 106 setBodyInnerHTML("<div id='target' style='position: relative'></div>");
107 107
108 PaintLayer* layer = 108 PaintLayer* layer =
109 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 109 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
110 EXPECT_FALSE(layer->sticksToViewport()); 110 EXPECT_FALSE(layer->fixedToViewport());
111 } 111 }
112 112
113 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) { 113 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPosition) {
114 setBodyInnerHTML("<div id='target' style='position: fixed'></div>"); 114 setBodyInnerHTML("<div id='target' style='position: fixed'></div>");
115 115
116 PaintLayer* layer = 116 PaintLayer* layer =
117 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 117 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
118 EXPECT_TRUE(layer->sticksToViewport()); 118 EXPECT_TRUE(layer->fixedToViewport());
119 } 119 }
120 120
121 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) { 121 TEST_P(PaintLayerTest, ScrollsWithViewportFixedPositionInsideTransform) {
122 // We don't intend to launch SPv2 without root layer scrolling, so skip this 122 // We don't intend to launch SPv2 without root layer scrolling, so skip this
123 // test in that configuration because it's broken. 123 // test in that configuration because it's broken.
124 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && 124 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() &&
125 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 125 !RuntimeEnabledFeatures::rootLayerScrollingEnabled())
126 return; 126 return;
127 setBodyInnerHTML( 127 setBodyInnerHTML(
128 "<div style='transform: translateZ(0)'>" 128 "<div style='transform: translateZ(0)'>"
129 " <div id='target' style='position: fixed'></div>" 129 " <div id='target' style='position: fixed'></div>"
130 "</div>" 130 "</div>"
131 "<div style='width: 10px; height: 1000px'></div>"); 131 "<div style='width: 10px; height: 1000px'></div>");
132 PaintLayer* layer = 132 PaintLayer* layer =
133 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 133 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
134 EXPECT_FALSE(layer->sticksToViewport()); 134 EXPECT_FALSE(layer->fixedToViewport());
135 } 135 }
136 136
137 TEST_P(PaintLayerTest, 137 TEST_P(PaintLayerTest,
138 ScrollsWithViewportFixedPositionInsideTransformNoScroll) { 138 ScrollsWithViewportFixedPositionInsideTransformNoScroll) {
139 setBodyInnerHTML( 139 setBodyInnerHTML(
140 "<div style='transform: translateZ(0)'>" 140 "<div style='transform: translateZ(0)'>"
141 " <div id='target' style='position: fixed'></div>" 141 " <div id='target' style='position: fixed'></div>"
142 "</div>"); 142 "</div>");
143 PaintLayer* layer = 143 PaintLayer* layer =
144 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 144 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
145 145
146 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all, 146 // In SPv2 mode, we correctly determine that the frame doesn't scroll at all,
147 // and so return true. 147 // and so return true.
148 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 148 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
149 EXPECT_TRUE(layer->sticksToViewport()); 149 EXPECT_TRUE(layer->fixedToViewport());
150 else 150 else
151 EXPECT_FALSE(layer->sticksToViewport()); 151 EXPECT_FALSE(layer->fixedToViewport());
152 } 152 }
153 153
154 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPosition) { 154 TEST_P(PaintLayerTest, SticksToScrollerStickyPosition) {
155 setBodyInnerHTML(
156 "<div style='transform: translateZ(0)'>"
157 " <div id='target' style='position: sticky; top: 0;'></div>"
158 "</div>"
159 "<div style='width: 10px; height: 1000px'></div>");
160
161 PaintLayer* layer =
162 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
163 EXPECT_TRUE(layer->sticksToScroller());
164 }
165
166 TEST_P(PaintLayerTest, SticksToScrollerNoAnchor) {
155 setBodyInnerHTML( 167 setBodyInnerHTML(
156 "<div style='transform: translateZ(0)'>" 168 "<div style='transform: translateZ(0)'>"
157 " <div id='target' style='position: sticky'></div>" 169 " <div id='target' style='position: sticky'></div>"
158 "</div>" 170 "</div>"
159 "<div style='width: 10px; height: 1000px'></div>"); 171 "<div style='width: 10px; height: 1000px'></div>");
160 172
161 PaintLayer* layer = 173 PaintLayer* layer =
162 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 174 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
163 EXPECT_TRUE(layer->sticksToViewport()); 175 EXPECT_FALSE(layer->sticksToScroller());
164 } 176 }
165 177
166 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionNoScroll) { 178 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionNoScroll) {
167 setBodyInnerHTML( 179 setBodyInnerHTML(
168 "<div style='transform: translateZ(0)'>" 180 "<div style='transform: translateZ(0)'>"
169 " <div id='target' style='position: sticky'></div>" 181 " <div id='target' style='position: sticky; top: 0;'></div>"
170 "</div>"); 182 "</div>");
171 183
172 PaintLayer* layer = 184 PaintLayer* layer =
173 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 185 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
174 EXPECT_TRUE(layer->sticksToViewport()); 186 EXPECT_TRUE(layer->sticksToScroller());
175 } 187 }
176 188
177 TEST_P(PaintLayerTest, ScrollsWithViewportStickyPositionInsideScroller) { 189 TEST_P(PaintLayerTest, SticksToScrollerStickyPositionInsideScroller) {
178 setBodyInnerHTML( 190 setBodyInnerHTML(
179 "<div style='overflow:scroll; width: 100px; height: 100px;'>" 191 "<div style='overflow:scroll; width: 100px; height: 100px;'>"
180 " <div id='target' style='position: sticky'></div>" 192 " <div id='target' style='position: sticky; top: 0;'></div>"
181 " <div style='width: 50px; height: 1000px;'></div>" 193 " <div style='width: 50px; height: 1000px;'></div>"
182 "</div>"); 194 "</div>");
183 195
184 PaintLayer* layer = 196 PaintLayer* layer =
185 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 197 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
186 EXPECT_FALSE(layer->sticksToViewport()); 198 EXPECT_TRUE(layer->sticksToScroller());
187 } 199 }
188 200
189 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) { 201 TEST_P(PaintLayerTest, CompositedScrollingNoNeedsRepaint) {
190 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) 202 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
191 return; 203 return;
192 204
193 enableCompositing(); 205 enableCompositing();
194 setBodyInnerHTML( 206 setBodyInnerHTML(
195 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;" 207 "<div id='scroll' style='width: 100px; height: 100px; overflow: scroll;"
196 " will-change: transform'>" 208 " will-change: transform'>"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location()); 727 EXPECT_EQ(LayoutPoint(-150, 50), spanner->location());
716 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location()); 728 EXPECT_EQ(LayoutPoint(100, 100), extraLayer->location());
717 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100) 729 // -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100)
718 // 20 = y-location(100) - column-height(80) 730 // 20 = y-location(100) - column-height(80)
719 EXPECT_EQ(LayoutPoint(-60, 20), 731 EXPECT_EQ(LayoutPoint(-60, 20),
720 extraLayer->visualOffsetFromAncestor(columns)); 732 extraLayer->visualOffsetFromAncestor(columns));
721 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns)); 733 EXPECT_EQ(LayoutPoint(-150, 50), spanner->visualOffsetFromAncestor(columns));
722 } 734 }
723 735
724 } // namespace blink 736 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698