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

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

Issue 15927026: Enabled using viewport on desktop browsers behind experimental flag (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: WIP Created 7 years, 5 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 /* 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 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 FrameView* view = mainFrameImpl()->frameView(); 1590 FrameView* view = mainFrameImpl()->frameView();
1591 if (!view) 1591 if (!view)
1592 return; 1592 return;
1593 1593
1594 WebSize oldSize = m_size; 1594 WebSize oldSize = m_size;
1595 float oldPageScaleFactor = pageScaleFactor(); 1595 float oldPageScaleFactor = pageScaleFactor();
1596 int oldContentsWidth = contentsSize().width(); 1596 int oldContentsWidth = contentsSize().width();
1597 1597
1598 m_size = newSize; 1598 m_size = newSize;
1599 1599
1600 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth; 1600 // On devices where resizes come from screen rotation, we want to anchor the scroll
1601 // when we resize
1602 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled()
1603 && settings()->anchorScrollPositionOnResize() && oldSize.width && oldCon tentsWidth;
1604
1601 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); 1605 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
1602 if (shouldAnchorAndRescaleViewport) { 1606 if (shouldAnchorAndRescaleViewport) {
1603 viewportAnchor.setAnchor(view->visibleContentRect(), 1607 viewportAnchor.setAnchor(view->visibleContentRect(),
1604 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord)); 1608 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord));
1605 } 1609 }
1606 1610
1607 // Set the fixed layout size from the viewport constraints before resizing. 1611 // Set the layout size from the viewport constraints before resizing.
1608 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments()); 1612 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments());
1609 1613
1610 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); 1614 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
1611 if (agentPrivate) 1615 if (agentPrivate)
1612 agentPrivate->webViewResized(newSize); 1616 agentPrivate->webViewResized(newSize);
1613 if (!agentPrivate || !agentPrivate->metricsOverridden()) { 1617 if (!agentPrivate || !agentPrivate->metricsOverridden()) {
1614 WebFrameImpl* webFrame = mainFrameImpl(); 1618 WebFrameImpl* webFrame = mainFrameImpl();
1615 if (webFrame->frameView()) { 1619 if (webFrame->frameView()) {
1616 webFrame->frameView()->resize(m_size); 1620 webFrame->frameView()->resize(m_size);
1617 if (m_pinchViewports) 1621 if (m_pinchViewports)
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 { 2919 {
2916 if (!page()) 2920 if (!page())
2917 return; 2921 return;
2918 2922
2919 page()->setDeviceScaleFactor(scaleFactor); 2923 page()->setDeviceScaleFactor(scaleFactor);
2920 2924
2921 if (m_layerTreeView) 2925 if (m_layerTreeView)
2922 m_layerTreeView->setDeviceScaleFactor(scaleFactor); 2926 m_layerTreeView->setDeviceScaleFactor(scaleFactor);
2923 } 2927 }
2924 2928
2925 bool WebViewImpl::isFixedLayoutModeEnabled() const
2926 {
2927 if (!page())
2928 return false;
2929
2930 Frame* frame = page()->mainFrame();
2931 if (!frame || !frame->view())
2932 return false;
2933
2934 return frame->view()->useFixedLayout();
2935 }
2936
2937 void WebViewImpl::enableFixedLayoutMode(bool enable)
2938 {
2939 if (!page())
2940 return;
2941
2942 Frame* frame = page()->mainFrame();
2943 if (!frame || !frame->view())
2944 return;
2945
2946 frame->view()->setUseFixedLayout(enable);
2947
2948 if (m_isAcceleratedCompositingActive)
2949 updateLayerTreeViewport();
2950 }
2951
2952
2953 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize) 2929 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize)
2954 { 2930 {
2955 m_shouldAutoResize = true; 2931 m_shouldAutoResize = true;
2956 m_minAutoSize = minSize; 2932 m_minAutoSize = minSize;
2957 m_maxAutoSize = maxSize; 2933 m_maxAutoSize = maxSize;
2958 configureAutoResizeMode(); 2934 configureAutoResizeMode();
2959 } 2935 }
2960 2936
2961 void WebViewImpl::disableAutoResizeMode() 2937 void WebViewImpl::disableAutoResizeMode()
2962 { 2938 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3026 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c ontentsSize(), verticalScrollbarWidth); 3002 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c ontentsSize(), verticalScrollbarWidth);
3027 } 3003 }
3028 3004
3029 float newPageScaleFactor = pageScaleFactor(); 3005 float newPageScaleFactor = pageScaleFactor();
3030 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina lConstraints().initialScale != -1) { 3006 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina lConstraints().initialScale != -1) {
3031 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia lScale; 3007 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia lScale;
3032 m_pageScaleConstraintsSet.setNeedsReset(false); 3008 m_pageScaleConstraintsSet.setNeedsReset(false);
3033 } 3009 }
3034 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor); 3010 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor);
3035 3011
3012 // Destroying the frameView turns off forced compositing mode, in the case o r a refresh it wont get turned
3013 // back on because we don't set a new page scale so we make sure it's on her e
3014 if (pageScaleFactor() && pageScaleFactor() != 1)
3015 enterForceCompositingMode(true);
aelias_OOO_until_Jul13 2013/07/31 22:31:21 This doesn't feel like the right place to put this
3016
3036 updateLayerTreeViewport(); 3017 updateLayerTreeViewport();
3037 3018
3038 // Relayout immediately to avoid violating the rule that needsLayout() 3019 // Relayout immediately to avoid violating the rule that needsLayout()
3039 // isn't set at the end of a layout. 3020 // isn't set at the end of a layout.
3040 if (view->needsLayout()) 3021 if (view->needsLayout())
3041 view->layout(); 3022 view->layout();
3042 } 3023 }
3043 3024
3044 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportArguments& arguments) 3025 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportArguments& arguments)
3045 { 3026 {
3046 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled() || !page() || !m_size.width || !m_size.height) 3027 if (!settings()->viewportEnabled() || !page() || !m_size.width || !m_size.he ight)
3047 return; 3028 return;
3048 3029
3049 m_pageScaleConstraintsSet.updatePageDefinedConstraints(arguments, m_size, pa ge()->settings()->layoutFallbackWidth()); 3030 m_pageScaleConstraintsSet.updatePageDefinedConstraints(arguments, m_size, pa ge()->settings()->layoutFallbackWidth());
3050 3031
3051 if (settingsImpl()->supportDeprecatedTargetDensityDPI()) 3032 if (settingsImpl()->supportDeprecatedTargetDensityDPI())
3052 m_pageScaleConstraintsSet.adjustPageDefinedConstraintsForAndroidWebView( arguments, m_size, page()->settings()->layoutFallbackWidth(), deviceScaleFactor( ), page()->settings()->useWideViewport(), page()->settings()->loadWithOverviewMo de()); 3033 m_pageScaleConstraintsSet.adjustPageDefinedConstraintsForAndroidWebView( arguments, m_size, page()->settings()->layoutFallbackWidth(), deviceScaleFactor( ), page()->settings()->useWideViewport(), page()->settings()->loadWithOverviewMo de());
3053 3034
3054 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon straints().layoutSize); 3035 if (!m_pageScaleConstraintsSet.pageDefinedConstraints().layoutSize.isEmpty() ) {
3036 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefine dConstraints().layoutSize);
3055 3037
3056 if (page()->settings() && page()->settings()->textAutosizingEnabled() && pag e()->mainFrame() 3038 if (page()->settings() && page()->settings()->textAutosizingEnabled() && page()->mainFrame()
3057 && layoutSize.width != fixedLayoutSize().width) 3039 && layoutSize.width != fixedLayoutSize().width)
3058 page()->mainFrame()->document()->textAutosizer()->recalculateMultipl iers(); 3040 page()->mainFrame()->document()->textAutosizer()->recalculateMul tipliers();
3059 3041
3060 setFixedLayoutSize(layoutSize); 3042 setFixedLayoutSize(layoutSize);
3043 }
3061 } 3044 }
3062 3045
3063 IntSize WebViewImpl::contentsSize() const 3046 IntSize WebViewImpl::contentsSize() const
3064 { 3047 {
3065 RenderView* root = page()->mainFrame()->contentRenderer(); 3048 RenderView* root = page()->mainFrame()->contentRenderer();
3066 if (!root) 3049 if (!root)
3067 return IntSize(); 3050 return IntSize();
3068 return root->documentRect().size(); 3051 return root->documentRect().size();
3069 } 3052 }
3070 3053
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3130 3113
3131 WebSize WebViewImpl::fixedLayoutSize() const 3114 WebSize WebViewImpl::fixedLayoutSize() const
3132 { 3115 {
3133 if (!page()) 3116 if (!page())
3134 return WebSize(); 3117 return WebSize();
3135 3118
3136 Frame* frame = page()->mainFrame(); 3119 Frame* frame = page()->mainFrame();
3137 if (!frame || !frame->view()) 3120 if (!frame || !frame->view())
3138 return WebSize(); 3121 return WebSize();
3139 3122
3140 return frame->view()->fixedLayoutSize(); 3123 return frame->view()->layoutSize();
3141 } 3124 }
3142 3125
3143 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize) 3126 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize)
3144 { 3127 {
3145 if (!page()) 3128 if (!page())
3146 return; 3129 return;
3147 3130
3148 Frame* frame = page()->mainFrame(); 3131 Frame* frame = page()->mainFrame();
3149 if (!frame || !frame->view()) 3132 if (!frame || !frame->view())
3150 return; 3133 return;
3151 3134
3152 frame->view()->setFixedLayoutSize(layoutSize); 3135 frame->view()->setLayoutSize(layoutSize);
3153 } 3136 }
3154 3137
3155 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action, 3138 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action,
3156 const WebPoint& location) 3139 const WebPoint& location)
3157 { 3140 {
3158 HitTestResult result = hitTestResultForWindowPos(location); 3141 HitTestResult result = hitTestResultForWindowPos(location);
3159 RefPtr<Node> node = result.innerNonSharedNode(); 3142 RefPtr<Node> node = result.innerNonSharedNode();
3160 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag )) 3143 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag ))
3161 return; 3144 return;
3162 3145
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
4149 eventType); 4132 eventType);
4150 } 4133 }
4151 4134
4152 bool WebViewImpl::shouldDisableDesktopWorkarounds() 4135 bool WebViewImpl::shouldDisableDesktopWorkarounds()
4153 { 4136 {
4154 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); 4137 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments();
4155 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom 4138 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom
4156 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); 4139 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto);
4157 } 4140 }
4158 4141
4142 bool WebViewImpl::useDesktopStyleLayoutResizing()
4143 {
4144 if (!page())
4145 return true;
4146
4147 return !page()->settings()->layoutFallbackWidth();
4148 }
4149
4159 } // namespace WebKit 4150 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698