Chromium Code Reviews| 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/layout/ScrollAnchor.h" | 5 #include "core/layout/ScrollAnchor.h" |
| 6 | 6 |
| 7 #include "core/dom/ClientRect.h" | 7 #include "core/dom/ClientRect.h" |
| 8 #include "core/frame/VisualViewport.h" | 8 #include "core/frame/VisualViewport.h" |
| 9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
| 10 #include "core/layout/LayoutTestHelper.h" | 10 #include "core/layout/LayoutTestHelper.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 setHeight(document().getElementById("div"), 100); | 148 setHeight(document().getElementById("div"), 100); |
| 149 EXPECT_EQ(document().getElementById("text")->layoutObject(), | 149 EXPECT_EQ(document().getElementById("text")->layoutObject(), |
| 150 scrollAnchor(lViewport).anchorObject()); | 150 scrollAnchor(lViewport).anchorObject()); |
| 151 EXPECT_EQ(top, vViewport.scrollPosition().y()); | 151 EXPECT_EQ(top, vViewport.scrollPosition().y()); |
| 152 | 152 |
| 153 // Scrolling the visual viewport should clear the anchor. | 153 // Scrolling the visual viewport should clear the anchor. |
| 154 vViewport.setLocation(FloatPoint(0, 0)); | 154 vViewport.setLocation(FloatPoint(0, 0)); |
| 155 EXPECT_EQ(nullptr, scrollAnchor(lViewport).anchorObject()); | 155 EXPECT_EQ(nullptr, scrollAnchor(lViewport).anchorObject()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Test that we don't descend into elements that clip overflow content since we | |
|
skobes
2016/07/11 21:25:03
nit: it's not that we will never descend into them
ymalik
2016/07/11 21:35:34
Done!
| |
| 159 // may end up with an anchor that we think is in the viewport but is really not. | |
| 160 TEST_F(ScrollAnchorTest, ClippedScrollersSkipped) | |
| 161 { | |
| 162 setBodyInnerHTML( | |
| 163 "<style>" | |
| 164 " body { height: 2000px; }" | |
| 165 " #scroller { overflow: scroll; width: 500px; height: 300px; }" | |
| 166 " .anchor {" | |
| 167 " position:relative; height: 100px; width: 150px;" | |
| 168 " background-color: #afa; border: 1px solid gray;" | |
| 169 " }" | |
| 170 " #forceScrolling { height: 500px; background-color: #fcc; }" | |
| 171 "</style>" | |
| 172 "<div id='scroller'>" | |
| 173 " <div id='innerChanger'></div>" | |
| 174 " <div id='innerAnchor' class='anchor'></div>" | |
| 175 " <div id='forceScrolling'></div>" | |
| 176 "</div>" | |
| 177 "<div id='outerChanger'></div>" | |
| 178 "<div id='outerAnchor' class='anchor'></div>"); | |
| 179 | |
| 180 ScrollableArea* scroller = scrollerForElement(document().getElementById("scr oller")); | |
| 181 ScrollableArea* viewport = layoutViewport(); | |
| 182 | |
| 183 document().getElementById("scroller")->setScrollTop(100); | |
| 184 scrollLayoutViewport(DoubleSize(0, 350)); | |
| 185 | |
| 186 setHeight(document().getElementById("innerChanger"), 200); | |
| 187 setHeight(document().getElementById("outerChanger"), 150); | |
| 188 | |
| 189 EXPECT_EQ(300, scroller->scrollPosition().y()); | |
| 190 EXPECT_EQ(document().getElementById("innerAnchor")->layoutObject(), | |
| 191 scrollAnchor(scroller).anchorObject()); | |
| 192 EXPECT_EQ(500, viewport->scrollPosition().y()); | |
| 193 EXPECT_EQ(document().getElementById("outerAnchor")->layoutObject(), | |
| 194 scrollAnchor(viewport).anchorObject()); | |
| 195 } | |
| 196 | |
| 158 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) | 197 TEST_F(ScrollAnchorTest, FractionalOffsetsAreRoundedBeforeComparing) |
| 159 { | 198 { |
| 160 setBodyInnerHTML( | 199 setBodyInnerHTML( |
| 161 "<style> body { height: 1000px } </style>" | 200 "<style> body { height: 1000px } </style>" |
| 162 "<div id='block1' style='height: 50.4px'>abc</div>" | 201 "<div id='block1' style='height: 50.4px'>abc</div>" |
| 163 "<div id='block2' style='height: 100px'>def</div>"); | 202 "<div id='block2' style='height: 100px'>def</div>"); |
| 164 | 203 |
| 165 ScrollableArea* viewport = layoutViewport(); | 204 ScrollableArea* viewport = layoutViewport(); |
| 166 scrollLayoutViewport(DoubleSize(0, 100)); | 205 scrollLayoutViewport(DoubleSize(0, 100)); |
| 167 | 206 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 "<div id=c></div>" | 650 "<div id=c></div>" |
| 612 "<div id=d></div>"); | 651 "<div id=d></div>"); |
| 613 | 652 |
| 614 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; | 653 checkCorner("b", Corner::TopRight, DoublePoint(-20, 20), DoubleSize(0, 0)) ; |
| 615 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); | 654 checkCorner("a", Corner::TopRight, DoublePoint(-420, 20), DoubleSize(400, 0 )); |
| 616 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); | 655 checkCorner("d", Corner::TopRight, DoublePoint(-20, 320), DoubleSize(0, -30 0)); |
| 617 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); | 656 checkCorner("c", Corner::TopRight, DoublePoint(-420, 320), DoubleSize(400, - 300)); |
| 618 } | 657 } |
| 619 | 658 |
| 620 } | 659 } |
| OLD | NEW |