Skip to content
Permalink
Browse files
[iOS][WK2] Improve the approximation of the scroll position of the dy…
…namic viewport size updates

https://bugs.webkit.org/show_bug.cgi?id=131720

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-04-16
Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _scrollToContentOffset:]):
The scrolling tree was forcing scroll at the wrong scale during the transition.

(-[WKWebView _setMinimumLayoutSizeOverride:]):
This was left out by accident. The WebProcess was getting the new layout size twice, making
WebPage::dynamicViewportSizeUpdate() very confused when the content size changes.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::dynamicViewportSizeUpdate):
Add scrolling adjustment for the dynamic relayout case:
-Sticky top and bottom like the UIProcess.
-Keep the same relative position of the unobscured rect's center.

Also fix a bug in the horizontal and vertical adjustments: the code was using the exposed rect
instead of the unobscured rect, which made the adjustments off by the size of the obscured insets.

The type is changed from double to float since ARMv7 has a grudge against double.


Canonical link: https://commits.webkit.org/149843@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167409 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Benjamin Poulain authored and BenjaminPoulain committed Apr 17, 2014
1 parent 942d139 commit c62fb0f9c8dcd91a328c125224ac3aedf1837eba
Showing 3 changed files with 64 additions and 9 deletions.
@@ -1,3 +1,29 @@
2014-04-16 Benjamin Poulain <bpoulain@apple.com>

[iOS][WK2] Improve the approximation of the scroll position of the dynamic viewport size updates
https://bugs.webkit.org/show_bug.cgi?id=131720

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _scrollToContentOffset:]):
The scrolling tree was forcing scroll at the wrong scale during the transition.

(-[WKWebView _setMinimumLayoutSizeOverride:]):
This was left out by accident. The WebProcess was getting the new layout size twice, making
WebPage::dynamicViewportSizeUpdate() very confused when the content size changes.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::dynamicViewportSizeUpdate):
Add scrolling adjustment for the dynamic relayout case:
-Sticky top and bottom like the UIProcess.
-Keep the same relative position of the unobscured rect's center.

Also fix a bug in the horizontal and vertical adjustments: the code was using the exposed rect
instead of the unobscured rect, which made the adjustments off by the size of the obscured insets.

The type is changed from double to float since ARMv7 has a grudge against double.

2014-04-16 Benjamin Poulain <bpoulain@apple.com>

[iOS][WK2] Do not update the visible content rects when setting the same obscured insets multiple times
@@ -549,10 +549,14 @@ - (void)_zoomToRect:(WebCore::FloatRect)targetRect atScale:(double)scale origin:

- (void)_scrollToContentOffset:(WebCore::FloatPoint)contentOffset
{
if (_isAnimatingResize)
return;

WebCore::FloatPoint scaledOffset = contentOffset;
CGFloat zoomScale = contentZoomScale(self);
scaledOffset.scale(zoomScale, zoomScale);

// FIXME: the offset is relative to the unobscured rect top, not the content insets!
UIEdgeInsets inset = [_scrollView contentInset];
scaledOffset += WebCore::FloatSize(-inset.left, -inset.top);

@@ -1257,7 +1261,8 @@ - (void)_setMinimumLayoutSizeOverride:(CGSize)minimumLayoutSizeOverride
{
_hasStaticMinimumLayoutSize = YES;
_minimumLayoutSizeOverride = minimumLayoutSizeOverride;
setViewportConfigurationMinimumLayoutSize(*_page, minimumLayoutSizeOverride);
if (!_isAnimatingResize)
setViewportConfigurationMinimumLayoutSize(*_page, minimumLayoutSizeOverride);
}

- (UIEdgeInsets)_obscuredInsets
@@ -1803,19 +1803,43 @@ static inline bool hasFocusableElement(Node* startNode, Page* page, bool isForwa
newUnobscuredContentRect.setWidth(std::min(static_cast<float>(newContentSize.width()), newExposedContentRect.width()));
newUnobscuredContentRect.setHeight(std::min(static_cast<float>(newContentSize.height()), newExposedContentRect.height()));

double horizontalAdjustment = 0;
if (oldContentSize != newContentSize) {
// If the content size has changed, keep the same relative position.
FloatPoint oldContentCenter = targetUnobscuredRect.center();
float relativeHorizontalPosition = oldContentCenter.x() / oldContentSize.width();
float relativeVerticalPosition = oldContentCenter.y() / oldContentSize.height();
FloatPoint newRelativeContentCenter(relativeHorizontalPosition * newContentSize.width(), relativeVerticalPosition * newContentSize.height());
FloatPoint newUnobscuredContentRectCenter = newUnobscuredContentRect.center();
FloatPoint positionDelta(newRelativeContentCenter.x() - newUnobscuredContentRectCenter.x(), newRelativeContentCenter.y() - newUnobscuredContentRectCenter.y());
newUnobscuredContentRect.moveBy(positionDelta);
newExposedContentRect.moveBy(positionDelta);
}

// Make the top/bottom edges "sticky" within 1 pixel.
if (targetUnobscuredRect.maxY() > oldContentSize.height() - 1) {
float bottomVerticalPosition = newContentSize.height() - newUnobscuredContentRect.height();
newUnobscuredContentRect.setY(bottomVerticalPosition);
newExposedContentRect.setY(bottomVerticalPosition);
}
if (targetUnobscuredRect.y() < 1) {
newUnobscuredContentRect.setY(0);
newExposedContentRect.setY(0);
}

float horizontalAdjustment = 0;
if (newExposedContentRect.maxX() > newContentSize.width())
horizontalAdjustment -= newExposedContentRect.maxX() - newContentSize.width();
double verticalAdjustment = 0;
horizontalAdjustment -= newUnobscuredContentRect.maxX() - newContentSize.width();
float verticalAdjustment = 0;
if (newExposedContentRect.maxY() > newContentSize.height())
verticalAdjustment -= newExposedContentRect.maxY() - newContentSize.height();
verticalAdjustment -= newUnobscuredContentRect.maxY() - newContentSize.height();
if (newExposedContentRect.x() < 0)
horizontalAdjustment += - newExposedContentRect.x();
horizontalAdjustment += - newUnobscuredContentRect.x();
if (newExposedContentRect.y() < 0)
verticalAdjustment += - newExposedContentRect.y();
verticalAdjustment += - newUnobscuredContentRect.y();

newUnobscuredContentRect.move(horizontalAdjustment, verticalAdjustment);
newExposedContentRect.move(horizontalAdjustment, verticalAdjustment);
FloatPoint adjustmentDelta(horizontalAdjustment, verticalAdjustment);
newUnobscuredContentRect.moveBy(adjustmentDelta);
newExposedContentRect.moveBy(adjustmentDelta);
}

frameView.setScrollVelocity(0, 0, 0, monotonicallyIncreasingTime());

0 comments on commit c62fb0f

Please sign in to comment.