| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/LayoutBox.h" | 5 #include "core/layout/LayoutBox.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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Because it can scroll due to local attachment, the opaque local background
in #target6 | 93 // Because it can scroll due to local attachment, the opaque local background
in #target6 |
| 94 // is treated as padding box for the clip rect, but remains the content box fo
r the known | 94 // is treated as padding box for the clip rect, but remains the content box fo
r the known |
| 95 // opaque rect. | 95 // opaque rect. |
| 96 layoutBox = toLayoutBox(getLayoutObjectByElementId("target6")); | 96 layoutBox = toLayoutBox(getLayoutObjectByElementId("target6")); |
| 97 EXPECT_EQ(LayoutRect(20, 20, 100, 100), | 97 EXPECT_EQ(LayoutRect(20, 20, 100, 100), |
| 98 layoutBox->backgroundRect(BackgroundKnownOpaqueRect)); | 98 layoutBox->backgroundRect(BackgroundKnownOpaqueRect)); |
| 99 EXPECT_EQ(LayoutRect(10, 10, 120, 120), | 99 EXPECT_EQ(LayoutRect(10, 10, 120, 120), |
| 100 layoutBox->backgroundRect(BackgroundClipRect)); | 100 layoutBox->backgroundRect(BackgroundClipRect)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(LayoutBoxTest, LocationContainer) { |
| 104 setBodyInnerHTML( |
| 105 "<div id='div'>" |
| 106 " <b>Inline content<img id='img'></b>" |
| 107 "</div>" |
| 108 "<table id='table'>" |
| 109 " <tbody id='tbody'>" |
| 110 " <tr id='row'>" |
| 111 " <td id='cell' style='width: 100px; height: 80px'></td>" |
| 112 " </tr>" |
| 113 " </tbody>" |
| 114 "</table>"); |
| 115 |
| 116 const LayoutBox* body = document().body()->layoutBox(); |
| 117 const LayoutBox* div = toLayoutBox(getLayoutObjectByElementId("div")); |
| 118 const LayoutBox* img = toLayoutBox(getLayoutObjectByElementId("img")); |
| 119 const LayoutBox* table = toLayoutBox(getLayoutObjectByElementId("table")); |
| 120 const LayoutBox* tbody = toLayoutBox(getLayoutObjectByElementId("tbody")); |
| 121 const LayoutBox* row = toLayoutBox(getLayoutObjectByElementId("row")); |
| 122 const LayoutBox* cell = toLayoutBox(getLayoutObjectByElementId("cell")); |
| 123 |
| 124 EXPECT_EQ(body, div->locationContainer()); |
| 125 EXPECT_EQ(div, img->locationContainer()); |
| 126 EXPECT_EQ(body, table->locationContainer()); |
| 127 EXPECT_EQ(table, tbody->locationContainer()); |
| 128 EXPECT_EQ(tbody, row->locationContainer()); |
| 129 EXPECT_EQ(tbody, cell->locationContainer()); |
| 130 } |
| 131 |
| 132 TEST_F(LayoutBoxTest, TopLeftLocationFlipped) { |
| 133 setBodyInnerHTML( |
| 134 "<div style='width: 600px; height: 200px; writing-mode: vertical-rl'>" |
| 135 " <div id='box1' style='width: 100px'></div>" |
| 136 " <div id='box2' style='width: 200px'></div>" |
| 137 "</div>"); |
| 138 |
| 139 const LayoutBox* box1 = toLayoutBox(getLayoutObjectByElementId("box1")); |
| 140 EXPECT_EQ(LayoutPoint(0, 0), box1->location()); |
| 141 EXPECT_EQ(LayoutPoint(500, 0), box1->topLeftLocation()); |
| 142 |
| 143 const LayoutBox* box2 = toLayoutBox(getLayoutObjectByElementId("box2")); |
| 144 EXPECT_EQ(LayoutPoint(100, 0), box2->location()); |
| 145 EXPECT_EQ(LayoutPoint(300, 0), box2->topLeftLocation()); |
| 146 } |
| 147 |
| 148 TEST_F(LayoutBoxTest, TableRowCellTopLeftLocationFlipped) { |
| 149 setBodyInnerHTML( |
| 150 "<div style='writing-mode: vertical-rl'>" |
| 151 " <table style='border-spacing: 0'>" |
| 152 " <thead><tr><td style='width: 50px'></td></tr></thead>" |
| 153 " <tbody>" |
| 154 " <tr id='row1'>" |
| 155 " <td id='cell1' style='width: 100px; height: 80px'></td>" |
| 156 " </tr>" |
| 157 " <tr id='row2'>" |
| 158 " <td id='cell2' style='width: 300px; height: 80px'></td>" |
| 159 " </tr>" |
| 160 " </tbody>" |
| 161 " </table>" |
| 162 "</div>"); |
| 163 |
| 164 // location and topLeftLocation of a table row or a table cell should be |
| 165 // relative to the containing section. |
| 166 |
| 167 const LayoutBox* row1 = toLayoutBox(getLayoutObjectByElementId("row1")); |
| 168 EXPECT_EQ(LayoutPoint(0, 0), row1->location()); |
| 169 EXPECT_EQ(LayoutPoint(300, 0), row1->topLeftLocation()); |
| 170 |
| 171 const LayoutBox* cell1 = toLayoutBox(getLayoutObjectByElementId("cell1")); |
| 172 EXPECT_EQ(LayoutPoint(0, 0), cell1->location()); |
| 173 EXPECT_EQ(LayoutPoint(300, 0), cell1->topLeftLocation()); |
| 174 |
| 175 const LayoutBox* row2 = toLayoutBox(getLayoutObjectByElementId("row2")); |
| 176 // TODO(crbug.com/652496): LayoutTableRow's location is in logical coordinates |
| 177 // of the containing section, and topLeftLocation() is incorrect. |
| 178 // This should be (100, 0). |
| 179 EXPECT_EQ(LayoutPoint(0, 100), row2->location()); |
| 180 // This should be (0, 0). |
| 181 EXPECT_EQ(LayoutPoint(100, 100), row2->topLeftLocation()); |
| 182 |
| 183 const LayoutBox* cell2 = toLayoutBox(getLayoutObjectByElementId("cell2")); |
| 184 EXPECT_EQ(LayoutPoint(100, 0), cell2->location()); |
| 185 EXPECT_EQ(LayoutPoint(0, 0), cell2->topLeftLocation()); |
| 186 } |
| 187 |
| 103 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |