Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp

Issue 2073563002: Rework mapToVisualRectInAncestorSpace to handle flipped blocks correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More feedback. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // TODO(wkorman): The calls to flipForWritingMode() here and in other test
175 // cases below are necessary because mapToVisualRectInAncestorSpace()
176 // currently expects the input rect to be in "physical coordinates without
chrishtr 2016/07/11 22:49:42 "physical coordinates (*not* "physical coordinates
wkorman 2016/07/11 22:54:51 Done.
177 // flipped block-flow direction" (see LayoutBoxModelObject.h).
178 target->flipForWritingMode(rect);
174 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); 179 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect));
175 // This rect is in physical coordinates of target. 180 // This rect is in physical coordinates of target.
176 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect); 181 EXPECT_EQ(LayoutRect(0, 0, 140, 70), rect);
177 182
178 rect = overflowRect; 183 rect = overflowRect;
184 target->flipForWritingMode(rect);
179 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 185 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect));
180 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect); 186 EXPECT_EQ(LayoutRect(222, 111, 140, 70), rect);
181 checkPaintInvalidationStateRectMapping(rect, overflowRect, *target, layoutVi ew(), layoutView()); 187 checkPaintInvalidationStateRectMapping(rect, overflowRect, *target, layoutVi ew(), layoutView());
182 } 188 }
183 189
184 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode) 190 TEST_F(VisualRectMappingTest, ContainerFlippedWritingMode)
185 { 191 {
186 setBodyInnerHTML( 192 setBodyInnerHTML(
187 "<div id='container' style='writing-mode: vertical-rl; position: absolut e; top: 111px; left: 222px'>" 193 "<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>" 194 " <div id='target' style='box-shadow: 40px 20px black; width: 100px; height: 90px'></div>"
189 " <div style='width: 100px; height: 100px'></div>" 195 " <div style='width: 100px; height: 100px'></div>"
190 "</div>"); 196 "</div>");
191 197
192 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); 198 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
193 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n(); 199 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n();
194 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori gin) 200 // -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) 201 // 140 = width(100) + box_shadow_offset_x(40)
196 // 110 = height(90) + box_shadow_offset_y(20) 202 // 110 = height(90) + box_shadow_offset_y(20)
197 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); 203 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect);
198 204
199 LayoutRect rect = targetOverflowRect; 205 LayoutRect rect = targetOverflowRect;
206 target->flipForWritingMode(rect);
200 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); 207 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect));
201 // This rect is in physical coordinates of target. 208 // This rect is in physical coordinates of target.
202 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); 209 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect);
203 210
204 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container ")); 211 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container "));
205 rect = targetOverflowRect; 212 rect = targetOverflowRect;
213 target->flipForWritingMode(rect);
206 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); 214 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect));
207 // 100 is the physical x location of target in container. 215 // 100 is the physical x location of target in container.
208 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect); 216 EXPECT_EQ(LayoutRect(100, 0, 140, 110), rect);
209 rect = targetOverflowRect; 217 rect = targetOverflowRect;
218 target->flipForWritingMode(rect);
210 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 219 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect));
211 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect); 220 EXPECT_EQ(LayoutRect(322, 111, 140, 110), rect);
212 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la youtView(), layoutView()); 221 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la youtView(), layoutView());
213 222
214 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval idation(); 223 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval idation();
215 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerOverflowRect); 224 EXPECT_EQ(LayoutRect(0, 0, 200, 100), containerOverflowRect);
216 rect = containerOverflowRect; 225 rect = containerOverflowRect;
226 container->flipForWritingMode(rect);
217 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); 227 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect));
218 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect); 228 EXPECT_EQ(LayoutRect(0, 0, 200, 100), rect);
219 rect = containerOverflowRect; 229 rect = containerOverflowRect;
230 container->flipForWritingMode(rect);
220 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 231 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect));
221 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect); 232 EXPECT_EQ(LayoutRect(222, 111, 200, 100), rect);
222 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain er, layoutView(), layoutView()); 233 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain er, layoutView(), layoutView());
223 } 234 }
224 235
225 TEST_F(VisualRectMappingTest, ContainerOverflowScroll) 236 TEST_F(VisualRectMappingTest, ContainerOverflowScroll)
226 { 237 {
227 setBodyInnerHTML( 238 setBodyInnerHTML(
228 "<div id='container' style='position: absolute; top: 111px; left: 222px; " 239 "<div id='container' style='position: absolute; top: 111px; left: 222px; "
229 " border: 10px solid red; overflow: scroll; width: 50px; height: 80px ;'>" 240 " border: 10px solid red; overflow: scroll; width: 50px; height: 80px ;'>"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 document().view()->updateAllLifecyclePhases(); 307 document().view()->updateAllLifecyclePhases();
297 308
298 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); 309 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
299 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n(); 310 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n();
300 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori gin) 311 // -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) 312 // 140 = width(100) + box_shadow_offset_x(40)
302 // 110 = height(90) + box_shadow_offset_y(20) 313 // 110 = height(90) + box_shadow_offset_y(20)
303 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); 314 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect);
304 315
305 LayoutRect rect = targetOverflowRect; 316 LayoutRect rect = targetOverflowRect;
317 target->flipForWritingMode(rect);
306 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); 318 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect));
307 // This rect is in physical coordinates of target. 319 // This rect is in physical coordinates of target.
308 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); 320 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect);
309 321
310 rect = targetOverflowRect; 322 rect = targetOverflowRect;
323 target->flipForWritingMode(rect);
311 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); 324 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect));
312 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142 ) 325 // -2 = target_physical_x(100) + container_border_left(40) - scroll_left(142 )
313 // 3 = target_y(0) + container_border_top(10) - scroll_top(7) 326 // 3 = target_y(0) + container_border_top(10) - scroll_top(7)
314 // Rect is clipped by container's overflow clip because of overflow:scroll. 327 // Rect is clipped by container's overflow clip because of overflow:scroll.
315 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect); 328 EXPECT_EQ(LayoutRect(-2, 3, 140, 110), rect);
316 329
317 rect = targetOverflowRect; 330 rect = targetOverflowRect;
331 target->flipForWritingMode(rect);
318 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 332 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect));
319 // (-2, 3, 140, 100) is first clipped by container's overflow clip, to (40, 10, 50, 80), 333 // (-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). 334 // 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 335 // 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. 336 // by extra horizontal border-widths because of layout error.
323 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect); 337 EXPECT_EQ(LayoutRect(322, 121, 50, 80), rect);
324 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la youtView(), layoutView()); 338 checkPaintInvalidationStateRectMapping(rect, targetOverflowRect, *target, la youtView(), layoutView());
325 339
326 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval idation(); 340 LayoutRect containerOverflowRect = container->localOverflowRectForPaintInval idation();
327 // Because container has overflow clip, its visual overflow doesn't include overflow from children. 341 // 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) 342 // 110 = width(50) + border_left_width(40) + border_right_width(20)
329 // 120 = height(80) + border_top_width(10) + border_bottom_width(30) 343 // 120 = height(80) + border_top_width(10) + border_bottom_width(30)
330 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect); 344 EXPECT_EQ(LayoutRect(0, 0, 110, 120), containerOverflowRect);
331 345
332 rect = containerOverflowRect; 346 rect = containerOverflowRect;
347 container->flipForWritingMode(rect);
333 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect)); 348 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(container, rect));
334 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect); 349 EXPECT_EQ(LayoutRect(0, 0, 110, 120), rect);
335 350
336 rect = containerOverflowRect; 351 rect = containerOverflowRect;
352 container->flipForWritingMode(rect);
337 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 353 EXPECT_TRUE(container->mapToVisualRectInAncestorSpace(&layoutView(), rect));
338 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by e xtra horizontal 354 // TODO(crbug.com/600039): rect.x() should be 222 (left), but is offset by e xtra horizontal
339 // border-widths because of layout error. 355 // border-widths because of layout error.
340 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect); 356 EXPECT_EQ(LayoutRect(282, 111, 110, 120), rect);
341 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain er, layoutView(), layoutView()); 357 checkPaintInvalidationStateRectMapping(rect, containerOverflowRect, *contain er, layoutView(), layoutView());
342 } 358 }
343 359
344 TEST_F(VisualRectMappingTest, ContainerOverflowHidden) 360 TEST_F(VisualRectMappingTest, ContainerOverflowHidden)
345 { 361 {
346 setBodyInnerHTML( 362 setBodyInnerHTML(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 document().view()->updateAllLifecyclePhases(); 407 document().view()->updateAllLifecyclePhases();
392 408
393 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); 409 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
394 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n(); 410 LayoutRect targetOverflowRect = target->localOverflowRectForPaintInvalidatio n();
395 // -40 = -box_shadow_offset_x(40) (with target's top-right corner as the ori gin) 411 // -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) 412 // 140 = width(100) + box_shadow_offset_x(40)
397 // 110 = height(90) + box_shadow_offset_y(20) 413 // 110 = height(90) + box_shadow_offset_y(20)
398 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect); 414 EXPECT_EQ(LayoutRect(-40, 0, 140, 110), targetOverflowRect);
399 415
400 LayoutRect rect = targetOverflowRect; 416 LayoutRect rect = targetOverflowRect;
417 target->flipForWritingMode(rect);
401 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect)); 418 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(target, rect));
402 // This rect is in physical coordinates of target. 419 // This rect is in physical coordinates of target.
403 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect); 420 EXPECT_EQ(LayoutRect(0, 0, 140, 110), rect);
404 421
405 rect = targetOverflowRect; 422 rect = targetOverflowRect;
423 target->flipForWritingMode(rect);
406 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect)); 424 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(container, rect));
407 // 58 = target_physical_x(100) + container_border_left(40) - scroll_left(58) 425 // 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. 426 // The other sides of the rect are clipped by container's overflow clip.
409 EXPECT_EQ(LayoutRect(58, 10, 32, 80), rect); 427 EXPECT_EQ(LayoutRect(58, 10, 32, 80), rect);
410 } 428 }
411 429
412 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode) 430 TEST_F(VisualRectMappingTest, ContainerAndTargetDifferentFlippedWritingMode)
413 { 431 {
414 setBodyInnerHTML( 432 setBodyInnerHTML(
415 "<div id='container' style='writing-mode: vertical-rl; position: absolut e; top: 111px; left: 222px;" 433 "<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
513 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid ation(); 531 LayoutRect absoluteOverflowRect = absolute->localOverflowRectForPaintInvalid ation();
514 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect); 532 EXPECT_EQ(LayoutRect(0, 0, 50, 50), absoluteOverflowRect);
515 LayoutRect rect = absoluteOverflowRect; 533 LayoutRect rect = absoluteOverflowRect;
516 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)) ; 534 EXPECT_TRUE(absolute->mapToVisualRectInAncestorSpace(stackingContext, rect)) ;
517 // -172 = top(50) - y_offset_of_stacking_context(222) 535 // -172 = top(50) - y_offset_of_stacking_context(222)
518 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect); 536 EXPECT_EQ(LayoutRect(50, -172, 50, 50), rect);
519 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute , layoutView(), *stackingContext); 537 checkPaintInvalidationStateRectMapping(rect, absoluteOverflowRect, *absolute , layoutView(), *stackingContext);
520 } 538 }
521 539
522 } // namespace blink 540 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698