OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/frame/FrameView.h" | 5 #include "core/frame/FrameView.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 TEST_P(FrameViewTest, StyleChangeUpdatesViewportConstrainedObjects) { | 173 TEST_P(FrameViewTest, StyleChangeUpdatesViewportConstrainedObjects) { |
174 // When using root layer scrolling there is no concept of viewport constrained | 174 // When using root layer scrolling there is no concept of viewport constrained |
175 // objects, so skip this test. | 175 // objects, so skip this test. |
176 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 176 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
177 return; | 177 return; |
178 | 178 |
179 GetDocument().body()->setInnerHTML( | 179 GetDocument().body()->setInnerHTML( |
180 "<style>.container { height: 200%; }" | 180 "<style>.container { height: 200%; }" |
181 "#sticky { position: sticky; top: 0; height: 50px; }</style>" | 181 "#sticky1 { position: sticky; top: 0; height: 50px; }" |
182 "<div class='container'><div id='sticky'></div></div>"); | 182 "#sticky2 { position: sticky; height: 50px; }</style>" |
| 183 "<div class='container'>" |
| 184 " <div id='sticky1'></div>" |
| 185 " <div id='sticky2'></div>" |
| 186 "</div>"); |
183 GetDocument().View()->UpdateAllLifecyclePhases(); | 187 GetDocument().View()->UpdateAllLifecyclePhases(); |
184 | 188 |
185 LayoutBoxModelObject* sticky = ToLayoutBoxModelObject( | 189 LayoutBoxModelObject* sticky1 = ToLayoutBoxModelObject( |
186 GetDocument().GetElementById("sticky")->GetLayoutObject()); | 190 GetDocument().GetElementById("sticky1")->GetLayoutObject()); |
| 191 LayoutBoxModelObject* sticky2 = ToLayoutBoxModelObject( |
| 192 GetDocument().GetElementById("sticky2")->GetLayoutObject()); |
187 | 193 |
188 EXPECT_TRUE( | 194 EXPECT_TRUE( |
189 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky)); | 195 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky1)); |
| 196 // #sticky2 is not viewport constrained because it has no anchor edges. |
| 197 EXPECT_FALSE( |
| 198 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky2)); |
190 | 199 |
191 // Making the element non-sticky should remove it from the set of | 200 // Making the element non-sticky should remove it from the set of |
192 // viewport-constrained objects. | 201 // viewport-constrained objects. |
193 GetDocument().GetElementById("sticky")->setAttribute(HTMLNames::styleAttr, | 202 GetDocument().GetElementById("sticky1")->setAttribute(HTMLNames::styleAttr, |
194 "position: relative"); | 203 "position: relative"); |
195 GetDocument().View()->UpdateAllLifecyclePhases(); | 204 GetDocument().View()->UpdateAllLifecyclePhases(); |
196 | 205 |
197 EXPECT_FALSE( | 206 EXPECT_FALSE( |
198 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky)); | 207 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky1)); |
199 | 208 |
200 // And making it sticky again should put it back in that list. | 209 // And making it sticky again should put it back in that list. |
201 GetDocument().GetElementById("sticky")->setAttribute(HTMLNames::styleAttr, | 210 GetDocument().GetElementById("sticky1")->setAttribute(HTMLNames::styleAttr, |
202 ""); | 211 ""); |
203 GetDocument().View()->UpdateAllLifecyclePhases(); | 212 GetDocument().View()->UpdateAllLifecyclePhases(); |
204 | 213 |
205 EXPECT_TRUE( | 214 EXPECT_TRUE( |
206 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky)); | 215 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky1)); |
| 216 |
| 217 // Adding an anchor edge on the non-anchored sticky should add it to the |
| 218 // viewport-constrained objects. |
| 219 GetDocument().GetElementById("sticky2")->setAttribute(HTMLNames::styleAttr, |
| 220 "top: 0"); |
| 221 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 222 |
| 223 EXPECT_TRUE( |
| 224 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky2)); |
| 225 |
| 226 // Removing the anchor edge on a sticky position element should remove it from |
| 227 // the viewport-constrained objects. |
| 228 GetDocument().GetElementById("sticky2")->setAttribute(HTMLNames::styleAttr, |
| 229 ""); |
| 230 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 231 |
| 232 EXPECT_FALSE( |
| 233 GetDocument().View()->ViewportConstrainedObjects()->Contains(sticky2)); |
207 } | 234 } |
208 | 235 |
209 } // namespace | 236 } // namespace |
210 } // namespace blink | 237 } // namespace blink |
OLD | NEW |