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

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

Issue 23819019: Refactor fixed layout mode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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
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 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 1652
1653 m_size = newSize; 1653 m_size = newSize;
1654 1654
1655 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth && newSize.width != oldSize.width; 1655 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth && newSize.width != oldSize.width;
1656 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); 1656 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
1657 if (shouldAnchorAndRescaleViewport) { 1657 if (shouldAnchorAndRescaleViewport) {
1658 viewportAnchor.setAnchor(view->visibleContentRect(), 1658 viewportAnchor.setAnchor(view->visibleContentRect(),
1659 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord)); 1659 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord));
1660 } 1660 }
1661 1661
1662 // If we're on a desktop style platform, we want to keep the page's layout
1663 // size fixed to the size of the WebViewImpl. Desktop-style is indicated
1664 // by layoutFallbackWidth == 0
1665 if (page() && !page()->settings().layoutFallbackWidth())
kenneth.r.christiansen 2013/09/05 07:54:24 With the move to using @viewport rules internally,
1666 view->setLayoutSize(m_size);
1667
1662 // Set the fixed layout size from the viewport constraints before resizing. 1668 // Set the fixed layout size from the viewport constraints before resizing.
1663 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments()); 1669 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments());
1664 1670
1665 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); 1671 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
1666 if (agentPrivate) 1672 if (agentPrivate)
1667 agentPrivate->webViewResized(newSize); 1673 agentPrivate->webViewResized(newSize);
1668 if (!agentPrivate || !agentPrivate->metricsOverridden()) { 1674 if (!agentPrivate || !agentPrivate->metricsOverridden()) {
1669 WebFrameImpl* webFrame = mainFrameImpl(); 1675 WebFrameImpl* webFrame = mainFrameImpl();
1670 if (webFrame->frameView()) { 1676 if (webFrame->frameView()) {
1671 webFrame->frameView()->resize(m_size); 1677 webFrame->frameView()->resize(m_size);
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 { 2867 {
2862 if (!page()) 2868 if (!page())
2863 return; 2869 return;
2864 2870
2865 page()->setDeviceScaleFactor(scaleFactor); 2871 page()->setDeviceScaleFactor(scaleFactor);
2866 2872
2867 if (m_layerTreeView) 2873 if (m_layerTreeView)
2868 m_layerTreeView->setDeviceScaleFactor(scaleFactor); 2874 m_layerTreeView->setDeviceScaleFactor(scaleFactor);
2869 } 2875 }
2870 2876
2871 bool WebViewImpl::isFixedLayoutModeEnabled() const
2872 {
2873 if (!page())
2874 return false;
2875
2876 Frame* frame = page()->mainFrame();
2877 if (!frame || !frame->view())
2878 return false;
2879
2880 return frame->view()->useFixedLayout();
2881 }
2882
2883 void WebViewImpl::enableFixedLayoutMode(bool enable) 2877 void WebViewImpl::enableFixedLayoutMode(bool enable)
2884 { 2878 {
2885 if (!page()) 2879 if (!page())
2886 return; 2880 return;
2887 2881
2888 Frame* frame = page()->mainFrame(); 2882 Frame* frame = page()->mainFrame();
2889 if (!frame || !frame->view()) 2883 if (!frame || !frame->view())
2890 return; 2884 return;
2891 2885
2892 frame->view()->setUseFixedLayout(enable); 2886 page()->settings().setLayoutFallbackWidth(enable ? 980 : 0);
kenneth.r.christiansen 2013/09/05 08:03:07 Hmm... I hope noone are overriding it then. This i
bokan 2013/09/05 20:03:36 Yes, this is a hack to keep the tests working. I'l
2893 2887
2894 if (m_isAcceleratedCompositingActive) 2888 if (m_isAcceleratedCompositingActive)
2895 updateLayerTreeViewport(); 2889 updateLayerTreeViewport();
2896 } 2890 }
2897 2891
2898 2892
2899 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize) 2893 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize)
2900 { 2894 {
2901 m_shouldAutoResize = true; 2895 m_shouldAutoResize = true;
2902 m_minAutoSize = minSize; 2896 m_minAutoSize = minSize;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2982 updateLayerTreeViewport(); 2976 updateLayerTreeViewport();
2983 2977
2984 // Relayout immediately to avoid violating the rule that needsLayout() 2978 // Relayout immediately to avoid violating the rule that needsLayout()
2985 // isn't set at the end of a layout. 2979 // isn't set at the end of a layout.
2986 if (view->needsLayout()) 2980 if (view->needsLayout())
2987 view->layout(); 2981 view->layout();
2988 } 2982 }
2989 2983
2990 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportArguments& arguments) 2984 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportArguments& arguments)
2991 { 2985 {
2992 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled() || !page() || !m_size.width || !m_size.height) 2986 if (!settings()->viewportEnabled() || !page() || !m_size.width || !m_size.he ight)
2993 return; 2987 return;
2994 2988
2995 ViewportArguments adjustedArguments = arguments; 2989 ViewportArguments adjustedArguments = arguments;
2996 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedArguments.type == ViewportArguments::ViewportMeta) 2990 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedArguments.type == ViewportArguments::ViewportMeta)
2997 adjustedArguments.type = ViewportArguments::ViewportMetaLayoutSizeQuirk; 2991 adjustedArguments.type = ViewportArguments::ViewportMetaLayoutSizeQuirk;
2998 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedArguments, m_ size, page()->settings().layoutFallbackWidth()); 2992 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedArguments, m_ size, page()->settings().layoutFallbackWidth());
2999 2993
3000 if (settingsImpl()->supportDeprecatedTargetDensityDPI()) 2994 if (settingsImpl()->supportDeprecatedTargetDensityDPI())
3001 m_pageScaleConstraintsSet.adjustPageDefinedConstraintsForAndroidWebView( adjustedArguments, m_size, page()->settings().layoutFallbackWidth(), deviceScale Factor(), page()->settings().useWideViewport(), page()->settings().loadWithOverv iewMode()); 2995 m_pageScaleConstraintsSet.adjustPageDefinedConstraintsForAndroidWebView( adjustedArguments, m_size, page()->settings().layoutFallbackWidth(), deviceScale Factor(), page()->settings().useWideViewport(), page()->settings().loadWithOverv iewMode());
3002 2996
3003 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon straints().layoutSize); 2997 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon straints().layoutSize);
3004 2998
3005 if (page()->settings().textAutosizingEnabled() && page()->mainFrame() && lay outSize.width != fixedLayoutSize().width) 2999 if (page()->settings().textAutosizingEnabled() && page()->mainFrame() && lay outSize.width != page()->mainFrame()->view()->layoutSize().width())
3006 page()->mainFrame()->document()->textAutosizer()->recalculateMultipliers (); 3000 page()->mainFrame()->document()->textAutosizer()->recalculateMultipliers ();
3007 3001
3008 setFixedLayoutSize(layoutSize); 3002 setLayoutSize(layoutSize);
3009 } 3003 }
3010 3004
3011 IntSize WebViewImpl::contentsSize() const 3005 IntSize WebViewImpl::contentsSize() const
3012 { 3006 {
3013 RenderView* root = page()->mainFrame()->contentRenderer(); 3007 RenderView* root = page()->mainFrame()->contentRenderer();
3014 if (!root) 3008 if (!root)
3015 return IntSize(); 3009 return IntSize();
3016 return root->documentRect().size(); 3010 return root->documentRect().size();
3017 } 3011 }
3018 3012
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3069 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState(); 3063 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
3070 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState(); 3064 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState();
3071 m_pageScaleConstraintsSet.setNeedsReset(true); 3065 m_pageScaleConstraintsSet.setNeedsReset(true);
3072 3066
3073 // Clobber saved scales and scroll offsets. 3067 // Clobber saved scales and scroll offsets.
3074 if (FrameView* view = page()->mainFrame()->document()->view()) 3068 if (FrameView* view = page()->mainFrame()->document()->view())
3075 view->cacheCurrentScrollPosition(); 3069 view->cacheCurrentScrollPosition();
3076 resetSavedScrollAndScaleState(); 3070 resetSavedScrollAndScaleState();
3077 } 3071 }
3078 3072
3079 WebSize WebViewImpl::fixedLayoutSize() const
3080 {
3081 if (!page())
3082 return WebSize();
3083
3084 Frame* frame = page()->mainFrame();
3085 if (!frame || !frame->view())
3086 return WebSize();
3087
3088 return frame->view()->fixedLayoutSize();
3089 }
3090
3091 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize) 3073 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize)
3092 { 3074 {
3075 setLayoutSize(layoutSize);
3076 }
3077
3078 void WebViewImpl::setLayoutSize(const WebSize& layoutSize)
3079 {
3093 if (!page()) 3080 if (!page())
3094 return; 3081 return;
3095 3082
3096 Frame* frame = page()->mainFrame(); 3083 Frame* frame = page()->mainFrame();
3097 if (!frame || !frame->view()) 3084 if (!frame || !frame->view())
3098 return; 3085 return;
3099 3086
3100 frame->view()->setFixedLayoutSize(layoutSize); 3087 frame->view()->setLayoutSize(layoutSize);
3101 } 3088 }
3102 3089
3103 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action, 3090 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action,
3104 const WebPoint& location) 3091 const WebPoint& location)
3105 { 3092 {
3106 HitTestResult result = hitTestResultForWindowPos(location); 3093 HitTestResult result = hitTestResultForWindowPos(location);
3107 RefPtr<Node> node = result.innerNonSharedNode(); 3094 RefPtr<Node> node = result.innerNonSharedNode();
3108 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag )) 3095 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag ))
3109 return; 3096 return;
3110 3097
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
4105 } 4092 }
4106 4093
4107 bool WebViewImpl::shouldDisableDesktopWorkarounds() 4094 bool WebViewImpl::shouldDisableDesktopWorkarounds()
4108 { 4095 {
4109 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); 4096 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments();
4110 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom 4097 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom
4111 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); 4098 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto);
4112 } 4099 }
4113 4100
4114 } // namespace WebKit 4101 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698