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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp

Issue 2776643002: Walk the container chain to correctly find nested inline sticky ancestors. (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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/layout/LayoutBoxModelObject.h" 5 #include "core/layout/LayoutBoxModelObject.h"
6 6
7 #include "core/dom/DOMTokenList.h" 7 #include "core/dom/DOMTokenList.h"
8 #include "core/dom/DocumentLifecycle.h" 8 #include "core/dom/DocumentLifecycle.h"
9 #include "core/html/HTMLElement.h" 9 #include "core/html/HTMLElement.h"
10 #include "core/layout/ImageQualityController.h" 10 #include "core/layout/ImageQualityController.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // 334 //
335 // In most cases, this pointer should be null since your parent is normally your 335 // In most cases, this pointer should be null since your parent is normally your
336 // containing block. However there are cases where this is not true, including 336 // containing block. However there are cases where this is not true, including
337 // inline blocks and tables. The latter is currently irrelevant since only table 337 // inline blocks and tables. The latter is currently irrelevant since only table
338 // cells can be sticky in CSS2.1, but we can test the former. 338 // cells can be sticky in CSS2.1, but we can test the former.
339 TEST_F(LayoutBoxModelObjectTest, 339 TEST_F(LayoutBoxModelObjectTest,
340 StickyPositionFindsCorrectStickyBoxShiftingAncestor) { 340 StickyPositionFindsCorrectStickyBoxShiftingAncestor) {
341 setBodyInnerHTML( 341 setBodyInnerHTML(
342 "<style>#stickyOuterDiv { position: sticky; }" 342 "<style>#stickyOuterDiv { position: sticky; }"
343 "#stickyOuterInline { position: sticky; display: inline; }" 343 "#stickyOuterInline { position: sticky; display: inline; }"
344 "#stickyInnerInline { position: sticky; display: inline; }</style>" 344 "#stickyInnerInline { position: sticky; display: inline; }"
345 "<div id='stickyOuterDiv'><div id='stickyOuterInline'>" 345 ".inline { display: inline; }</style>"
346 "<div id='stickyInnerInline'></div></div></div>"); 346 "<div id='stickyOuterDiv'>"
347 " <div id='stickyOuterInline'>"
348 " <div class='inline'>"
349 " <div id='stickyInnerInline'></div>"
350 " </div>"
351 " </div>"
352 "</div>");
347 353
348 LayoutBoxModelObject* stickyOuterDiv = 354 LayoutBoxModelObject* stickyOuterDiv =
349 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyOuterDiv")); 355 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyOuterDiv"));
350 LayoutBoxModelObject* stickyOuterInline = 356 LayoutBoxModelObject* stickyOuterInline =
351 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyOuterInline")); 357 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyOuterInline"));
352 LayoutBoxModelObject* stickyInnerInline = 358 LayoutBoxModelObject* stickyInnerInline =
353 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyInnerInline")); 359 toLayoutBoxModelObject(getLayoutObjectByElementId("stickyInnerInline"));
354 360
355 PaintLayerScrollableArea* scrollableArea = 361 PaintLayerScrollableArea* scrollableArea =
356 stickyOuterDiv->layer()->ancestorOverflowLayer()->getScrollableArea(); 362 stickyOuterDiv->layer()->ancestorOverflowLayer()->getScrollableArea();
357 ASSERT_TRUE(scrollableArea); 363 ASSERT_TRUE(scrollableArea);
358 StickyConstraintsMap constraintsMap = scrollableArea->stickyConstraintsMap(); 364 StickyConstraintsMap constraintsMap = scrollableArea->stickyConstraintsMap();
359 365
360 ASSERT_TRUE(constraintsMap.contains(stickyOuterDiv->layer())); 366 ASSERT_TRUE(constraintsMap.contains(stickyOuterDiv->layer()));
361 ASSERT_TRUE(constraintsMap.contains(stickyOuterInline->layer())); 367 ASSERT_TRUE(constraintsMap.contains(stickyOuterInline->layer()));
362 ASSERT_TRUE(constraintsMap.contains(stickyInnerInline->layer())); 368 ASSERT_TRUE(constraintsMap.contains(stickyInnerInline->layer()));
363 369
364 // The outer block element trivially has no sticky-box shifting ancestor. 370 // The outer block element trivially has no sticky-box shifting ancestor.
365 EXPECT_FALSE(constraintsMap.at(stickyOuterDiv->layer()) 371 EXPECT_FALSE(constraintsMap.at(stickyOuterDiv->layer())
366 .nearestStickyBoxShiftingStickyBox()); 372 .nearestStickyBoxShiftingStickyBox());
367 373
368 // Neither does the outer inline element, as its parent element is also its 374 // Neither does the outer inline element, as its parent element is also its
369 // containing block. 375 // containing block.
370 EXPECT_FALSE(constraintsMap.at(stickyOuterInline->layer()) 376 EXPECT_FALSE(constraintsMap.at(stickyOuterInline->layer())
371 .nearestStickyBoxShiftingStickyBox()); 377 .nearestStickyBoxShiftingStickyBox());
372 378
373 // However the inner inline element does have a sticky-box shifting ancestor, 379 // However the inner inline element does have a sticky-box shifting ancestor,
374 // as its containing block is the ancestor block element, not its parent. 380 // as its containing block is the ancestor block element, above its ancestor
381 // sticky element.
375 EXPECT_EQ(stickyOuterInline, 382 EXPECT_EQ(stickyOuterInline,
376 constraintsMap.at(stickyInnerInline->layer()) 383 constraintsMap.at(stickyInnerInline->layer())
377 .nearestStickyBoxShiftingStickyBox()); 384 .nearestStickyBoxShiftingStickyBox());
378 } 385 }
379 386
380 // Verifies that the correct containing-block shifting ancestor is found when 387 // Verifies that the correct containing-block shifting ancestor is found when
381 // computing the sticky constraints. Any such ancestor is the first sticky 388 // computing the sticky constraints. Any such ancestor is the first sticky
382 // element between your containing block (inclusive) and your ancestor overflow 389 // element between your containing block (inclusive) and your ancestor overflow
383 // layer (exclusive). 390 // layer (exclusive).
384 TEST_F(LayoutBoxModelObjectTest, 391 TEST_F(LayoutBoxModelObjectTest,
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 EXPECT_EQ(LayoutSize(0, 25), innerStickyTh->stickyPositionOffset()); 843 EXPECT_EQ(LayoutSize(0, 25), innerStickyTh->stickyPositionOffset());
837 } 844 }
838 845
839 // Verifies that the calculated position:sticky offsets are correct in the case 846 // Verifies that the calculated position:sticky offsets are correct in the case
840 // of nested inline elements. 847 // of nested inline elements.
841 TEST_F(LayoutBoxModelObjectTest, StickyPositionNestedInlineElements) { 848 TEST_F(LayoutBoxModelObjectTest, StickyPositionNestedInlineElements) {
842 setBodyInnerHTML( 849 setBodyInnerHTML(
843 "<style>#scroller { width: 100px; height: 100px; overflow-y: scroll; }" 850 "<style>#scroller { width: 100px; height: 100px; overflow-y: scroll; }"
844 "#paddingBefore { height: 50px; }" 851 "#paddingBefore { height: 50px; }"
845 "#outerInline { display: inline; position: sticky; top: 0; }" 852 "#outerInline { display: inline; position: sticky; top: 0; }"
853 ".inline {display: inline;}"
846 "#innerInline { display: inline; position: sticky; top: 25px; }" 854 "#innerInline { display: inline; position: sticky; top: 25px; }"
847 "#paddingAfter { height: 200px; }</style>" 855 "#paddingAfter { height: 200px; }</style>"
848 "<div id='scroller'><div id='paddingBefore'></div><div id='outerInline'>" 856 "<div id='scroller'>"
849 "<div id='innerInline'></div></div><div id='paddingAfter'></div></div>"); 857 " <div id='paddingBefore'></div>"
858 " <div id='outerInline'>"
859 " <div class='inline'>"
860 " <div id='innerInline'></div>"
861 " </div>"
862 " </div>"
863 " <div id='paddingAfter'></div>"
864 "</div>");
850 865
851 LayoutBoxModelObject* outerInline = 866 LayoutBoxModelObject* outerInline =
852 toLayoutBoxModelObject(getLayoutObjectByElementId("outerInline")); 867 toLayoutBoxModelObject(getLayoutObjectByElementId("outerInline"));
853 LayoutBoxModelObject* innerInline = 868 LayoutBoxModelObject* innerInline =
854 toLayoutBoxModelObject(getLayoutObjectByElementId("innerInline")); 869 toLayoutBoxModelObject(getLayoutObjectByElementId("innerInline"));
855 870
856 // Scroll the page down. 871 // Scroll the page down.
857 LayoutBoxModelObject* scroller = 872 LayoutBoxModelObject* scroller =
858 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 873 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
859 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); 874 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 920
906 // TODO(smcgruer): Until http://crbug.com/686164 is fixed, we need to update 921 // TODO(smcgruer): Until http://crbug.com/686164 is fixed, we need to update
907 // the constraints here before calculations will be correct. 922 // the constraints here before calculations will be correct.
908 innerSticky->updateStickyPositionConstraints(); 923 innerSticky->updateStickyPositionConstraints();
909 924
910 EXPECT_EQ(LayoutSize(0, 100), outerSticky->stickyPositionOffset()); 925 EXPECT_EQ(LayoutSize(0, 100), outerSticky->stickyPositionOffset());
911 EXPECT_EQ(LayoutSize(0, 25), innerSticky->stickyPositionOffset()); 926 EXPECT_EQ(LayoutSize(0, 25), innerSticky->stickyPositionOffset());
912 } 927 }
913 928
914 } // namespace blink 929 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698