OLD | NEW |
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/ng/ng_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
6 | 6 |
7 #include "core/dom/NodeComputedStyle.h" | 7 #include "core/dom/NodeComputedStyle.h" |
8 #include "core/dom/TagCollection.h" | 8 #include "core/dom/TagCollection.h" |
9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
10 #include "core/layout/ng/layout_ng_block_flow.h" | 10 #include "core/layout/ng/layout_ng_block_flow.h" |
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 )HTML"); | 1899 )HTML"); |
1900 // #container is the new parent for our float because it's height != 0. | 1900 // #container is the new parent for our float because it's height != 0. |
1901 Element* container = GetDocument().GetElementById("container"); | 1901 Element* container = GetDocument().GetElementById("container"); |
1902 auto& floating_objects = | 1902 auto& floating_objects = |
1903 const_cast<FloatingObjects*>( | 1903 const_cast<FloatingObjects*>( |
1904 ToLayoutBlockFlow(container->GetLayoutObject())->GetFloatingObjects()) | 1904 ToLayoutBlockFlow(container->GetLayoutObject())->GetFloatingObjects()) |
1905 ->MutableSet(); | 1905 ->MutableSet(); |
1906 ASSERT_EQ(1UL, floating_objects.size()); | 1906 ASSERT_EQ(1UL, floating_objects.size()); |
1907 auto floating_object = floating_objects.TakeFirst(); | 1907 auto floating_object = floating_objects.TakeFirst(); |
1908 // left-float's margin = 15. | 1908 // left-float's margin = 15. |
1909 EXPECT_THAT(LayoutUnit(15), floating_object->X()); | 1909 EXPECT_THAT(floating_object->X(), LayoutUnit(15)); |
1910 EXPECT_THAT(LayoutUnit(15), floating_object->Y()); | 1910 EXPECT_THAT(floating_object->Y(), LayoutUnit(15)); |
1911 | 1911 |
1912 RefPtr<const NGPhysicalBoxFragment> html_fragment; | 1912 RefPtr<const NGPhysicalBoxFragment> html_fragment; |
1913 std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement( | 1913 std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement( |
1914 GetDocument().getElementsByTagName("html")->item(0)); | 1914 GetDocument().getElementsByTagName("html")->item(0)); |
1915 auto* body_fragment = | 1915 auto* body_fragment = |
1916 ToNGPhysicalBoxFragment(html_fragment->Children()[0].Get()); | 1916 ToNGPhysicalBoxFragment(html_fragment->Children()[0].Get()); |
1917 auto* container_fragment = | 1917 auto* container_fragment = |
1918 ToNGPhysicalBoxFragment(body_fragment->Children()[0].Get()); | 1918 ToNGPhysicalBoxFragment(body_fragment->Children()[0].Get()); |
1919 auto* empty_block1 = | 1919 auto* empty_block1 = |
1920 ToNGPhysicalBoxFragment(container_fragment->Children()[0].Get()); | 1920 ToNGPhysicalBoxFragment(container_fragment->Children()[0].Get()); |
1921 // empty-block1's margin == 8 | 1921 // empty-block1's margin == 8 |
1922 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8)), | 1922 EXPECT_THAT(empty_block1->Offset(), |
1923 empty_block1->Offset()); | 1923 NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8))); |
1924 | 1924 |
1925 auto* empty_block2 = | 1925 auto* empty_block2 = |
1926 ToNGPhysicalBoxFragment(container_fragment->Children()[1].Get()); | 1926 ToNGPhysicalBoxFragment(container_fragment->Children()[1].Get()); |
1927 // empty-block2's margin == 50 | 1927 // empty-block2's margin == 50 |
1928 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50)), | 1928 EXPECT_THAT(empty_block2->Offset(), |
1929 empty_block2->Offset()); | 1929 NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50))); |
1930 } | 1930 } |
1931 | 1931 |
1932 // Verifies that we can correctly position blocks with clearance and | 1932 // Verifies that we can correctly position blocks with clearance and |
1933 // intruding floats. | 1933 // intruding floats. |
1934 TEST_F(NGBlockLayoutAlgorithmTest, | 1934 TEST_F(NGBlockLayoutAlgorithmTest, |
1935 PositionBlocksWithClearanceAndIntrudingFloats) { | 1935 PositionBlocksWithClearanceAndIntrudingFloats) { |
1936 SetBodyInnerHTML(R"HTML( | 1936 SetBodyInnerHTML(R"HTML( |
1937 <!DOCTYPE html> | 1937 <!DOCTYPE html> |
1938 <style> | 1938 <style> |
1939 body { margin: 80px; } | 1939 body { margin: 80px; } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2263 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(20)), child->Size()); | 2263 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(20)), child->Size()); |
2264 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), child->Offset()); | 2264 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(0)), child->Offset()); |
2265 | 2265 |
2266 child = iterator.NextChild(); | 2266 child = iterator.NextChild(); |
2267 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); | 2267 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); |
2268 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); | 2268 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); |
2269 | 2269 |
2270 EXPECT_FALSE(iterator.NextChild()); | 2270 EXPECT_FALSE(iterator.NextChild()); |
2271 } | 2271 } |
2272 | 2272 |
2273 TEST_F(NGBlockLayoutAlgorithmTest, NewFormattingContextBlock) {} | 2273 // Verifies that we correctly position a new FC block with the Layout |
| 2274 // Opportunity iterator. |
| 2275 TEST_F(NGBlockLayoutAlgorithmTest, |
| 2276 NewFcBlockWithAdjoiningFloatCollapsesMargins) { |
| 2277 SetBodyInnerHTML(R"HTML( |
| 2278 <!DOCTYPE html> |
| 2279 <style> |
| 2280 #container { |
| 2281 width: 200px; outline: solid purple 1px; |
| 2282 } |
| 2283 #float { |
| 2284 float: left; width: 100px; height: 30px; background: red; |
| 2285 } |
| 2286 #new-fc { |
| 2287 contain: paint; margin-top: 20px; background: purple; |
| 2288 height: 50px; |
| 2289 } |
| 2290 </style> |
| 2291 <div id="container"> |
| 2292 <div id="float"></div> |
| 2293 <div id="new-fc"></div> |
| 2294 </div> |
| 2295 )HTML"); |
2274 | 2296 |
| 2297 const NGPhysicalBoxFragment* body_fragment; |
| 2298 const NGPhysicalBoxFragment* container_fragment; |
| 2299 const NGPhysicalBoxFragment* new_fc_fragment; |
| 2300 RefPtr<const NGPhysicalBoxFragment> fragment; |
| 2301 auto run_test = [&](const Length& block_width) { |
| 2302 Element* new_fc_block = GetDocument().GetElementById("new-fc"); |
| 2303 new_fc_block->MutableComputedStyle()->SetWidth(block_width); |
| 2304 std::tie(fragment, std::ignore) = RunBlockLayoutAlgorithmForElement( |
| 2305 GetDocument().getElementsByTagName("html")->item(0)); |
| 2306 ASSERT_EQ(1UL, fragment->Children().size()); |
| 2307 body_fragment = ToNGPhysicalBoxFragment(fragment->Children()[0].Get()); |
| 2308 container_fragment = |
| 2309 ToNGPhysicalBoxFragment(body_fragment->Children()[0].Get()); |
| 2310 ASSERT_EQ(1UL, container_fragment->Children().size()); |
| 2311 new_fc_fragment = |
| 2312 ToNGPhysicalBoxFragment(container_fragment->Children()[0].Get()); |
| 2313 }; |
| 2314 |
| 2315 // #new-fc is small enough to fit on the same line with #float. |
| 2316 run_test(Length(80, kFixed)); |
| 2317 // 100 = float's width, 0 = no margin collapsing |
| 2318 EXPECT_THAT(new_fc_fragment->Offset(), |
| 2319 NGPhysicalOffset(LayoutUnit(100), LayoutUnit(0))); |
| 2320 // 8 = body's margins, 20 = new-fc's margin top(20) collapses with |
| 2321 // body's margin(8) |
| 2322 EXPECT_THAT(body_fragment->Offset(), |
| 2323 NGPhysicalOffset(LayoutUnit(8), LayoutUnit(20))); |
| 2324 |
| 2325 // #new-fc is too wide to be positioned on the same line with #float |
| 2326 run_test(Length(120, kFixed)); |
| 2327 // 30 = #float's height |
| 2328 EXPECT_THAT(new_fc_fragment->Offset(), |
| 2329 NGPhysicalOffset(LayoutUnit(0), LayoutUnit(30))); |
| 2330 // 8 = body's margins, no margin collapsing |
| 2331 EXPECT_THAT(body_fragment->Offset(), |
| 2332 NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8))); |
| 2333 } |
2275 } // namespace | 2334 } // namespace |
2276 } // namespace blink | 2335 } // namespace blink |
OLD | NEW |