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 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 | 1708 |
1709 m_size = newSize; | 1709 m_size = newSize; |
1710 | 1710 |
1711 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi
ze.width && oldContentsWidth && newSize.width != oldSize.width; | 1711 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi
ze.width && oldContentsWidth && newSize.width != oldSize.width; |
1712 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); | 1712 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); |
1713 if (shouldAnchorAndRescaleViewport) { | 1713 if (shouldAnchorAndRescaleViewport) { |
1714 viewportAnchor.setAnchor(view->visibleContentRect(), | 1714 viewportAnchor.setAnchor(view->visibleContentRect(), |
1715 FloatSize(viewportAnchorXCoord, viewportAnchorY
Coord)); | 1715 FloatSize(viewportAnchorXCoord, viewportAnchorY
Coord)); |
1716 } | 1716 } |
1717 | 1717 |
1718 // Set the fixed layout size from the viewport constraints before resizing. | 1718 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document()->v
iewportDescription()); |
1719 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()->
viewportDescription()); | 1719 updateMainFrameLayoutSize(); |
1720 | 1720 |
1721 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); | 1721 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); |
1722 if (agentPrivate) | 1722 if (agentPrivate) |
1723 agentPrivate->webViewResized(newSize); | 1723 agentPrivate->webViewResized(newSize); |
1724 if (!agentPrivate || !agentPrivate->metricsOverridden()) { | 1724 if (!agentPrivate || !agentPrivate->metricsOverridden()) { |
1725 WebFrameImpl* webFrame = mainFrameImpl(); | 1725 WebFrameImpl* webFrame = mainFrameImpl(); |
1726 if (webFrame->frameView()) { | 1726 if (webFrame->frameView()) { |
1727 webFrame->frameView()->resize(m_size); | 1727 webFrame->frameView()->resize(m_size); |
1728 if (m_pinchViewports) | 1728 if (m_pinchViewports) |
1729 m_pinchViewports->setViewportSize(m_size); | 1729 m_pinchViewports->setViewportSize(m_size); |
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2917 { | 2917 { |
2918 if (!page()) | 2918 if (!page()) |
2919 return; | 2919 return; |
2920 | 2920 |
2921 page()->setDeviceScaleFactor(scaleFactor); | 2921 page()->setDeviceScaleFactor(scaleFactor); |
2922 | 2922 |
2923 if (m_layerTreeView) | 2923 if (m_layerTreeView) |
2924 m_layerTreeView->setDeviceScaleFactor(scaleFactor); | 2924 m_layerTreeView->setDeviceScaleFactor(scaleFactor); |
2925 } | 2925 } |
2926 | 2926 |
2927 bool WebViewImpl::isFixedLayoutModeEnabled() const | |
2928 { | |
2929 if (!page()) | |
2930 return false; | |
2931 | |
2932 Frame* frame = page()->mainFrame(); | |
2933 if (!frame || !frame->view()) | |
2934 return false; | |
2935 | |
2936 return frame->view()->useFixedLayout(); | |
2937 } | |
2938 | |
2939 void WebViewImpl::enableFixedLayoutMode(bool enable) | |
2940 { | |
2941 if (!page()) | |
2942 return; | |
2943 | |
2944 Frame* frame = page()->mainFrame(); | |
2945 if (!frame || !frame->view()) | |
2946 return; | |
2947 | |
2948 frame->view()->setUseFixedLayout(enable); | |
2949 | |
2950 if (m_isAcceleratedCompositingActive) | |
2951 updateLayerTreeViewport(); | |
2952 } | |
2953 | |
2954 | |
2955 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma
xSize) | 2927 void WebViewImpl::enableAutoResizeMode(const WebSize& minSize, const WebSize& ma
xSize) |
2956 { | 2928 { |
2957 m_shouldAutoResize = true; | 2929 m_shouldAutoResize = true; |
2958 m_minAutoSize = minSize; | 2930 m_minAutoSize = minSize; |
2959 m_maxAutoSize = maxSize; | 2931 m_maxAutoSize = maxSize; |
2960 configureAutoResizeMode(); | 2932 configureAutoResizeMode(); |
2961 } | 2933 } |
2962 | 2934 |
2963 void WebViewImpl::disableAutoResizeMode() | 2935 void WebViewImpl::disableAutoResizeMode() |
2964 { | 2936 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3011 } | 2983 } |
3012 setUserAgentPageScaleConstraints(constraints); | 2984 setUserAgentPageScaleConstraints(constraints); |
3013 } | 2985 } |
3014 | 2986 |
3015 void WebViewImpl::refreshPageScaleFactorAfterLayout() | 2987 void WebViewImpl::refreshPageScaleFactorAfterLayout() |
3016 { | 2988 { |
3017 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()-
>view()) | 2989 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()-
>view()) |
3018 return; | 2990 return; |
3019 FrameView* view = page()->mainFrame()->view(); | 2991 FrameView* view = page()->mainFrame()->view(); |
3020 | 2992 |
3021 updatePageDefinedPageScaleConstraints(mainFrameImpl()->frame()->document()->
viewportDescription()); | 2993 updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document()->v
iewportDescription()); |
3022 m_pageScaleConstraintsSet.computeFinalConstraints(); | 2994 m_pageScaleConstraintsSet.computeFinalConstraints(); |
3023 | 2995 |
3024 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { | 2996 if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) { |
3025 int verticalScrollbarWidth = 0; | 2997 int verticalScrollbarWidth = 0; |
3026 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc
rollbar()) | 2998 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc
rollbar()) |
3027 verticalScrollbarWidth = view->verticalScrollbar()->width(); | 2999 verticalScrollbarWidth = view->verticalScrollbar()->width(); |
3028 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c
ontentsSize(), verticalScrollbarWidth); | 3000 m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, c
ontentsSize(), verticalScrollbarWidth); |
3029 } | 3001 } |
3030 | 3002 |
3031 float newPageScaleFactor = pageScaleFactor(); | 3003 float newPageScaleFactor = pageScaleFactor(); |
3032 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina
lConstraints().initialScale != -1) { | 3004 if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.fina
lConstraints().initialScale != -1) { |
3033 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia
lScale; | 3005 newPageScaleFactor = m_pageScaleConstraintsSet.finalConstraints().initia
lScale; |
3034 m_pageScaleConstraintsSet.setNeedsReset(false); | 3006 m_pageScaleConstraintsSet.setNeedsReset(false); |
3035 } | 3007 } |
3036 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor); | 3008 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor); |
3037 | 3009 |
3038 updateLayerTreeViewport(); | 3010 updateLayerTreeViewport(); |
3039 | 3011 |
3040 // Relayout immediately to avoid violating the rule that needsLayout() | 3012 // Relayout immediately to avoid violating the rule that needsLayout() |
3041 // isn't set at the end of a layout. | 3013 // isn't set at the end of a layout. |
3042 if (view->needsLayout()) | 3014 if (view->needsLayout()) |
3043 view->layout(); | 3015 view->layout(); |
3044 } | 3016 } |
3045 | 3017 |
3046 void WebViewImpl::updatePageDefinedPageScaleConstraints(const ViewportDescriptio
n& description) | 3018 void WebViewImpl::updatePageDefinedViewportConstraints(const ViewportDescription
& description) |
3047 { | 3019 { |
3048 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled() || !page()
|| !m_size.width || !m_size.height) | 3020 if (!settings()->viewportEnabled() || !page() || !m_size.width || !m_size.he
ight) |
3049 return; | 3021 return; |
3050 | 3022 |
3051 ViewportDescription adjustedDescription = description; | 3023 ViewportDescription adjustedDescription = description; |
3052 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedDescription.typ
e == ViewportDescription::ViewportMeta) { | 3024 if (settingsImpl()->viewportMetaLayoutSizeQuirk() && adjustedDescription.typ
e == ViewportDescription::ViewportMeta) { |
3053 if (adjustedDescription.maxWidth.type() == ExtendToZoom) | 3025 if (adjustedDescription.maxWidth.type() == ExtendToZoom) |
3054 adjustedDescription.maxWidth = Length(); // auto | 3026 adjustedDescription.maxWidth = Length(); // auto |
3055 adjustedDescription.minWidth = adjustedDescription.maxWidth; | 3027 adjustedDescription.minWidth = adjustedDescription.maxWidth; |
3056 adjustedDescription.minHeight = adjustedDescription.maxHeight; | 3028 adjustedDescription.minHeight = adjustedDescription.maxHeight; |
3057 } | 3029 } |
3058 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedDescription,
m_size); | 3030 m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedDescription,
m_size); |
3059 m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedDescription,
m_size, page()->settings().layoutFallbackWidth(), deviceScaleFactor(), settings
Impl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuir
kEnabled(), page()->settings().useWideViewport(), page()->settings().loadWithOve
rviewMode()); | 3031 m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedDescription,
m_size, page()->settings().layoutFallbackWidth(), deviceScaleFactor(), settings
Impl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuir
kEnabled(), page()->settings().useWideViewport(), page()->settings().loadWithOve
rviewMode()); |
3060 | 3032 |
3061 WebSize layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedCon
straints().layoutSize); | 3033 updateMainFrameLayoutSize(); |
| 3034 } |
3062 | 3035 |
3063 if (page()->settings().textAutosizingEnabled() && page()->mainFrame() && lay
outSize.width != fixedLayoutSize().width) | 3036 void WebViewImpl::updateMainFrameLayoutSize() |
3064 page()->mainFrame()->document()->textAutosizer()->recalculateMultipliers
(); | 3037 { |
| 3038 if (m_fixedLayoutSizeLock || !mainFrameImpl()) |
| 3039 return; |
3065 | 3040 |
3066 if (page()->mainFrame() && page()->mainFrame()->view() && !m_fixedLayoutSize
Lock) | 3041 FrameView* view = mainFrameImpl()->frameView(); |
3067 page()->mainFrame()->view()->setFixedLayoutSize(layoutSize); | 3042 if (!view) |
| 3043 return; |
| 3044 |
| 3045 WebSize layoutSize = m_size; |
| 3046 |
| 3047 if (settings()->viewportEnabled()) { |
| 3048 layoutSize = flooredIntSize(m_pageScaleConstraintsSet.pageDefinedConstra
ints().layoutSize); |
| 3049 |
| 3050 if (page()->settings().textAutosizingEnabled() && layoutSize.width != vi
ew->layoutSize().width()) |
| 3051 page()->mainFrame()->document()->textAutosizer()->recalculateMultipl
iers(); |
| 3052 } |
| 3053 |
| 3054 view->setLayoutSize(layoutSize); |
3068 } | 3055 } |
3069 | 3056 |
3070 IntSize WebViewImpl::contentsSize() const | 3057 IntSize WebViewImpl::contentsSize() const |
3071 { | 3058 { |
3072 RenderView* root = page()->mainFrame()->contentRenderer(); | 3059 RenderView* root = page()->mainFrame()->contentRenderer(); |
3073 if (!root) | 3060 if (!root) |
3074 return IntSize(); | 3061 return IntSize(); |
3075 return root->documentRect().size(); | 3062 return root->documentRect().size(); |
3076 } | 3063 } |
3077 | 3064 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState(); | 3115 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState(); |
3129 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState(); | 3116 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState(); |
3130 m_pageScaleConstraintsSet.setNeedsReset(true); | 3117 m_pageScaleConstraintsSet.setNeedsReset(true); |
3131 | 3118 |
3132 // Clobber saved scales and scroll offsets. | 3119 // Clobber saved scales and scroll offsets. |
3133 if (FrameView* view = page()->mainFrame()->document()->view()) | 3120 if (FrameView* view = page()->mainFrame()->document()->view()) |
3134 view->cacheCurrentScrollPosition(); | 3121 view->cacheCurrentScrollPosition(); |
3135 resetSavedScrollAndScaleState(); | 3122 resetSavedScrollAndScaleState(); |
3136 } | 3123 } |
3137 | 3124 |
3138 WebSize WebViewImpl::fixedLayoutSize() const | |
3139 { | |
3140 if (!page()) | |
3141 return WebSize(); | |
3142 | |
3143 Frame* frame = page()->mainFrame(); | |
3144 if (!frame || !frame->view()) | |
3145 return WebSize(); | |
3146 | |
3147 return frame->view()->fixedLayoutSize(); | |
3148 } | |
3149 | |
3150 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize) | 3125 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize) |
3151 { | 3126 { |
3152 if (!page()) | 3127 if (!page()) |
3153 return; | 3128 return; |
3154 | 3129 |
3155 Frame* frame = page()->mainFrame(); | 3130 Frame* frame = page()->mainFrame(); |
3156 if (!frame) | 3131 if (!frame) |
3157 return; | 3132 return; |
3158 | 3133 |
3159 FrameView* view = frame->view(); | 3134 FrameView* view = frame->view(); |
3160 if (!view) | 3135 if (!view) |
3161 return; | 3136 return; |
3162 | 3137 |
3163 m_fixedLayoutSizeLock = layoutSize.width || layoutSize.height; | 3138 m_fixedLayoutSizeLock = layoutSize.width || layoutSize.height; |
3164 | 3139 |
3165 if (m_fixedLayoutSizeLock) | 3140 if (m_fixedLayoutSizeLock) |
3166 view->setFixedLayoutSize(layoutSize); | 3141 view->setLayoutSize(layoutSize); |
3167 else | 3142 else |
3168 view->setFixedLayoutSize(flooredIntSize(m_pageScaleConstraintsSet.pageDe
finedConstraints().layoutSize)); | 3143 updateMainFrameLayoutSize(); |
3169 } | 3144 } |
3170 | 3145 |
3171 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action, | 3146 void WebViewImpl::performMediaPlayerAction(const WebMediaPlayerAction& action, |
3172 const WebPoint& location) | 3147 const WebPoint& location) |
3173 { | 3148 { |
3174 HitTestResult result = hitTestResultForWindowPos(location); | 3149 HitTestResult result = hitTestResultForWindowPos(location); |
3175 RefPtr<Node> node = result.innerNonSharedNode(); | 3150 RefPtr<Node> node = result.innerNonSharedNode(); |
3176 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag
)) | 3151 if (!isHTMLVideoElement(node.get()) && !node->hasTagName(HTMLNames::audioTag
)) |
3177 return; | 3152 return; |
3178 | 3153 |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4185 const WebMouseEvent& mouseEvent = static_cast<const WebMouseEvent&>(event); | 4160 const WebMouseEvent& mouseEvent = static_cast<const WebMouseEvent&>(event); |
4186 | 4161 |
4187 if (page()) | 4162 if (page()) |
4188 page()->pointerLockController().dispatchLockedMouseEvent( | 4163 page()->pointerLockController().dispatchLockedMouseEvent( |
4189 PlatformMouseEventBuilder(mainFrameImpl()->frameView(), mouseEvent), | 4164 PlatformMouseEventBuilder(mainFrameImpl()->frameView(), mouseEvent), |
4190 eventType); | 4165 eventType); |
4191 } | 4166 } |
4192 | 4167 |
4193 bool WebViewImpl::shouldDisableDesktopWorkarounds() | 4168 bool WebViewImpl::shouldDisableDesktopWorkarounds() |
4194 { | 4169 { |
4195 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled()) | 4170 if (!settings()->viewportEnabled()) |
4196 return false; | 4171 return false; |
4197 | 4172 |
4198 // A document is considered adapted to small screen UAs if one of these hold
s: | 4173 // A document is considered adapted to small screen UAs if one of these hold
s: |
4199 // 1. The author specified viewport has a constrained width that is equal to | 4174 // 1. The author specified viewport has a constrained width that is equal to |
4200 // the initial viewport width. | 4175 // the initial viewport width. |
4201 // 2. The author has disabled viewport zoom. | 4176 // 2. The author has disabled viewport zoom. |
4202 | 4177 |
4203 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4178 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4204 | 4179 |
4205 return fixedLayoutSize().width == m_size.width | 4180 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
| 4181 return false; |
| 4182 |
| 4183 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4206 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4184 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4207 } | 4185 } |
4208 | 4186 |
4209 } // namespace WebKit | 4187 } // namespace WebKit |
OLD | NEW |