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 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 "frame", | 132 "frame", |
133 "<style>body { margin: 0; }</style><span><img style='width: 20px; " | 133 "<style>body { margin: 0; }</style><span><img style='width: 20px; " |
134 "height: 100px'></span>text text text"); | 134 "height: 100px'></span>text text text"); |
135 document().view()->updateAllLifecyclePhases(); | 135 document().view()->updateAllLifecyclePhases(); |
136 | 136 |
137 LayoutBlock* frameContainer = | 137 LayoutBlock* frameContainer = |
138 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 138 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
139 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); | 139 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); |
140 LayoutText* frameText = toLayoutText(frameBody->lastChild()); | 140 LayoutText* frameText = toLayoutText(frameBody->lastChild()); |
141 | 141 |
142 // This case involves clipping: frame height is 50, y-coordinate of result rec
t is 13, | 142 // This case involves clipping: frame height is 50, y-coordinate of result |
143 // so height should be clipped to (50 - 13) == 37. | 143 // rect is 13, so height should be clipped to (50 - 13) == 37. |
144 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), | 144 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), |
145 ProgrammaticScroll); | 145 ProgrammaticScroll); |
146 LayoutRect originalRect(4, 60, 20, 80); | 146 LayoutRect originalRect(4, 60, 20, 80); |
147 LayoutRect rect = originalRect; | 147 LayoutRect rect = originalRect; |
148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
150 | 150 |
151 rect = originalRect; | 151 rect = originalRect; |
152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
(...skipping 19 matching lines...) Expand all Loading... |
173 "frame", | 173 "frame", |
174 "<style>body { margin: 0; }</style><div id='target' style='position: " | 174 "<style>body { margin: 0; }</style><div id='target' style='position: " |
175 "relative; width: 100px; height: 100px; left: 0.5px'>"); | 175 "relative; width: 100px; height: 100px; left: 0.5px'>"); |
176 document().view()->updateAllLifecyclePhases(); | 176 document().view()->updateAllLifecyclePhases(); |
177 | 177 |
178 LayoutBlock* frameContainer = | 178 LayoutBlock* frameContainer = |
179 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 179 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
180 LayoutObject* target = frameDocument.getElementById("target")->layoutObject(); | 180 LayoutObject* target = frameDocument.getElementById("target")->layoutObject(); |
181 LayoutRect rect(0, 0, 100, 100); | 181 LayoutRect rect(0, 0, 100, 100); |
182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100,
100) is expanded to (0, 0, 100, 100), and then offset by | 183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, |
184 // the 0.5 offset of frameContainer. | 184 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of |
| 185 // frameContainer. |
185 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), | 186 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), |
186 rect); | 187 rect); |
187 } | 188 } |
188 | 189 |
189 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { | 190 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { |
190 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 191 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
191 setBodyInnerHTML( | 192 setBodyInnerHTML( |
192 "<style>body { margin: 0; }</style>" | 193 "<style>body { margin: 0; }</style>" |
193 "<div id=frameContainer>" | 194 "<div id=frameContainer>" |
194 " <iframe id=frame src='http://test.com' width='50' height='50' " | 195 " <iframe id=frame src='http://test.com' width='50' height='50' " |
195 "frameBorder='0'></iframe>" | 196 "frameBorder='0'></iframe>" |
196 "</div>"); | 197 "</div>"); |
197 | 198 |
198 Document& frameDocument = | 199 Document& frameDocument = |
199 setupChildIframe("frame", | 200 setupChildIframe("frame", |
200 "<style>body { margin: 0; }</style><div " | 201 "<style>body { margin: 0; }</style><div " |
201 "style='width:100px;height:100px;'></div>"); | 202 "style='width:100px;height:100px;'></div>"); |
202 document().view()->updateAllLifecyclePhases(); | 203 document().view()->updateAllLifecyclePhases(); |
203 | 204 |
204 LayoutBlock* frameContainer = | 205 LayoutBlock* frameContainer = |
205 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); | 206 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); |
206 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); | 207 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); |
207 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); | 208 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); |
208 | 209 |
209 // This part is copied from the LayoutView test, just to ensure that the mappe
d | 210 // This part is copied from the LayoutView test, just to ensure that the |
210 // rect is valid before display:none is set on the iframe. | 211 // mapped rect is valid before display:none is set on the iframe. |
211 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), | 212 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), |
212 ProgrammaticScroll); | 213 ProgrammaticScroll); |
213 LayoutRect originalRect(4, 60, 20, 80); | 214 LayoutRect originalRect(4, 60, 20, 80); |
214 LayoutRect rect = originalRect; | 215 LayoutRect rect = originalRect; |
215 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); | 216 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); |
216 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | 217 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); |
217 | 218 |
218 Element* frameElement = document().getElementById("frame"); | 219 Element* frameElement = document().getElementById("frame"); |
219 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); | 220 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); |
220 document().view()->updateAllLifecyclePhases(); | 221 document().view()->updateAllLifecyclePhases(); |
221 | 222 |
222 rect = originalRect; | 223 rect = originalRect; |
223 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 224 EXPECT_FALSE(frameDiv->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
224 EXPECT_EQ(rect, LayoutRect()); | 225 EXPECT_EQ(rect, LayoutRect()); |
225 } | 226 } |
226 | 227 |
227 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { | 228 TEST_F(VisualRectMappingTest, SelfFlippedWritingMode) { |
228 setBodyInnerHTML( | 229 setBodyInnerHTML( |
229 "<div id='target' style='writing-mode: vertical-rl; box-shadow: 40px " | 230 "<div id='target' style='writing-mode: vertical-rl; box-shadow: 40px " |
230 "20px black;" | 231 "20px black;" |
231 " width: 100px; height: 50px; position: absolute; top: 111px; left: " | 232 " width: 100px; height: 50px; position: absolute; top: 111px; left: " |
232 "222px'>" | 233 "222px'>" |
233 "</div>"); | 234 "</div>"); |
234 | 235 |
235 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 236 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
236 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); | 237 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); |
237 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the origi
n) | 238 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 239 // origin) |
238 // 140 = width(100) + box_shadow_offset_x(40) | 240 // 140 = width(100) + box_shadow_offset_x(40) |
239 // 70 = height(50) + box_shadow_offset_y(20) | 241 // 70 = height(50) + box_shadow_offset_y(20) |
240 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); | 242 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); |
241 | 243 |
242 LayoutRect rect = overflowRect; | 244 LayoutRect rect = overflowRect; |
243 // TODO(wkorman): The calls to flipForWritingMode() here and in other test | 245 // TODO(wkorman): The calls to flipForWritingMode() here and in other test |
244 // cases below are necessary because mapToVisualRectInAncestorSpace() | 246 // cases below are necessary because mapToVisualRectInAncestorSpace() |
245 // currently expects the input rect to be in "physical coordinates" (*not* | 247 // currently expects the input rect to be in "physical coordinates" (*not* |
246 // "physical coordinates with flipped block-flow direction"), see | 248 // "physical coordinates with flipped block-flow direction"), see |
247 // LayoutBoxModelObject.h. | 249 // LayoutBoxModelObject.h. |
(...skipping 15 matching lines...) Expand all Loading... |
263 "<div id='container' style='writing-mode: vertical-rl; position: " | 265 "<div id='container' style='writing-mode: vertical-rl; position: " |
264 "absolute; top: 111px; left: 222px'>" | 266 "absolute; top: 111px; left: 222px'>" |
265 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 267 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " |
266 "height: 90px'></div>" | 268 "height: 90px'></div>" |
267 " <div style='width: 100px; height: 100px'></div>" | 269 " <div style='width: 100px; height: 100px'></div>" |
268 "</div>"); | 270 "</div>"); |
269 | 271 |
270 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 272 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
271 LayoutRect targetOverflowRect = | 273 LayoutRect targetOverflowRect = |
272 target->localOverflowRectForPaintInvalidation(); | 274 target->localOverflowRectForPaintInvalidation(); |
273 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the origi
n) | 275 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 276 // origin) |
274 // 140 = width(100) + box_shadow_offset_x(40) | 277 // 140 = width(100) + box_shadow_offset_x(40) |
275 // 110 = height(90) + box_shadow_offset_y(20) | 278 // 110 = height(90) + box_shadow_offset_y(20) |
276 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 279 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
277 | 280 |
278 LayoutRect rect = targetOverflowRect; | 281 LayoutRect rect = targetOverflowRect; |
279 target->flipForWritingMode(rect); | 282 target->flipForWritingMode(rect); |
280 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 283 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
281 // This rect is in physical coordinates of target. | 284 // This rect is in physical coordinates of target. |
282 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 285 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
283 | 286 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); | 338 EXPECT_EQ(LayoutRect(0, 0, 140, 110), targetOverflowRect); |
336 LayoutRect rect = targetOverflowRect; | 339 LayoutRect rect = targetOverflowRect; |
337 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 340 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
338 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 341 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
339 | 342 |
340 rect = targetOverflowRect; | 343 rect = targetOverflowRect; |
341 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 344 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
342 rect.move(-container->scrolledContentOffset()); | 345 rect.move(-container->scrolledContentOffset()); |
343 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) | 346 // 2 = target_x(0) + container_border_left(10) - scroll_left(8) |
344 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 347 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
345 // Rect is not clipped by container's overflow clip because of overflow:scroll
. | 348 // Rect is not clipped by container's overflow clip because of |
| 349 // overflow:scroll. |
346 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); | 350 EXPECT_EQ(LayoutRect(2, 3, 140, 110), rect); |
347 | 351 |
348 rect = targetOverflowRect; | 352 rect = targetOverflowRect; |
349 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 353 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
350 // (2, 3, 140, 100) is first clipped by container's overflow clip, to (10, 10,
50, 80), | 354 // (2, 3, 140, 100) is first clipped by container's overflow clip, to |
351 // then is by added container's offset in LayoutView (111, 222). | 355 // (10, 10, 50, 80), then is by added container's offset in LayoutView |
| 356 // (111, 222). |
352 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); | 357 EXPECT_EQ(LayoutRect(232, 121, 50, 80), rect); |
353 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, | 358 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, |
354 layoutView(), layoutView()); | 359 layoutView(), layoutView()); |
355 | 360 |
356 LayoutRect containerOverflowRect = | 361 LayoutRect containerOverflowRect = |
357 container->localOverflowRectForPaintInvalidation(); | 362 container->localOverflowRectForPaintInvalidation(); |
358 // Because container has overflow clip, its visual overflow doesn't include ov
erflow from children. | 363 // Because container has overflow clip, its visual overflow doesn't include |
| 364 // overflow from children. |
359 // 70 = width(50) + border_left_width(10) + border_right_width(10) | 365 // 70 = width(50) + border_left_width(10) + border_right_width(10) |
360 // 100 = height(80) + border_top_width(10) + border_bottom_width(10) | 366 // 100 = height(80) + border_top_width(10) + border_bottom_width(10) |
361 EXPECT_EQ(LayoutRect(0, 0, 70, 100), containerOverflowRect); | 367 EXPECT_EQ(LayoutRect(0, 0, 70, 100), containerOverflowRect); |
362 rect = containerOverflowRect; | 368 rect = containerOverflowRect; |
363 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 369 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
364 // Container should not apply overflow clip on its own overflow rect. | 370 // Container should not apply overflow clip on its own overflow rect. |
365 EXPECT_EQ(LayoutRect(0, 0, 70, 100), rect); | 371 EXPECT_EQ(LayoutRect(0, 0, 70, 100), rect); |
366 | 372 |
367 rect = containerOverflowRect; | 373 rect = containerOverflowRect; |
368 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 374 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
369 EXPECT_EQ(LayoutRect(222, 111, 70, 100), rect); | 375 EXPECT_EQ(LayoutRect(222, 111, 70, 100), rect); |
370 checkPaintInvalidationStateRectMapping( | 376 checkPaintInvalidationStateRectMapping( |
371 rect, containerOverflowRect, *container, layoutView(), layoutView()); | 377 rect, containerOverflowRect, *container, layoutView(), layoutView()); |
372 } | 378 } |
373 | 379 |
374 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowScroll) { | 380 TEST_F(VisualRectMappingTest, ContainerFlippedWritingModeAndOverflowScroll) { |
375 setBodyInnerHTML( | 381 setBodyInnerHTML( |
376 "<div id='container' style='writing-mode: vertical-rl; position: " | 382 "<div id='container' style='writing-mode: vertical-rl; position: " |
377 "absolute; top: 111px; left: 222px;" | 383 "absolute; top: 111px; left: 222px;" |
378 " border: solid red; border-width: 10px 20px 30px 40px;" | 384 " border: solid red; border-width: 10px 20px 30px 40px;" |
379 " overflow: scroll; width: 50px; height: 80px'>" | 385 " overflow: scroll; width: 50px; height: 80px'>" |
380 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 386 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " |
381 "height: 90px'></div>" | 387 "height: 90px'></div>" |
382 " <div style='width: 100px; height: 100px'></div>" | 388 " <div style='width: 100px; height: 100px'></div>" |
383 "</div>"); | 389 "</div>"); |
384 | 390 |
385 LayoutBlock* container = | 391 LayoutBlock* container = |
386 toLayoutBlock(getLayoutObjectByElementId("container")); | 392 toLayoutBlock(getLayoutObjectByElementId("container")); |
387 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 393 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
388 // The initial scroll offset is to the left-most because of flipped blocks wri
ting mode. | 394 // The initial scroll offset is to the left-most because of flipped blocks |
| 395 // writing mode. |
389 // 150 = total_layout_overflow(100 + 100) - width(50) | 396 // 150 = total_layout_overflow(100 + 100) - width(50) |
390 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 397 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
391 container->setScrollTop(LayoutUnit(7)); | 398 container->setScrollTop(LayoutUnit(7)); |
392 container->setScrollLeft( | 399 container->setScrollLeft( |
393 LayoutUnit(142)); // Scroll to the right by 8 pixels. | 400 LayoutUnit(142)); // Scroll to the right by 8 pixels. |
394 document().view()->updateAllLifecyclePhases(); | 401 document().view()->updateAllLifecyclePhases(); |
395 | 402 |
396 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 403 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
397 LayoutRect targetOverflowRect = | 404 LayoutRect targetOverflowRect = |
398 target->localOverflowRectForPaintInvalidation(); | 405 target->localOverflowRectForPaintInvalidation(); |
399 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the origi
n) | 406 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 407 // origin) |
400 // 140 = width(100) + box_shadow_offset_x(40) | 408 // 140 = width(100) + box_shadow_offset_x(40) |
401 // 110 = height(90) + box_shadow_offset_y(20) | 409 // 110 = height(90) + box_shadow_offset_y(20) |
402 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 410 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
403 | 411 |
404 LayoutRect rect = targetOverflowRect; | 412 LayoutRect rect = targetOverflowRect; |
405 target->flipForWritingMode(rect); | 413 target->flipForWritingMode(rect); |
406 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 414 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
407 // This rect is in physical coordinates of target. | 415 // This rect is in physical coordinates of target. |
408 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 416 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
409 | 417 |
410 rect = targetOverflowRect; | 418 rect = targetOverflowRect; |
411 target->flipForWritingMode(rect); | 419 target->flipForWritingMode(rect); |
412 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 420 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
413 rect.move(-container->scrolledContentOffset()); | 421 rect.move(-container->scrolledContentOffset()); |
414 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) | 422 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142) |
415 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 423 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
416 // Rect is clipped by container's overflow clip because of overflow:scroll. | 424 // Rect is clipped by container's overflow clip because of overflow:scroll. |
417 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 425 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
418 | 426 |
419 rect = targetOverflowRect; | 427 rect = targetOverflowRect; |
420 target->flipForWritingMode(rect); | 428 target->flipForWritingMode(rect); |
421 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 429 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
422 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40, 10
, 50, 80), | 430 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to |
423 // then is added by container's offset in LayoutView (111, 222). | 431 // (40, 10, 50, 80), then is added by container's offset in LayoutView |
424 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but is
offset | 432 // (111, 222). |
| 433 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but is |
| 434 // offset |
425 // by extra horizontal border-widths because of layout error. | 435 // by extra horizontal border-widths because of layout error. |
426 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); | 436 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); |
427 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, | 437 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, |
428 layoutView(), layoutView()); | 438 layoutView(), layoutView()); |
429 | 439 |
430 LayoutRect containerOverflowRect = | 440 LayoutRect containerOverflowRect = |
431 container->localOverflowRectForPaintInvalidation(); | 441 container->localOverflowRectForPaintInvalidation(); |
432 // Because container has overflow clip, its visual overflow doesn't include ov
erflow from children. | 442 // Because container has overflow clip, its visual overflow doesn't include |
| 443 // overflow from children. |
433 // 110 = width(50) + border_left_width(40) + border_right_width(20) | 444 // 110 = width(50) + border_left_width(40) + border_right_width(20) |
434 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) | 445 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) |
435 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); | 446 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); |
436 | 447 |
437 rect = containerOverflowRect; | 448 rect = containerOverflowRect; |
438 container->flipForWritingMode(rect); | 449 container->flipForWritingMode(rect); |
439 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 450 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
440 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); | 451 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); |
441 | 452 |
442 rect = containerOverflowRect; | 453 rect = containerOverflowRect; |
443 container->flipForWritingMode(rect); | 454 container->flipForWritingMode(rect); |
444 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 455 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
445 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by ext
ra horizontal | 456 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by |
| 457 // extra horizontal |
446 // border-widths because of layout error. | 458 // border-widths because of layout error. |
447 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); | 459 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); |
448 checkPaintInvalidationStateRectMapping( | 460 checkPaintInvalidationStateRectMapping( |
449 rect, containerOverflowRect, *container, layoutView(), layoutView()); | 461 rect, containerOverflowRect, *container, layoutView(), layoutView()); |
450 } | 462 } |
451 | 463 |
452 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) { | 464 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) { |
453 setBodyInnerHTML( | 465 setBodyInnerHTML( |
454 "<div id='container' style='position: absolute; top: 111px; left: 222px;" | 466 "<div id='container' style='position: absolute; top: 111px; left: 222px;" |
455 " border: 10px solid red; overflow: hidden; width: 50px; height: " | 467 " border: 10px solid red; overflow: hidden; width: 50px; height: " |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 " border: solid red; border-width: 10px 20px 30px 40px;" | 501 " border: solid red; border-width: 10px 20px 30px 40px;" |
490 " overflow: hidden; width: 50px; height: 80px'>" | 502 " overflow: hidden; width: 50px; height: 80px'>" |
491 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " | 503 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; " |
492 "height: 90px'></div>" | 504 "height: 90px'></div>" |
493 " <div style='width: 100px; height: 100px'></div>" | 505 " <div style='width: 100px; height: 100px'></div>" |
494 "</div>"); | 506 "</div>"); |
495 | 507 |
496 LayoutBlock* container = | 508 LayoutBlock* container = |
497 toLayoutBlock(getLayoutObjectByElementId("container")); | 509 toLayoutBlock(getLayoutObjectByElementId("container")); |
498 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 510 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
499 // The initial scroll offset is to the left-most because of flipped blocks wri
ting mode. | 511 // The initial scroll offset is to the left-most because of flipped blocks |
| 512 // writing mode. |
500 // 150 = total_layout_overflow(100 + 100) - width(50) | 513 // 150 = total_layout_overflow(100 + 100) - width(50) |
501 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 514 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
502 container->setScrollTop(LayoutUnit(7)); | 515 container->setScrollTop(LayoutUnit(7)); |
503 container->setScrollLeft(LayoutUnit(82)); // Scroll to the right by 8 pixels. | 516 container->setScrollLeft(LayoutUnit(82)); // Scroll to the right by 8 pixels. |
504 document().view()->updateAllLifecyclePhases(); | 517 document().view()->updateAllLifecyclePhases(); |
505 | 518 |
506 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 519 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
507 LayoutRect targetOverflowRect = | 520 LayoutRect targetOverflowRect = |
508 target->localOverflowRectForPaintInvalidation(); | 521 target->localOverflowRectForPaintInvalidation(); |
509 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the origi
n) | 522 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the |
| 523 // origin) |
510 // 140 = width(100) + box_shadow_offset_x(40) | 524 // 140 = width(100) + box_shadow_offset_x(40) |
511 // 110 = height(90) + box_shadow_offset_y(20) | 525 // 110 = height(90) + box_shadow_offset_y(20) |
512 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 526 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
513 | 527 |
514 LayoutRect rect = targetOverflowRect; | 528 LayoutRect rect = targetOverflowRect; |
515 target->flipForWritingMode(rect); | 529 target->flipForWritingMode(rect); |
516 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 530 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
517 // This rect is in physical coordinates of target. | 531 // This rect is in physical coordinates of target. |
518 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 532 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
519 | 533 |
(...skipping 11 matching lines...) Expand all Loading... |
531 " border: solid red; border-width: 10px 20px 30px 40px;" | 545 " border: solid red; border-width: 10px 20px 30px 40px;" |
532 " overflow: scroll; width: 50px; height: 80px'>" | 546 " overflow: scroll; width: 50px; height: 80px'>" |
533 " <div id='target' style='writing-mode: vertical-lr; box-shadow: 40px " | 547 " <div id='target' style='writing-mode: vertical-lr; box-shadow: 40px " |
534 "20px black; width: 100px; height: 90px'></div>" | 548 "20px black; width: 100px; height: 90px'></div>" |
535 " <div style='width: 100px; height: 100px'></div>" | 549 " <div style='width: 100px; height: 100px'></div>" |
536 "</div>"); | 550 "</div>"); |
537 | 551 |
538 LayoutBlock* container = | 552 LayoutBlock* container = |
539 toLayoutBlock(getLayoutObjectByElementId("container")); | 553 toLayoutBlock(getLayoutObjectByElementId("container")); |
540 EXPECT_EQ(LayoutUnit(), container->scrollTop()); | 554 EXPECT_EQ(LayoutUnit(), container->scrollTop()); |
541 // The initial scroll offset is to the left-most because of flipped blocks wri
ting mode. | 555 // The initial scroll offset is to the left-most because of flipped blocks |
| 556 // writing mode. |
542 // 150 = total_layout_overflow(100 + 100) - width(50) | 557 // 150 = total_layout_overflow(100 + 100) - width(50) |
543 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); | 558 EXPECT_EQ(LayoutUnit(150), container->scrollLeft()); |
544 container->setScrollTop(LayoutUnit(7)); | 559 container->setScrollTop(LayoutUnit(7)); |
545 container->setScrollLeft( | 560 container->setScrollLeft( |
546 LayoutUnit(142)); // Scroll to the right by 8 pixels. | 561 LayoutUnit(142)); // Scroll to the right by 8 pixels. |
547 document().view()->updateAllLifecyclePhases(); | 562 document().view()->updateAllLifecyclePhases(); |
548 | 563 |
549 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 564 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
550 LayoutRect targetOverflowRect = | 565 LayoutRect targetOverflowRect = |
551 target->localOverflowRectForPaintInvalidation(); | 566 target->localOverflowRectForPaintInvalidation(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 ContainerOfAbsoluteAbovePaintInvalidationContainer) { | 637 ContainerOfAbsoluteAbovePaintInvalidationContainer) { |
623 enableCompositing(); | 638 enableCompositing(); |
624 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); | 639 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
625 | 640 |
626 setBodyInnerHTML( | 641 setBodyInnerHTML( |
627 "<div id='container' style='position: absolute; top: 88px; left: 99px'>" | 642 "<div id='container' style='position: absolute; top: 88px; left: 99px'>" |
628 " <div style='height: 222px'></div>" | 643 " <div style='height: 222px'></div>" |
629 // This div makes stacking-context composited. | 644 // This div makes stacking-context composited. |
630 " <div style='position: absolute; width: 1px; height: 1px; " | 645 " <div style='position: absolute; width: 1px; height: 1px; " |
631 "background:yellow; will-change: transform'></div>" | 646 "background:yellow; will-change: transform'></div>" |
632 // This stacking context is paintInvalidationContainer of the absolute chi
ld, but not a container of it. | 647 // This stacking context is paintInvalidationContainer of the absolute |
| 648 // child, but not a container of it. |
633 " <div id='stacking-context' style='opacity: 0.9'>" | 649 " <div id='stacking-context' style='opacity: 0.9'>" |
634 " <div id='absolute' style='position: absolute; top: 50px; left: " | 650 " <div id='absolute' style='position: absolute; top: 50px; left: " |
635 "50px; width: 50px; height: 50px; background: green'></div>" | 651 "50px; width: 50px; height: 50px; background: green'></div>" |
636 " </div>" | 652 " </div>" |
637 "</div>"); | 653 "</div>"); |
638 | 654 |
639 LayoutBlock* stackingContext = | 655 LayoutBlock* stackingContext = |
640 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); | 656 toLayoutBlock(getLayoutObjectByElementId("stacking-context")); |
641 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); | 657 LayoutBlock* absolute = toLayoutBlock(getLayoutObjectByElementId("absolute")); |
642 LayoutBlock* container = | 658 LayoutBlock* container = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 target->localOverflowRectForPaintInvalidation(); | 705 target->localOverflowRectForPaintInvalidation(); |
690 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetOverflowRect); | 706 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetOverflowRect); |
691 LayoutRect rect = targetOverflowRect; | 707 LayoutRect rect = targetOverflowRect; |
692 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 708 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
693 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); | 709 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); |
694 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, | 710 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, |
695 layoutView(), layoutView()); | 711 layoutView(), layoutView()); |
696 } | 712 } |
697 | 713 |
698 } // namespace blink | 714 } // namespace blink |
OLD | NEW |