| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "WebFrame.h" | 33 #include "WebFrame.h" |
| 34 | 34 |
| 35 #include "DocumentMarkerController.h" | 35 #include "DocumentMarkerController.h" |
| 36 #include "FloatRect.h" | 36 #include "FloatRect.h" |
| 37 #include "Frame.h" | 37 #include "Frame.h" |
| 38 #include "FrameTestHelpers.h" | 38 #include "FrameTestHelpers.h" |
| 39 #include "FrameView.h" | 39 #include "FrameView.h" |
| 40 #include "HitTestResult.h" |
| 40 #include "PlatformContextSkia.h" | 41 #include "PlatformContextSkia.h" |
| 41 #include "Range.h" | 42 #include "Range.h" |
| 42 #include "RenderView.h" | 43 #include "RenderView.h" |
| 43 #include "ResourceError.h" | 44 #include "ResourceError.h" |
| 44 #include "ScrollbarTheme.h" | 45 #include "ScrollbarTheme.h" |
| 45 #include "Settings.h" | 46 #include "Settings.h" |
| 46 #include "SkBitmap.h" | 47 #include "SkBitmap.h" |
| 47 #include "SkCanvas.h" | 48 #include "SkCanvas.h" |
| 48 #include "URLTestHelpers.h" | 49 #include "URLTestHelpers.h" |
| 49 #include "WebDataSource.h" | 50 #include "WebDataSource.h" |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 649 |
| 649 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web
View->fixedLayoutSize().width, 1.0f); | 650 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web
View->fixedLayoutSize().width, 1.0f); |
| 650 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we
bView->fixedLayoutSize().height, 1.0f); | 651 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we
bView->fixedLayoutSize().height, 1.0f); |
| 651 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag
eScaleFactor(), 0.01f); | 652 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag
eScaleFactor(), 0.01f); |
| 652 | 653 |
| 653 m_webView->close(); | 654 m_webView->close(); |
| 654 m_webView = 0; | 655 m_webView = 0; |
| 655 } | 656 } |
| 656 } | 657 } |
| 657 | 658 |
| 659 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& absolut
eOffset, const WebCore::LayoutRect& rect) |
| 660 { |
| 661 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - re
ct.location(); |
| 662 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height()); |
| 663 return relativeOffset; |
| 664 } |
| 665 |
| 666 TEST_F(WebFrameTest, ResizeYieldsCorrectScrollAndScaleForFixedLayout) |
| 667 { |
| 668 registerMockedHttpURLLoad("resize_scroll_fixed_layout.html"); |
| 669 |
| 670 const WebSize viewportSize = WebSize(320, 240); |
| 671 |
| 672 // With a fixed layout, pageScaleFactor scales by the relative change in vie
wport width. |
| 673 |
| 674 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "resize_scrol
l_fixed_layout.html", true); |
| 675 m_webView->settings()->setViewportEnabled(true); |
| 676 m_webView->enableFixedLayoutMode(true); |
| 677 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); |
| 678 |
| 679 // Resize at origin |
| 680 float pageScaleFactor = 2.0f; |
| 681 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 682 m_webView->setPageScaleFactor(pageScaleFactor, WebPoint()); |
| 683 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 684 EXPECT_EQ(pageScaleFactor * viewportSize.height / viewportSize.width, webVie
wImpl->pageScaleFactor()); |
| 685 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset()); |
| 686 |
| 687 // Rotation via resize |
| 688 const WebSize scrollOffset = WebSize(200, 400); |
| 689 pageScaleFactor = webViewImpl->pageScaleFactor(); |
| 690 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 691 EXPECT_EQ(pageScaleFactor * viewportSize.width / viewportSize.height, webVie
wImpl->pageScaleFactor()); |
| 692 webViewImpl->mainFrame()->setScrollOffset(scrollOffset); |
| 693 |
| 694 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + WebCore::I
ntPoint(viewportSize.width / 2, 0); |
| 695 RefPtr<WebCore::Node> anchorNode |
| 696 = webViewImpl->mainFrameImpl()->frame()->eventHandler()->hitTestResultAt
Point(anchorPoint).innerNode(); |
| 697 ASSERT(anchorNode); |
| 698 |
| 699 pageScaleFactor = webViewImpl->pageScaleFactor(); |
| 700 const WebCore::FloatSize preResizeRelativeOffset |
| 701 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); |
| 702 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 703 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->mainFrame(
)->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); |
| 704 const WebCore::FloatSize postResizeRelativeOffset |
| 705 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox()); |
| 706 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffset.width(
), 0.1f); |
| 707 EXPECT_EQ(pageScaleFactor * viewportSize.height / viewportSize.width, webVie
wImpl->pageScaleFactor()); |
| 708 } |
| 709 |
| 710 TEST_F(WebFrameTest, ResizeYieldsCorrectScrollAndScaleForFixedWidth) |
| 711 { |
| 712 registerMockedHttpURLLoad("resize_scroll_fixed_width.html"); |
| 713 |
| 714 const WebSize viewportSize = WebSize(320, 240); |
| 715 |
| 716 // With a fixed width, pageScaleFactor scales by the relative change in view
port width. |
| 717 |
| 718 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "resize_scrol
l_fixed_width.html", true); |
| 719 m_webView->settings()->setViewportEnabled(true); |
| 720 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); |
| 721 |
| 722 // Resize at origin |
| 723 float pageScaleFactor = 2.0f; |
| 724 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 725 m_webView->setPageScaleFactor(pageScaleFactor, WebPoint()); |
| 726 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 727 EXPECT_EQ(pageScaleFactor * viewportSize.height / viewportSize.width, webVie
wImpl->pageScaleFactor()); |
| 728 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset()); |
| 729 |
| 730 // Rotation via resize |
| 731 const WebSize scrollOffset = WebSize(200, 400); |
| 732 pageScaleFactor = webViewImpl->pageScaleFactor(); |
| 733 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 734 EXPECT_EQ(pageScaleFactor * viewportSize.width / viewportSize.height, webVie
wImpl->pageScaleFactor()); |
| 735 webViewImpl->mainFrame()->setScrollOffset(scrollOffset); |
| 736 |
| 737 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + WebCore::I
ntPoint(viewportSize.width / 2, 0); |
| 738 RefPtr<WebCore::Node> anchorNode |
| 739 = webViewImpl->mainFrameImpl()->frame()->eventHandler()->hitTestResultAt
Point(anchorPoint).innerNode(); |
| 740 ASSERT(anchorNode); |
| 741 |
| 742 pageScaleFactor = webViewImpl->pageScaleFactor(); |
| 743 const WebCore::FloatSize preResizeRelativeOffset |
| 744 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); |
| 745 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 746 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->mainFrame(
)->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); |
| 747 const WebCore::FloatSize postResizeRelativeOffset |
| 748 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox()); |
| 749 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffset.width(
), 0.1f); |
| 750 EXPECT_EQ(pageScaleFactor * viewportSize.height / viewportSize.width, webVie
wImpl->pageScaleFactor()); |
| 751 } |
| 752 |
| 753 TEST_F(WebFrameTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) |
| 754 { |
| 755 registerMockedHttpURLLoad("resize_scroll_mobile.html"); |
| 756 |
| 757 // With width=device-width, pageScaleFactor is preserved across resizes as |
| 758 // long as the content adjusts according to the device-width. |
| 759 |
| 760 const WebSize viewportSize = WebSize(240, 320); |
| 761 |
| 762 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "resize_scrol
l_mobile.html", true); |
| 763 m_webView->settings()->setViewportEnabled(true); |
| 764 m_webView->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 765 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); |
| 766 |
| 767 // Resize at origin |
| 768 const float pageScaleFactor = 1; |
| 769 m_webView->setPageScaleFactor(pageScaleFactor, WebPoint()); |
| 770 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 771 EXPECT_EQ(pageScaleFactor, webViewImpl->pageScaleFactor()); |
| 772 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 773 EXPECT_NEAR(pageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| 774 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset()); |
| 775 |
| 776 // Rotation via resize |
| 777 const WebSize scrollOffset = WebSize(0, 200); |
| 778 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| 779 EXPECT_NEAR(pageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| 780 webViewImpl->mainFrame()->setScrollOffset(scrollOffset); |
| 781 |
| 782 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + WebCore::I
ntPoint(viewportSize.width / 2, 0); |
| 783 RefPtr<WebCore::Node> anchorNode |
| 784 = webViewImpl->mainFrameImpl()->frame()->eventHandler()->hitTestResultAt
Point(anchorPoint).innerNode(); |
| 785 ASSERT(anchorNode); |
| 786 |
| 787 const WebCore::FloatSize preResizeRelativeOffset |
| 788 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); |
| 789 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| 790 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->mainFrame(
)->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); |
| 791 const WebCore::FloatSize postResizeRelativeOffset |
| 792 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox()); |
| 793 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffset.width(
), 0.1f); |
| 794 EXPECT_NEAR(pageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| 795 } |
| 796 |
| 658 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) | 797 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) |
| 659 { | 798 { |
| 660 registerMockedHttpURLLoad("fixed_layout.html"); | 799 registerMockedHttpURLLoad("fixed_layout.html"); |
| 661 | 800 |
| 662 FixedLayoutTestWebViewClient client; | 801 FixedLayoutTestWebViewClient client; |
| 663 client.m_screenInfo.deviceScaleFactor = 1; | 802 client.m_screenInfo.deviceScaleFactor = 1; |
| 664 int viewportWidth = 50; | 803 int viewportWidth = 50; |
| 665 int viewportHeight = 50; | 804 int viewportHeight = 50; |
| 666 | 805 |
| 667 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 806 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); |
| (...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 EXPECT_FALSE(client.wasProgrammaticScroll()); | 2797 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 2659 EXPECT_TRUE(client.wasUserScroll()); | 2798 EXPECT_TRUE(client.wasUserScroll()); |
| 2660 client.reset(); | 2799 client.reset(); |
| 2661 | 2800 |
| 2662 m_webView->close(); | 2801 m_webView->close(); |
| 2663 m_webView = 0; | 2802 m_webView = 0; |
| 2664 } | 2803 } |
| 2665 | 2804 |
| 2666 | 2805 |
| 2667 } // namespace | 2806 } // namespace |
| OLD | NEW |