| 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/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 TEST_F(LayoutObjectTest, OverflowRectMappingWithSelfFlippedWritingMode) | 206 TEST_F(LayoutObjectTest, OverflowRectMappingWithSelfFlippedWritingMode) |
| 207 { | 207 { |
| 208 setBodyInnerHTML( | 208 setBodyInnerHTML( |
| 209 "<div id='target' style='writing-mode: vertical-rl; box-shadow: 40px 20p
x black;" | 209 "<div id='target' style='writing-mode: vertical-rl; box-shadow: 40px 20p
x black;" |
| 210 " width: 100px; height: 50px; position: absolute; top: 111px; left: 2
22px'>" | 210 " width: 100px; height: 50px; position: absolute; top: 111px; left: 2
22px'>" |
| 211 "</div>"); | 211 "</div>"); |
| 212 | 212 |
| 213 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 213 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 214 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); | 214 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); |
| 215 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
| 216 // 140 = width(100) + box_shadow_offset_x(40) |
| 217 // 70 = height(50) + box_shadow_offset_y(20) |
| 215 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); | 218 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); |
| 219 |
| 216 LayoutRect rect = overflowRect; | 220 LayoutRect rect = overflowRect; |
| 217 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 221 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 222 // This rect is in physical coordinates of target. |
| 218 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); | 223 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); |
| 224 |
| 219 rect = overflowRect; | 225 rect = overflowRect; |
| 220 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 226 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 221 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); | 227 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); |
| 222 } | 228 } |
| 223 | 229 |
| 224 TEST_F(LayoutObjectTest, OverflowRectMappingWithContainerFlippedWritingMode) | 230 TEST_F(LayoutObjectTest, OverflowRectMappingWithContainerFlippedWritingMode) |
| 225 { | 231 { |
| 226 setBodyInnerHTML( | 232 setBodyInnerHTML( |
| 227 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px'>" | 233 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px'>" |
| 228 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" | 234 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" |
| 229 " <div style='width: 100px; height: 100px'></div>" | 235 " <div style='width: 100px; height: 100px'></div>" |
| 230 "</div>"); | 236 "</div>"); |
| 231 | 237 |
| 232 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 238 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 233 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); | 239 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
| 240 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
| 241 // 140 = width(100) + box_shadow_offset_x(40) |
| 242 // 110 = height(90) + box_shadow_offset_y(20) |
| 234 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 243 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
| 244 |
| 235 LayoutRect rect = targetOverflowRect; | 245 LayoutRect rect = targetOverflowRect; |
| 236 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 246 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 247 // This rect is in physical coordinates of target. |
| 237 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 248 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 238 | 249 |
| 239 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); | 250 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 240 rect = targetOverflowRect; | 251 rect = targetOverflowRect; |
| 241 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 252 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 253 // 100 is the physical x location of target in container. |
| 242 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); | 254 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); |
| 243 rect = targetOverflowRect; | 255 rect = targetOverflowRect; |
| 244 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 256 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 245 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); | 257 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); |
| 246 | 258 |
| 247 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); | 259 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); |
| 248 EXPECT_EQ(LayoutRect(-40, 0, 240, 110), containerOverflowRect); | 260 EXPECT_EQ(LayoutRect(-40, 0, 240, 110), containerOverflowRect); |
| 249 rect = containerOverflowRect; | 261 rect = containerOverflowRect; |
| 250 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 262 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 251 EXPECT_EQ(LayoutRect(0, 0, 240, 110), rect); | 263 EXPECT_EQ(LayoutRect(0, 0, 240, 110), rect); |
| 252 rect = containerOverflowRect; | 264 rect = containerOverflowRect; |
| 253 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 265 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 254 EXPECT_EQ(LayoutRect(222, 111, 240, 110), rect); | 266 EXPECT_EQ(LayoutRect(222, 111, 240, 110), rect); |
| 255 } | 267 } |
| 256 | 268 |
| 269 TEST_F(LayoutObjectTest, OverflowRectMappingWithContainerOverflowClip) |
| 270 { |
| 271 setBodyInnerHTML( |
| 272 "<div id='container' style='position: absolute; top: 111px; left: 222px;
" |
| 273 " border: 10px solid red; overflow: hidden; width: 50px; height: 80px
;'>" |
| 274 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" |
| 275 "</div>"); |
| 276 |
| 277 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 278 EXPECT_EQ(LayoutUnit(0), container->scrollTop()); |
| 279 EXPECT_EQ(LayoutUnit(0), container->scrollLeft()); |
| 280 container->setScrollTop(LayoutUnit(7)); |
| 281 container->setScrollLeft(LayoutUnit(8)); |
| 282 |
| 283 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 284 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
| 285 // 140 = width(100) + box_shadow_offset_x(40) |
| 286 // 110 = height(90) + box_shadow_offset_y(20) |
| 287 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); |
| 288 LayoutRect rect = targetOverflowRect; |
| 289 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 290 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 291 |
| 292 rect = targetOverflowRect; |
| 293 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 294 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) |
| 295 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 296 // Rect is not clipped by container's overflow clip. |
| 297 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); |
| 298 |
| 299 rect = targetOverflowRect; |
| 300 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 301 // (2, 3, 140, 100) is first clipped by container's overflow clip, to (10, 1
0, 50, 80), |
| 302 // then is by added container's offset in LayoutView (111, 222). |
| 303 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); |
| 304 |
| 305 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); |
| 306 // Because container has overflow clip, its visual overflow doesn't include
overflow from children. |
| 307 // 70 = width(50) + border_left_width(10) + border_right_width(10) |
| 308 // 100 = height(80) + border_top_width(10) + border_bottom_width(10) |
| 309 EXPECT_EQ(LayoutRect(0, 0, 70, 100), containerOverflowRect); |
| 310 rect = containerOverflowRect; |
| 311 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 312 // Container should not apply overflow clip on its own overflow rect. |
| 313 EXPECT_EQ(LayoutRect(0, 0, 70, 100), rect); |
| 314 |
| 315 rect = containerOverflowRect; |
| 316 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 317 EXPECT_EQ(LayoutRect(222, 111, 70, 100), rect); |
| 318 } |
| 319 |
| 320 TEST_F(LayoutObjectTest, OverflowRectMappingWithContainerFlippedWritingModeAndOv
erflowClip) |
| 321 { |
| 322 setBodyInnerHTML( |
| 323 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px;" |
| 324 " border: solid red; border-width: 10px 20px 30px 40px;" |
| 325 " overflow: hidden; width: 50px; height: 80px'>" |
| 326 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" |
| 327 " <div style='width: 100px; height: 100px'></div>" |
| 328 "</div>"); |
| 329 |
| 330 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 331 EXPECT_EQ(LayoutUnit(0), container->scrollTop()); |
| 332 // The initial scroll offset is to the left-most because of flipped blocks w
riting mode. |
| 333 // 150 = total_layout_overflow(100 + 100) - width(50) |
| 334 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
| 335 container->setScrollTop(LayoutUnit(7)); |
| 336 container->setScrollLeft(LayoutUnit(142)); // Scroll to the right by 8 pixel
s. |
| 337 |
| 338 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 339 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
| 340 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
| 341 // 140 = width(100) + box_shadow_offset_x(40) |
| 342 // 110 = height(90) + box_shadow_offset_y(20) |
| 343 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
| 344 |
| 345 LayoutRect rect = targetOverflowRect; |
| 346 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 347 // This rect is in physical coordinates of target. |
| 348 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 349 |
| 350 rect = targetOverflowRect; |
| 351 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 352 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) |
| 353 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 354 // Rect is not clipped by container's overflow clip. |
| 355 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
| 356 |
| 357 rect = targetOverflowRect; |
| 358 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 359 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40,
10, 50, 80), |
| 360 // then is added by container's offset in LayoutView (111, 222). |
| 361 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but
is offset |
| 362 // by extra horizontal border-widths because of layout error. |
| 363 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); |
| 364 |
| 365 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); |
| 366 // Because container has overflow clip, its visual overflow doesn't include
overflow from children. |
| 367 // 110 = width(50) + border_left_width(40) + border_right_width(20) |
| 368 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) |
| 369 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); |
| 370 |
| 371 rect = containerOverflowRect; |
| 372 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 373 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); |
| 374 |
| 375 rect = containerOverflowRect; |
| 376 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 377 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by e
xtra horizontal |
| 378 // border-widths because of layout error. |
| 379 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); |
| 380 } |
| 381 |
| 257 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |