 Chromium Code Reviews
 Chromium Code Reviews Issue 225303014:
  [Pinch-to-zoom] Moved scale factor into PinchViewport  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 225303014:
  [Pinch-to-zoom] Moved scale factor into PinchViewport  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| OLD | NEW | 
|---|---|
| 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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1563 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document( )->viewportDescription()); | 1563 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document( )->viewportDescription()); | 
| 1564 updateMainFrameLayoutSize(); | 1564 updateMainFrameLayoutSize(); | 
| 1565 | 1565 | 
| 1566 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); | 1566 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); | 
| 1567 if (agentPrivate) | 1567 if (agentPrivate) | 
| 1568 agentPrivate->webViewResized(newSize); | 1568 agentPrivate->webViewResized(newSize); | 
| 1569 WebFrameImpl* webFrame = mainFrameImpl(); | 1569 WebFrameImpl* webFrame = mainFrameImpl(); | 
| 1570 if (webFrame->frameView()) { | 1570 if (webFrame->frameView()) { | 
| 1571 webFrame->frameView()->resize(m_size); | 1571 webFrame->frameView()->resize(m_size); | 
| 1572 if (page()->settings().pinchVirtualViewportEnabled()) | 1572 if (page()->settings().pinchVirtualViewportEnabled()) | 
| 1573 page()->frameHost().pinchViewport().setSize(m_size); | 1573 page()->frameHost().pinchViewport().mainFrameDidChangeSize(); | 
| 1574 } | 1574 } | 
| 1575 } | 1575 } | 
| 1576 | 1576 | 
| 1577 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { | 1577 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { | 
| 1578 // Relayout immediately to recalculate the minimum scale limit. | 1578 // Relayout immediately to recalculate the minimum scale limit. | 
| 1579 if (view->needsLayout()) | 1579 if (view->needsLayout()) | 
| 1580 view->layout(); | 1580 view->layout(); | 
| 1581 | 1581 | 
| 1582 if (shouldAnchorAndRescaleViewport) { | 1582 if (shouldAnchorAndRescaleViewport) { | 
| 1583 float viewportWidthRatio = static_cast<float>(newSize.width) / oldSi ze.width; | 1583 float viewportWidthRatio = static_cast<float>(newSize.width) / oldSi ze.width; | 
| (...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2630 { | 2630 { | 
| 2631 // Since factor = 1.2^level, level = log(factor) / log(1.2) | 2631 // Since factor = 1.2^level, level = log(factor) / log(1.2) | 
| 2632 return log(factor) / log(textSizeMultiplierRatio); | 2632 return log(factor) / log(textSizeMultiplierRatio); | 
| 2633 } | 2633 } | 
| 2634 | 2634 | 
| 2635 float WebViewImpl::pageScaleFactor() const | 2635 float WebViewImpl::pageScaleFactor() const | 
| 2636 { | 2636 { | 
| 2637 if (!page()) | 2637 if (!page()) | 
| 2638 return 1; | 2638 return 1; | 
| 2639 | 2639 | 
| 2640 if (page()->settings().pinchVirtualViewportEnabled()) | |
| 2641 return page()->frameHost().pinchViewport().scale(); | |
| 2642 | |
| 2640 return page()->pageScaleFactor(); | 2643 return page()->pageScaleFactor(); | 
| 2641 } | 2644 } | 
| 2642 | 2645 | 
| 2643 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) const | 2646 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) const | 
| 2644 { | 2647 { | 
| 2645 return m_pageScaleConstraintsSet.finalConstraints().clampToConstraints(scale Factor); | 2648 return m_pageScaleConstraintsSet.finalConstraints().clampToConstraints(scale Factor); | 
| 2646 } | 2649 } | 
| 2647 | 2650 | 
| 2648 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) | 2651 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) | 
| 2649 { | 2652 { | 
| 2650 FrameView* view = mainFrameImpl()->frameView(); | 2653 FrameView* view = mainFrameImpl()->frameView(); | 
| 2651 if (!view) | 2654 if (!view) | 
| 2652 return offset; | 2655 return offset; | 
| 2653 | 2656 | 
| 2654 return view->clampOffsetAtScale(offset, scale); | 2657 return view->clampOffsetAtScale(offset, scale); | 
| 2655 } | 2658 } | 
| 2656 | 2659 | 
| 2660 void WebViewImpl::setPageScaleFactor(float scaleFactor) | |
| 2661 { | |
| 2662 ASSERT(page()->settings().pinchVirtualViewportEnabled()); | |
| 2663 | |
| 2664 if (!page()) | |
| 2665 return; | |
| 2666 | |
| 2667 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); | |
| 2668 | |
| 2669 page()->frameHost().pinchViewport().setScale(scaleFactor); | |
| 2670 deviceOrPageScaleFactorChanged(); | |
| 2671 } | |
| 2672 | |
| 2657 void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin) | 2673 void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin) | 
| 2658 { | 2674 { | 
| 2659 if (!page()) | 2675 if (!page()) | 
| 2660 return; | 2676 return; | 
| 2661 | 2677 | 
| 2662 IntPoint newScrollOffset = origin; | 2678 IntPoint newScrollOffset = origin; | 
| 2663 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); | 2679 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); | 
| 2664 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor); | 2680 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor); | 
| 2665 | 2681 | 
| 2666 page()->setPageScaleFactor(scaleFactor, newScrollOffset); | 2682 if (page()->settings().pinchVirtualViewportEnabled()) { | 
| 2683 page()->frameHost().pinchViewport().setScale(scaleFactor); | |
| 2684 deviceOrPageScaleFactorChanged(); | |
| 2685 | |
| 2686 if (FrameView* view = page()->mainFrame()->view()) { | |
| 2687 view->notifyScrollPositionChanged(origin); | |
| 2688 | |
| 2689 IntSize remaining = IntSize(origin.x, origin.y) - view->scrollOffset (); | |
| 
aelias_OOO_until_Jul13
2014/04/09 08:41:22
Hmm, this is doing distribution which we would lik
 
bokan
2014/04/09 15:30:59
There's actually a few other uses (Fullscreen elem
 
aelias_OOO_until_Jul13
2014/04/09 18:35:32
Well, keep in mind that clamping can cause issue w
 
bokan
2014/04/09 19:57:19
Ok, I replaced all uses in unit tests since they a
 
bokan
2014/04/09 20:21:53
Erm, I had to leave setPageScale in WebView since
 | |
| 2690 page()->frameHost().pinchViewport().setLocation( | |
| 2691 IntPoint(remaining.width(), remaining.height())); | |
| 2692 } | |
| 2693 } else { | |
| 2694 page()->setPageScaleFactor(scaleFactor, newScrollOffset); | |
| 2695 } | |
| 2667 } | 2696 } | 
| 2668 | 2697 | 
| 2669 void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor) | 2698 void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor) | 
| 2670 { | 2699 { | 
| 2671 if (clampPageScaleFactorToLimits(scaleFactor) == pageScaleFactor()) | 2700 if (clampPageScaleFactorToLimits(scaleFactor) == pageScaleFactor()) | 
| 2672 return; | 2701 return; | 
| 2673 | 2702 | 
| 2674 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->scroll Offset().height); | 2703 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->scroll Offset().height); | 
| 2675 setPageScaleFactor(scaleFactor, scrollOffset); | 2704 setPageScaleFactor(scaleFactor, scrollOffset); | 
| 2676 } | 2705 } | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2905 } | 2934 } | 
| 2906 | 2935 | 
| 2907 void WebViewImpl::resetSavedScrollAndScaleState() | 2936 void WebViewImpl::resetSavedScrollAndScaleState() | 
| 2908 { | 2937 { | 
| 2909 m_savedPageScaleFactor = 0; | 2938 m_savedPageScaleFactor = 0; | 
| 2910 m_savedScrollOffset = IntSize(); | 2939 m_savedScrollOffset = IntSize(); | 
| 2911 } | 2940 } | 
| 2912 | 2941 | 
| 2913 void WebViewImpl::resetScrollAndScaleState() | 2942 void WebViewImpl::resetScrollAndScaleState() | 
| 2914 { | 2943 { | 
| 2915 page()->setPageScaleFactor(1, IntPoint()); | 2944 setPageScaleFactor(1, IntPoint()); | 
| 2916 | 2945 | 
| 2917 // Clear out the values for the current history item. This will prevent the history item from clobbering the | 2946 // Clear out the values for the current history item. This will prevent the history item from clobbering the | 
| 2918 // value determined during page scale initialization, which may be less than 1. | 2947 // value determined during page scale initialization, which may be less than 1. | 
| 2919 page()->mainFrame()->loader().clearScrollPositionAndViewState(); | 2948 page()->mainFrame()->loader().clearScrollPositionAndViewState(); | 
| 2920 m_pageScaleConstraintsSet.setNeedsReset(true); | 2949 m_pageScaleConstraintsSet.setNeedsReset(true); | 
| 2921 | 2950 | 
| 2922 // Clobber saved scales and scroll offsets. | 2951 // Clobber saved scales and scroll offsets. | 
| 2923 if (FrameView* view = page()->mainFrame()->document()->view()) | 2952 if (FrameView* view = page()->mainFrame()->document()->view()) | 
| 2924 view->cacheCurrentScrollPosition(); | 2953 view->cacheCurrentScrollPosition(); | 
| 2925 resetSavedScrollAndScaleState(); | 2954 resetSavedScrollAndScaleState(); | 
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3613 } | 3642 } | 
| 3614 | 3643 | 
| 3615 void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* layer) | 3644 void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* layer) | 
| 3616 { | 3645 { | 
| 3617 bool pinchVirtualViewportEnabled = page()->settings().pinchVirtualViewportEn abled(); | 3646 bool pinchVirtualViewportEnabled = page()->settings().pinchVirtualViewportEn abled(); | 
| 3618 suppressInvalidations(true); | 3647 suppressInvalidations(true); | 
| 3619 | 3648 | 
| 3620 if (pinchVirtualViewportEnabled) { | 3649 if (pinchVirtualViewportEnabled) { | 
| 3621 PinchViewport& pinchViewport = page()->frameHost().pinchViewport(); | 3650 PinchViewport& pinchViewport = page()->frameHost().pinchViewport(); | 
| 3622 pinchViewport.attachToLayerTree(layer, graphicsLayerFactory()); | 3651 pinchViewport.attachToLayerTree(layer, graphicsLayerFactory()); | 
| 3623 pinchViewport.setSize(mainFrameImpl()->frame()->view()->frameRect().size ()); | |
| 3624 if (layer) { | 3652 if (layer) { | 
| 3625 m_rootGraphicsLayer = pinchViewport.rootGraphicsLayer(); | 3653 m_rootGraphicsLayer = pinchViewport.rootGraphicsLayer(); | 
| 3626 m_rootLayer = pinchViewport.rootGraphicsLayer()->platformLayer(); | 3654 m_rootLayer = pinchViewport.rootGraphicsLayer()->platformLayer(); | 
| 3627 m_rootTransformLayer = 0; | 3655 m_rootTransformLayer = 0; | 
| 3628 } else { | 3656 } else { | 
| 3629 m_rootGraphicsLayer = 0; | 3657 m_rootGraphicsLayer = 0; | 
| 3630 m_rootLayer = 0; | 3658 m_rootLayer = 0; | 
| 3631 m_rootTransformLayer = 0; | 3659 m_rootTransformLayer = 0; | 
| 3632 } | 3660 } | 
| 3633 } else { | 3661 } else { | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3805 frameView->setInProgrammaticScroll(programmaticScroll); | 3833 frameView->setInProgrammaticScroll(programmaticScroll); | 
| 3806 frameView->notifyScrollPositionChanged(scrollPosition); | 3834 frameView->notifyScrollPositionChanged(scrollPosition); | 
| 3807 frameView->setInProgrammaticScroll(oldProgrammaticScroll); | 3835 frameView->setInProgrammaticScroll(oldProgrammaticScroll); | 
| 3808 } | 3836 } | 
| 3809 | 3837 | 
| 3810 void WebViewImpl::applyScrollAndScale(const WebSize& scrollDelta, float pageScal eDelta) | 3838 void WebViewImpl::applyScrollAndScale(const WebSize& scrollDelta, float pageScal eDelta) | 
| 3811 { | 3839 { | 
| 3812 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 3840 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 
| 3813 return; | 3841 return; | 
| 3814 | 3842 | 
| 3815 // With virtual viewport we need only set the scale (see TODO below). | |
| 3816 if (page()->settings().pinchVirtualViewportEnabled()) { | 3843 if (page()->settings().pinchVirtualViewportEnabled()) { | 
| 3817 WebSize scrollOffset = mainFrame()->scrollOffset(); | 3844 if (pageScaleDelta != 1) { | 
| 3818 WebPoint scrollPoint(scrollOffset.width, scrollOffset.height); | 3845 // When the virtual viewport is enabled, offsets are already set for us. | 
| 3819 setPageScaleFactor(pageScaleFactor() * pageScaleDelta, scrollPoint); | 3846 setPageScaleFactor(pageScaleFactor() * pageScaleDelta); | 
| 3820 m_doubleTapZoomPending = false; | 3847 m_doubleTapZoomPending = false; | 
| 3848 } | |
| 3849 | |
| 3821 return; | 3850 return; | 
| 3822 } | 3851 } | 
| 3823 | 3852 | 
| 3824 // TODO(bokan): Old pinch path only - virtual viewport pinch scrolls are aut omatically updated via GraphicsLayer::DidScroll. | 3853 // TODO(bokan): Old pinch path only - virtual viewport pinch scrolls are aut omatically updated via GraphicsLayer::DidScroll. | 
| 3825 // this should be removed once old pinch is removed. | 3854 // this should be removed once old pinch is removed. | 
| 3826 if (pageScaleDelta == 1) { | 3855 if (pageScaleDelta == 1) { | 
| 3827 TRACE_EVENT_INSTANT2("webkit", "WebViewImpl::applyScrollAndScale::scroll By", "x", scrollDelta.width, "y", scrollDelta.height); | 3856 TRACE_EVENT_INSTANT2("webkit", "WebViewImpl::applyScrollAndScale::scroll By", "x", scrollDelta.width, "y", scrollDelta.height); | 
| 3828 WebSize webScrollOffset = mainFrame()->scrollOffset(); | 3857 WebSize webScrollOffset = mainFrame()->scrollOffset(); | 
| 3829 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height); | 3858 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height); | 
| 3830 updateMainFrameScrollPosition(scrollOffset, false); | 3859 updateMainFrameScrollPosition(scrollOffset, false); | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3992 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); | 4021 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); | 
| 3993 | 4022 | 
| 3994 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4023 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 
| 3995 return false; | 4024 return false; | 
| 3996 | 4025 | 
| 3997 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4026 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 
| 3998 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); | 4027 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); | 
| 3999 } | 4028 } | 
| 4000 | 4029 | 
| 4001 } // namespace blink | 4030 } // namespace blink | 
| OLD | NEW |