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

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

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Fix README.md Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/LayoutInline.h" 5 #include "core/layout/LayoutInline.h"
6 #include "core/layout/LayoutTestHelper.h" 6 #include "core/layout/LayoutTestHelper.h"
7 #include "core/layout/LayoutView.h" 7 #include "core/layout/LayoutView.h"
8 #include "platform/geometry/TransformState.h" 8 #include "platform/geometry/TransformState.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 setBodyInnerHTML( 133 setBodyInnerHTML(
134 "<div id='overflow' style='height: 100px; width: 100px; border:8px " 134 "<div id='overflow' style='height: 100px; width: 100px; border:8px "
135 "solid; padding:7px; overflow:scroll'>" 135 "solid; padding:7px; overflow:scroll'>"
136 " <div style='height:200px; width:200px'></div>" 136 " <div style='height:200px; width:200px'></div>"
137 " <div id='target' style='margin:10px; border:666px; " 137 " <div id='target' style='margin:10px; border:666px; "
138 "padding:666px;'></div>" 138 "padding:666px;'></div>"
139 "</div>"); 139 "</div>");
140 140
141 LayoutObject* target = getLayoutObjectByElementId("target"); 141 LayoutObject* target = getLayoutObjectByElementId("target");
142 LayoutObject* overflow = getLayoutObjectByElementId("overflow"); 142 LayoutObject* overflow = getLayoutObjectByElementId("overflow");
143 toLayoutBox(overflow)->scrollToOffset(DoubleSize(32, 54)); 143 toLayoutBox(overflow)->scrollToPosition(FloatPoint(32, 54));
144 144
145 FloatPoint mappedPoint = mapLocalToAncestor( 145 FloatPoint mappedPoint = mapLocalToAncestor(
146 target, toLayoutBoxModelObject(target->parent()), FloatPoint(100, 100)); 146 target, toLayoutBoxModelObject(target->parent()), FloatPoint(100, 100));
147 EXPECT_EQ(FloatPoint(93, 271), mappedPoint); 147 EXPECT_EQ(FloatPoint(93, 271), mappedPoint);
148 mappedPoint = mapAncestorToLocal( 148 mappedPoint = mapAncestorToLocal(
149 target, toLayoutBoxModelObject(target->parent()), mappedPoint); 149 target, toLayoutBoxModelObject(target->parent()), mappedPoint);
150 EXPECT_EQ(FloatPoint(100, 100), mappedPoint); 150 EXPECT_EQ(FloatPoint(100, 100), mappedPoint);
151 } 151 }
152 152
153 TEST_F(MapCoordinatesTest, TextInRelPosInline) { 153 TEST_F(MapCoordinatesTest, TextInRelPosInline) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 506
507 TEST_F(MapCoordinatesTest, FixedPosInTransform) { 507 TEST_F(MapCoordinatesTest, FixedPosInTransform) {
508 setBodyInnerHTML( 508 setBodyInnerHTML(
509 "<style>#container { transform: translateY(100px); position: absolute; " 509 "<style>#container { transform: translateY(100px); position: absolute; "
510 "left: 0; top: 100px; }" 510 "left: 0; top: 100px; }"
511 ".fixed { position: fixed; top: 0; }" 511 ".fixed { position: fixed; top: 0; }"
512 ".spacer { height: 2000px; } </style>" 512 ".spacer { height: 2000px; } </style>"
513 "<div id='container'><div class='fixed' id='target'></div></div>" 513 "<div id='container'><div class='fixed' id='target'></div></div>"
514 "<div class='spacer'></div>"); 514 "<div class='spacer'></div>");
515 515
516 document().view()->setScrollPosition(DoublePoint(0.0, 50), 516 document().view()->setScrollOffset(ScrollOffset(0.0, 50), ProgrammaticScroll);
517 ProgrammaticScroll);
518 document().view()->updateAllLifecyclePhases(); 517 document().view()->updateAllLifecyclePhases();
519 EXPECT_EQ(50, document().view()->scrollPosition().y()); 518 EXPECT_EQ(50, document().view()->scrollOffsetInt().height());
520 519
521 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); 520 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target"));
522 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); 521 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container"));
523 LayoutBox* body = container->parentBox(); 522 LayoutBox* body = container->parentBox();
524 LayoutBox* html = body->parentBox(); 523 LayoutBox* html = body->parentBox();
525 LayoutBox* view = html->parentBox(); 524 LayoutBox* view = html->parentBox();
526 ASSERT_TRUE(view->isLayoutView()); 525 ASSERT_TRUE(view->isLayoutView());
527 526
528 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint()); 527 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint());
529 EXPECT_EQ(FloatPoint(0, 100), mappedPoint); 528 EXPECT_EQ(FloatPoint(0, 100), mappedPoint);
(...skipping 13 matching lines...) Expand all
543 542
544 TEST_F(MapCoordinatesTest, FixedPosInContainPaint) { 543 TEST_F(MapCoordinatesTest, FixedPosInContainPaint) {
545 setBodyInnerHTML( 544 setBodyInnerHTML(
546 "<style>#container { contain: paint; position: absolute; left: 0; top: " 545 "<style>#container { contain: paint; position: absolute; left: 0; top: "
547 "100px; }" 546 "100px; }"
548 ".fixed { position: fixed; top: 0; }" 547 ".fixed { position: fixed; top: 0; }"
549 ".spacer { height: 2000px; } </style>" 548 ".spacer { height: 2000px; } </style>"
550 "<div id='container'><div class='fixed' id='target'></div></div>" 549 "<div id='container'><div class='fixed' id='target'></div></div>"
551 "<div class='spacer'></div>"); 550 "<div class='spacer'></div>");
552 551
553 document().view()->setScrollPosition(DoublePoint(0.0, 50), 552 document().view()->setScrollOffset(ScrollOffset(0.0, 50), ProgrammaticScroll);
554 ProgrammaticScroll);
555 document().view()->updateAllLifecyclePhases(); 553 document().view()->updateAllLifecyclePhases();
556 EXPECT_EQ(50, document().view()->scrollPosition().y()); 554 EXPECT_EQ(50, document().view()->scrollOffsetInt().height());
557 555
558 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target")); 556 LayoutBox* target = toLayoutBox(getLayoutObjectByElementId("target"));
559 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); 557 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container"));
560 LayoutBox* body = container->parentBox(); 558 LayoutBox* body = container->parentBox();
561 LayoutBox* html = body->parentBox(); 559 LayoutBox* html = body->parentBox();
562 LayoutBox* view = html->parentBox(); 560 LayoutBox* view = html->parentBox();
563 ASSERT_TRUE(view->isLayoutView()); 561 ASSERT_TRUE(view->isLayoutView());
564 562
565 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint()); 563 FloatPoint mappedPoint = mapLocalToAncestor(target, view, FloatPoint());
566 EXPECT_EQ(FloatPoint(0, 100), mappedPoint); 564 EXPECT_EQ(FloatPoint(0, 100), mappedPoint);
(...skipping 19 matching lines...) Expand all
586 "<div style='width: 200; height: 8000px'></div>" 584 "<div style='width: 200; height: 8000px'></div>"
587 "<iframe id=frame src='http://test.com' width='500' height='500' " 585 "<iframe id=frame src='http://test.com' width='500' height='500' "
588 "frameBorder='0'>" 586 "frameBorder='0'>"
589 "</iframe>"); 587 "</iframe>");
590 588
591 Document& frameDocument = setupChildIframe( 589 Document& frameDocument = setupChildIframe(
592 "frame", 590 "frame",
593 "<style>body { margin: 0; } #target { width: 200px; height: 200px; " 591 "<style>body { margin: 0; } #target { width: 200px; height: 200px; "
594 "position:fixed}</style><div id=target></div>"); 592 "position:fixed}</style><div id=target></div>");
595 593
596 document().view()->setScrollPosition(DoublePoint(0.0, 1000), 594 document().view()->setScrollOffset(ScrollOffset(0.0, 1000),
597 ProgrammaticScroll); 595 ProgrammaticScroll);
598 document().view()->updateAllLifecyclePhases(); 596 document().view()->updateAllLifecyclePhases();
599 597
600 Element* target = frameDocument.getElementById("target"); 598 Element* target = frameDocument.getElementById("target");
601 ASSERT_TRUE(target); 599 ASSERT_TRUE(target);
602 FloatPoint mappedPoint = 600 FloatPoint mappedPoint =
603 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70), 601 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70),
604 TraverseDocumentBoundaries); 602 TraverseDocumentBoundaries);
605 603
606 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame. 604 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame.
607 // The scroll is not taken into account because the element is not fixed to th e root LayoutView, 605 // The scroll is not taken into account because the element is not fixed to th e root LayoutView,
608 // and the space of the root LayoutView does not include scroll. 606 // and the space of the root LayoutView does not include scroll.
609 EXPECT_EQ(FloatPoint(10, -7930), mappedPoint); 607 EXPECT_EQ(FloatPoint(10, -7930), mappedPoint);
610 } 608 }
611 609
612 TEST_F(MapCoordinatesTest, IFrameTransformed) { 610 TEST_F(MapCoordinatesTest, IFrameTransformed) {
613 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 611 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
614 setBodyInnerHTML( 612 setBodyInnerHTML(
615 "<style>body { margin: 0; }</style>" 613 "<style>body { margin: 0; }</style>"
616 "<iframe style='transform: scale(2)' id=frame src='http://test.com' " 614 "<iframe style='transform: scale(2)' id=frame src='http://test.com' "
617 "width='500' height='500' frameBorder='0'>" 615 "width='500' height='500' frameBorder='0'>"
618 "</iframe>"); 616 "</iframe>");
619 617
620 Document& frameDocument = 618 Document& frameDocument =
621 setupChildIframe("frame", 619 setupChildIframe("frame",
622 "<style>body { margin: 0; } #target { width: 200px; " 620 "<style>body { margin: 0; } #target { width: 200px; "
623 "height: 8000px}</style><div id=target></div>"); 621 "height: 8000px}</style><div id=target></div>");
624 622
625 document().view()->updateAllLifecyclePhases(); 623 document().view()->updateAllLifecyclePhases();
626 624
627 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 1000), 625 frameDocument.view()->setScrollOffset(ScrollOffset(0.0, 1000),
628 ProgrammaticScroll); 626 ProgrammaticScroll);
629 frameDocument.view()->updateAllLifecyclePhases(); 627 frameDocument.view()->updateAllLifecyclePhases();
630 628
631 Element* target = frameDocument.getElementById("target"); 629 Element* target = frameDocument.getElementById("target");
632 ASSERT_TRUE(target); 630 ASSERT_TRUE(target);
633 FloatPoint mappedPoint = 631 FloatPoint mappedPoint =
634 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200), 632 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200),
635 TraverseDocumentBoundaries | UseTransforms); 633 TraverseDocumentBoundaries | UseTransforms);
636 634
637 // Derivation: 635 // Derivation:
638 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is a t the center of the 500x500 iframe) 636 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is a t the center of the 500x500 iframe)
(...skipping 14 matching lines...) Expand all
653 "height='768'></iframe>" 651 "height='768'></iframe>"
654 "</div>"); 652 "</div>");
655 653
656 Document& frameDocument = setupChildIframe( 654 Document& frameDocument = setupChildIframe(
657 "frame", 655 "frame",
658 "<style>* { margin: 0; } #target { width: 200px; height: 200px; " 656 "<style>* { margin: 0; } #target { width: 200px; height: 200px; "
659 "position:fixed}</style><div id=target></div>" 657 "position:fixed}</style><div id=target></div>"
660 "<div style='width: 200; height: 8000px'></div>"); 658 "<div style='width: 200; height: 8000px'></div>");
661 659
662 document().view()->updateAllLifecyclePhases(); 660 document().view()->updateAllLifecyclePhases();
663 frameDocument.view()->setScrollPosition(DoublePoint(0.0, 1000), 661 frameDocument.view()->setScrollOffset(ScrollOffset(0.0, 1000),
664 ProgrammaticScroll); 662 ProgrammaticScroll);
665 663
666 Element* target = frameDocument.getElementById("target"); 664 Element* target = frameDocument.getElementById("target");
667 ASSERT_TRUE(target); 665 ASSERT_TRUE(target);
668 FloatPoint mappedPoint = 666 FloatPoint mappedPoint =
669 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0), 667 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0),
670 UseTransforms | TraverseDocumentBoundaries); 668 UseTransforms | TraverseDocumentBoundaries);
671 669
672 EXPECT_EQ(FloatPoint(0, 0), mappedPoint); 670 EXPECT_EQ(FloatPoint(0, 0), mappedPoint);
673 } 671 }
674 672
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 LayoutUnit::epsilon()); 1443 LayoutUnit::epsilon());
1446 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), 1444 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(),
1447 LayoutUnit::epsilon()); 1445 LayoutUnit::epsilon());
1448 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), 1446 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(),
1449 LayoutUnit::epsilon()); 1447 LayoutUnit::epsilon());
1450 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), 1448 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(),
1451 LayoutUnit::epsilon()); 1449 LayoutUnit::epsilon());
1452 } 1450 }
1453 1451
1454 } // namespace blink 1452 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutView.cpp ('k') | third_party/WebKit/Source/core/layout/PaintInvalidationState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698