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 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2907 { | 2907 { |
2908 return m_pageScaleConstraintsSet.finalConstraints().clampToConstraints(scale
Factor); | 2908 return m_pageScaleConstraintsSet.finalConstraints().clampToConstraints(scale
Factor); |
2909 } | 2909 } |
2910 | 2910 |
2911 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) | 2911 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) |
2912 { | 2912 { |
2913 FrameView* view = mainFrameImpl()->frameView(); | 2913 FrameView* view = mainFrameImpl()->frameView(); |
2914 if (!view) | 2914 if (!view) |
2915 return offset; | 2915 return offset; |
2916 | 2916 |
2917 return view->clampOffsetAtScale(offset, scale); | 2917 if (!pinchVirtualViewportEnabled()) |
| 2918 return view->clampOffsetAtScale(offset, scale); |
| 2919 |
| 2920 return page()->frameHost().pinchViewport().clampDocumentOffsetAtScale(offset
, scale); |
2918 } | 2921 } |
2919 | 2922 |
2920 bool WebViewImpl::pinchVirtualViewportEnabled() const | 2923 bool WebViewImpl::pinchVirtualViewportEnabled() const |
2921 { | 2924 { |
2922 ASSERT(page()); | 2925 ASSERT(page()); |
2923 return page()->settings().pinchVirtualViewportEnabled(); | 2926 return page()->settings().pinchVirtualViewportEnabled(); |
2924 } | 2927 } |
2925 | 2928 |
2926 void WebViewImpl::setPinchViewportOffset(const WebFloatPoint& offset) | 2929 void WebViewImpl::setPinchViewportOffset(const WebFloatPoint& offset) |
2927 { | 2930 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 // Order is important: pinch viewport location is clamped based on | 2969 // Order is important: pinch viewport location is clamped based on |
2967 // main frame scroll position and pinch viewport scale. | 2970 // main frame scroll position and pinch viewport scale. |
2968 | 2971 |
2969 view->setScrollOffset(mainFrameOrigin); | 2972 view->setScrollOffset(mainFrameOrigin); |
2970 | 2973 |
2971 setPageScaleFactor(scaleFactor); | 2974 setPageScaleFactor(scaleFactor); |
2972 | 2975 |
2973 page()->frameHost().pinchViewport().setLocation(pinchViewportOrigin); | 2976 page()->frameHost().pinchViewport().setLocation(pinchViewportOrigin); |
2974 } | 2977 } |
2975 | 2978 |
| 2979 void WebViewImpl::setPageScaleFactorAndLocation(float scaleFactor, const FloatPo
int& location) |
| 2980 { |
| 2981 ASSERT(pinchVirtualViewportEnabled()); |
| 2982 ASSERT(page()); |
| 2983 |
| 2984 page()->frameHost().pinchViewport().setScaleAndLocation( |
| 2985 clampPageScaleFactorToLimits(scaleFactor), |
| 2986 location); |
| 2987 deviceOrPageScaleFactorChanged(); |
| 2988 } |
| 2989 |
2976 void WebViewImpl::setPageScaleFactor(float scaleFactor) | 2990 void WebViewImpl::setPageScaleFactor(float scaleFactor) |
2977 { | 2991 { |
2978 ASSERT(page()); | 2992 ASSERT(page()); |
2979 | 2993 |
2980 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); | 2994 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); |
2981 if (scaleFactor == pageScaleFactor()) | 2995 if (scaleFactor == pageScaleFactor()) |
2982 return; | 2996 return; |
2983 | 2997 |
2984 // TODO(bokan): Old-style pinch path. Remove when we're migrated to | 2998 // FIXME(bokan): Old-style pinch path. Remove when we're migrated to |
2985 // virtual viewport pinch. | 2999 // virtual viewport pinch. |
2986 if (!pinchVirtualViewportEnabled()) { | 3000 if (!pinchVirtualViewportEnabled()) { |
2987 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->sc
rollOffset().height); | 3001 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->sc
rollOffset().height); |
2988 setPageScaleFactor(scaleFactor, scrollOffset); | 3002 setPageScaleFactor(scaleFactor, scrollOffset); |
2989 return; | 3003 return; |
2990 } | 3004 } |
2991 | 3005 |
2992 page()->frameHost().pinchViewport().setScale(scaleFactor); | 3006 page()->frameHost().pinchViewport().setScale(scaleFactor); |
2993 deviceOrPageScaleFactorChanged(); | 3007 deviceOrPageScaleFactorChanged(); |
2994 } | 3008 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 return m_pageScaleConstraintsSet.finalConstraints().minimumScale; | 3264 return m_pageScaleConstraintsSet.finalConstraints().minimumScale; |
3251 } | 3265 } |
3252 | 3266 |
3253 float WebViewImpl::maximumPageScaleFactor() const | 3267 float WebViewImpl::maximumPageScaleFactor() const |
3254 { | 3268 { |
3255 return m_pageScaleConstraintsSet.finalConstraints().maximumScale; | 3269 return m_pageScaleConstraintsSet.finalConstraints().maximumScale; |
3256 } | 3270 } |
3257 | 3271 |
3258 void WebViewImpl::resetScrollAndScaleState() | 3272 void WebViewImpl::resetScrollAndScaleState() |
3259 { | 3273 { |
3260 // TODO: This is done by the pinchViewport().reset() call below and can be r
emoved when | 3274 // FIXME(bokan): This is done by the pinchViewport().reset() call below and |
3261 // the new pinch path is the only one. | 3275 // can be removed when the new pinch path is the only one. |
3262 setPageScaleFactor(1); | 3276 setPageScaleFactor(1); |
3263 updateMainFrameScrollPosition(IntPoint(), true); | 3277 updateMainFrameScrollPosition(IntPoint(), true); |
3264 page()->frameHost().pinchViewport().reset(); | 3278 page()->frameHost().pinchViewport().reset(); |
3265 | 3279 |
3266 if (!page()->mainFrame()->isLocalFrame()) | 3280 if (!page()->mainFrame()->isLocalFrame()) |
3267 return; | 3281 return; |
3268 | 3282 |
3269 // Clear out the values for the current history item. This will prevent the
history item from clobbering the | 3283 // Clear out the values for the current history item. This will prevent the
history item from clobbering the |
3270 // value determined during page scale initialization, which may be less than
1. | 3284 // value determined during page scale initialization, which may be less than
1. |
3271 page()->deprecatedLocalMainFrame()->loader().clearScrollPositionAndViewState
(); | 3285 page()->deprecatedLocalMainFrame()->loader().clearScrollPositionAndViewState
(); |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4186 | 4200 |
4187 if (frameView->scrollPosition() == scrollPosition) | 4201 if (frameView->scrollPosition() == scrollPosition) |
4188 return; | 4202 return; |
4189 | 4203 |
4190 bool oldProgrammaticScroll = frameView->inProgrammaticScroll(); | 4204 bool oldProgrammaticScroll = frameView->inProgrammaticScroll(); |
4191 frameView->setInProgrammaticScroll(programmaticScroll); | 4205 frameView->setInProgrammaticScroll(programmaticScroll); |
4192 frameView->notifyScrollPositionChanged(scrollPosition); | 4206 frameView->notifyScrollPositionChanged(scrollPosition); |
4193 frameView->setInProgrammaticScroll(oldProgrammaticScroll); | 4207 frameView->setInProgrammaticScroll(oldProgrammaticScroll); |
4194 } | 4208 } |
4195 | 4209 |
| 4210 void WebViewImpl::applyViewportDeltas( |
| 4211 const WebSize& pinchViewportDelta, |
| 4212 const WebSize& mainFrameDelta, |
| 4213 float pageScaleDelta, |
| 4214 float topControlsDelta) |
| 4215 { |
| 4216 ASSERT(pinchVirtualViewportEnabled()); |
| 4217 |
| 4218 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
| 4219 return; |
| 4220 |
| 4221 setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta); |
| 4222 |
| 4223 FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visible
Rect().location(); |
| 4224 pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height
); |
| 4225 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, pinchViewp
ortOffset); |
| 4226 |
| 4227 if (pageScaleDelta != 1) |
| 4228 m_doubleTapZoomPending = false; |
| 4229 |
| 4230 IntPoint mainFrameScrollOffset = IntPoint(mainFrame()->scrollOffset()); |
| 4231 mainFrameScrollOffset.move(mainFrameDelta.width, mainFrameDelta.height); |
| 4232 updateMainFrameScrollPosition(mainFrameScrollOffset, false); |
| 4233 } |
| 4234 |
4196 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal
eDelta, float topControlsDelta) | 4235 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal
eDelta, float topControlsDelta) |
4197 { | 4236 { |
4198 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4237 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4199 return; | 4238 return; |
4200 | 4239 |
4201 setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta); | 4240 setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta); |
4202 | 4241 |
4203 if (pinchVirtualViewportEnabled()) { | |
4204 if (pageScaleDelta != 1) { | |
4205 // When the virtual viewport is enabled, offsets are already set for
us. | |
4206 setPageScaleFactor(pageScaleFactor() * pageScaleDelta); | |
4207 m_doubleTapZoomPending = false; | |
4208 } | |
4209 | |
4210 return; | |
4211 } | |
4212 | |
4213 // TODO(bokan): Old pinch path only - virtual viewport pinch scrolls are aut
omatically updated via GraphicsLayer::DidScroll. | |
4214 // this should be removed once old pinch is removed. | |
4215 if (pageScaleDelta == 1) { | 4242 if (pageScaleDelta == 1) { |
4216 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB
y", "x", scrollDelta.width, "y", scrollDelta.height); | 4243 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB
y", "x", scrollDelta.width, "y", scrollDelta.height); |
4217 WebSize webScrollOffset = mainFrame()->scrollOffset(); | 4244 WebSize webScrollOffset = mainFrame()->scrollOffset(); |
4218 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro
llOffset.height + scrollDelta.height); | 4245 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro
llOffset.height + scrollDelta.height); |
4219 updateMainFrameScrollPosition(scrollOffset, false); | 4246 updateMainFrameScrollPosition(scrollOffset, false); |
4220 } else { | 4247 } else { |
4221 // The page scale changed, so apply a scale and scroll in a single | 4248 // The page scale changed, so apply a scale and scroll in a single |
4222 // operation. | 4249 // operation. |
4223 WebSize scrollOffset = mainFrame()->scrollOffset(); | 4250 WebSize scrollOffset = mainFrame()->scrollOffset(); |
4224 scrollOffset.width += scrollDelta.width; | 4251 scrollOffset.width += scrollDelta.width; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4373 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4400 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4374 | 4401 |
4375 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4402 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4376 return false; | 4403 return false; |
4377 | 4404 |
4378 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4405 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4379 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4406 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4380 } | 4407 } |
4381 | 4408 |
4382 } // namespace blink | 4409 } // namespace blink |
OLD | NEW |