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" |
9 #include "core/layout/LayoutBoxModelObject.h" | 10 #include "core/layout/LayoutBoxModelObject.h" |
10 #include "core/layout/LayoutTestHelper.h" | 11 #include "core/layout/LayoutTestHelper.h" |
11 #include "core/layout/LayoutView.h" | 12 #include "core/layout/LayoutView.h" |
| 13 #include "core/loader/EmptyClients.h" |
12 #include "core/paint/PaintLayer.h" | 14 #include "core/paint/PaintLayer.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace blink { | 17 namespace blink { |
16 | 18 |
17 class CompositedLayerMappingTest : public RenderingTest { | 19 class CompositedLayerMappingTest : public RenderingTest { |
18 public: | 20 public: |
19 CompositedLayerMappingTest() | 21 CompositedLayerMappingTest() |
20 : RenderingTest(SingleChildFrameLoaderClient::create()) | 22 : RenderingTest(SingleChildFrameLoaderClient::create()) |
21 , m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) | 23 , m_originalSlimmingPaintSynchronizedPaintingEnabled(RuntimeEnabledFeatu
res::slimmingPaintSynchronizedPaintingEnabled()) |
(...skipping 27 matching lines...) Expand all Loading... |
49 | 51 |
50 RenderingTest::SetUp(); | 52 RenderingTest::SetUp(); |
51 enableCompositing(); | 53 enableCompositing(); |
52 GraphicsLayer::setDrawDebugRedFillForTesting(false); | 54 GraphicsLayer::setDrawDebugRedFillForTesting(false); |
53 } | 55 } |
54 | 56 |
55 void TearDown() override | 57 void TearDown() override |
56 { | 58 { |
57 GraphicsLayer::setDrawDebugRedFillForTesting(true); | 59 GraphicsLayer::setDrawDebugRedFillForTesting(true); |
58 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_or
iginalSlimmingPaintSynchronizedPaintingEnabled); | 60 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 const IntRect& actualRect = actual; \ | 68 EXPECT_EQ(expected.x(), actual.x()); \ |
69 EXPECT_EQ(expected.x(), actualRect.x()); \ | 69 EXPECT_EQ(expected.y(), actual.y()); \ |
70 EXPECT_EQ(expected.y(), actualRect.y()); \ | 70 EXPECT_EQ(expected.width(), actual.width()); \ |
71 EXPECT_EQ(expected.width(), actualRect.width()); \ | 71 EXPECT_EQ(expected.height(), actual.height()); \ |
72 EXPECT_EQ(expected.height(), actualRect.height()); \ | |
73 } while (false) | 72 } while (false) |
74 | 73 |
75 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) | 74 TEST_F(CompositedLayerMappingTest, SimpleInterestRect) |
76 { | 75 { |
77 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); | 76 setBodyInnerHTML("<div id='target' style='width: 200px; height: 200px; will-
change: transform'></div>"); |
78 | 77 |
79 document().view()->updateAllLifecyclePhases(); | 78 document().view()->updateAllLifecyclePhases(); |
80 Element* element = document().getElementById("target"); | 79 Element* element = document().getElementById("target"); |
81 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); | 80 PaintLayer* paintLayer = toLayoutBoxModelObject(element->layoutObject())->la
yer(); |
82 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); | 81 ASSERT_TRUE(!!paintLayer->graphicsLayerBacking()); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" | 481 " <div id='squashed' style='height: 1000px; width: 10000px; right: 0;
position: absolute'></div>" |
483 " </div>" | 482 " </div>" |
484 "</div>"); | 483 "</div>"); |
485 | 484 |
486 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); | 485 CompositedLayerMapping* groupedMapping = document().getElementById("squashed
")->layoutBox()->layer()->groupedMapping(); |
487 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. | 486 // The squashing layer is at (-9600, 0, 10000, 1000) in viewport coordinates
. |
488 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. | 487 // The following rect is at (-4000, 0, 4400, 1000) in viewport coordinates. |
489 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); | 488 EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterest
Rect(groupedMapping->squashingLayer(), IntRect())); |
490 } | 489 } |
491 | 490 |
492 TEST_F(CompositedLayerMappingTest, InterestRectOfIframeInScrolledDiv) | 491 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) |
493 { | 492 { |
494 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 493 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
495 setBodyInnerHTML( | 494 setBodyInnerHTML( |
496 "<style>body { margin: 0; }</style>" | 495 "<style>body { margin: 0; }</style>" |
497 "<div style='width: 200; height: 8000px'></div>" | 496 "<div style='width: 200; height: 8000px'></div>" |
498 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" | 497 "<iframe id=frame src='http://test.com' width='500' height='500' frameBo
rder='0'>" |
499 "</iframe>"); | 498 "</iframe>"); |
500 | 499 |
501 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0
; } #target { width: 200px; height: 200px; will-change: transform}</style><div i
d=target></div>"); | 500 HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("
frame")); |
| 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); |
502 | 512 |
503 // Scroll 8000 pixels down to move the iframe into view. | 513 // Scroll 8000 pixels down to move the iframe into view. |
504 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); | 514 document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticS
croll); |
505 document().view()->updateAllLifecyclePhases(); | 515 document().view()->updateAllLifecyclePhases(); |
506 | 516 |
507 Element* target = frameDocument.getElementById("target"); | 517 Element* target = frameDocument.getElementById("target"); |
508 ASSERT_TRUE(target); | 518 ASSERT_TRUE(target); |
509 | 519 |
510 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); | 520 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layout
Object()->enclosingLayer()->graphicsLayerBacking())); |
511 } | |
512 | 521 |
513 TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) | 522 subframe->detach(FrameDetachType::Remove); |
514 { | 523 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); |
515 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 524 document().frame()->host()->decrementSubframeCount(); |
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())); | |
556 } | 525 } |
557 | 526 |
558 } // namespace blink | 527 } // namespace blink |
OLD | NEW |