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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.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
« no previous file with comments | « third_party/WebKit/Source/web/tests/WebFrameTest.cpp ('k') | ui/gfx/geometry/scroll_offset.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 1465
1466 // Make the page scale and scroll with the given paremeters. 1466 // Make the page scale and scroll with the given paremeters.
1467 webViewImpl->setPageScaleFactor(2.0f); 1467 webViewImpl->setPageScaleFactor(2.0f);
1468 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); 1468 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111));
1469 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); 1469 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
1470 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); 1470 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width);
1471 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); 1471 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height);
1472 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame()); 1472 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame());
1473 mainFrameLocal->loader().saveScrollState(); 1473 mainFrameLocal->loader().saveScrollState();
1474 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); 1474 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor());
1475 EXPECT_EQ(94, mainFrameLocal->loader().currentItem()->scrollPoint().x()); 1475 EXPECT_EQ(94, mainFrameLocal->loader().currentItem()->scrollOffset().width());
1476 EXPECT_EQ(111, mainFrameLocal->loader().currentItem()->scrollPoint().y()); 1476 EXPECT_EQ(111,
1477 mainFrameLocal->loader().currentItem()->scrollOffset().height());
1477 1478
1478 // Confirm that resetting the page state resets the saved scroll position. 1479 // Confirm that resetting the page state resets the saved scroll position.
1479 webViewImpl->resetScrollAndScaleState(); 1480 webViewImpl->resetScrollAndScaleState();
1480 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); 1481 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor());
1481 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); 1482 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
1482 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); 1483 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
1483 EXPECT_EQ(1.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); 1484 EXPECT_EQ(1.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor());
1484 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().x()); 1485 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollOffset().width());
1485 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().y()); 1486 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollOffset().height());
1486 } 1487 }
1487 1488
1488 TEST_F(WebViewTest, BackForwardRestoreScroll) { 1489 TEST_F(WebViewTest, BackForwardRestoreScroll) {
1489 URLTestHelpers::registerMockedURLFromBaseURL( 1490 URLTestHelpers::registerMockedURLFromBaseURL(
1490 WebString::fromUTF8(m_baseURL.c_str()), 1491 WebString::fromUTF8(m_baseURL.c_str()),
1491 WebString::fromUTF8("back_forward_restore_scroll.html")); 1492 WebString::fromUTF8("back_forward_restore_scroll.html"));
1492 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad( 1493 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(
1493 m_baseURL + "back_forward_restore_scroll.html"); 1494 m_baseURL + "back_forward_restore_scroll.html");
1494 webViewImpl->resize(WebSize(640, 480)); 1495 webViewImpl->resize(WebSize(640, 480));
1495 webViewImpl->updateAllLifecyclePhases(); 1496 webViewImpl->updateAllLifecyclePhases();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 1562
1562 // Enter fullscreen. 1563 // Enter fullscreen.
1563 Element* element = static_cast<Element*>( 1564 Element* element = static_cast<Element*>(
1564 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); 1565 webViewImpl->mainFrame()->document().getElementById("fullscreenElement"));
1565 webViewImpl->enterFullscreenForElement(element); 1566 webViewImpl->enterFullscreenForElement(element);
1566 webViewImpl->didEnterFullscreen(); 1567 webViewImpl->didEnterFullscreen();
1567 webViewImpl->updateAllLifecyclePhases(); 1568 webViewImpl->updateAllLifecyclePhases();
1568 1569
1569 // Sanity-check. There should be no scrolling possible. 1570 // Sanity-check. There should be no scrolling possible.
1570 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); 1571 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
1571 ASSERT_EQ( 1572 ASSERT_EQ(0, webViewImpl->mainFrameImpl()
1572 0, 1573 ->frameView()
1573 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); 1574 ->maximumScrollOffset()
1575 .height());
1574 1576
1575 // Confirm that after exiting and doing a layout, the scroll and scale 1577 // Confirm that after exiting and doing a layout, the scroll and scale
1576 // parameters are reset. The page sets display: none on overflowing elements 1578 // parameters are reset. The page sets display: none on overflowing elements
1577 // while in fullscreen so if we try to restore before the style and layout 1579 // while in fullscreen so if we try to restore before the style and layout
1578 // is applied the offsets will be clamped. 1580 // is applied the offsets will be clamped.
1579 webViewImpl->didExitFullscreen(); 1581 webViewImpl->didExitFullscreen();
1580 EXPECT_TRUE(webViewImpl->mainFrameImpl()->frameView()->needsLayout()); 1582 EXPECT_TRUE(webViewImpl->mainFrameImpl()->frameView()->needsLayout());
1581 webViewImpl->updateAllLifecyclePhases(); 1583 webViewImpl->updateAllLifecyclePhases();
1582 1584
1583 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); 1585 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height);
(...skipping 16 matching lines...) Expand all
1600 1602
1601 // Enter fullscreen. 1603 // Enter fullscreen.
1602 Element* element = static_cast<Element*>( 1604 Element* element = static_cast<Element*>(
1603 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")); 1605 webViewImpl->mainFrame()->document().getElementById("fullscreenElement"));
1604 webViewImpl->enterFullscreenForElement(element); 1606 webViewImpl->enterFullscreenForElement(element);
1605 webViewImpl->didEnterFullscreen(); 1607 webViewImpl->didEnterFullscreen();
1606 webViewImpl->updateAllLifecyclePhases(); 1608 webViewImpl->updateAllLifecyclePhases();
1607 1609
1608 // Sanity-check. There should be no scrolling possible. 1610 // Sanity-check. There should be no scrolling possible.
1609 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); 1611 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
1610 ASSERT_EQ( 1612 ASSERT_EQ(0, webViewImpl->mainFrameImpl()
1611 0, 1613 ->frameView()
1612 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); 1614 ->maximumScrollOffset()
1615 .height());
1613 1616
1614 // Exit and, without performing a layout, reenter fullscreen again. We 1617 // Exit and, without performing a layout, reenter fullscreen again. We
1615 // shouldn't try to restore the scroll and scale values when we layout to 1618 // shouldn't try to restore the scroll and scale values when we layout to
1616 // enter fullscreen. 1619 // enter fullscreen.
1617 webViewImpl->exitFullscreenForElement(element); 1620 webViewImpl->exitFullscreenForElement(element);
1618 webViewImpl->didExitFullscreen(); 1621 webViewImpl->didExitFullscreen();
1619 webViewImpl->enterFullscreenForElement(element); 1622 webViewImpl->enterFullscreenForElement(element);
1620 webViewImpl->didEnterFullscreen(); 1623 webViewImpl->didEnterFullscreen();
1621 webViewImpl->updateAllLifecyclePhases(); 1624 webViewImpl->updateAllLifecyclePhases();
1622 1625
1623 // Sanity-check. There should be no scrolling possible. 1626 // Sanity-check. There should be no scrolling possible.
1624 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); 1627 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
1625 ASSERT_EQ( 1628 ASSERT_EQ(0, webViewImpl->mainFrameImpl()
1626 0, 1629 ->frameView()
1627 webViewImpl->mainFrameImpl()->frameView()->maximumScrollPosition().y()); 1630 ->maximumScrollOffset()
1631 .height());
1628 1632
1629 // When we exit now, we should restore the original scroll value. 1633 // When we exit now, we should restore the original scroll value.
1630 webViewImpl->exitFullscreenForElement(element); 1634 webViewImpl->exitFullscreenForElement(element);
1631 webViewImpl->didExitFullscreen(); 1635 webViewImpl->didExitFullscreen();
1632 webViewImpl->updateAllLifecyclePhases(); 1636 webViewImpl->updateAllLifecyclePhases();
1633 1637
1634 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); 1638 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height);
1635 } 1639 }
1636 1640
1637 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) { 1641 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) {
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
4040 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator(); 4044 DevToolsEmulator* devToolsEmulator = webViewImpl->devToolsEmulator();
4041 4045
4042 TransformationMatrix expectedMatrix; 4046 TransformationMatrix expectedMatrix;
4043 expectedMatrix.makeIdentity(); 4047 expectedMatrix.makeIdentity();
4044 EXPECT_EQ(expectedMatrix, 4048 EXPECT_EQ(expectedMatrix,
4045 webViewImpl->getDeviceEmulationTransformForTesting()); 4049 webViewImpl->getDeviceEmulationTransformForTesting());
4046 4050
4047 // Initial transform takes current page scale and scroll position into 4051 // Initial transform takes current page scale and scroll position into
4048 // account. 4052 // account.
4049 webViewImpl->setPageScaleFactor(1.5f); 4053 webViewImpl->setPageScaleFactor(1.5f);
4050 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, 4054 frameView->setScrollOffset(ScrollOffset(100, 150), ProgrammaticScroll,
4051 ScrollBehaviorInstant); 4055 ScrollBehaviorInstant);
4052 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f); 4056 devToolsEmulator->forceViewport(WebFloatPoint(50, 55), 2.f);
4053 expectedMatrix.makeIdentity() 4057 expectedMatrix.makeIdentity()
4054 .scale(2.f) 4058 .scale(2.f)
4055 .translate(-50, -55) 4059 .translate(-50, -55)
4056 .translate(100, 150) 4060 .translate(100, 150)
4057 .scale(1. / 1.5f); 4061 .scale(1. / 1.5f);
4058 EXPECT_EQ(expectedMatrix, 4062 EXPECT_EQ(expectedMatrix,
4059 webViewImpl->getDeviceEmulationTransformForTesting()); 4063 webViewImpl->getDeviceEmulationTransformForTesting());
4060 // Page scroll and scale are irrelevant for visibleContentRect. 4064 // Page scroll and scale are irrelevant for visibleContentRect.
4061 EXPECT_EQ(IntRect(50, 55, 50, 75), 4065 EXPECT_EQ(IntRect(50, 55, 50, 75),
4062 *devToolsEmulator->visibleContentRectForPainting()); 4066 *devToolsEmulator->visibleContentRectForPainting());
4063 4067
4064 // Transform adapts to scroll changes. 4068 // Transform adapts to scroll changes.
4065 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, 4069 frameView->setScrollOffset(ScrollOffset(50, 55), ProgrammaticScroll,
4066 ScrollBehaviorInstant); 4070 ScrollBehaviorInstant);
4067 expectedMatrix.makeIdentity() 4071 expectedMatrix.makeIdentity()
4068 .scale(2.f) 4072 .scale(2.f)
4069 .translate(-50, -55) 4073 .translate(-50, -55)
4070 .translate(50, 55) 4074 .translate(50, 55)
4071 .scale(1. / 1.5f); 4075 .scale(1. / 1.5f);
4072 EXPECT_EQ(expectedMatrix, 4076 EXPECT_EQ(expectedMatrix,
4073 webViewImpl->getDeviceEmulationTransformForTesting()); 4077 webViewImpl->getDeviceEmulationTransformForTesting());
4074 // visibleContentRect doesn't change. 4078 // visibleContentRect doesn't change.
4075 EXPECT_EQ(IntRect(50, 55, 50, 75), 4079 EXPECT_EQ(IntRect(50, 55, 50, 75),
4076 *devToolsEmulator->visibleContentRectForPainting()); 4080 *devToolsEmulator->visibleContentRectForPainting());
4077 4081
4078 // Transform adapts to page scale changes. 4082 // Transform adapts to page scale changes.
4079 webViewImpl->setPageScaleFactor(2.f); 4083 webViewImpl->setPageScaleFactor(2.f);
4080 expectedMatrix.makeIdentity() 4084 expectedMatrix.makeIdentity()
4081 .scale(2.f) 4085 .scale(2.f)
4082 .translate(-50, -55) 4086 .translate(-50, -55)
4083 .translate(50, 55) 4087 .translate(50, 55)
4084 .scale(1. / 2.f); 4088 .scale(1. / 2.f);
4085 EXPECT_EQ(expectedMatrix, 4089 EXPECT_EQ(expectedMatrix,
4086 webViewImpl->getDeviceEmulationTransformForTesting()); 4090 webViewImpl->getDeviceEmulationTransformForTesting());
4087 // visibleContentRect doesn't change. 4091 // visibleContentRect doesn't change.
4088 EXPECT_EQ(IntRect(50, 55, 50, 75), 4092 EXPECT_EQ(IntRect(50, 55, 50, 75),
4089 *devToolsEmulator->visibleContentRectForPainting()); 4093 *devToolsEmulator->visibleContentRectForPainting());
4090 } 4094 }
4091 4095
4092 } // namespace blink 4096 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/tests/WebFrameTest.cpp ('k') | ui/gfx/geometry/scroll_offset.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698