| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 54 |
| 57 RenderingTest::SetUp(); | 55 RenderingTest::SetUp(); |
| 58 enableCompositing(); | 56 enableCompositing(); |
| 59 GraphicsLayer::setDrawDebugRedFillForTesting(false); | 57 GraphicsLayer::setDrawDebugRedFillForTesting(false); |
| 60 } | 58 } |
| 61 | 59 |
| 62 void TearDown() override | 60 void TearDown() override |
| 63 { | 61 { |
| 64 GraphicsLayer::setDrawDebugRedFillForTesting(true); | 62 GraphicsLayer::setDrawDebugRedFillForTesting(true); |
| 65 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); | 63 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); |
| 64 |
| 65 RenderingTest::TearDown(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; | 68 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 #define EXPECT_RECT_EQ(expected, actual) \ | 71 #define EXPECT_RECT_EQ(expected, actual) \ |
| 72 do { \ | 72 do { \ |
| 73 EXPECT_EQ(expected.x(), actual.x()); \ | 73 const IntRect& actualRect = actual; \ |
| 74 EXPECT_EQ(expected.y(), actual.y()); \ | 74 EXPECT_EQ(expected.x(), actualRect.x()); \ |
| 75 EXPECT_EQ(expected.width(), actual.width()); \ | 75 EXPECT_EQ(expected.y(), actualRect.y()); \ |
| 76 EXPECT_EQ(expected.height(), actual.height()); \ | 76 EXPECT_EQ(expected.width(), actualRect.width()); \ |
| 77 EXPECT_EQ(expected.height(), actualRect.height()); \ |
| 77 } while (false) | 78 } while (false) |
| 78 | 79 |
| 79 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) | 80 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) |
| 80 { | 81 { |
| 81 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); | 82 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); |
| 82 | 83 |
| 83 document().view()->updateAllLifecyclePhases(); | 84 document().view()->updateAllLifecyclePhases(); |
| 84 Element* element = document().getElementById("target"); | 85 Element* element = document().getElementById("target"); |
| 85 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); | 86 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); |
| 86 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | 87 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" | 506 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" |
| 506 " </div>" | 507 " </div>" |
| 507 "</div>"); | 508 "</div>"); |
| 508 | 509 |
| 509 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); | 510 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); |
| 510 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. | 511 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. |
| 511 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. | 512 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. |
| 512 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); | 513 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); |
| 513 } | 514 } |
| 514 | 515 |
| 515 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) | 516 TEST_F(CompositedLayerMappingTest, InterestRectOfIframeInScrolledDiv) |
| 516 { | 517 { |
| 517 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 518 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 518 setBodyInnerHTML( | 519 setBodyInnerHTML( |
| 519 "<style>body { margin: 0; }</style>" | 520 "<style>body { margin: 0; }</style>" |
| 520 "<div style='width: 200; height: 8000px'></div>" | 521 "<div style='width: 200; height: 8000px'></div>" |
| 521 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" | 522 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
| 522 "</iframe>"); | 523 "</iframe>"); |
| 523 | 524 |
| 524 HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("
frame")); | 525 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 200px; will-change: transform}</style><div i
d=target></div>"); |
| 525 OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientW
ithParent::create(document().frame()); | |
| 526 RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoader
Client.get(), document().frame()->host(), &iframe); | |
| 527 subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); | |
| 528 subframe->init(); | |
| 529 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(subframe.get()); | |
| 530 document().frame()->host()->incrementSubframeCount(); | |
| 531 Document& frameDocument = *iframe.contentDocument(); | |
| 532 | |
| 533 frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | |
| 534 frameDocument.body()->setInnerHTML("<style>body { margin: 0; } #target { wid
th: 200px; height: 200px; will-change: transform}</style><div id=target></div>", | |
| 535 ASSERT_NO_EXCEPTION); | |
| 536 | 526 |
| 537 // Scroll 8000 pixels down to move the iframe into view. | 527 // Scroll 8000 pixels down to move the iframe into view. |
| 538 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); | 528 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); |
| 539 document().view()->updateAllLifecyclePhases(); | 529 document().view()->updateAllLifecyclePhases(); |
| 540 | 530 |
| 541 Element* target = frameDocument.getElementById("target"); | 531 Element* target = frameDocument.getElementById("target"); |
| 542 ASSERT_TRUE(target); | 532 ASSERT_TRUE(target); |
| 543 | 533 |
| 544 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); | 534 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); |
| 535 } |
| 545 | 536 |
| 546 subframe->detach(FrameDetachType::Remove); | 537 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) |
| 547 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); | 538 { |
| 548 document().frame()->host()->decrementSubframeCount(); | 539 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 540 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 541 setBodyInnerHTML( |
| 542 "<style>body { margin: 0; } ::-webkit-scrollbar { display: none; }</styl
e>" |
| 543 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
| 544 "</iframe>"); |
| 545 |
| 546 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 8000px;}</style><div id=target></div>"); |
| 547 |
| 548 document().view()->updateAllLifecyclePhases(); |
| 549 |
| 550 // Scroll 7500 pixels down to bring the scrollable area to the bottom. |
| 551 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 7500.0), Programmat
icScroll); |
| 552 document().view()->updateAllLifecyclePhases(); |
| 553 |
| 554 ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); |
| 555 EXPECT_RECT_EQ(IntRect(0, 3500, 500, 4500), recomputeInterestRect(frameDocum
ent.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); |
| 556 } |
| 557 |
| 558 TEST_F(CompositedLayerMappingTest, InterestRectOfIframeWithContentBoxOffset) |
| 559 { |
| 560 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 561 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 562 // Set a 10px border in order to have a contentBoxOffset for the iframe elem
ent. |
| 563 setBodyInnerHTML( |
| 564 "<style>body { margin: 0; } #frame { border: 10px solid black; } ::-webk
it-scrollbar { display: none; }</style>" |
| 565 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
| 566 "</iframe>"); |
| 567 |
| 568 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 8000px;}</style> <div id=target></div>"); |
| 569 |
| 570 document().view()->updateAllLifecyclePhases(); |
| 571 |
| 572 // Scroll 3000 pixels down to bring the scrollable area to somewhere in the
middle. |
| 573 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 3000.0), Programmat
icScroll); |
| 574 document().view()->updateAllLifecyclePhases(); |
| 575 |
| 576 ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); |
| 577 // The width is 485 pixels due to the size of the scrollbar. |
| 578 EXPECT_RECT_EQ(IntRect(0, 0, 500, 7500), recomputeInterestRect(frameDocument
.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); |
| 549 } | 579 } |
| 550 | 580 |
| 551 } // namespace blink | 581 } // namespace blink |
| OLD | NEW |