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

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 597683007: Revert of Revert of Initial draft - modify ViewportAnchor to know about both inner and outer viewports. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('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 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 1682
1683 bool shouldAnchorAndRescaleViewport = settings()->mainFrameResizesAreOrienta tionChanges() 1683 bool shouldAnchorAndRescaleViewport = settings()->mainFrameResizesAreOrienta tionChanges()
1684 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen(); 1684 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen();
1685 float oldPageScaleFactor = pageScaleFactor(); 1685 float oldPageScaleFactor = pageScaleFactor();
1686 float oldMinimumPageScaleFactor = minimumPageScaleFactor(); 1686 float oldMinimumPageScaleFactor = minimumPageScaleFactor();
1687 1687
1688 m_size = newSize; 1688 m_size = newSize;
1689 1689
1690 ViewportAnchor viewportAnchor(&localFrameRootTemporary()->frame()->eventHand ler()); 1690 ViewportAnchor viewportAnchor(&localFrameRootTemporary()->frame()->eventHand ler());
1691 if (shouldAnchorAndRescaleViewport) { 1691 if (shouldAnchorAndRescaleViewport) {
1692 viewportAnchor.setAnchor(view->visibleContentRect(), 1692 viewportAnchor.setAnchor(
1693 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord)); 1693 view->visibleContentRect(),
1694 visibleRectInDocument(),
1695 FloatSize(viewportAnchorXCoord, viewportAnchorYCoord));
1694 } 1696 }
1695 1697
1696 // FIXME: TextAutosizer does not yet support out-of-process frames. 1698 // FIXME: TextAutosizer does not yet support out-of-process frames.
1697 if (mainFrameImpl() && mainFrameImpl()->frame()->isLocalFrame()) 1699 if (mainFrameImpl() && mainFrameImpl()->frame()->isLocalFrame())
1698 { 1700 {
1699 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated. 1701 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated.
1700 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page()); 1702 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
1701 performResize(); 1703 performResize();
1702 } else { 1704 } else {
1703 performResize(); 1705 performResize();
1704 } 1706 }
1705 1707
1706 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { 1708 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) {
1707 // Relayout immediately to recalculate the minimum scale limit. 1709 // Relayout immediately to recalculate the minimum scale limit.
1708 if (view->needsLayout()) 1710 if (view->needsLayout())
1709 view->layout(); 1711 view->layout();
1710 1712
1711 if (shouldAnchorAndRescaleViewport) { 1713 if (shouldAnchorAndRescaleViewport) {
1712 float newPageScaleFactor = oldPageScaleFactor / oldMinimumPageScaleF actor * minimumPageScaleFactor(); 1714 float newPageScaleFactor = oldPageScaleFactor / oldMinimumPageScaleF actor * minimumPageScaleFactor();
1713 IntSize scaledViewportSize = newSize; 1715 newPageScaleFactor = clampPageScaleFactorToLimits(newPageScaleFactor );
1714 scaledViewportSize.scale(1 / newPageScaleFactor); 1716
1715 setPageScaleFactor(newPageScaleFactor, viewportAnchor.computeOrigin( scaledViewportSize)); 1717 FloatSize pinchViewportSize = FloatSize(newSize);
1718 pinchViewportSize.scale(1 / newPageScaleFactor);
1719
1720 IntPoint mainFrameOrigin;
1721 FloatPoint pinchViewportOrigin;
1722 viewportAnchor.computeOrigins(*view, pinchViewportSize,
1723 mainFrameOrigin, pinchViewportOrigin);
1724 scrollAndRescaleViewports(newPageScaleFactor, mainFrameOrigin, pinch ViewportOrigin);
1716 } 1725 }
1717 } 1726 }
1718 1727
1719 sendResizeEventAndRepaint(); 1728 sendResizeEventAndRepaint();
1720 } 1729 }
1721 1730
1731 IntRect WebViewImpl::visibleRectInDocument() const
1732 {
1733 if (pinchVirtualViewportEnabled()) {
1734 // Inner viewport in the document coordinates
1735 return enclosedIntRect(page()->frameHost().pinchViewport().visibleRectIn Document());
1736 }
1737
1738 // Outer viewport in the document coordinates
1739 return localFrameRootTemporary()->frameView()->visibleContentRect();
1740 }
1741
1722 void WebViewImpl::willEndLiveResize() 1742 void WebViewImpl::willEndLiveResize()
1723 { 1743 {
1724 if (mainFrameImpl() && mainFrameImpl()->frameView()) 1744 if (mainFrameImpl() && mainFrameImpl()->frameView())
1725 mainFrameImpl()->frameView()->willEndLiveResize(); 1745 mainFrameImpl()->frameView()->willEndLiveResize();
1726 1746
1727 LocalFrame* frame = mainFrameImpl()->frame(); 1747 LocalFrame* frame = mainFrameImpl()->frame();
1728 WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainer FromFrame(frame); 1748 WebPluginContainerImpl* pluginContainer = WebLocalFrameImpl::pluginContainer FromFrame(frame);
1729 if (pluginContainer) 1749 if (pluginContainer)
1730 pluginContainer->willEndLiveResize(); 1750 pluginContainer->willEndLiveResize();
1731 } 1751 }
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 WebFloatPoint WebViewImpl::pinchViewportOffset() const 2931 WebFloatPoint WebViewImpl::pinchViewportOffset() const
2912 { 2932 {
2913 ASSERT(page()); 2933 ASSERT(page());
2914 2934
2915 if (!pinchVirtualViewportEnabled()) 2935 if (!pinchVirtualViewportEnabled())
2916 return WebFloatPoint(); 2936 return WebFloatPoint();
2917 2937
2918 return page()->frameHost().pinchViewport().visibleRect().location(); 2938 return page()->frameHost().pinchViewport().visibleRect().location();
2919 } 2939 }
2920 2940
2941 void WebViewImpl::scrollAndRescaleViewports(float scaleFactor,
2942 const IntPoint& mainFrameOrigin,
2943 const FloatPoint& pinchViewportOrigin)
2944 {
2945 // Old way
2946 if (!pinchVirtualViewportEnabled()) {
2947 setPageScaleFactor(scaleFactor, mainFrameOrigin);
2948 return;
2949 }
2950
2951 if (!page())
2952 return;
2953
2954 if (!mainFrameImpl())
2955 return;
2956
2957 FrameView * view = mainFrameImpl()->frameView();
2958 if (!view)
2959 return;
2960
2961 // Order is important: pinch viewport location is clamped based on
2962 // main frame scroll position and pinch viewport scale.
2963
2964 view->setScrollOffset(mainFrameOrigin);
2965
2966 setPageScaleFactor(scaleFactor);
2967
2968 page()->frameHost().pinchViewport().setLocation(pinchViewportOrigin);
2969 }
2970
2921 void WebViewImpl::setPageScaleFactor(float scaleFactor) 2971 void WebViewImpl::setPageScaleFactor(float scaleFactor)
2922 { 2972 {
2923 ASSERT(page()); 2973 ASSERT(page());
2924 2974
2925 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); 2975 scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
2926 if (scaleFactor == pageScaleFactor()) 2976 if (scaleFactor == pageScaleFactor())
2927 return; 2977 return;
2928 2978
2929 // TODO(bokan): Old-style pinch path. Remove when we're migrated to 2979 // TODO(bokan): Old-style pinch path. Remove when we're migrated to
2930 // virtual viewport pinch. 2980 // virtual viewport pinch.
(...skipping 22 matching lines...) Expand all
2953 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor); 3003 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor);
2954 3004
2955 if (pinchVirtualViewportEnabled()) 3005 if (pinchVirtualViewportEnabled())
2956 setPageScaleFactor(scaleFactor); 3006 setPageScaleFactor(scaleFactor);
2957 // Note, we don't set the offset in the new path. This method is going 3007 // Note, we don't set the offset in the new path. This method is going
2958 // away for the new pinch model so that's ok. 3008 // away for the new pinch model so that's ok.
2959 else 3009 else
2960 page()->setPageScaleFactor(scaleFactor, newScrollOffset); 3010 page()->setPageScaleFactor(scaleFactor, newScrollOffset);
2961 } 3011 }
2962 3012
2963
2964 float WebViewImpl::deviceScaleFactor() const 3013 float WebViewImpl::deviceScaleFactor() const
2965 { 3014 {
2966 if (!page()) 3015 if (!page())
2967 return 1; 3016 return 1;
2968 3017
2969 return page()->deviceScaleFactor(); 3018 return page()->deviceScaleFactor();
2970 } 3019 }
2971 3020
2972 void WebViewImpl::setDeviceScaleFactor(float scaleFactor) 3021 void WebViewImpl::setDeviceScaleFactor(float scaleFactor)
2973 { 3022 {
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
4319 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4368 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4320 4369
4321 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4370 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4322 return false; 4371 return false;
4323 4372
4324 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4373 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4325 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4374 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4326 } 4375 }
4327 4376
4328 } // namespace blink 4377 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698