| 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/paint/PaintControllerPaintTest.h" | 6 #include "core/paint/PaintControllerPaintTest.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutText.h" | 8 #include "core/layout/LayoutText.h" |
| 9 #include "core/layout/line/InlineTextBox.h" | 9 #include "core/layout/line/InlineTextBox.h" |
| 10 #include "core/page/FocusController.h" | 10 #include "core/page/FocusController.h" |
| 11 #include "core/paint/LayoutObjectDrawingRecorder.h" | 11 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 12 #include "core/paint/PaintLayerPainter.h" | 12 #include "core/paint/PaintLayerPainter.h" |
| 13 #include "platform/graphics/GraphicsContext.h" | 13 #include "platform/graphics/GraphicsContext.h" |
| 14 #include "platform/graphics/paint/DrawingDisplayItem.h" | 14 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 TEST_F(PaintControllerPaintTest, FullDocumentPaintingWithCaret) | 18 INSTANTIATE_TEST_CASE_P(All, PaintControllerPaintTestForSlimmingPaintV1AndV2, ::
testing::Bool()); |
| 19 |
| 20 TEST_P(PaintControllerPaintTestForSlimmingPaintV1AndV2, FullDocumentPaintingWith
Caret) |
| 19 { | 21 { |
| 20 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'>
XYZ</div>"); | 22 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'>
XYZ</div>"); |
| 21 document().page()->focusController().setActive(true); | 23 document().page()->focusController().setActive(true); |
| 22 document().page()->focusController().setFocused(true); | |
| 23 PaintLayer& rootLayer = *layoutView().layer(); | |
| 24 Element& div = *toElement(document().body()->firstChild()); | |
| 25 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje
ct(); | |
| 26 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject(
))->firstTextBox(); | |
| 27 | |
| 28 GraphicsContext context(rootPaintController()); | |
| 29 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 600),
GlobalPaintNormalPhase, LayoutSize()); | |
| 30 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo, Pain
tLayerPaintingCompositingAllPhases); | |
| 31 rootPaintController().commitNewDisplayItems(); | |
| 32 | |
| 33 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, | |
| 34 TestDisplayItem(layoutView(), backgroundType), | |
| 35 TestDisplayItem(textInlineBox, foregroundType)); | |
| 36 | |
| 37 div.focus(); | |
| 38 document().view()->updateAllLifecyclePhases(); | |
| 39 EXPECT_TRUE(rootPaintController().clientCacheIsValid(layoutView().displayIte
mClient())); | |
| 40 EXPECT_FALSE(rootPaintController().clientCacheIsValid(divLayoutObject.displa
yItemClient())); | |
| 41 EXPECT_TRUE(rootPaintController().clientCacheIsValid(textInlineBox.displayIt
emClient())); | |
| 42 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo, Pain
tLayerPaintingCompositingAllPhases); | |
| 43 rootPaintController().commitNewDisplayItems(); | |
| 44 | |
| 45 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 3, | |
| 46 TestDisplayItem(layoutView(), backgroundType), | |
| 47 TestDisplayItem(textInlineBox, foregroundType), | |
| 48 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! | |
| 49 } | |
| 50 | |
| 51 TEST_F(PaintControllerPaintTest, InlineRelayout) | |
| 52 { | |
| 53 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA
A BBBBBBBBBB</div>"); | |
| 54 PaintLayer& rootLayer = *layoutView().layer(); | |
| 55 Element& div = *toElement(document().body()->firstChild()); | |
| 56 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo
utObject()); | |
| 57 LayoutText& text = *toLayoutText(divBlock.firstChild()); | |
| 58 InlineTextBox& firstTextBox = *text.firstTextBox(); | |
| 59 DisplayItemClient firstTextBoxDisplayItemClient = firstTextBox.displayItemCl
ient(); | |
| 60 | |
| 61 GraphicsContext context(rootPaintController()); | |
| 62 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 600),
GlobalPaintNormalPhase, LayoutSize()); | |
| 63 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo, Pain
tLayerPaintingCompositingAllPhases); | |
| 64 rootPaintController().commitNewDisplayItems(); | |
| 65 | |
| 66 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, | |
| 67 TestDisplayItem(layoutView(), backgroundType), | |
| 68 TestDisplayItem(firstTextBox, foregroundType)); | |
| 69 | |
| 70 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); | |
| 71 document().view()->updateAllLifecyclePhases(); | |
| 72 EXPECT_TRUE(rootPaintController().clientCacheIsValid(layoutView().displayIte
mClient())); | |
| 73 EXPECT_FALSE(rootPaintController().clientCacheIsValid(divBlock.displayItemCl
ient())); | |
| 74 EXPECT_FALSE(rootPaintController().clientCacheIsValid(firstTextBoxDisplayIte
mClient)); | |
| 75 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo, Pain
tLayerPaintingCompositingAllPhases); | |
| 76 rootPaintController().commitNewDisplayItems(); | |
| 77 | |
| 78 LayoutText& newText = *toLayoutText(divBlock.firstChild()); | |
| 79 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); | |
| 80 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); | |
| 81 | |
| 82 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 3, | |
| 83 TestDisplayItem(layoutView(), backgroundType), | |
| 84 TestDisplayItem(newFirstTextBox, foregroundType), | |
| 85 TestDisplayItem(secondTextBox, foregroundType)); | |
| 86 } | |
| 87 | |
| 88 TEST_F(PaintControllerPaintTestForSlimmingPaintV2, FullDocumentPaintingWithCaret
) | |
| 89 { | |
| 90 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'>
XYZ</div>"); | |
| 91 document().page()->focusController().setActive(true); | |
| 92 document().page()->focusController().setFocused(true); | 24 document().page()->focusController().setFocused(true); |
| 93 PaintLayer& rootLayer = *layoutView().layer(); | 25 PaintLayer& rootLayer = *layoutView().layer(); |
| 94 Element& div = *toElement(document().body()->firstChild()); | 26 Element& div = *toElement(document().body()->firstChild()); |
| 95 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje
ct(); | 27 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje
ct(); |
| 96 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject(
))->firstTextBox(); | 28 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject(
))->firstTextBox(); |
| 97 | 29 |
| 98 document().view()->updateAllLifecyclePhases(); | 30 if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) { |
| 31 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 4, |
| 32 TestDisplayItem(layoutView(), backgroundType), |
| 33 TestDisplayItem(rootLayer, subsequenceType), |
| 34 TestDisplayItem(textInlineBox, foregroundType), |
| 35 TestDisplayItem(rootLayer, endSubsequenceType)); |
| 36 } else { |
| 37 GraphicsContext context(rootPaintController()); |
| 38 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 60
0), GlobalPaintNormalPhase, LayoutSize()); |
| 39 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo,
PaintLayerPaintingCompositingAllPhases); |
| 40 rootPaintController().commitNewDisplayItems(); |
| 99 | 41 |
| 100 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 4, | 42 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, |
| 101 TestDisplayItem(layoutView(), backgroundType), | 43 TestDisplayItem(layoutView(), backgroundType), |
| 102 TestDisplayItem(rootLayer, subsequenceType), | 44 TestDisplayItem(textInlineBox, foregroundType)); |
| 103 TestDisplayItem(textInlineBox, foregroundType), | 45 } |
| 104 TestDisplayItem(rootLayer, endSubsequenceType)); | |
| 105 | 46 |
| 106 div.focus(); | 47 div.focus(); |
| 107 document().view()->updateAllLifecyclePhases(); | 48 document().view()->updateAllLifecyclePhases(); |
| 108 | 49 |
| 109 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 5, | 50 if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) { |
| 110 TestDisplayItem(layoutView(), backgroundType), | 51 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 5, |
| 111 TestDisplayItem(rootLayer, subsequenceType), | 52 TestDisplayItem(layoutView(), backgroundType), |
| 112 TestDisplayItem(textInlineBox, foregroundType), | 53 TestDisplayItem(rootLayer, subsequenceType), |
| 113 TestDisplayItem(divLayoutObject, DisplayItem::Caret), // New! | 54 TestDisplayItem(textInlineBox, foregroundType), |
| 114 TestDisplayItem(rootLayer, endSubsequenceType)); | 55 TestDisplayItem(divLayoutObject, DisplayItem::Caret), // New! |
| 56 TestDisplayItem(rootLayer, endSubsequenceType)); |
| 57 } else { |
| 58 GraphicsContext context(rootPaintController()); |
| 59 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 60
0), GlobalPaintNormalPhase, LayoutSize()); |
| 60 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo,
PaintLayerPaintingCompositingAllPhases); |
| 61 rootPaintController().commitNewDisplayItems(); |
| 62 |
| 63 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 3, |
| 64 TestDisplayItem(layoutView(), backgroundType), |
| 65 TestDisplayItem(textInlineBox, foregroundType), |
| 66 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! |
| 67 } |
| 115 } | 68 } |
| 116 | 69 |
| 117 TEST_F(PaintControllerPaintTestForSlimmingPaintV2, InlineRelayout) | 70 TEST_P(PaintControllerPaintTestForSlimmingPaintV1AndV2, InlineRelayout) |
| 118 { | 71 { |
| 119 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA
A BBBBBBBBBB</div>"); | 72 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA
A BBBBBBBBBB</div>"); |
| 120 PaintLayer& rootLayer = *layoutView().layer(); | 73 PaintLayer& rootLayer = *layoutView().layer(); |
| 121 Element& div = *toElement(document().body()->firstChild()); | 74 Element& div = *toElement(document().body()->firstChild()); |
| 122 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo
utObject()); | 75 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo
utObject()); |
| 123 LayoutText& text = *toLayoutText(divBlock.firstChild()); | 76 LayoutText& text = *toLayoutText(divBlock.firstChild()); |
| 124 InlineTextBox& firstTextBox = *text.firstTextBox(); | 77 InlineTextBox& firstTextBox = *text.firstTextBox(); |
| 125 | 78 |
| 126 document().view()->updateAllLifecyclePhases(); | 79 if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) { |
| 80 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 4, |
| 81 TestDisplayItem(layoutView(), backgroundType), |
| 82 TestDisplayItem(rootLayer, subsequenceType), |
| 83 TestDisplayItem(firstTextBox, foregroundType), |
| 84 TestDisplayItem(rootLayer, endSubsequenceType)); |
| 85 } else { |
| 86 GraphicsContext context(rootPaintController()); |
| 87 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 60
0), GlobalPaintNormalPhase, LayoutSize()); |
| 88 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo,
PaintLayerPaintingCompositingAllPhases); |
| 89 rootPaintController().commitNewDisplayItems(); |
| 127 | 90 |
| 128 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 4, | 91 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 2, |
| 129 TestDisplayItem(layoutView(), backgroundType), | 92 TestDisplayItem(layoutView(), backgroundType), |
| 130 TestDisplayItem(rootLayer, subsequenceType), | 93 TestDisplayItem(firstTextBox, foregroundType)); |
| 131 TestDisplayItem(firstTextBox, foregroundType), | 94 } |
| 132 TestDisplayItem(rootLayer, endSubsequenceType)); | |
| 133 | 95 |
| 134 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); | 96 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); |
| 135 document().view()->updateAllLifecyclePhases(); | 97 document().view()->updateAllLifecyclePhases(); |
| 136 | 98 |
| 137 LayoutText& newText = *toLayoutText(divBlock.firstChild()); | 99 LayoutText& newText = *toLayoutText(divBlock.firstChild()); |
| 138 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); | 100 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); |
| 139 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); | 101 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); |
| 140 | 102 |
| 141 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 5, | 103 if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled()) { |
| 142 TestDisplayItem(layoutView(), backgroundType), | 104 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 5, |
| 143 TestDisplayItem(rootLayer, subsequenceType), | 105 TestDisplayItem(layoutView(), backgroundType), |
| 144 TestDisplayItem(newFirstTextBox, foregroundType), | 106 TestDisplayItem(rootLayer, subsequenceType), |
| 145 TestDisplayItem(secondTextBox, foregroundType), | 107 TestDisplayItem(newFirstTextBox, foregroundType), |
| 146 TestDisplayItem(rootLayer, endSubsequenceType)); | 108 TestDisplayItem(secondTextBox, foregroundType), |
| 109 TestDisplayItem(rootLayer, endSubsequenceType)); |
| 110 } else { |
| 111 GraphicsContext context(rootPaintController()); |
| 112 PaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 800, 60
0), GlobalPaintNormalPhase, LayoutSize()); |
| 113 PaintLayerPainter(rootLayer).paintLayerContents(&context, paintingInfo,
PaintLayerPaintingCompositingAllPhases); |
| 114 rootPaintController().commitNewDisplayItems(); |
| 115 |
| 116 EXPECT_DISPLAY_LIST(rootPaintController().displayItemList(), 3, |
| 117 TestDisplayItem(layoutView(), backgroundType), |
| 118 TestDisplayItem(newFirstTextBox, foregroundType), |
| 119 TestDisplayItem(secondTextBox, foregroundType)); |
| 120 } |
| 147 } | 121 } |
| 148 | 122 |
| 149 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |