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

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: git rebase Created 7 years, 2 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 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 1711
1712 m_size = newSize; 1712 m_size = newSize;
1713 1713
1714 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth && newSize.width != oldSize.width; 1714 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth && newSize.width != oldSize.width;
1715 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); 1715 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
1716 if (shouldAnchorAndRescaleViewport) { 1716 if (shouldAnchorAndRescaleViewport) {
1717 viewportAnchor.setAnchor(view->visibleContentRect(), 1717 viewportAnchor.setAnchor(view->visibleContentRect(),
1718 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord)); 1718 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord));
1719 } 1719 }
1720 1720
1721 // Set the fixed layout size from the viewport constraints before resizing. 1721 updateMainFrameLayoutSize();
aelias_OOO_until_Jul13 2013/10/01 05:09:30 Please call: updatePageDefinedViewportConstraints
bokan 2013/10/02 17:44:01 Done.
1722 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments());
1723 1722
1724 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); 1723 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
1725 if (agentPrivate) 1724 if (agentPrivate)
1726 agentPrivate->webViewResized(newSize); 1725 agentPrivate->webViewResized(newSize);
1727 if (!agentPrivate || !agentPrivate->metricsOverridden()) { 1726 if (!agentPrivate || !agentPrivate->metricsOverridden()) {
1728 WebFrameImpl* webFrame = mainFrameImpl(); 1727 WebFrameImpl* webFrame = mainFrameImpl();
1729 if (webFrame->frameView()) { 1728 if (webFrame->frameView()) {
1730 webFrame->frameView()->resize(m_size); 1729 webFrame->frameView()->resize(m_size);
1731 if (m_pinchViewports) 1730 if (m_pinchViewports)
1732 m_pinchViewports->setViewportSize(m_size); 1731 m_pinchViewports->setViewportSize(m_size);
1733 } 1732 }
1734 } 1733 }
1735 1734
1736 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { 1735 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) {
1737 // Relayout immediately to recalculate the minimum scale limit. 1736 // Relayout immediately to recalculate the minimum scale limit.
1738 if (view->needsLayout()) 1737 if (view->needsLayout())
1739 view->layout(); 1738 view->layout();
aelias_OOO_until_Jul13 2013/10/01 05:09:30 Could you delete this layout call? It should no l
bokan 2013/10/02 17:44:01 Why is that so? None of the calls I added above wi
1740 1739
1741 if (shouldAnchorAndRescaleViewport) { 1740 if (shouldAnchorAndRescaleViewport) {
1742 float viewportWidthRatio = static_cast<float>(newSize.width) / oldSi ze.width; 1741 float viewportWidthRatio = static_cast<float>(newSize.width) / oldSi ze.width;
1743 float contentsWidthRatio = static_cast<float>(contentsSize().width() ) / oldContentsWidth; 1742 float contentsWidthRatio = static_cast<float>(contentsSize().width() ) / oldContentsWidth;
1744 float scaleMultiplier = viewportWidthRatio / contentsWidthRatio; 1743 float scaleMultiplier = viewportWidthRatio / contentsWidthRatio;
1745 1744
1746 IntSize viewportSize = view->visibleContentRect().size(); 1745 IntSize viewportSize = view->visibleContentRect().size();
1747 if (scaleMultiplier != 1) { 1746 if (scaleMultiplier != 1) {
1748 float newPageScaleFactor = oldPageScaleFactor * scaleMultiplier; 1747 float newPageScaleFactor = oldPageScaleFactor * scaleMultiplier;
1749 viewportSize.scale(pageScaleFactor() / newPageScaleFactor); 1748 viewportSize.scale(pageScaleFactor() / newPageScaleFactor);
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2920 { 2919 {
2921 if (!page()) 2920 if (!page())
2922 return; 2921 return;
2923 2922
2924 page()->setDeviceScaleFactor(scaleFactor); 2923 page()->setDeviceScaleFactor(scaleFactor);
2925 2924
2926 if (m_layerTreeView) 2925 if (m_layerTreeView)
2927 m_layerTreeView->setDeviceScaleFactor(scaleFactor); 2926 m_layerTreeView->setDeviceScaleFactor(scaleFactor);
2928 } 2927 }
2929 2928
2930 bool WebViewImpl::isFixedLayoutModeEnabled() const
2931 {
2932 if (!page())
2933 return false;
2934
2935 Frame* frame = page()->mainFrame();
2936 if (!frame || !frame->view())
2937 return false;
2938
2939 return frame->view()->useFixedLayout();
2940 }
2941
2942 void WebViewImpl::enableFixedLayoutMode(bool enable)
2943 {
2944 if (!page())
2945 return;
2946
2947 Frame* frame = page()->mainFrame();
2948 if (!frame || !frame->view())
2949 return;
2950
2951 frame->view()->setUseFixedLayout(enable);
2952
2953 if (m_isAcceleratedCompositingActive)
2954 updateLayerTreeViewport();
2955 }
2956
2957
2958 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize) 2929 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma xSize)
2959 { 2930 {
2960 m_shouldAutoResize = true; 2931 m_shouldAutoResize = true;
2961 m_minAutoSize = minSize; 2932 m_minAutoSize = minSize;
2962 m_maxAutoSize = maxSize; 2933 m_maxAutoSize = maxSize;
2963 configureAutoResizeMode(); 2934 configureAutoResizeMode();
2964 } 2935 }
2965 2936
2966 void WebViewImpl::disableAutoResizeMode() 2937 void WebViewImpl::disableAutoResizeMode()
2967 { 2938 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 } 2985 }
3015 setUserAgentPageScaleConstraints(constraints); 2986 setUserAgentPageScaleConstraints(constraints);
3016 } 2987 }
3017 2988
3018 void WebViewImpl::refreshPageScaleFactorAfterLayout() 2989 void WebViewImpl::refreshPageScaleFactorAfterLayout()
3019 { 2990 {
3020 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()- >view()) 2991 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()- >view())
3021 return; 2992 return;
3022 FrameView* view = page()->mainFrame()->view(); 2993 FrameView* view = page()->mainFrame()->view();
3023 2994
3024 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()-> viewportArguments()); 2995 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document()->v iewportArguments());
3025 m_pageScaleConstraintsSet.computeFinalConstraints(); 2996 m_pageScaleConstraintsSet.computeFinalConstraints();
3026 2997
3027 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { 2998 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) {
3028 int verticalScrollbarWidth = 0; 2999 int verticalScrollbarWidth = 0;
3029 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc rollbar()) 3000 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc rollbar())
3030 verticalScrollbarWidth = view->verticalScrollbar()->width(); 3001 verticalScrollbarWidth = view->verticalScrollbar()->width();
3031 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c ontentsSize(), verticalScrollbarWidth); 3002 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c ontentsSize(), verticalScrollbarWidth);
3032 } 3003 }
3033 3004
3034 float newPageScaleFactor = pageScaleFactor(); 3005 float newPageScaleFactor = pageScaleFactor();
3035 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina lConstraints().initialScale != -1) { 3006 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina lConstraints().initialScale != -1) {
3036 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia lScale; 3007 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia lScale;
3037 m_pageScaleConstraintsSet.setNeedsReset(false); 3008 m_pageScaleConstraintsSet.setNeedsReset(false);
3038 } 3009 }
3039 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor); 3010 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor);
3040 3011
3041 updateLayerTreeViewport(); 3012 updateLayerTreeViewport();
3042 3013
3043 // Relayout immediately to avoid violating the rule that needsLayout() 3014 // Relayout immediately to avoid violating the rule that needsLayout()
3044 // isn't set at the end of a layout. 3015 // isn't set at the end of a layout.
3045 if (view->needsLayout()) 3016 if (view->needsLayout())
3046 view->layout(); 3017 view->layout();
3047 } 3018 }
3048 3019
3049 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportArguments& arguments) 3020 void WebViewImpl::updatePageDefinedViewportConstraints(const ViewportArguments& arguments)
3050 { 3021 {
3051 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled() || !page() || !m_size.width || !m_size.height) 3022 if (!settings()->viewportEnabled() || !page() || !m_size.width || !m_size.he ight)
3052 return; 3023 return;
3053 3024
3054 ViewportArguments adjustedArguments = arguments; 3025 ViewportArguments adjustedArguments = arguments;
3055 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedArguments.type == ViewportArguments::ViewportMeta) { 3026 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedArguments.type == ViewportArguments::ViewportMeta) {
3056 if (adjustedArguments.maxWidth.type() == ExtendToZoom) 3027 if (adjustedArguments.maxWidth.type() == ExtendToZoom)
3057 adjustedArguments.maxWidth = Length(); // auto 3028 adjustedArguments.maxWidth = Length(); // auto
3058 adjustedArguments.minWidth = adjustedArguments.maxWidth; 3029 adjustedArguments.minWidth = adjustedArguments.maxWidth;
3059 adjustedArguments.minHeight = adjustedArguments.maxHeight; 3030 adjustedArguments.minHeight = adjustedArguments.maxHeight;
3060 } 3031 }
3061 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedArguments, m_ size); 3032 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedArguments, m_ size);
3062 m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedArguments, m _size, page()->settings().layoutFallbackWidth(), deviceScaleFactor(), settingsIm pl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuirkE nabled(), page()->settings().useWideViewport(), page()->settings().loadWithOverv iewMode()); 3033 m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedArguments, m _size, page()->settings().layoutFallbackWidth(), deviceScaleFactor(), settingsIm pl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuirkE nabled(), page()->settings().useWideViewport(), page()->settings().loadWithOverv iewMode());
3063 3034
3064 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon straints().layoutSize); 3035 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon straints().layoutSize);
3065 3036
3066 if (page()->settings().textAutosizingEnabled() && page()->mainFrame() && lay outSize.width != fixedLayoutSize().width) 3037 if (page()->settings().textAutosizingEnabled() && page()->mainFrame() && lay outSize.width != page()->mainFrame()->view()->layoutSize().width())
3067 page()->mainFrame()->document()->textAutosizer()->recalculateMultipliers (); 3038 page()->mainFrame()->document()->textAutosizer()->recalculateMultipliers ();
aelias_OOO_until_Jul13 2013/10/01 05:09:30 Please move this line into updateMainFrameLayoutSi
bokan 2013/10/02 17:44:01 Done.
3068 3039
3069 if (page()->mainFrame() && page()->mainFrame()->view() && !m_fixedLayoutSize Lock) 3040 if (page()->mainFrame() && page()->mainFrame()->view() && !m_fixedLayoutSize Lock)
3070 page()->mainFrame()->view()->setFixedLayoutSize(layoutSize); 3041 page()->mainFrame()->view()->setLayoutSize(layoutSize);
aelias_OOO_until_Jul13 2013/10/01 05:09:30 Just call updateMainFrameLayoutSize from here inst
bokan 2013/10/02 17:44:01 Done.
3042 }
3043
3044 void WebViewImpl::updateMainFrameLayoutSize()
3045 {
3046 FrameView* view = mainFrameImpl()->frameView();
3047 if (!view)
3048 return;
3049
3050 if (!settings()->viewportEnabled() && !m_fixedLayoutSizeLock)
3051 view->setLayoutSize(m_size);
3052 else
3053 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document( )->viewportArguments());
aelias_OOO_until_Jul13 2013/10/01 05:09:30 I don't like going into complex viewport tag proce
bokan 2013/10/02 17:44:01 Done.
3071 } 3054 }
3072 3055
3073 IntSize WebViewImpl::contentsSize() const 3056 IntSize WebViewImpl::contentsSize() const
3074 { 3057 {
3075 RenderView* root = page()->mainFrame()->contentRenderer(); 3058 RenderView* root = page()->mainFrame()->contentRenderer();
3076 if (!root) 3059 if (!root)
3077 return IntSize(); 3060 return IntSize();
3078 return root->documentRect().size(); 3061 return root->documentRect().size();
3079 } 3062 }
3080 3063
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState(); 3114 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
3132 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState(); 3115 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState();
3133 m_pageScaleConstraintsSet.setNeedsReset(true); 3116 m_pageScaleConstraintsSet.setNeedsReset(true);
3134 3117
3135 // Clobber saved scales and scroll offsets. 3118 // Clobber saved scales and scroll offsets.
3136 if (FrameView* view = page()->mainFrame()->document()->view()) 3119 if (FrameView* view = page()->mainFrame()->document()->view())
3137 view->cacheCurrentScrollPosition(); 3120 view->cacheCurrentScrollPosition();
3138 resetSavedScrollAndScaleState(); 3121 resetSavedScrollAndScaleState();
3139 } 3122 }
3140 3123
3141 WebSize WebViewImpl::fixedLayoutSize() const
3142 {
3143 if (!page())
3144 return WebSize();
3145
3146 Frame* frame = page()->mainFrame();
3147 if (!frame || !frame->view())
3148 return WebSize();
3149
3150 return frame->view()->fixedLayoutSize();
3151 }
3152
3153 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize) 3124 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize)
3154 { 3125 {
3155 if (!page()) 3126 if (!page())
3156 return; 3127 return;
3157 3128
3158 Frame* frame = page()->mainFrame(); 3129 Frame* frame = page()->mainFrame();
3159 if (!frame) 3130 if (!frame)
3160 return; 3131 return;
3161 3132
3162 FrameView* view = frame->view(); 3133 FrameView* view = frame->view();
3163 if (!view) 3134 if (!view)
3164 return; 3135 return;
3165 3136
3166 m_fixedLayoutSizeLock = layoutSize.width || layoutSize.height; 3137 m_fixedLayoutSizeLock = layoutSize.width || layoutSize.height;
3167 3138
3168 if (m_fixedLayoutSizeLock) 3139 if (m_fixedLayoutSizeLock)
3169 view->setFixedLayoutSize(layoutSize); 3140 view->setLayoutSize(layoutSize);
3170 else 3141 else
3171 view->setFixedLayoutSize(flooredIntSize(m_pageScaleConstraintsSet.pageDe finedConstraints().layoutSize)); 3142 updateMainFrameLayoutSize();
3172 } 3143 }
3173 3144
3174 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action, 3145 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action,
3175 const WebPoint& location) 3146 const WebPoint& location)
3176 { 3147 {
3177 HitTestResult result = hitTestResultForWindowPos(location); 3148 HitTestResult result = hitTestResultForWindowPos(location);
3178 RefPtr<Node> node = result.innerNonSharedNode(); 3149 RefPtr<Node> node = result.innerNonSharedNode();
3179 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag )) 3150 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag ))
3180 return; 3151 return;
3181 3152
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 const WebMouseEvent& mouseEvent = static_cast<const WebMouseEvent&>(event); 4152 const WebMouseEvent& mouseEvent = static_cast<const WebMouseEvent&>(event);
4182 4153
4183 if (page()) 4154 if (page())
4184 page()->pointerLockController().dispatchLockedMouseEvent( 4155 page()->pointerLockController().dispatchLockedMouseEvent(
4185 PlatformMouseEventBuilder(mainFrameImpl()->frameView(), mouseEvent), 4156 PlatformMouseEventBuilder(mainFrameImpl()->frameView(), mouseEvent),
4186 eventType); 4157 eventType);
4187 } 4158 }
4188 4159
4189 bool WebViewImpl::shouldDisableDesktopWorkarounds() 4160 bool WebViewImpl::shouldDisableDesktopWorkarounds()
4190 { 4161 {
4191 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled()) 4162 if (!settings()->viewportEnabled())
4192 return false; 4163 return false;
4193 4164
4194 // A document is considered adapted to small screen UAs if one of these hold s: 4165 // A document is considered adapted to small screen UAs if one of these hold s:
4195 // 1. The author specified viewport has a constrained width that is equal to 4166 // 1. The author specified viewport has a constrained width that is equal to
4196 // the initial viewport width. 4167 // the initial viewport width.
4197 // 2. The author has disabled viewport zoom. 4168 // 2. The author has disabled viewport zoom.
4198 4169
4199 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints(); 4170 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi nedConstraints();
4200 4171
4201 return fixedLayoutSize().width == m_size.width 4172 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4173 return false;
4174
4175 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4202 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4176 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4203 } 4177 }
4204 4178
4205 } // namespace WebKit 4179 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698