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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698