Chromium Code Reviews| 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 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class VisualRectMappingTest : public RenderingTest { | 13 class VisualRectMappingTest : public RenderingTest { |
| 14 public: | 14 public: |
| 15 VisualRectMappingTest() | 15 VisualRectMappingTest() |
| 16 : RenderingTest(SingleChildFrameLoaderClient::create()) {} | 16 : RenderingTest(SingleChildFrameLoaderClient::create()) {} |
| 17 | 17 |
| 18 protected: | 18 protected: |
| 19 LayoutView& layoutView() const { return *document().layoutView(); } | 19 LayoutView& layoutView() const { return *document().layoutView(); } |
| 20 | 20 |
| 21 void checkPaintInvalidationStateRectMapping( | 21 void checkPaintInvalidationVisualRect(const LayoutObject& object) { |
|
chrishtr
2016/12/27 19:31:36
Looks like this CL got rebased wrong on top of the
Xianzhu
2016/12/28 02:47:02
Fixed.
| |
| 22 const LayoutRect& expectedRect, | 22 LayoutRect rect = object.localVisualRect(); |
| 23 const LayoutRect& rect, | 23 if (object.isBox()) |
| 24 const LayoutObject& object, | 24 toLayoutBox(object).flipForWritingMode(rect); |
| 25 const LayoutView& layoutView, | 25 const LayoutBoxModelObject& paintInvalidationContainer = |
| 26 const LayoutObject& paintInvalidationContainer) { | 26 object.containerForPaintInvalidation(); |
| 27 Vector<const LayoutObject*> ancestors; | 27 object.mapToVisualRectInAncestorSpace(&paintInvalidationContainer, rect); |
| 28 for (const LayoutObject* ancestor = &object; ancestor != layoutView; | 28 if (rect.isEmpty() && object.visualRect().isEmpty()) |
| 29 ancestor = ancestor->slowPaintInvalidationParentForTesting()) | 29 return; |
| 30 ancestors.append(ancestor); | 30 // The following condition can be false if paintInvalidationContainer is |
| 31 | 31 // a LayoutView and compositing is not enabled. |
| 32 Vector<Optional<PaintInvalidationState>> paintInvalidationStates( | 32 if (paintInvalidationContainer.isPaintInvalidationContainer()) { |
| 33 ancestors.size() + 1); | 33 PaintLayer::mapRectInPaintInvalidationContainerToBacking( |
| 34 Vector<const LayoutObject*> pendingDelayedPaintInvalidations; | 34 paintInvalidationContainer, rect); |
| 35 paintInvalidationStates[0].emplace(layoutView, | |
| 36 pendingDelayedPaintInvalidations); | |
| 37 if (layoutView != object) | |
| 38 paintInvalidationStates[0]->updateForChildren(PaintInvalidationFull); | |
| 39 for (size_t i = 1; i < paintInvalidationStates.size(); ++i) { | |
| 40 paintInvalidationStates[i].emplace(*paintInvalidationStates[i - 1], | |
| 41 *ancestors[ancestors.size() - i]); | |
| 42 if (paintInvalidationStates[i]->m_currentObject != object) | |
| 43 paintInvalidationStates[i]->updateForChildren(PaintInvalidationFull); | |
| 44 } | 35 } |
| 45 | 36 EXPECT_EQ(rect, object.visualRect()); |
| 46 const PaintInvalidationState& paintInvalidationState = | |
| 47 *paintInvalidationStates.back(); | |
| 48 ASSERT_EQ(paintInvalidationState.m_currentObject, object); | |
| 49 ASSERT_EQ(&paintInvalidationState.paintInvalidationContainer(), | |
| 50 &paintInvalidationContainer); | |
| 51 | |
| 52 LayoutRect r = rect; | |
| 53 paintInvalidationState.mapLocalRectToPaintInvalidationContainer(r); | |
| 54 EXPECT_EQ(expectedRect, r); | |
| 55 } | 37 } |
| 56 }; | 38 }; |
| 57 | 39 |
| 58 TEST_F(VisualRectMappingTest, LayoutText) { | 40 TEST_F(VisualRectMappingTest, LayoutText) { |
| 59 setBodyInnerHTML( | 41 setBodyInnerHTML( |
| 60 "<style>body { margin: 0; }</style>" | 42 "<style>body { margin: 0; }</style>" |
| 61 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>" | 43 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>" |
| 62 " <span><img style='width: 20px; height: 100px'></span>" | 44 " <span><img style='width: 20px; height: 100px'></span>" |
| 63 " text text text text text text text" | 45 " text text text text text text text" |
| 64 "</div>"); | 46 "</div>"); |
| 65 | 47 |
| 66 LayoutBlock* container = | 48 LayoutBlock* container = |
| 67 toLayoutBlock(getLayoutObjectByElementId("container")); | 49 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 68 LayoutText* text = toLayoutText(container->lastChild()); | 50 LayoutText* text = toLayoutText(container->lastChild()); |
| 69 | 51 |
| 70 container->setScrollTop(LayoutUnit(50)); | 52 container->setScrollTop(LayoutUnit(50)); |
| 53 document().view()->updateAllLifecyclePhases(); | |
| 54 | |
| 71 LayoutRect originalRect(0, 60, 20, 80); | 55 LayoutRect originalRect(0, 60, 20, 80); |
| 72 LayoutRect rect = originalRect; | 56 LayoutRect rect = originalRect; |
| 73 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect)); | 57 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(container, rect)); |
| 74 rect.move(-container->scrolledContentOffset()); | 58 rect.move(-container->scrolledContentOffset()); |
| 75 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); | 59 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 76 | 60 |
| 77 rect = originalRect; | 61 rect = originalRect; |
| 78 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 62 EXPECT_TRUE(text->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 79 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); | 63 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); |
| 80 checkPaintInvalidationStateRectMapping(rect, originalRect, *text, | 64 |
| 81 layoutView(), layoutView()); | 65 checkPaintInvalidationVisualRect(*text); |
| 82 | 66 |
| 83 rect = LayoutRect(0, 60, 80, 0); | 67 rect = LayoutRect(0, 60, 80, 0); |
| 84 EXPECT_TRUE( | 68 EXPECT_TRUE( |
| 85 text->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); | 69 text->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); |
| 86 rect.move(-container->scrolledContentOffset()); | 70 rect.move(-container->scrolledContentOffset()); |
| 87 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | 71 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 88 } | 72 } |
| 89 | 73 |
| 90 TEST_F(VisualRectMappingTest, LayoutInline) { | 74 TEST_F(VisualRectMappingTest, LayoutInline) { |
| 91 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 75 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 92 setBodyInnerHTML( | 76 setBodyInnerHTML( |
| 93 "<style>body { margin: 0; }</style>" | 77 "<style>body { margin: 0; }</style>" |
| 94 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>" | 78 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>" |
| 95 " <span><img style='width: 20px; height: 100px'></span>" | 79 " <span><img style='width: 20px; height: 100px'></span>" |
| 96 " <span id=leaf></span></div>"); | 80 " <span id='leaf'></span>" |
| 81 "</div>"); | |
| 97 | 82 |
| 98 LayoutBlock* container = | 83 LayoutBlock* container = |
| 99 toLayoutBlock(getLayoutObjectByElementId("container")); | 84 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 100 LayoutObject* leaf = container->lastChild(); | 85 LayoutObject* leaf = container->lastChild(); |
| 101 | 86 |
| 102 container->setScrollTop(LayoutUnit(50)); | 87 container->setScrollTop(LayoutUnit(50)); |
| 88 document().view()->updateAllLifecyclePhases(); | |
| 89 | |
| 103 LayoutRect originalRect(0, 60, 20, 80); | 90 LayoutRect originalRect(0, 60, 20, 80); |
| 104 LayoutRect rect = originalRect; | 91 LayoutRect rect = originalRect; |
| 105 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect)); | 92 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(container, rect)); |
| 106 rect.move(-container->scrolledContentOffset()); | 93 rect.move(-container->scrolledContentOffset()); |
| 107 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); | 94 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 108 | 95 |
| 109 rect = originalRect; | 96 rect = originalRect; |
| 110 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 97 EXPECT_TRUE(leaf->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 111 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); | 98 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 40)); |
| 112 checkPaintInvalidationStateRectMapping(rect, originalRect, *leaf, | 99 |
| 113 layoutView(), layoutView()); | 100 checkPaintInvalidationVisualRect(*leaf); |
| 114 | 101 |
| 115 rect = LayoutRect(0, 60, 80, 0); | 102 rect = LayoutRect(0, 60, 80, 0); |
| 116 EXPECT_TRUE( | 103 EXPECT_TRUE( |
| 117 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); | 104 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); |
| 118 rect.move(-container->scrolledContentOffset()); | 105 rect.move(-container->scrolledContentOffset()); |
| 119 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | 106 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); |
| 120 } | 107 } |
| 121 | 108 |
| 122 TEST_F(VisualRectMappingTest, LayoutView) { | 109 TEST_F(VisualRectMappingTest, LayoutView) { |
| 123 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 110 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 124 setBodyInnerHTML( | 111 setBodyInnerHTML( |
| 125 "<style>body { margin: 0; }</style>" | 112 "<style>body { margin: 0; }</style>" |
| 126 "<div id=frameContainer>" | 113 "<div id=frameContainer>" |
| 127 " <iframe src='http://test.com' width='50' height='50' " | 114 " <iframe src='http://test.com' width='50' height='50' " |
| 128 "frameBorder='0'></iframe>" | 115 " frameBorder='0'></iframe>" |
| 129 "</div>"); | 116 "</div>"); |
| 130 setChildFrameHTML( | 117 setChildFrameHTML( |
| 131 "<style>body { margin: 0; }</style><span><img style='width: 20px; " | 118 "<style>body { margin: 0; }</style>" |
| 132 "height: 100px'></span>text text text"); | 119 "<span><img style='width: 20px; height: 100px'></span>text text text"); |
| 133 | |
| 134 document().view()->updateAllLifecyclePhases(); | 120 document().view()->updateAllLifecyclePhases(); |
| 135 | 121 |
| 136 LayoutBlock* frameContainer = | 122 LayoutBlock* frameContainer = |
| 137 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 123 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 138 LayoutBlock* frameBody = | 124 LayoutBlock* frameBody = |
| 139 toLayoutBlock(childDocument().body()->layoutObject()); | 125 toLayoutBlock(childDocument().body()->layoutObject()); |
| 140 LayoutText* frameText = toLayoutText(frameBody->lastChild()); | 126 LayoutText* frameText = toLayoutText(frameBody->lastChild()); |
| 141 | 127 |
| 142 // This case involves clipping: frame height is 50, y-coordinate of result | 128 // This case involves clipping: frame height is 50, y-coordinate of result |
| 143 // rect is 13, so height should be clipped to (50 - 13) == 37. | 129 // rect is 13, so height should be clipped to (50 - 13) == 37. |
| 144 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), | 130 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), |
| 145 ProgrammaticScroll); | 131 ProgrammaticScroll); |
| 132 document().view()->updateAllLifecyclePhases(); | |
| 133 | |
| 146 LayoutRect originalRect(4, 60, 20, 80); | 134 LayoutRect originalRect(4, 60, 20, 80); |
| 147 LayoutRect rect = originalRect; | 135 LayoutRect rect = originalRect; |
| 148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 136 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 137 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 150 | 138 |
| 151 rect = originalRect; | 139 rect = originalRect; |
| 152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 140 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 141 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 154 checkPaintInvalidationStateRectMapping(rect, originalRect, *frameText, | 142 |
| 155 layoutView(), layoutView()); | 143 checkPaintInvalidationVisualRect(*frameText); |
| 156 | 144 |
| 157 rect = LayoutRect(4, 60, 0, 80); | 145 rect = LayoutRect(4, 60, 0, 80); |
| 158 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect, | 146 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect, |
| 159 EdgeInclusive)); | 147 EdgeInclusive)); |
| 160 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); | 148 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); |
| 161 } | 149 } |
| 162 | 150 |
| 163 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) { | 151 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) { |
| 164 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 152 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 165 setBodyInnerHTML( | 153 setBodyInnerHTML( |
| 166 "<style>body { margin: 0; }</style>" | 154 "<style>body { margin: 0; }</style>" |
| 167 "<div id=frameContainer style='position: relative; left: 0.5px'>" | 155 "<div id=frameContainer style='position: relative; left: 0.5px'>" |
| 168 " <iframe style='position: relative; left: 0.5px' " | 156 " <iframe style='position: relative; left: 0.5px' width='200'" |
| 169 "src='http://test.com' width='200' height='200' frameBorder='0'></iframe>" | 157 " height='200' src='http://test.com' frameBorder='0'></iframe>" |
| 170 "</div>"); | 158 "</div>"); |
| 171 setChildFrameHTML( | 159 setChildFrameHTML( |
| 172 "<style>body { margin: 0; }</style><div id='target' style='position: " | 160 "<style>body { margin: 0; }</style>" |
| 173 "relative; width: 100px; height: 100px; left: 0.5px'>"); | 161 "<div id='target' style='position: relative; width: 100px; height: 100px;" |
| 162 " left: 0.5px'></div>"); | |
| 174 | 163 |
| 175 document().view()->updateAllLifecyclePhases(); | 164 document().view()->updateAllLifecyclePhases(); |
| 176 | 165 |
| 177 LayoutBlock* frameContainer = | 166 LayoutBlock* frameContainer = |
| 178 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 167 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 179 LayoutObject* target = | 168 LayoutObject* target = |
| 180 childDocument().getElementById("target")->layoutObject(); | 169 childDocument().getElementById("target")->layoutObject(); |
| 181 LayoutRect rect(0, 0, 100, 100); | 170 LayoutRect rect(0, 0, 100, 100); |
| 182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 171 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, | 172 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, |
| 184 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of | 173 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of |
| 185 // frameContainer. | 174 // frameContainer. |
| 186 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), | 175 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), |
| 187 rect); | 176 rect); |
| 188 } | 177 } |
| 189 | 178 |
| 190 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { | 179 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { |
| 191 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 180 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
| 192 setBodyInnerHTML( | 181 setBodyInnerHTML( |
| 193 "<style>body { margin: 0; }</style>" | 182 "<style>body { margin: 0; }</style>" |
| 194 "<div id=frameContainer>" | 183 "<div id=frameContainer>" |
| 195 " <iframe id='frame' src='http://test.com' width='50' height='50' " | 184 " <iframe id='frame' src='http://test.com' width='50' height='50' " |
| 196 "frameBorder='0'></iframe>" | 185 " frameBorder='0'></iframe>" |
| 197 "</div>"); | 186 "</div>"); |
| 198 setChildFrameHTML( | 187 setChildFrameHTML( |
| 199 "<style>body { margin: 0; }</style><div " | 188 "<style>body { margin: 0; }</style>" |
| 200 "style='width:100px;height:100px;'></div>"); | 189 "<div style='width:100px;height:100px;'></div>"); |
| 201 | |
| 202 document().view()->updateAllLifecyclePhases(); | 190 document().view()->updateAllLifecyclePhases(); |
| 203 | 191 |
| 204 LayoutBlock* frameContainer = | 192 LayoutBlock* frameContainer = |
| 205 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 193 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
| 206 LayoutBlock* frameBody = | 194 LayoutBlock* frameBody = |
| 207 toLayoutBlock(childDocument().body()->layoutObject()); | 195 toLayoutBlock(childDocument().body()->layoutObject()); |
| 208 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); | 196 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); |
| 209 | 197 |
| 210 // This part is copied from the LayoutView test, just to ensure that the | 198 // This part is copied from the LayoutView test, just to ensure that the |
| 211 // mapped rect is valid before display:none is set on the iframe. | 199 // mapped rect is valid before display:none is set on the iframe. |
| 212 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), | 200 childDocument().view()->setScrollOffset(ScrollOffset(0, 47), |
| 213 ProgrammaticScroll); | 201 ProgrammaticScroll); |
| 202 document().view()->updateAllLifecyclePhases(); | |
| 203 | |
| 214 LayoutRect originalRect(4, 60, 20, 80); | 204 LayoutRect originalRect(4, 60, 20, 80); |
| 215 LayoutRect rect = originalRect; | 205 LayoutRect rect = originalRect; |
| 216 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 206 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
| 217 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 207 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
| 218 | 208 |
| 219 Element* frameElement = document().getElementById("frame"); | 209 Element* frameElement = document().getElementById("frame"); |
| 220 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); | 210 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); |
| 221 document().view()->updateAllLifecyclePhases(); | 211 document().view()->updateAllLifecyclePhases(); |
| 222 | 212 |
| 223 rect = originalRect; | 213 rect = originalRect; |
| 224 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 214 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 225 EXPECT_EQ(rect, LayoutRect()); | 215 EXPECT_EQ(rect, LayoutRect()); |
| 226 } | 216 } |
| 227 | 217 |
| 228 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { | 218 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { |
| 229 setBodyInnerHTML( | 219 setBodyInnerHTML( |
| 230 "<div id='target' style='writing-mode: vertical-rl; box-shadow: 40px " | 220 "<div id='target' style='writing-mode: vertical-rl;" |
| 231 "20px black;" | 221 " box-shadow: 40px 20px black; width: 100px; height: 50px;" |
| 232 " width: 100px; height: 50px; position: absolute; top: 111px; left: " | 222 " position: absolute; top: 111px; left: 222px'>" |
| 233 "222px'>" | |
| 234 "</div>"); | 223 "</div>"); |
| 235 | 224 |
| 236 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 225 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 237 LayoutRect visualRect = target->localVisualRect(); | 226 LayoutRect localVisualRect = target->localVisualRect(); |
| 238 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the | 227 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 239 // origin) | 228 // origin) |
| 240 // 140 = width(100) + box_shadow_offset_x(40) | 229 // 140 = width(100) + box_shadow_offset_x(40) |
| 241 // 70 = height(50) + box_shadow_offset_y(20) | 230 // 70 = height(50) + box_shadow_offset_y(20) |
| 242 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), visualRect); | 231 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), localVisualRect); |
| 243 | 232 |
| 244 LayoutRect rect = visualRect; | 233 LayoutRect rect = localVisualRect; |
| 245 // TODO(wkorman): The calls to flipForWritingMode() here and in other test | 234 // TODO(wkorman): The calls to flipForWritingMode() here and in other test |
| 246 // cases below are necessary because mapToVisualRectInAncestorSpace() | 235 // cases below are necessary because mapToVisualRectInAncestorSpace() |
| 247 // currently expects the input rect to be in "physical coordinates" (*not* | 236 // currently expects the input rect to be in "physical coordinates" (*not* |
| 248 // "physical coordinates with flipped block-flow direction"), see | 237 // "physical coordinates with flipped block-flow direction"), see |
| 249 // LayoutBoxModelObject.h. | 238 // LayoutBoxModelObject.h. |
| 250 target->flipForWritingMode(rect); | 239 target->flipForWritingMode(rect); |
| 251 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 240 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 252 // This rect is in physical coordinates of target. | 241 // This rect is in physical coordinates of target. |
| 253 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); | 242 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); |
| 254 | 243 |
| 255 rect = visualRect; | 244 rect = localVisualRect; |
| 256 target->flipForWritingMode(rect); | 245 target->flipForWritingMode(rect); |
| 257 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 246 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 258 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); | 247 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); |
| 259 checkPaintInvalidationStateRectMapping(rect, visualRect, *target, | 248 EXPECT_EQ(rect, target->visualRect()); |
| 260 layoutView(), layoutView()); | |
| 261 } | 249 } |
| 262 | 250 |
| 263 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode) { | 251 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode) { |
| 264 setBodyInnerHTML( | 252 setBodyInnerHTML( |
| 265 "<div id='container' style='writing-mode: vertical-rl; position: " | 253 "<div id='container' style='writing-mode: vertical-rl;" |
| 266 "absolute; top: 111px; left: 222px'>" | 254 " position: absolute; top: 111px; left: 222px'>" |
| 267 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 255 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;" |
| 268 "height: 90px'></div>" | 256 " height: 90px'></div>" |
| 269 " <div style='width: 100px; height: 100px'></div>" | 257 " <div style='width: 100px; height: 100px'></div>" |
| 270 "</div>"); | 258 "</div>"); |
| 271 | 259 |
| 272 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 260 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 273 LayoutRect targetVisualRect = target->localVisualRect(); | 261 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 274 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the | 262 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 275 // origin) | 263 // origin) |
| 276 // 140 = width(100) + box_shadow_offset_x(40) | 264 // 140 = width(100) + box_shadow_offset_x(40) |
| 277 // 110 = height(90) + box_shadow_offset_y(20) | 265 // 110 = height(90) + box_shadow_offset_y(20) |
| 278 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetVisualRect); | 266 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetLocalVisualRect); |
| 279 | 267 |
| 280 LayoutRect rect = targetVisualRect; | 268 LayoutRect rect = targetLocalVisualRect; |
| 281 target->flipForWritingMode(rect); | 269 target->flipForWritingMode(rect); |
| 282 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 270 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 283 // This rect is in physical coordinates of target. | 271 // This rect is in physical coordinates of target. |
| 284 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 272 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 285 | 273 |
| 286 LayoutBlock* container = | 274 LayoutBlock* container = |
| 287 toLayoutBlock(getLayoutObjectByElementId("container")); | 275 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 288 rect = targetVisualRect; | 276 rect = targetLocalVisualRect; |
| 289 target->flipForWritingMode(rect); | 277 target->flipForWritingMode(rect); |
| 290 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 278 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 291 // 100 is the physical x location of target in container. | 279 // 100 is the physical x location of target in container. |
| 292 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); | 280 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); |
| 293 rect = targetVisualRect; | 281 rect = targetLocalVisualRect; |
| 294 target->flipForWritingMode(rect); | 282 target->flipForWritingMode(rect); |
| 295 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 283 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 296 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); | 284 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); |
| 297 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 285 EXPECT_EQ(rect, target->visualRect()); |
| 298 layoutView(), layoutView()); | |
| 299 | 286 |
| 300 LayoutRect containerVisualRect = container->localVisualRect(); | 287 LayoutRect containerLocalVisualRect = container->localVisualRect(); |
| 301 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerVisualRect); | 288 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerLocalVisualRect); |
| 302 rect = containerVisualRect; | 289 rect = containerLocalVisualRect; |
| 303 container->flipForWritingMode(rect); | 290 container->flipForWritingMode(rect); |
| 304 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 291 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 305 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect); | 292 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect); |
| 306 rect = containerVisualRect; | 293 rect = containerLocalVisualRect; |
| 307 container->flipForWritingMode(rect); | 294 container->flipForWritingMode(rect); |
| 308 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 295 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 309 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect); | 296 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect); |
| 310 checkPaintInvalidationStateRectMapping(rect, containerVisualRect, *container, | 297 EXPECT_EQ(rect, container->visualRect()); |
| 311 layoutView(), layoutView()); | |
| 312 } | 298 } |
| 313 | 299 |
| 314 TEST_F(VisualRectMappingTest, ContainerOverflowScroll) { | 300 TEST_F(VisualRectMappingTest, ContainerOverflowScroll) { |
| 315 setBodyInnerHTML( | 301 setBodyInnerHTML( |
| 316 "<div id='container' style='position: absolute; top: 111px; left: 222px;" | 302 "<div id='container' style='position: absolute; top: 111px; left: 222px;" |
| 317 " border: 10px solid red; overflow: scroll; width: 50px; height: " | 303 " border: 10px solid red; overflow: scroll; width: 50px;" |
| 318 "80px;'>" | 304 " height: 80px'>" |
| 319 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 305 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;" |
| 320 "height: 90px'></div>" | 306 " height: 90px'></div>" |
| 321 "</div>"); | 307 "</div>"); |
| 322 | 308 |
| 323 LayoutBlock* container = | 309 LayoutBlock* container = |
| 324 toLayoutBlock(getLayoutObjectByElementId("container")); | 310 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 325 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 311 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
| 326 EXPECT_EQ(LayoutUnit(), container->scrollLeft()); | 312 EXPECT_EQ(LayoutUnit(), container->scrollLeft()); |
| 327 container->setScrollTop(LayoutUnit(7)); | 313 container->setScrollTop(LayoutUnit(7)); |
| 328 container->setScrollLeft(LayoutUnit(8)); | 314 container->setScrollLeft(LayoutUnit(8)); |
| 329 document().view()->updateAllLifecyclePhases(); | 315 document().view()->updateAllLifecyclePhases(); |
| 330 | 316 |
| 331 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 317 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 332 LayoutRect targetVisualRect = target->localVisualRect(); | 318 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 333 // 140 = width(100) + box_shadow_offset_x(40) | 319 // 140 = width(100) + box_shadow_offset_x(40) |
| 334 // 110 = height(90) + box_shadow_offset_y(20) | 320 // 110 = height(90) + box_shadow_offset_y(20) |
| 335 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetVisualRect); | 321 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetLocalVisualRect); |
| 336 LayoutRect rect = targetVisualRect; | 322 LayoutRect rect = targetLocalVisualRect; |
| 337 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 323 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 338 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 324 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 339 | 325 |
| 340 rect = targetVisualRect; | 326 rect = targetLocalVisualRect; |
| 341 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 327 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 342 rect.move(-container->scrolledContentOffset()); | 328 rect.move(-container->scrolledContentOffset()); |
| 343 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) | 329 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) |
| 344 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 330 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 345 // Rect is not clipped by container's overflow clip because of | 331 // Rect is not clipped by container's overflow clip because of |
| 346 // overflow:scroll. | 332 // overflow:scroll. |
| 347 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); | 333 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); |
| 348 | 334 |
| 349 rect = targetVisualRect; | 335 rect = targetLocalVisualRect; |
| 350 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 336 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 351 // (2, 3, 140, 100) is first clipped by container's overflow clip, to | 337 // (2, 3, 140, 100) is first clipped by container's overflow clip, to |
| 352 // (10, 10, 50, 80), then is by added container's offset in LayoutView | 338 // (10, 10, 50, 80), then is by added container's offset in LayoutView |
| 353 // (111, 222). | 339 // (111, 222). |
| 354 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); | 340 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); |
| 355 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 341 EXPECT_EQ(rect, target->visualRect()); |
| 356 layoutView(), layoutView()); | |
| 357 | 342 |
| 358 LayoutRect containerVisualRect = container->localVisualRect(); | 343 LayoutRect containerLocalVisualRect = container->localVisualRect(); |
| 359 // Because container has overflow clip, its visual overflow doesn't include | 344 // Because container has overflow clip, its visual overflow doesn't include |
| 360 // overflow from children. | 345 // overflow from children. |
| 361 // 70 = width(50) + border_left_width(10) + border_right_width(10) | 346 // 70 = width(50) + border_left_width(10) + border_right_width(10) |
| 362 // 100 = height(80) + border_top_width(10) + border_bottom_width(10) | 347 // 100 = height(80) + border_top_width(10) + border_bottom_width(10) |
| 363 EXPECT_EQ(LayoutRect(0, 0, 70, 100), containerVisualRect); | 348 EXPECT_EQ(LayoutRect(0, 0, 70, 100), containerLocalVisualRect); |
| 364 rect = containerVisualRect; | 349 rect = containerLocalVisualRect; |
| 365 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 350 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 366 // Container should not apply overflow clip on its own overflow rect. | 351 // Container should not apply overflow clip on its own overflow rect. |
| 367 EXPECT_EQ(LayoutRect(0, 0, 70, 100), rect); | 352 EXPECT_EQ(LayoutRect(0, 0, 70, 100), rect); |
| 368 | 353 |
| 369 rect = containerVisualRect; | 354 rect = containerLocalVisualRect; |
| 370 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 355 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 371 EXPECT_EQ(LayoutRect(222, 111, 70, 100), rect); | 356 EXPECT_EQ(LayoutRect(222, 111, 70, 100), rect); |
| 372 checkPaintInvalidationStateRectMapping(rect, containerVisualRect, *container, | 357 EXPECT_EQ(rect, container->visualRect()); |
| 373 layoutView(), layoutView()); | |
| 374 } | 358 } |
| 375 | 359 |
| 376 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowScroll) { | 360 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowScroll) { |
| 377 setBodyInnerHTML( | 361 setBodyInnerHTML( |
| 378 "<div id='container' style='writing-mode: vertical-rl; position: " | 362 "<div id='container' style='writing-mode: vertical-rl;" |
| 379 "absolute; top: 111px; left: 222px;" | 363 " position: absolute; top: 111px; left: 222px; border: solid red;" |
| 380 " border: solid red; border-width: 10px 20px 30px 40px;" | 364 " border-width: 10px 20px 30px 40px; overflow: scroll; width: 50px;" |
| 381 " overflow: scroll; width: 50px; height: 80px'>" | 365 " height: 80px'>" |
| 382 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 366 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;" |
| 383 "height: 90px'></div>" | 367 " height: 90px'></div>" |
| 384 " <div style='width: 100px; height: 100px'></div>" | 368 " <div style='width: 100px; height: 100px'></div>" |
| 385 "</div>"); | 369 "</div>"); |
| 386 | 370 |
| 387 LayoutBlock* container = | 371 LayoutBlock* container = |
| 388 toLayoutBlock(getLayoutObjectByElementId("container")); | 372 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 389 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 373 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
| 390 // The initial scroll offset is to the left-most because of flipped blocks | 374 // The initial scroll offset is to the left-most because of flipped blocks |
| 391 // writing mode. | 375 // writing mode. |
| 392 // 150 = total_layout_overflow(100 + 100) - width(50) | 376 // 150 = total_layout_overflow(100 + 100) - width(50) |
| 393 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 377 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
| 394 container->setScrollTop(LayoutUnit(7)); | 378 container->setScrollTop(LayoutUnit(7)); |
| 395 container->setScrollLeft( | 379 container->setScrollLeft( |
| 396 LayoutUnit(142)); // Scroll to the right by 8 pixels. | 380 LayoutUnit(142)); // Scroll to the right by 8 pixels. |
| 397 document().view()->updateAllLifecyclePhases(); | 381 document().view()->updateAllLifecyclePhases(); |
| 398 | 382 |
| 399 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 383 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 400 LayoutRect targetVisualRect = target->localVisualRect(); | 384 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 401 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the | 385 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 402 // origin) | 386 // origin) |
| 403 // 140 = width(100) + box_shadow_offset_x(40) | 387 // 140 = width(100) + box_shadow_offset_x(40) |
| 404 // 110 = height(90) + box_shadow_offset_y(20) | 388 // 110 = height(90) + box_shadow_offset_y(20) |
| 405 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetVisualRect); | 389 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetLocalVisualRect); |
| 406 | 390 |
| 407 LayoutRect rect = targetVisualRect; | 391 LayoutRect rect = targetLocalVisualRect; |
| 408 target->flipForWritingMode(rect); | 392 target->flipForWritingMode(rect); |
| 409 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 393 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 410 // This rect is in physical coordinates of target. | 394 // This rect is in physical coordinates of target. |
| 411 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 395 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 412 | 396 |
| 413 rect = targetVisualRect; | 397 rect = targetLocalVisualRect; |
| 414 target->flipForWritingMode(rect); | 398 target->flipForWritingMode(rect); |
| 415 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 399 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 416 rect.move(-container->scrolledContentOffset()); | 400 rect.move(-container->scrolledContentOffset()); |
| 417 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) | 401 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) |
| 418 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 402 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 419 // Rect is clipped by container's overflow clip because of overflow:scroll. | 403 // Rect is clipped by container's overflow clip because of overflow:scroll. |
| 420 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 404 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
| 421 | 405 |
| 422 rect = targetVisualRect; | 406 rect = targetLocalVisualRect; |
| 423 target->flipForWritingMode(rect); | 407 target->flipForWritingMode(rect); |
| 424 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 408 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 425 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to | 409 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to |
| 426 // (40, 10, 50, 80), then is added by container's offset in LayoutView | 410 // (40, 10, 50, 80), then is added by container's offset in LayoutView |
| 427 // (111, 222). | 411 // (111, 222). |
| 428 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but is | 412 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but is |
| 429 // offset | 413 // offset |
| 430 // by extra horizontal border-widths because of layout error. | 414 // by extra horizontal border-widths because of layout error. |
| 431 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); | 415 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); |
| 432 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 416 EXPECT_EQ(rect, target->visualRect()); |
| 433 layoutView(), layoutView()); | |
| 434 | 417 |
| 435 LayoutRect containerVisualRect = container->localVisualRect(); | 418 LayoutRect containerLocalVisualRect = container->localVisualRect(); |
| 436 // Because container has overflow clip, its visual overflow doesn't include | 419 // Because container has overflow clip, its visual overflow doesn't include |
| 437 // overflow from children. | 420 // overflow from children. |
| 438 // 110 = width(50) + border_left_width(40) + border_right_width(20) | 421 // 110 = width(50) + border_left_width(40) + border_right_width(20) |
| 439 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) | 422 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) |
| 440 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerVisualRect); | 423 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerLocalVisualRect); |
| 441 | 424 |
| 442 rect = containerVisualRect; | 425 rect = containerLocalVisualRect; |
| 443 container->flipForWritingMode(rect); | 426 container->flipForWritingMode(rect); |
| 444 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 427 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
| 445 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); | 428 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); |
| 446 | 429 |
| 447 rect = containerVisualRect; | 430 rect = containerLocalVisualRect; |
| 448 container->flipForWritingMode(rect); | 431 container->flipForWritingMode(rect); |
| 449 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 432 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 450 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by | 433 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by |
| 451 // extra horizontal | 434 // extra horizontal |
| 452 // border-widths because of layout error. | 435 // border-widths because of layout error. |
| 453 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); | 436 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); |
| 454 checkPaintInvalidationStateRectMapping(rect, containerVisualRect, *container, | 437 EXPECT_EQ(rect, container->visualRect()); |
| 455 layoutView(), layoutView()); | |
| 456 } | 438 } |
| 457 | 439 |
| 458 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) { | 440 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) { |
| 459 setBodyInnerHTML( | 441 setBodyInnerHTML( |
| 460 "<div id='container' style='position: absolute; top: 111px; left: 222px;" | 442 "<div id='container' style='position: absolute; top: 111px; left: 222px;" |
| 461 " border: 10px solid red; overflow: hidden; width: 50px; height: " | 443 " border: 10px solid red; overflow: hidden; width: 50px;" |
| 462 "80px;'>" | 444 " height: 80px;'>" |
| 463 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 445 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;" |
| 464 "height: 90px'></div>" | 446 " height: 90px'></div>" |
| 465 "</div>"); | 447 "</div>"); |
| 466 | 448 |
| 467 LayoutBlock* container = | 449 LayoutBlock* container = |
| 468 toLayoutBlock(getLayoutObjectByElementId("container")); | 450 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 469 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 451 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
| 470 EXPECT_EQ(LayoutUnit(), container->scrollLeft()); | 452 EXPECT_EQ(LayoutUnit(), container->scrollLeft()); |
| 471 container->setScrollTop(LayoutUnit(27)); | 453 container->setScrollTop(LayoutUnit(27)); |
| 472 container->setScrollLeft(LayoutUnit(28)); | 454 container->setScrollLeft(LayoutUnit(28)); |
| 473 document().view()->updateAllLifecyclePhases(); | 455 document().view()->updateAllLifecyclePhases(); |
| 474 | 456 |
| 475 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 457 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 476 LayoutRect targetVisualRect = target->localVisualRect(); | 458 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 477 // 140 = width(100) + box_shadow_offset_x(40) | 459 // 140 = width(100) + box_shadow_offset_x(40) |
| 478 // 110 = height(90) + box_shadow_offset_y(20) | 460 // 110 = height(90) + box_shadow_offset_y(20) |
| 479 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetVisualRect); | 461 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetLocalVisualRect); |
| 480 LayoutRect rect = targetVisualRect; | 462 LayoutRect rect = targetLocalVisualRect; |
| 481 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 463 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 482 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 464 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 483 | 465 |
| 484 rect = targetVisualRect; | 466 rect = targetLocalVisualRect; |
| 485 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 467 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 486 // Rect is not clipped by container's overflow clip. | 468 // Rect is not clipped by container's overflow clip. |
| 487 EXPECT_EQ(LayoutRect(10, 10, 140, 110), rect); | 469 EXPECT_EQ(LayoutRect(10, 10, 140, 110), rect); |
| 488 } | 470 } |
| 489 | 471 |
| 490 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowHidden) { | 472 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowHidden) { |
| 491 setBodyInnerHTML( | 473 setBodyInnerHTML( |
| 492 "<div id='container' style='writing-mode: vertical-rl; position: " | 474 "<div id='container' style='writing-mode: vertical-rl; " |
| 493 "absolute; top: 111px; left: 222px;" | 475 " position: absolute; top: 111px; left: 222px; border: solid red; " |
| 494 " border: solid red; border-width: 10px 20px 30px 40px;" | 476 " border-width: 10px 20px 30px 40px; overflow: hidden; width: 50px; " |
| 495 " overflow: hidden; width: 50px; height: 80px'>" | 477 " height: 80px'>" |
| 496 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 478 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " |
| 497 "height: 90px'></div>" | 479 " height: 90px'></div>" |
| 498 " <div style='width: 100px; height: 100px'></div>" | 480 " <div style='width: 100px; height: 100px'></div>" |
| 499 "</div>"); | 481 "</div>"); |
| 500 | 482 |
| 501 LayoutBlock* container = | 483 LayoutBlock* container = |
| 502 toLayoutBlock(getLayoutObjectByElementId("container")); | 484 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 503 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 485 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
| 504 // The initial scroll offset is to the left-most because of flipped blocks | 486 // The initial scroll offset is to the left-most because of flipped blocks |
| 505 // writing mode. | 487 // writing mode. |
| 506 // 150 = total_layout_overflow(100 + 100) - width(50) | 488 // 150 = total_layout_overflow(100 + 100) - width(50) |
| 507 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 489 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
| 508 container->setScrollTop(LayoutUnit(7)); | 490 container->setScrollTop(LayoutUnit(7)); |
| 509 container->setScrollLeft(LayoutUnit(82)); // Scroll to the right by 8 pixels. | 491 container->setScrollLeft(LayoutUnit(82)); // Scroll to the right by 8 pixels. |
| 510 document().view()->updateAllLifecyclePhases(); | 492 document().view()->updateAllLifecyclePhases(); |
| 511 | 493 |
| 512 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 494 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 513 LayoutRect targetVisualRect = target->localVisualRect(); | 495 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 514 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the | 496 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 515 // origin) | 497 // origin) |
| 516 // 140 = width(100) + box_shadow_offset_x(40) | 498 // 140 = width(100) + box_shadow_offset_x(40) |
| 517 // 110 = height(90) + box_shadow_offset_y(20) | 499 // 110 = height(90) + box_shadow_offset_y(20) |
| 518 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetVisualRect); | 500 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetLocalVisualRect); |
| 519 | 501 |
| 520 LayoutRect rect = targetVisualRect; | 502 LayoutRect rect = targetLocalVisualRect; |
| 521 target->flipForWritingMode(rect); | 503 target->flipForWritingMode(rect); |
| 522 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 504 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 523 // This rect is in physical coordinates of target. | 505 // This rect is in physical coordinates of target. |
| 524 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 506 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 525 | 507 |
| 526 rect = targetVisualRect; | 508 rect = targetLocalVisualRect; |
| 527 target->flipForWritingMode(rect); | 509 target->flipForWritingMode(rect); |
| 528 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 510 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 529 // 58 = target_physical_x(100) + container_border_left(40) - scroll_left(58) | 511 // 58 = target_physical_x(100) + container_border_left(40) - scroll_left(58) |
| 530 EXPECT_EQ(LayoutRect(-10, 10, 140, 110), rect); | 512 EXPECT_EQ(LayoutRect(-10, 10, 140, 110), rect); |
| 531 } | 513 } |
| 532 | 514 |
| 533 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode) { | 515 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode) { |
| 534 setBodyInnerHTML( | 516 setBodyInnerHTML( |
| 535 "<div id='container' style='writing-mode: vertical-rl; position: " | 517 "<div id='container' style='writing-mode: vertical-rl;" |
| 536 "absolute; top: 111px; left: 222px;" | 518 " position: absolute; top: 111px; left: 222px; border: solid red;" |
| 537 " border: solid red; border-width: 10px 20px 30px 40px;" | 519 " border-width: 10px 20px 30px 40px; overflow: scroll; width: 50px;" |
| 538 " overflow: scroll; width: 50px; height: 80px'>" | 520 " height: 80px'>" |
| 539 " <div id='target' style='writing-mode: vertical-lr; box-shadow: 40px " | 521 " <div id='target' style='writing-mode: vertical-lr; width: 100px;" |
| 540 "20px black; width: 100px; height: 90px'></div>" | 522 " height: 90px; box-shadow: 40px 20px black'></div>" |
| 541 " <div style='width: 100px; height: 100px'></div>" | 523 " <div style='width: 100px; height: 100px'></div>" |
| 542 "</div>"); | 524 "</div>"); |
| 543 | 525 |
| 544 LayoutBlock* container = | 526 LayoutBlock* container = |
| 545 toLayoutBlock(getLayoutObjectByElementId("container")); | 527 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 546 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 528 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
| 547 // The initial scroll offset is to the left-most because of flipped blocks | 529 // The initial scroll offset is to the left-most because of flipped blocks |
| 548 // writing mode. | 530 // writing mode. |
| 549 // 150 = total_layout_overflow(100 + 100) - width(50) | 531 // 150 = total_layout_overflow(100 + 100) - width(50) |
| 550 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 532 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
| 551 container->setScrollTop(LayoutUnit(7)); | 533 container->setScrollTop(LayoutUnit(7)); |
| 552 container->setScrollLeft( | 534 container->setScrollLeft( |
| 553 LayoutUnit(142)); // Scroll to the right by 8 pixels. | 535 LayoutUnit(142)); // Scroll to the right by 8 pixels. |
| 554 document().view()->updateAllLifecyclePhases(); | 536 document().view()->updateAllLifecyclePhases(); |
| 555 | 537 |
| 556 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 538 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 557 LayoutRect targetVisualRect = target->localVisualRect(); | 539 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 558 // 140 = width(100) + box_shadow_offset_x(40) | 540 // 140 = width(100) + box_shadow_offset_x(40) |
| 559 // 110 = height(90) + box_shadow_offset_y(20) | 541 // 110 = height(90) + box_shadow_offset_y(20) |
| 560 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetVisualRect); | 542 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetLocalVisualRect); |
| 561 | 543 |
| 562 LayoutRect rect = targetVisualRect; | 544 LayoutRect rect = targetLocalVisualRect; |
| 563 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 545 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
| 564 // This rect is in physical coordinates of target. | 546 // This rect is in physical coordinates of target. |
| 565 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 547 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
| 566 | 548 |
| 567 rect = targetVisualRect; | 549 rect = targetLocalVisualRect; |
| 568 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 550 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
| 569 rect.move(-container->scrolledContentOffset()); | 551 rect.move(-container->scrolledContentOffset()); |
| 570 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) | 552 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) |
| 571 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 553 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
| 572 // Rect is not clipped by container's overflow clip. | 554 // Rect is not clipped by container's overflow clip. |
| 573 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 555 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
| 574 } | 556 } |
| 575 | 557 |
| 576 TEST_F(VisualRectMappingTest, | 558 TEST_F(VisualRectMappingTest, |
| 577 DifferentPaintInvalidaitionContainerForAbsolutePosition) { | 559 DifferentPaintInvalidaitionContainerForAbsolutePosition) { |
| 578 enableCompositing(); | 560 enableCompositing(); |
| 579 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); | 561 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 580 | 562 |
| 581 setBodyInnerHTML( | 563 setBodyInnerHTML( |
| 582 "<div id='stacking-context' style='opacity: 0.9; background: blue; " | 564 "<div id='stacking-context' style='opacity: 0.9; background: blue;" |
| 583 "will-change: transform'>" | 565 " will-change: transform'>" |
| 584 " <div id='scroller' style='overflow: scroll; width: 80px; height: " | 566 " <div id='scroller' style='overflow: scroll; width: 80px;" |
| 585 "80px'>" | 567 " height: 80px'>" |
| 586 " <div id='absolute' style='position: absolute; top: 111px; left: " | 568 " <div id='absolute' style='position: absolute; top: 111px;" |
| 587 "222px; width: 50px; height: 50px; background: green'></div>" | 569 " left: 222px; width: 50px; height: 50px; background: green'>" |
| 588 " <div id='normal-flow' style='width: 2000px; height: 2000px; " | |
| 589 "background: yellow'></div>" | |
| 590 " </div>" | 570 " </div>" |
| 571 " <div id='normal-flow' style='width: 2000px; height: 2000px;" | |
| 572 " background: yellow'></div>" | |
| 573 " </div>" | |
| 591 "</div>"); | 574 "</div>"); |
| 592 | 575 |
| 593 LayoutBlock* scroller = toLayoutBlock(getLayoutObjectByElementId("scroller")); | 576 LayoutBlock* scroller = toLayoutBlock(getLayoutObjectByElementId("scroller")); |
| 594 scroller->setScrollTop(LayoutUnit(77)); | 577 scroller->setScrollTop(LayoutUnit(77)); |
| 595 scroller->setScrollLeft(LayoutUnit(88)); | 578 scroller->setScrollLeft(LayoutUnit(88)); |
| 596 document().view()->updateAllLifecyclePhases(); | 579 document().view()->updateAllLifecyclePhases(); |
| 597 | 580 |
| 598 LayoutBlock* normalFlow = | 581 LayoutBlock* normalFlow = |
| 599 toLayoutBlock(getLayoutObjectByElementId("normal-flow")); | 582 toLayoutBlock(getLayoutObjectByElementId("normal-flow")); |
| 600 EXPECT_EQ(scroller, &normalFlow->containerForPaintInvalidation()); | 583 EXPECT_EQ(scroller, &normalFlow->containerForPaintInvalidation()); |
| 601 | 584 |
| 602 LayoutRect normalFlowVisualRect = normalFlow->localVisualRect(); | 585 LayoutRect normalFlowVisualRect = normalFlow->localVisualRect(); |
| 603 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), normalFlowVisualRect); | 586 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), normalFlowVisualRect); |
| 604 LayoutRect rect = normalFlowVisualRect; | 587 LayoutRect rect = normalFlowVisualRect; |
| 605 EXPECT_TRUE(normalFlow->mapToVisualRectInAncestorSpace(scroller, rect)); | 588 EXPECT_TRUE(normalFlow->mapToVisualRectInAncestorSpace(scroller, rect)); |
| 606 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), rect); | 589 EXPECT_EQ(LayoutRect(0, 0, 2000, 2000), rect); |
| 607 checkPaintInvalidationStateRectMapping(rect, normalFlowVisualRect, | 590 EXPECT_EQ(rect, normalFlow->visualRect()); |
| 608 *normalFlow, layoutView(), *scroller); | |
| 609 | 591 |
| 610 LayoutBlock* stackingContext = | 592 LayoutBlock* stackingContext = |
| 611 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); | 593 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); |
| 612 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); | 594 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); |
| 613 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); | 595 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); |
| 614 EXPECT_EQ(stackingContext, absolute->container()); | 596 EXPECT_EQ(stackingContext, absolute->container()); |
| 615 | 597 |
| 616 LayoutRect absoluteVisualRect = absolute->localVisualRect(); | 598 LayoutRect absoluteVisualRect = absolute->localVisualRect(); |
| 617 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteVisualRect); | 599 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteVisualRect); |
| 618 rect = absoluteVisualRect; | 600 rect = absoluteVisualRect; |
| 619 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)); | 601 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)); |
| 620 EXPECT_EQ(LayoutRect(222, 111, 50, 50), rect); | 602 EXPECT_EQ(LayoutRect(222, 111, 50, 50), rect); |
| 621 checkPaintInvalidationStateRectMapping(rect, absoluteVisualRect, *absolute, | 603 EXPECT_EQ(rect, absolute->visualRect()); |
| 622 layoutView(), *stackingContext); | |
| 623 } | 604 } |
| 624 | 605 |
| 625 TEST_F(VisualRectMappingTest, | 606 TEST_F(VisualRectMappingTest, |
| 626 ContainerOfAbsoluteAbovePaintInvalidationContainer) { | 607 ContainerOfAbsoluteAbovePaintInvalidationContainer) { |
| 627 enableCompositing(); | 608 enableCompositing(); |
| 628 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); | 609 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 629 | 610 |
| 630 setBodyInnerHTML( | 611 setBodyInnerHTML( |
| 631 "<div id='container' style='position: absolute; top: 88px; left: 99px'>" | 612 "<div id='container' style='position: absolute; top: 88px; left: 99px'>" |
| 632 " <div style='height: 222px'></div>" | 613 " <div style='height: 222px'></div>" |
| 633 // This div makes stacking-context composited. | 614 // This div makes stacking-context composited. |
| 634 " <div style='position: absolute; width: 1px; height: 1px; " | 615 " <div style='position: absolute; width: 1px; height: 1px; " |
| 635 "background:yellow; will-change: transform'></div>" | 616 " background:yellow; will-change: transform'></div>" |
| 636 // This stacking context is paintInvalidationContainer of the absolute | 617 // This stacking context is paintInvalidationContainer of the absolute |
| 637 // child, but not a container of it. | 618 // child, but not a container of it. |
| 638 " <div id='stacking-context' style='opacity: 0.9'>" | 619 " <div id='stacking-context' style='opacity: 0.9'>" |
| 639 " <div id='absolute' style='position: absolute; top: 50px; left: " | 620 " <div id='absolute' style='position: absolute; top: 50px; left: 50px;" |
| 640 "50px; width: 50px; height: 50px; background: green'></div>" | 621 " width: 50px; height: 50px; background: green'></div>" |
| 641 " </div>" | 622 " </div>" |
| 642 "</div>"); | 623 "</div>"); |
| 643 | 624 |
| 644 LayoutBlock* stackingContext = | 625 LayoutBlock* stackingContext = |
| 645 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); | 626 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); |
| 646 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); | 627 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); |
| 647 LayoutBlock* container = | 628 LayoutBlock* container = |
| 648 toLayoutBlock(getLayoutObjectByElementId("container")); | 629 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 649 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); | 630 EXPECT_EQ(stackingContext, &absolute->containerForPaintInvalidation()); |
| 650 EXPECT_EQ(container, absolute->container()); | 631 EXPECT_EQ(container, absolute->container()); |
| 651 | 632 |
| 652 LayoutRect absoluteVisualRect = absolute->localVisualRect(); | 633 LayoutRect absoluteVisualRect = absolute->localVisualRect(); |
| 653 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteVisualRect); | 634 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteVisualRect); |
| 654 LayoutRect rect = absoluteVisualRect; | 635 LayoutRect rect = absoluteVisualRect; |
| 655 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)); | 636 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)); |
| 656 // -172 = top(50) - y_offset_of_stacking_context(222) | 637 // -172 = top(50) - y_offset_of_stacking_context(222) |
| 657 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); | 638 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); |
| 658 checkPaintInvalidationStateRectMapping(rect, absoluteVisualRect, *absolute, | 639 // Use checkPaintInvalidationVisualRect to deals with layer squashing. |
| 659 layoutView(), *stackingContext); | 640 checkPaintInvalidationVisualRect(*absolute); |
| 660 } | 641 } |
| 661 | 642 |
| 662 TEST_F(VisualRectMappingTest, CSSClip) { | 643 TEST_F(VisualRectMappingTest, CSSClip) { |
| 663 setBodyInnerHTML( | 644 setBodyInnerHTML( |
| 664 "<div id='container' style='position: absolute; top: 0px; left: 0px; " | 645 "<div id='container' style='position: absolute; top: 0px; left: 0px; " |
| 665 "clip: rect(0px, 200px, 200px, 0px)'>" | 646 " clip: rect(0px, 200px, 200px, 0px)'>" |
| 666 " <div id='target' style='width: 400px; height: 400px'></div>" | 647 " <div id='target' style='width: 400px; height: 400px'></div>" |
| 667 " </div>" | |
| 668 "</div>"); | 648 "</div>"); |
| 669 | 649 |
| 670 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); | 650 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 671 | 651 |
| 672 LayoutRect targetVisualRect = target->localVisualRect(); | 652 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 673 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect); | 653 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetLocalVisualRect); |
| 674 LayoutRect rect = targetVisualRect; | 654 LayoutRect rect = targetLocalVisualRect; |
| 675 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 655 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 676 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); | 656 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); |
| 677 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 657 EXPECT_EQ(rect, target->visualRect()); |
| 678 layoutView(), layoutView()); | |
| 679 } | 658 } |
| 680 | 659 |
| 681 TEST_F(VisualRectMappingTest, ContainPaint) { | 660 TEST_F(VisualRectMappingTest, ContainPaint) { |
| 682 setBodyInnerHTML( | 661 setBodyInnerHTML( |
| 683 "<div id='container' style='position: absolute; top: 0px; left: 0px; " | 662 "<div id='container' style='position: absolute; top: 0px; left: 0px; " |
| 684 "width: 200px; height: 200px; contain: paint'>" | 663 " width: 200px; height: 200px; contain: paint'>" |
| 685 " <div id='target' style='width: 400px; height: 400px'></div>" | 664 " <div id='target' style='width: 400px; height: 400px'></div>" |
| 686 " </div>" | |
| 687 "</div>"); | 665 "</div>"); |
| 688 | 666 |
| 689 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); | 667 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); |
| 690 | 668 |
| 691 LayoutRect targetVisualRect = target->localVisualRect(); | 669 LayoutRect targetLocalVisualRect = target->localVisualRect(); |
| 692 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect); | 670 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetLocalVisualRect); |
| 693 LayoutRect rect = targetVisualRect; | 671 LayoutRect rect = targetLocalVisualRect; |
| 694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 672 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
| 695 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); | 673 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); |
| 696 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, | 674 EXPECT_EQ(rect, target->visualRect()); |
| 697 layoutView(), layoutView()); | |
| 698 } | 675 } |
| 699 | 676 |
| 700 } // namespace blink | 677 } // namespace blink |
| OLD | NEW |