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 "config.h" | 5 #include "config.h" |
6 #include "core/layout/compositing/CompositedLayerMapping.h" | 6 #include "core/layout/compositing/CompositedLayerMapping.h" |
7 | 7 |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/html/HTMLIFrameElement.h" | |
10 #include "core/layout/LayoutBoxModelObject.h" | 9 #include "core/layout/LayoutBoxModelObject.h" |
11 #include "core/layout/LayoutTestHelper.h" | 10 #include "core/layout/LayoutTestHelper.h" |
12 #include "core/layout/LayoutView.h" | 11 #include "core/layout/LayoutView.h" |
13 #include "core/loader/EmptyClients.h" | |
14 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 class CompositedLayerMappingTest : public RenderingTest { | 17 class CompositedLayerMappingTest : public RenderingTest { |
20 public: | 18 public: |
21 CompositedLayerMappingTest() | 19 CompositedLayerMappingTest() |
22 : RenderingTest(SingleChildFrameLoaderClient::create()) | 20 : RenderingTest(SingleChildFrameLoaderClient::create()) |
23 , m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) | 21 , m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) |
(...skipping 27 matching lines...) Expand all Loading... |
51 | 49 |
52 RenderingTest::SetUp(); | 50 RenderingTest::SetUp(); |
53 enableCompositing(); | 51 enableCompositing(); |
54 GraphicsLayer::setDrawDebugRedFillForTesting(false); | 52 GraphicsLayer::setDrawDebugRedFillForTesting(false); |
55 } | 53 } |
56 | 54 |
57 void TearDown() override | 55 void TearDown() override |
58 { | 56 { |
59 GraphicsLayer::setDrawDebugRedFillForTesting(true); | 57 GraphicsLayer::setDrawDebugRedFillForTesting(true); |
60 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); | 58 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); |
| 59 |
| 60 RenderingTest::TearDown(); |
61 } | 61 } |
62 | 62 |
63 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; | 63 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; |
64 }; | 64 }; |
65 | 65 |
66 #define EXPECT_RECT_EQ(expected, actual) \ | 66 #define EXPECT_RECT_EQ(expected, actual) \ |
67 do { \ | 67 do { \ |
68 EXPECT_EQ(expected.x(), actual.x()); \ | 68 const IntRect& actualRect = actual; \ |
69 EXPECT_EQ(expected.y(), actual.y()); \ | 69 EXPECT_EQ(expected.x(), actualRect.x()); \ |
70 EXPECT_EQ(expected.width(), actual.width()); \ | 70 EXPECT_EQ(expected.y(), actualRect.y()); \ |
71 EXPECT_EQ(expected.height(), actual.height()); \ | 71 EXPECT_EQ(expected.width(), actualRect.width()); \ |
| 72 EXPECT_EQ(expected.height(), actualRect.height()); \ |
72 } while (false) | 73 } while (false) |
73 | 74 |
74 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) | 75 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) |
75 { | 76 { |
76 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); | 77 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); |
77 | 78 |
78 document().view()->updateAllLifecyclePhases(); | 79 document().view()->updateAllLifecyclePhases(); |
79 Element* element = document().getElementById("target"); | 80 Element* element = document().getElementById("target"); |
80 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); | 81 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); |
81 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | 82 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" | 482 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" |
482 " </div>" | 483 " </div>" |
483 "</div>"); | 484 "</div>"); |
484 | 485 |
485 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); | 486 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); |
486 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. | 487 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. |
487 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. | 488 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. |
488 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); | 489 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); |
489 } | 490 } |
490 | 491 |
491 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) | 492 TEST_F(CompositedLayerMappingTest, InterestRectOfIframeInScrolledDiv) |
492 { | 493 { |
493 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 494 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
494 setBodyInnerHTML( | 495 setBodyInnerHTML( |
495 "<style>body { margin: 0; }</style>" | 496 "<style>body { margin: 0; }</style>" |
496 "<div style='width: 200; height: 8000px'></div>" | 497 "<div style='width: 200; height: 8000px'></div>" |
497 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" | 498 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
498 "</iframe>"); | 499 "</iframe>"); |
499 | 500 |
500 HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("
frame")); | 501 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 200px; will-change: transform}</style><div i
d=target></div>"); |
501 OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientW
ithParent::create(document().frame()); | |
502 RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoader
Client.get(), document().frame()->host(), &iframe); | |
503 subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); | |
504 subframe->init(); | |
505 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(subframe.get()); | |
506 document().frame()->host()->incrementSubframeCount(); | |
507 Document& frameDocument = *iframe.contentDocument(); | |
508 | |
509 frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | |
510 frameDocument.body()->setInnerHTML("<style>body { margin: 0; } #target { wid
th: 200px; height: 200px; will-change: transform}</style><div id=target></div>", | |
511 ASSERT_NO_EXCEPTION); | |
512 | 502 |
513 // Scroll 8000 pixels down to move the iframe into view. | 503 // Scroll 8000 pixels down to move the iframe into view. |
514 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); | 504 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); |
515 document().view()->updateAllLifecyclePhases(); | 505 document().view()->updateAllLifecyclePhases(); |
516 | 506 |
517 Element* target = frameDocument.getElementById("target"); | 507 Element* target = frameDocument.getElementById("target"); |
518 ASSERT_TRUE(target); | 508 ASSERT_TRUE(target); |
519 | 509 |
520 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); | 510 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); |
| 511 } |
521 | 512 |
522 subframe->detach(FrameDetachType::Remove); | 513 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) |
523 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); | 514 { |
524 document().frame()->host()->decrementSubframeCount(); | 515 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 516 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 517 setBodyInnerHTML( |
| 518 "<style>body { margin: 0; }</style>" |
| 519 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
| 520 "</iframe>"); |
| 521 |
| 522 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 8000px;}</style><div id=target></div>"); |
| 523 |
| 524 document().view()->updateAllLifecyclePhases(); |
| 525 |
| 526 // Scroll 7500 pixels down to bring the scrollable area to the bottom. |
| 527 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 7500.0), Programmat
icScroll); |
| 528 document().view()->updateAllLifecyclePhases(); |
| 529 |
| 530 ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); |
| 531 // The width is 485 pixels due to the size of the scrollbar. |
| 532 EXPECT_RECT_EQ(IntRect(0, 3500, 485, 4500), recomputeInterestRect(frameDocum
ent.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); |
| 533 } |
| 534 |
| 535 TEST_F(CompositedLayerMappingTest, InterestRectOfIframeWithContentBoxOffset) |
| 536 { |
| 537 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 538 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 539 // Set a 10px border in order to have a contentBoxOffset for the iframe elem
ent. |
| 540 setBodyInnerHTML( |
| 541 "<style>body { margin: 0; } #frame { border: 10px solid black; }</style>
" |
| 542 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
| 543 "</iframe>"); |
| 544 |
| 545 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 8000px;}</style> <div id=target></div>"); |
| 546 |
| 547 document().view()->updateAllLifecyclePhases(); |
| 548 |
| 549 // Scroll 3000 pixels down to bring the scrollable area to somewhere in the
middle. |
| 550 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 3000.0), Programmat
icScroll); |
| 551 document().view()->updateAllLifecyclePhases(); |
| 552 |
| 553 ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); |
| 554 // The width is 485 pixels due to the size of the scrollbar. |
| 555 EXPECT_RECT_EQ(IntRect(0, 0, 485, 7500), recomputeInterestRect(frameDocument
.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); |
525 } | 556 } |
526 | 557 |
527 } // namespace blink | 558 } // namespace blink |
OLD | NEW |