| 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/LayoutTestHelper.h" | 5 #include "core/layout/LayoutTestHelper.h" |
| 6 #include "core/layout/LayoutView.h" | 6 #include "core/layout/LayoutView.h" |
| 7 #include "core/layout/PaintInvalidationState.h" | 7 #include "core/layout/PaintInvalidationState.h" |
| 8 #include "core/paint/PaintLayer.h" | 8 #include "core/paint/PaintLayer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 " text text text text text text text" | 53 " text text text text text text text" |
| 54 "</div>"); | 54 "</div>"); |
| 55 | 55 |
| 56 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); | 56 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 57 LayoutText* text = toLayoutText(container->lastChild()); | 57 LayoutText* text = toLayoutText(container->lastChild()); |
| 58 | 58 |
| 59 container->setScrollTop(LayoutUnit(50)); | 59 container->setScrollTop(LayoutUnit(50)); |
| 60 LayoutRect originalRect(0, 60, 20, 80); | 60 LayoutRect originalRect(0, 60, 20, 80); |
| 61 LayoutRect rect = originalRect; | 61 LayoutRect rect = originalRect; |
| 62 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect)); | 62 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect)); |
| 63 rect.move(-container->scrolledContentOffset()); |
| 63 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); | 64 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 64 | 65 |
| 65 rect = originalRect; | 66 rect = originalRect; |
| 66 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 67 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 67 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); | 68 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); |
| 68 checkPaintInvalidationStateRectMapping(rect, originalRect, *text, layoutView
(), layoutView()); | 69 checkPaintInvalidationStateRectMapping(rect, originalRect, *text, layoutView
(), layoutView()); |
| 69 | 70 |
| 70 rect = LayoutRect(0, 60, 80, 0); | 71 rect = LayoutRect(0, 60, 80, 0); |
| 71 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect, EdgeInclus
ive)); | 72 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect, EdgeInclus
ive)); |
| 73 rect.move(-container->scrolledContentOffset()); |
| 72 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | 74 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 73 } | 75 } |
| 74 | 76 |
| 75 TEST_F(VisualRectMappingTest, LayoutInline) | 77 TEST_F(VisualRectMappingTest, LayoutInline) |
| 76 { | 78 { |
| 77 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 79 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 78 setBodyInnerHTML( | 80 setBodyInnerHTML( |
| 79 "<style>body { margin: 0; }</style>" | 81 "<style>body { margin: 0; }</style>" |
| 80 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'
>" | 82 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'
>" |
| 81 " <span><img style='width: 20px; height: 100px'></span>" | 83 " <span><img style='width: 20px; height: 100px'></span>" |
| 82 " <span id=leaf></span></div>"); | 84 " <span id=leaf></span></div>"); |
| 83 | 85 |
| 84 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); | 86 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
| 85 LayoutObject* leaf = container->lastChild(); | 87 LayoutObject* leaf = container->lastChild(); |
| 86 | 88 |
| 87 container->setScrollTop(LayoutUnit(50)); | 89 container->setScrollTop(LayoutUnit(50)); |
| 88 LayoutRect originalRect(0, 60, 20, 80); | 90 LayoutRect originalRect(0, 60, 20, 80); |
| 89 LayoutRect rect = originalRect; | 91 LayoutRect rect = originalRect; |
| 90 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect)); | 92 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect)); |
| 93 rect.move(-container->scrolledContentOffset()); |
| 91 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); | 94 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 92 | 95 |
| 93 rect = originalRect; | 96 rect = originalRect; |
| 94 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 97 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 95 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); | 98 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); |
| 96 checkPaintInvalidationStateRectMapping(rect, originalRect, *leaf, layoutView
(), layoutView()); | 99 checkPaintInvalidationStateRectMapping(rect, originalRect, *leaf, layoutView
(), layoutView()); |
| 97 | 100 |
| 98 rect = LayoutRect(0, 60, 80, 0); | 101 rect = LayoutRect(0, 60, 80, 0); |
| 99 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclus
ive)); | 102 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclus
ive)); |
| 103 rect.move(-container->scrolledContentOffset()); |
| 100 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | 104 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 101 } | 105 } |
| 102 | 106 |
| 103 TEST_F(VisualRectMappingTest, LayoutView) | 107 TEST_F(VisualRectMappingTest, LayoutView) |
| 104 { | 108 { |
| 105 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 109 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 106 setBodyInnerHTML( | 110 setBodyInnerHTML( |
| 107 "<style>body { margin: 0; }</style>" | 111 "<style>body { margin: 0; }</style>" |
| 108 "<div id=frameContainer>" | 112 "<div id=frameContainer>" |
| 109 " <iframe id=frame src='http://test.com' width='50' height='50' frameBo
rder='0'></iframe>" | 113 " <iframe id=frame src='http://test.com' width='50' height='50' frameBo
rder='0'></iframe>" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); | 257 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
| 254 // 140 = width(100) + box_shadow_offset_x(40) | 258 // 140 = width(100) + box_shadow_offset_x(40) |
| 255 // 110 = height(90) + box_shadow_offset_y(20) | 259 // 110 = height(90) + box_shadow_offset_y(20) |
| 256 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); | 260 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); |
| 257 LayoutRect rect = targetOverflowRect; | 261 LayoutRect rect = targetOverflowRect; |
| 258 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 262 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 259 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 263 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 260 | 264 |
| 261 rect = targetOverflowRect; | 265 rect = targetOverflowRect; |
| 262 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 266 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 267 rect.move(-container->scrolledContentOffset()); |
| 263 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) | 268 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) |
| 264 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 269 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 265 // Rect is not clipped by container's overflow clip because of overflow:scro
ll. | 270 // Rect is not clipped by container's overflow clip because of overflow:scro
ll. |
| 266 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); | 271 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); |
| 267 | 272 |
| 268 rect = targetOverflowRect; | 273 rect = targetOverflowRect; |
| 269 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 274 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 270 // (2, 3, 140, 100) is first clipped by container's overflow clip, to (10, 1
0, 50, 80), | 275 // (2, 3, 140, 100) is first clipped by container's overflow clip, to (10, 1
0, 50, 80), |
| 271 // then is by added container's offset in LayoutView (111, 222). | 276 // then is by added container's offset in LayoutView (111, 222). |
| 272 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); | 277 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 321 |
| 317 LayoutRect rect = targetOverflowRect; | 322 LayoutRect rect = targetOverflowRect; |
| 318 target->flipForWritingMode(rect); | 323 target->flipForWritingMode(rect); |
| 319 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 324 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 320 // This rect is in physical coordinates of target. | 325 // This rect is in physical coordinates of target. |
| 321 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 326 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 322 | 327 |
| 323 rect = targetOverflowRect; | 328 rect = targetOverflowRect; |
| 324 target->flipForWritingMode(rect); | 329 target->flipForWritingMode(rect); |
| 325 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 330 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 331 rect.move(-container->scrolledContentOffset()); |
| 326 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) | 332 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) |
| 327 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 333 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 328 // Rect is clipped by container's overflow clip because of overflow:scroll. | 334 // Rect is clipped by container's overflow clip because of overflow:scroll. |
| 329 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 335 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
| 330 | 336 |
| 331 rect = targetOverflowRect; | 337 rect = targetOverflowRect; |
| 332 target->flipForWritingMode(rect); | 338 target->flipForWritingMode(rect); |
| 333 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 339 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 334 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40,
10, 50, 80), | 340 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40,
10, 50, 80), |
| 335 // then is added by container's offset in LayoutView (111, 222). | 341 // then is added by container's offset in LayoutView (111, 222). |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // 110 = height(90) + box_shadow_offset_y(20) | 459 // 110 = height(90) + box_shadow_offset_y(20) |
| 454 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); | 460 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); |
| 455 | 461 |
| 456 LayoutRect rect = targetOverflowRect; | 462 LayoutRect rect = targetOverflowRect; |
| 457 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 463 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 458 // This rect is in physical coordinates of target. | 464 // This rect is in physical coordinates of target. |
| 459 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 465 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 460 | 466 |
| 461 rect = targetOverflowRect; | 467 rect = targetOverflowRect; |
| 462 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 468 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 469 rect.move(-container->scrolledContentOffset()); |
| 463 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) | 470 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) |
| 464 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 471 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 465 // Rect is not clipped by container's overflow clip. | 472 // Rect is not clipped by container's overflow clip. |
| 466 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 473 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
| 467 } | 474 } |
| 468 | 475 |
| 469 TEST_F(VisualRectMappingTest, DifferentPaintInvalidaitionContainerForAbsolutePos
ition) | 476 TEST_F(VisualRectMappingTest, DifferentPaintInvalidaitionContainerForAbsolutePos
ition) |
| 470 { | 477 { |
| 471 enableCompositing(); | 478 enableCompositing(); |
| 472 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); | 479 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 484 scroller->setScrollLeft(LayoutUnit(88)); | 491 scroller->setScrollLeft(LayoutUnit(88)); |
| 485 document().view()->updateAllLifecyclePhases(); | 492 document().view()->updateAllLifecyclePhases(); |
| 486 | 493 |
| 487 LayoutBlock* normalFlow = toLayoutBlock(getLayoutObjectByElementId("normal-f
low")); | 494 LayoutBlock* normalFlow = toLayoutBlock(getLayoutObjectByElementId("normal-f
low")); |
| 488 EXPECT_EQ(scroller, &normalFlow->containerForPaintInvalidation()); | 495 EXPECT_EQ(scroller, &normalFlow->containerForPaintInvalidation()); |
| 489 | 496 |
| 490 LayoutRect normalFlowOverflowRect = normalFlow->localOverflowRectForPaintInv
alidation(); | 497 LayoutRect normalFlowOverflowRect = normalFlow->localOverflowRectForPaintInv
alidation(); |
| 491 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), normalFlowOverflowRect); | 498 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), normalFlowOverflowRect); |
| 492 LayoutRect rect = normalFlowOverflowRect; | 499 LayoutRect rect = normalFlowOverflowRect; |
| 493 EXPECT_TRUE(normalFlow->mapToVisualRectInAncestorSpace(scroller, rect)); | 500 EXPECT_TRUE(normalFlow->mapToVisualRectInAncestorSpace(scroller, rect)); |
| 494 EXPECT_EQ(LayoutRect(-88, -77, 2000, 2000), rect); | 501 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), rect); |
| 495 checkPaintInvalidationStateRectMapping(rect, normalFlowOverflowRect, *normal
Flow, layoutView(), *scroller); | 502 checkPaintInvalidationStateRectMapping(rect, normalFlowOverflowRect, *normal
Flow, layoutView(), *scroller); |
| 496 | 503 |
| 497 LayoutBlock* stackingContext = toLayoutBlock(getLayoutObjectByElementId("sta
cking-context")); | 504 LayoutBlock* stackingContext = toLayoutBlock(getLayoutObjectByElementId("sta
cking-context")); |
| 498 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")
); | 505 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")
); |
| 499 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); | 506 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); |
| 500 EXPECT_EQ(stackingContext, absolute->container()); | 507 EXPECT_EQ(stackingContext, absolute->container()); |
| 501 | 508 |
| 502 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); | 509 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); |
| 503 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); | 510 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); |
| 504 rect = absoluteOverflowRect; | 511 rect = absoluteOverflowRect; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 532 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); | 539 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); |
| 533 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); | 540 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); |
| 534 LayoutRect rect = absoluteOverflowRect; | 541 LayoutRect rect = absoluteOverflowRect; |
| 535 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect))
; | 542 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect))
; |
| 536 // -172 = top(50) - y_offset_of_stacking_context(222) | 543 // -172 = top(50) - y_offset_of_stacking_context(222) |
| 537 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); | 544 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); |
| 538 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute
, layoutView(), *stackingContext); | 545 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute
, layoutView(), *stackingContext); |
| 539 } | 546 } |
| 540 | 547 |
| 541 } // namespace blink | 548 } // namespace blink |
| OLD | NEW |