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

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

Issue 2494933002: Exclude border from overflow scroller in sticky constraints. (Closed)
Patch Set: Created 4 years, 1 month 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/html/HTMLElement.h" 7 #include "core/html/HTMLElement.h"
8 #include "core/layout/ImageQualityController.h" 8 #include "core/layout/ImageQualityController.h"
9 #include "core/layout/LayoutTestHelper.h" 9 #include "core/layout/LayoutTestHelper.h"
10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" 10 #include "core/page/scrolling/StickyPositionScrollingConstraints.h"
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 }; 28 };
29 29
30 // Verifies that the sticky constraints are correctly computed. 30 // Verifies that the sticky constraints are correctly computed.
31 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) { 31 TEST_F(LayoutBoxModelObjectTest, StickyPositionConstraints) {
32 setBodyInnerHTML( 32 setBodyInnerHTML(
33 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " 33 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; "
34 "}" 34 "}"
35 "#container { box-sizing: border-box; position: relative; top: 100px; " 35 "#container { box-sizing: border-box; position: relative; top: 100px; "
36 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }" 36 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; }"
37 "#scroller { height: 100px; overflow: auto; position: relative; top: " 37 "#scroller { width: 400px; height: 100px; overflow: auto; "
38 "200px; }" 38 "position: relative; top: 200px; border: 2px solid black; }"
39 ".spacer { height: 1000px; }</style>" 39 ".spacer { height: 1000px; }</style>"
40 "<div id='scroller'><div id='container'><div " 40 "<div id='scroller'><div id='container'><div "
41 "id='sticky'></div></div><div class='spacer'></div></div>"); 41 "id='sticky'></div></div><div class='spacer'></div></div>");
42 LayoutBoxModelObject* scroller = 42 LayoutBoxModelObject* scroller =
43 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 43 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
44 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); 44 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
45 scrollableArea->scrollToAbsolutePosition( 45 scrollableArea->scrollToAbsolutePosition(
46 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50)); 46 FloatPoint(scrollableArea->scrollOffsetInt().width(), 50));
47 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); 47 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y());
48 LayoutBoxModelObject* sticky = 48 LayoutBoxModelObject* sticky =
49 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky")); 49 toLayoutBoxModelObject(getLayoutObjectByElementId("sticky"));
50 sticky->updateStickyPositionConstraints(); 50 sticky->updateStickyPositionConstraints();
51 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer()); 51 ASSERT_EQ(scroller->layer(), sticky->layer()->ancestorOverflowLayer());
52 52
53 const StickyPositionScrollingConstraints& constraints = 53 const StickyPositionScrollingConstraints& constraints =
54 scrollableArea->stickyConstraintsMap().get(sticky->layer()); 54 scrollableArea->stickyConstraintsMap().get(sticky->layer());
55 ASSERT_EQ(0.f, constraints.topOffset()); 55 ASSERT_EQ(0.f, constraints.topOffset());
56 56
57 // The coordinates of the constraint rects should all be with respect to the 57 // The coordinates of the constraint rects should all be with respect to the
58 // unscrolled scroller. 58 // unscrolled scroller.
59 ASSERT_EQ(IntRect(15, 115, 170, 370), 59 ASSERT_EQ(IntRect(15, 115, 170, 370),
60 enclosingIntRect( 60 enclosingIntRect(
61 getScrollContainerRelativeContainingBlockRect(constraints))); 61 getScrollContainerRelativeContainingBlockRect(constraints)));
62 ASSERT_EQ( 62 ASSERT_EQ(
63 IntRect(15, 115, 100, 100), 63 IntRect(15, 115, 100, 100),
64 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 64 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
65
66 // The sticky constraining rect also doesn't include the border offset.
chrishtr 2016/11/12 00:17:20 Please add a vertical-rl example also.
flackr 2016/11/14 14:50:14 Done.
67 ASSERT_EQ(IntRect(0, 50, 400, 100),
68 enclosingIntRect(sticky->computeStickyConstrainingRect()));
65 } 69 }
66 70
67 // Verifies that the sticky constraints are not affected by transforms 71 // Verifies that the sticky constraints are not affected by transforms
68 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) { 72 TEST_F(LayoutBoxModelObjectTest, StickyPositionTransforms) {
69 setBodyInnerHTML( 73 setBodyInnerHTML(
70 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " 74 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; "
71 "transform: scale(2); transform-origin: top left; }" 75 "transform: scale(2); transform-origin: top left; }"
72 "#container { box-sizing: border-box; position: relative; top: 100px; " 76 "#container { box-sizing: border-box; position: relative; top: 100px; "
73 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; " 77 "height: 400px; width: 200px; padding: 10px; border: 5px solid black; "
74 "transform: scale(2); transform-origin: top left; }" 78 "transform: scale(2); transform-origin: top left; }"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 141 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
138 } 142 }
139 143
140 // Verifies that the sticky constraints are correct when the sticky position 144 // Verifies that the sticky constraints are correct when the sticky position
141 // container is also the ancestor scroller. 145 // container is also the ancestor scroller.
142 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) { 146 TEST_F(LayoutBoxModelObjectTest, StickyPositionContainerIsScroller) {
143 setBodyInnerHTML( 147 setBodyInnerHTML(
144 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; " 148 "<style>#sticky { position: sticky; top: 0; width: 100px; height: 100px; "
145 "}" 149 "}"
146 "#scroller { height: 100px; width: 400px; overflow: auto; position: " 150 "#scroller { height: 100px; width: 400px; overflow: auto; position: "
147 "relative; top: 200px; }" 151 "relative; top: 200px; border: 2px solid black; }"
148 ".spacer { height: 1000px; }</style>" 152 ".spacer { height: 1000px; }</style>"
149 "<div id='scroller'><div id='sticky'></div><div " 153 "<div id='scroller'><div id='sticky'></div><div "
150 "class='spacer'></div></div>"); 154 "class='spacer'></div></div>");
151 LayoutBoxModelObject* scroller = 155 LayoutBoxModelObject* scroller =
152 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller")); 156 toLayoutBoxModelObject(getLayoutObjectByElementId("scroller"));
153 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea(); 157 PaintLayerScrollableArea* scrollableArea = scroller->getScrollableArea();
154 scrollableArea->scrollToAbsolutePosition( 158 scrollableArea->scrollToAbsolutePosition(
155 FloatPoint(scrollableArea->scrollPosition().x(), 50)); 159 FloatPoint(scrollableArea->scrollPosition().x(), 50));
156 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y()); 160 ASSERT_EQ(50.0, scrollableArea->scrollPosition().y());
157 LayoutBoxModelObject* sticky = 161 LayoutBoxModelObject* sticky =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 const StickyPositionScrollingConstraints& constraints = 201 const StickyPositionScrollingConstraints& constraints =
198 scrollableArea->stickyConstraintsMap().get(sticky->layer()); 202 scrollableArea->stickyConstraintsMap().get(sticky->layer());
199 ASSERT_EQ(IntRect(15, 115, 170, 370), 203 ASSERT_EQ(IntRect(15, 115, 170, 370),
200 enclosingIntRect( 204 enclosingIntRect(
201 getScrollContainerRelativeContainingBlockRect(constraints))); 205 getScrollContainerRelativeContainingBlockRect(constraints)));
202 ASSERT_EQ( 206 ASSERT_EQ(
203 IntRect(15, 165, 100, 100), 207 IntRect(15, 165, 100, 100),
204 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints))); 208 enclosingIntRect(getScrollContainerRelativeStickyBoxRect(constraints)));
205 } 209 }
206 } // namespace blink 210 } // 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