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/ng/layout_ng_block_flow.h" | 9 #include "core/layout/ng/layout_ng_block_flow.h" |
10 #include "core/layout/ng/ng_block_node.h" | 10 #include "core/layout/ng/ng_block_node.h" |
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8)), | 2089 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8)), |
2090 empty_block1->Offset()); | 2090 empty_block1->Offset()); |
2091 | 2091 |
2092 auto* empty_block2 = | 2092 auto* empty_block2 = |
2093 toNGPhysicalBoxFragment(container_fragment->Children()[1].get()); | 2093 toNGPhysicalBoxFragment(container_fragment->Children()[1].get()); |
2094 // empty-block2's margin == 50 | 2094 // empty-block2's margin == 50 |
2095 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50)), | 2095 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50)), |
2096 empty_block2->Offset()); | 2096 empty_block2->Offset()); |
2097 } | 2097 } |
2098 | 2098 |
| 2099 // Verifies that we can correctly position blocks with clearance and |
| 2100 // intruding floats. |
| 2101 TEST_F(NGBlockLayoutAlgorithmTest, |
| 2102 PositionBlocksWithClearanceAndIntrudingFloats) { |
| 2103 setBodyInnerHTML(R"HTML( |
| 2104 <!DOCTYPE html> |
| 2105 <style> |
| 2106 body { margin: 80px; } |
| 2107 #left-float { |
| 2108 background: green; |
| 2109 float: left; |
| 2110 width: 50px; |
| 2111 height: 50px; |
| 2112 } |
| 2113 #right-float { |
| 2114 background: red; |
| 2115 float: right; |
| 2116 margin: 0 80px 0 10px; |
| 2117 width: 50px; |
| 2118 height: 80px; |
| 2119 } |
| 2120 #block1 { |
| 2121 outline: purple solid; |
| 2122 height: 30px; |
| 2123 margin: 130px 0 20px 0; |
| 2124 } |
| 2125 #zero { |
| 2126 margin-top: 30px; |
| 2127 } |
| 2128 #container-clear { |
| 2129 clear: left; |
| 2130 outline: orange solid; |
| 2131 } |
| 2132 #clears-right { |
| 2133 clear: right; |
| 2134 height: 20px; |
| 2135 background: lightblue; |
| 2136 } |
| 2137 </style> |
| 2138 |
| 2139 <div id="left-float"></div> |
| 2140 <div id="right-float"></div> |
| 2141 <div id="block1"></div> |
| 2142 <div id="container-clear"> |
| 2143 <div id="zero"></div> |
| 2144 <div id="clears-right"></div> |
| 2145 </div> |
| 2146 )HTML"); |
| 2147 |
| 2148 // Run LayoutNG algorithm. |
| 2149 RefPtr<NGPhysicalBoxFragment> html_fragment; |
| 2150 std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement( |
| 2151 document().getElementsByTagName("html")->item(0)); |
| 2152 auto* body_fragment = |
| 2153 toNGPhysicalBoxFragment(html_fragment->Children()[0].get()); |
| 2154 ASSERT_EQ(2UL, body_fragment->Children().size()); |
| 2155 |
| 2156 // Verify #container-clear block |
| 2157 auto* container_clear_fragment = |
| 2158 toNGPhysicalBoxFragment(body_fragment->Children()[1].get()); |
| 2159 // 60 = block1's height 30 + std::max(block1's margin 20, zero's margin 30) |
| 2160 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(60)), |
| 2161 container_clear_fragment->Offset()); |
| 2162 Element* container_clear = document().getElementById("container-clear"); |
| 2163 // 190 = block1's margin 130 + block1's height 30 + |
| 2164 // std::max(block1's margin 20, zero's margin 30) |
| 2165 EXPECT_THAT(container_clear->offsetTop(), 190); |
| 2166 |
| 2167 // Verify #clears-right block |
| 2168 ASSERT_EQ(2UL, container_clear_fragment->Children().size()); |
| 2169 auto* clears_right_fragment = |
| 2170 toNGPhysicalBoxFragment(container_clear_fragment->Children()[1].get()); |
| 2171 // 20 = right-float's block end offset (130 + 80) - |
| 2172 // container_clear->offsetTop() 190 |
| 2173 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(20)), |
| 2174 clears_right_fragment->Offset()); |
| 2175 } |
| 2176 |
2099 } // namespace | 2177 } // namespace |
2100 } // namespace blink | 2178 } // namespace blink |
OLD | NEW |