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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 "</div>"); | 164 "</div>"); |
165 | 165 |
166 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 166 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
167 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); | 167 LayoutRect overflowRect = target->localOverflowRectForPaintInvalidation(); |
168 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) | 168 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
169 // 140 = width(100) + box_shadow_offset_x(40) | 169 // 140 = width(100) + box_shadow_offset_x(40) |
170 // 70 = height(50) + box_shadow_offset_y(20) | 170 // 70 = height(50) + box_shadow_offset_y(20) |
171 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); | 171 EXPECT_EQ(LayoutRect(-40, 0, 140, 70), overflowRect); |
172 | 172 |
173 LayoutRect rect = overflowRect; | 173 LayoutRect rect = overflowRect; |
| 174 target->flipForWritingMode(rect); |
174 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 175 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
175 // This rect is in physical coordinates of target. | 176 // This rect is in physical coordinates of target. |
176 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); | 177 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); |
177 | 178 |
178 rect = overflowRect; | 179 rect = overflowRect; |
| 180 target->flipForWritingMode(rect); |
179 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 181 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
180 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); | 182 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); |
181 checkPaintInvalidationStateRectMapping(rect, overflowRect, *target, layoutVi
ew(), layoutView()); | 183 checkPaintInvalidationStateRectMapping(rect, overflowRect, *target, layoutVi
ew(), layoutView()); |
182 } | 184 } |
183 | 185 |
184 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode) | 186 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode) |
185 { | 187 { |
186 setBodyInnerHTML( | 188 setBodyInnerHTML( |
187 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px'>" | 189 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px'>" |
188 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" | 190 " <div id='target' style='box-shadow: 40px 20px black; width: 100px;
height: 90px'></div>" |
189 " <div style='width: 100px; height: 100px'></div>" | 191 " <div style='width: 100px; height: 100px'></div>" |
190 "</div>"); | 192 "</div>"); |
191 | 193 |
192 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 194 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
193 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); | 195 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
194 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) | 196 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
195 // 140 = width(100) + box_shadow_offset_x(40) | 197 // 140 = width(100) + box_shadow_offset_x(40) |
196 // 110 = height(90) + box_shadow_offset_y(20) | 198 // 110 = height(90) + box_shadow_offset_y(20) |
197 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 199 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
198 | 200 |
199 LayoutRect rect = targetOverflowRect; | 201 LayoutRect rect = targetOverflowRect; |
| 202 target->flipForWritingMode(rect); |
200 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 203 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
201 // This rect is in physical coordinates of target. | 204 // This rect is in physical coordinates of target. |
202 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 205 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
203 | 206 |
204 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); | 207 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container
")); |
205 rect = targetOverflowRect; | 208 rect = targetOverflowRect; |
| 209 target->flipForWritingMode(rect); |
206 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 210 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
207 // 100 is the physical x location of target in container. | 211 // 100 is the physical x location of target in container. |
208 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); | 212 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); |
209 rect = targetOverflowRect; | 213 rect = targetOverflowRect; |
| 214 target->flipForWritingMode(rect); |
210 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 215 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
211 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); | 216 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); |
212 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la
youtView(), layoutView()); | 217 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la
youtView(), layoutView()); |
213 | 218 |
214 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); | 219 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); |
215 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerOverflowRect); | 220 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerOverflowRect); |
216 rect = containerOverflowRect; | 221 rect = containerOverflowRect; |
| 222 container->flipForWritingMode(rect); |
217 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 223 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
218 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect); | 224 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect); |
219 rect = containerOverflowRect; | 225 rect = containerOverflowRect; |
| 226 container->flipForWritingMode(rect); |
220 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 227 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
221 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect); | 228 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect); |
222 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain
er, layoutView(), layoutView()); | 229 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain
er, layoutView(), layoutView()); |
223 } | 230 } |
224 | 231 |
225 TEST_F(VisualRectMappingTest, ContainerOverflowScroll) | 232 TEST_F(VisualRectMappingTest, ContainerOverflowScroll) |
226 { | 233 { |
227 setBodyInnerHTML( | 234 setBodyInnerHTML( |
228 "<div id='container' style='position: absolute; top: 111px; left: 222px;
" | 235 "<div id='container' style='position: absolute; top: 111px; left: 222px;
" |
229 " border: 10px solid red; overflow: scroll; width: 50px; height: 80px
;'>" | 236 " border: 10px solid red; overflow: scroll; width: 50px; height: 80px
;'>" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 document().view()->updateAllLifecyclePhases(); | 303 document().view()->updateAllLifecyclePhases(); |
297 | 304 |
298 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 305 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
299 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); | 306 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
300 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) | 307 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
301 // 140 = width(100) + box_shadow_offset_x(40) | 308 // 140 = width(100) + box_shadow_offset_x(40) |
302 // 110 = height(90) + box_shadow_offset_y(20) | 309 // 110 = height(90) + box_shadow_offset_y(20) |
303 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 310 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
304 | 311 |
305 LayoutRect rect = targetOverflowRect; | 312 LayoutRect rect = targetOverflowRect; |
| 313 target->flipForWritingMode(rect); |
306 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 314 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
307 // This rect is in physical coordinates of target. | 315 // This rect is in physical coordinates of target. |
308 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 316 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
309 | 317 |
310 rect = targetOverflowRect; | 318 rect = targetOverflowRect; |
| 319 target->flipForWritingMode(rect); |
311 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 320 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
312 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) | 321 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142
) |
313 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) | 322 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) |
314 // Rect is clipped by container's overflow clip because of overflow:scroll. | 323 // Rect is clipped by container's overflow clip because of overflow:scroll. |
315 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); | 324 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); |
316 | 325 |
317 rect = targetOverflowRect; | 326 rect = targetOverflowRect; |
| 327 target->flipForWritingMode(rect); |
318 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 328 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
319 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40,
10, 50, 80), | 329 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40,
10, 50, 80), |
320 // then is added by container's offset in LayoutView (111, 222). | 330 // then is added by container's offset in LayoutView (111, 222). |
321 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but
is offset | 331 // TODO(crbug.com/600039): rect.x() should be 262 (left + border-left), but
is offset |
322 // by extra horizontal border-widths because of layout error. | 332 // by extra horizontal border-widths because of layout error. |
323 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); | 333 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); |
324 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la
youtView(), layoutView()); | 334 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la
youtView(), layoutView()); |
325 | 335 |
326 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); | 336 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval
idation(); |
327 // Because container has overflow clip, its visual overflow doesn't include
overflow from children. | 337 // Because container has overflow clip, its visual overflow doesn't include
overflow from children. |
328 // 110 = width(50) + border_left_width(40) + border_right_width(20) | 338 // 110 = width(50) + border_left_width(40) + border_right_width(20) |
329 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) | 339 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) |
330 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); | 340 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); |
331 | 341 |
332 rect = containerOverflowRect; | 342 rect = containerOverflowRect; |
| 343 container->flipForWritingMode(rect); |
333 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); | 344 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); |
334 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); | 345 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); |
335 | 346 |
336 rect = containerOverflowRect; | 347 rect = containerOverflowRect; |
| 348 container->flipForWritingMode(rect); |
337 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 349 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
338 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by e
xtra horizontal | 350 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by e
xtra horizontal |
339 // border-widths because of layout error. | 351 // border-widths because of layout error. |
340 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); | 352 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); |
341 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain
er, layoutView(), layoutView()); | 353 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain
er, layoutView(), layoutView()); |
342 } | 354 } |
343 | 355 |
344 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) | 356 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) |
345 { | 357 { |
346 setBodyInnerHTML( | 358 setBodyInnerHTML( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 document().view()->updateAllLifecyclePhases(); | 403 document().view()->updateAllLifecyclePhases(); |
392 | 404 |
393 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); | 405 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
394 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); | 406 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio
n(); |
395 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) | 407 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori
gin) |
396 // 140 = width(100) + box_shadow_offset_x(40) | 408 // 140 = width(100) + box_shadow_offset_x(40) |
397 // 110 = height(90) + box_shadow_offset_y(20) | 409 // 110 = height(90) + box_shadow_offset_y(20) |
398 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); | 410 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); |
399 | 411 |
400 LayoutRect rect = targetOverflowRect; | 412 LayoutRect rect = targetOverflowRect; |
| 413 target->flipForWritingMode(rect); |
401 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); | 414 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); |
402 // This rect is in physical coordinates of target. | 415 // This rect is in physical coordinates of target. |
403 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); | 416 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); |
404 | 417 |
405 rect = targetOverflowRect; | 418 rect = targetOverflowRect; |
| 419 target->flipForWritingMode(rect); |
406 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); | 420 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); |
407 // 58 = target_physical_x(100) + container_border_left(40) - scroll_left(58) | 421 // 58 = target_physical_x(100) + container_border_left(40) - scroll_left(58) |
408 // The other sides of the rect are clipped by container's overflow clip. | 422 // The other sides of the rect are clipped by container's overflow clip. |
409 EXPECT_EQ(LayoutRect(58, 10, 32, 80), rect); | 423 EXPECT_EQ(LayoutRect(58, 10, 32, 80), rect); |
410 } | 424 } |
411 | 425 |
412 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode) | 426 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode) |
413 { | 427 { |
414 setBodyInnerHTML( | 428 setBodyInnerHTML( |
415 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px;" | 429 "<div id='container' style='writing-mode: vertical-rl; position: absolut
e; top: 111px; left: 222px;" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); | 527 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid
ation(); |
514 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); | 528 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); |
515 LayoutRect rect = absoluteOverflowRect; | 529 LayoutRect rect = absoluteOverflowRect; |
516 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect))
; | 530 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect))
; |
517 // -172 = top(50) - y_offset_of_stacking_context(222) | 531 // -172 = top(50) - y_offset_of_stacking_context(222) |
518 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); | 532 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); |
519 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute
, layoutView(), *stackingContext); | 533 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute
, layoutView(), *stackingContext); |
520 } | 534 } |
521 | 535 |
522 } // namespace blink | 536 } // namespace blink |
OLD | NEW |