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

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

Powered by Google App Engine
This is Rietveld 408576698