diff --git a/Source/core/frame/PinchViewport.h b/Source/core/frame/PinchViewport.h index fc6ae2fea5e..b934131c2f5 100644 --- a/Source/core/frame/PinchViewport.h +++ b/Source/core/frame/PinchViewport.h @@ -80,7 +80,6 @@ class PinchViewport FINAL : public GraphicsLayerClient, public ScrollableArea { // coordinates are in partial CSS pixels. void setLocation(const FloatPoint&); void move(const FloatPoint&); - FloatPoint location() const { return m_offset; } // used in unit tests // Sets the size of the inner viewport when unscaled in CSS pixels. // This will be clamped to the size of the outer viewport (the main frame). diff --git a/Source/platform/scroll/ScrollView.h b/Source/platform/scroll/ScrollView.h index d4815df014b..19e365cb95d 100644 --- a/Source/platform/scroll/ScrollView.h +++ b/Source/platform/scroll/ScrollView.h @@ -55,6 +55,9 @@ class PLATFORM_EXPORT ScrollView : public Widget, public ScrollableArea { virtual void notifyPageThatContentAreaWillPaint() const; + // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea. + virtual void scrollTo(const IntSize& newOffset); + // The window that hosts the ScrollView. The ScrollView will communicate scrolls and repaints to the // host window in the window's coordinate space. virtual HostWindow* hostWindow() const = 0; @@ -256,9 +259,6 @@ class PLATFORM_EXPORT ScrollView : public Widget, public ScrollableArea { protected: ScrollView(); - // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea. - virtual void scrollTo(const IntSize& newOffset); - virtual void contentRectangleForPaintInvalidation(const IntRect&); virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0; diff --git a/Source/web/ViewportAnchor.cpp b/Source/web/ViewportAnchor.cpp index d4ec6563f8a..4a6a3d40164 100644 --- a/Source/web/ViewportAnchor.cpp +++ b/Source/web/ViewportAnchor.cpp @@ -35,7 +35,6 @@ #include "core/dom/Node.h" #include "core/page/EventHandler.h" #include "core/rendering/HitTestResult.h" -#include "platform/scroll/ScrollView.h" namespace blink { @@ -69,76 +68,31 @@ Node* findNonEmptyAnchorNode(const IntPoint& point, const IntRect& viewRect, Eve return node; } -void moveToEncloseRect(IntRect& outer, const FloatRect& inner) -{ - IntPoint minimumPosition = ceiledIntPoint(inner.location() + inner.size() - FloatSize(outer.size())); - IntPoint maximumPosition = flooredIntPoint(inner.location()); - - IntPoint outerOrigin = outer.location(); - outerOrigin = outerOrigin.expandedTo(minimumPosition); - outerOrigin = outerOrigin.shrunkTo(maximumPosition); - - outer.setLocation(outerOrigin); -} - -void moveIntoRect(FloatRect& inner, const IntRect& outer) -{ - FloatPoint minimumPosition = FloatPoint(outer.location()); - FloatPoint maximumPosition = minimumPosition + outer.size() - inner.size(); - - // Adjust maximumPosition to the nearest lower integer because - // PinchViewport::maximumScrollPosition() does the same. - // The value of minumumPosition is already adjusted since it is - // constructed from an integer point. - maximumPosition = flooredIntPoint(maximumPosition); - - FloatPoint innerOrigin = inner.location(); - innerOrigin = innerOrigin.expandedTo(minimumPosition); - innerOrigin = innerOrigin.shrunkTo(maximumPosition); - - inner.setLocation(innerOrigin); -} - } // namespace ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) : m_eventHandler(eventHandler) { } -void ViewportAnchor::setAnchor(const IntRect& outerViewRect, const IntRect& innerViewRect, - const FloatSize& anchorInInnerViewCoords) +void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorInViewCoords) { - // Preserve the inner viewport position in document in case we won't find the anchor - m_pinchViewportInDocument = innerViewRect.location(); - + m_viewRect = viewRect; m_anchorNode.clear(); m_anchorNodeBounds = LayoutRect(); m_anchorInNodeCoords = FloatSize(); - m_anchorInInnerViewCoords = anchorInInnerViewCoords; - m_normalizedPinchViewportOffset = FloatSize(); + m_anchorInViewCoords = anchorInViewCoords; - if (innerViewRect.isEmpty()) + if (viewRect.isEmpty()) return; // Preserve origins at the absolute screen origin - if (innerViewRect.location() == IntPoint::zero()) + if (viewRect.location() == IntPoint::zero()) return; - // Inner rectangle should be within the outer one. - ASSERT(outerViewRect.contains(innerViewRect)); - - // Outer rectangle is used as a scale, we need positive width and height. - ASSERT(!outerViewRect.isEmpty()); + FloatSize anchorOffset = viewRect.size(); + anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); + const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffset; - m_normalizedPinchViewportOffset = innerViewRect.location() - outerViewRect.location(); - - // Normalize by the size of the outer rect - m_normalizedPinchViewportOffset.scale(1.0 / outerViewRect.width(), 1.0 / outerViewRect.height()); - - FloatSize anchorOffset = innerViewRect.size(); - anchorOffset.scale(anchorInInnerViewCoords.width(), anchorInInnerViewCoords.height()); - const FloatPoint anchorPoint = FloatPoint(innerViewRect.location()) + anchorOffset; - - Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), innerViewRect, m_eventHandler); + Node* node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), viewRect, m_eventHandler); if (!node) return; @@ -148,39 +102,14 @@ void ViewportAnchor::setAnchor(const IntRect& outerViewRect, const IntRect& inne m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorNodeBounds.height()); } -void ViewportAnchor::computeOrigins(const ScrollView& scrollView, const FloatSize& innerSize, - IntPoint& mainFrameOffset, FloatPoint& pinchViewportOffset) const -{ - IntSize outerSize = scrollView.visibleContentRect().size(); - - // Compute the viewport origins in CSS pixels relative to the document. - FloatSize absPinchViewportOffset = m_normalizedPinchViewportOffset; - absPinchViewportOffset.scale(outerSize.width(), outerSize.height()); - - FloatPoint innerOrigin = getInnerOrigin(innerSize); - FloatPoint outerOrigin = innerOrigin - absPinchViewportOffset; - - IntRect outerRect = IntRect(flooredIntPoint(outerOrigin), outerSize); - FloatRect innerRect = FloatRect(innerOrigin, innerSize); - - moveToEncloseRect(outerRect, innerRect); - - outerRect.setLocation(scrollView.adjustScrollPositionWithinRange(outerRect.location())); - - moveIntoRect(innerRect, outerRect); - - mainFrameOffset = outerRect.location(); - pinchViewportOffset = FloatPoint(innerRect.location() - outerRect.location()); -} - -FloatPoint ViewportAnchor::getInnerOrigin(const FloatSize& innerSize) const +IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const { if (!m_anchorNode || !m_anchorNode->inDocument()) - return m_pinchViewportInDocument; + return m_viewRect.location(); const LayoutRect currentNodeBounds = m_anchorNode->boundingBox(); if (m_anchorNodeBounds == currentNodeBounds) - return m_pinchViewportInDocument; + return m_viewRect.location(); // Compute the new anchor point relative to the node position FloatSize anchorOffsetFromNode = currentNodeBounds.size(); @@ -188,9 +117,9 @@ FloatPoint ViewportAnchor::getInnerOrigin(const FloatSize& innerSize) const FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode; // Compute the new origin point relative to the new anchor point - FloatSize anchorOffsetFromOrigin = innerSize; - anchorOffsetFromOrigin.scale(m_anchorInInnerViewCoords.width(), m_anchorInInnerViewCoords.height()); - return anchorPoint - anchorOffsetFromOrigin; + FloatSize anchorOffsetFromOrigin = currentViewSize; + anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoords.height()); + return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); } } // namespace blink diff --git a/Source/web/ViewportAnchor.h b/Source/web/ViewportAnchor.h index 46f86f03a78..8bd0a7b92b1 100644 --- a/Source/web/ViewportAnchor.h +++ b/Source/web/ViewportAnchor.h @@ -43,7 +43,6 @@ namespace blink { class EventHandler; class IntSize; class Node; -class ScrollView; // ViewportAnchor provides a way to anchor a viewport origin to a DOM node. // In particular, the user supplies the current viewport (in CSS coordinates) @@ -57,31 +56,22 @@ class ViewportAnchor { public: explicit ViewportAnchor(EventHandler*); - void setAnchor(const IntRect& outerViewRect, const IntRect& innerViewRect, const FloatSize& anchorInViewCoords); + void setAnchor(const IntRect& viewRect, const FloatSize& anchorInViewCoords); - void computeOrigins(const ScrollView&, const FloatSize& innerSize, - IntPoint& mainFrameOffset, FloatPoint& pinchViewportOffset) const; - -private: - FloatPoint getInnerOrigin(const FloatSize& innerSize) const; + IntPoint computeOrigin(const IntSize& currentViewSize) const; private: RawPtrWillBeMember m_eventHandler; - // Inner viewport origin in the reference frame of the document in CSS pixels - FloatPoint m_pinchViewportInDocument; - - // Inner viewport origin in the reference frame of the outer viewport - // normalized to the outer viewport size. - FloatSize m_normalizedPinchViewportOffset; + IntRect m_viewRect; RefPtrWillBeMember m_anchorNode; LayoutRect m_anchorNodeBounds; - FloatSize m_anchorInInnerViewCoords; + FloatSize m_anchorInViewCoords; FloatSize m_anchorInNodeCoords; }; } // namespace blink -#endif + #endif diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp index 3cc40830398..07b9363d1fa 100644 --- a/Source/web/WebViewImpl.cpp +++ b/Source/web/WebViewImpl.cpp @@ -1705,10 +1705,8 @@ void WebViewImpl::resize(const WebSize& newSize) ViewportAnchor viewportAnchor(&localFrameRootTemporary()->frame()->eventHandler()); if (shouldAnchorAndRescaleViewport) { - viewportAnchor.setAnchor( - view->visibleContentRect(), - visibleRectInDocument(), - FloatSize(viewportAnchorXCoord, viewportAnchorYCoord)); + viewportAnchor.setAnchor(view->visibleContentRect(), + FloatSize(viewportAnchorXCoord, viewportAnchorYCoord)); } // FIXME: TextAutosizer does not yet support out-of-process frames. @@ -1728,33 +1726,15 @@ void WebViewImpl::resize(const WebSize& newSize) if (shouldAnchorAndRescaleViewport) { float newPageScaleFactor = oldPageScaleFactor / oldMinimumPageScaleFactor * minimumPageScaleFactor(); - newPageScaleFactor = clampPageScaleFactorToLimits(newPageScaleFactor); - - FloatSize pinchViewportSize = FloatSize(newSize); - pinchViewportSize.scale(1 / newPageScaleFactor); - - IntPoint mainFrameOrigin; - FloatPoint pinchViewportOrigin; - viewportAnchor.computeOrigins(*view, pinchViewportSize, - mainFrameOrigin, pinchViewportOrigin); - scrollAndRescaleViewports(newPageScaleFactor, mainFrameOrigin, pinchViewportOrigin); + IntSize scaledViewportSize = newSize; + scaledViewportSize.scale(1 / newPageScaleFactor); + setPageScaleFactor(newPageScaleFactor, viewportAnchor.computeOrigin(scaledViewportSize)); } } sendResizeEventAndRepaint(); } -IntRect WebViewImpl::visibleRectInDocument() const -{ - if (pinchVirtualViewportEnabled()) { - // Inner viewport in the document coordinates - return enclosedIntRect(page()->frameHost().pinchViewport().visibleRectInDocument()); - } - - // Outer viewport in the document coordinates - return localFrameRootTemporary()->frameView()->visibleContentRect(); -} - void WebViewImpl::willEndLiveResize() { if (mainFrameImpl() && mainFrameImpl()->frameView()) @@ -2960,36 +2940,6 @@ WebFloatPoint WebViewImpl::pinchViewportOffset() const return page()->frameHost().pinchViewport().visibleRect().location(); } -void WebViewImpl::scrollAndRescaleViewports(float scaleFactor, - const IntPoint& mainFrameOrigin, - const FloatPoint& pinchViewportOrigin) -{ - // Old way - if (!pinchVirtualViewportEnabled()) { - setPageScaleFactor(scaleFactor, mainFrameOrigin); - return; - } - - if (!page()) - return; - - if (!mainFrameImpl()) - return; - - FrameView * view = mainFrameImpl()->frameView(); - if (!view) - return; - - // Order is important: pinch viewport location is clamped based on - // main frame scroll position and pinch viewport scale. - - view->setScrollOffset(mainFrameOrigin); - - setPageScaleFactor(scaleFactor); - - page()->frameHost().pinchViewport().setLocation(pinchViewportOrigin); -} - void WebViewImpl::setPageScaleFactor(float scaleFactor) { ASSERT(page()); @@ -3032,6 +2982,7 @@ void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin) page()->setPageScaleFactor(scaleFactor, newScrollOffset); } + float WebViewImpl::deviceScaleFactor() const { if (!page()) diff --git a/Source/web/WebViewImpl.h b/Source/web/WebViewImpl.h index 0b8cd936563..4e8b1d452c1 100644 --- a/Source/web/WebViewImpl.h +++ b/Source/web/WebViewImpl.h @@ -505,10 +505,6 @@ class WebViewImpl FINAL : public WebView // prevent external usage virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) OVERRIDE; - void scrollAndRescaleViewports(float scaleFactor, const IntPoint& mainFrameOrigin, const FloatPoint& pinchViewportOrigin); - - IntRect visibleRectInDocument() const; - float legibleScale() const; void refreshPageScaleFactorAfterLayout(); void resumeTreeViewCommits(); diff --git a/Source/web/tests/PinchViewportTest.cpp b/Source/web/tests/PinchViewportTest.cpp index c18b7d663f0..5e34221f8fe 100644 --- a/Source/web/tests/PinchViewportTest.cpp +++ b/Source/web/tests/PinchViewportTest.cpp @@ -153,7 +153,6 @@ class PinchViewportTest : public testing::Test { settings->setViewportEnabled(true); settings->setViewportMetaEnabled(true); settings->setShrinksViewportContentToFit(true); - settings->setMainFrameResizesAreOrientationChanges(true); } protected: @@ -194,125 +193,6 @@ TEST_F(PinchViewportTest, TestResize) EXPECT_SIZE_EQ(newViewportSize, pinchViewport.size()); } -// Test that the PinchViewport works as expected in case of a scaled -// and scrolled viewport - scroll down. -TEST_F(PinchViewportTest, TestResizeAfterVerticalScroll) -{ - /* - 200 200 - | | | | - | | | | - | | 800 | | 800 - |-------------------| | | - | | | | - | | | | - | | | | - | | --------> | | - | 300 | | | - | | | | - | 400 | | | - | | |-------------------| - | | | 75 | - | 50 | | 50 100| - o----- | o---- | - | | | | | 25 | - | |100 | |-------------------| - | | | | | - | | | | | - -------------------- -------------------- - - */ - - initializeWithAndroidSettings(); - - registerMockedHttpURLLoad("200-by-800-viewport.html"); - navigateTo(m_baseURL + "200-by-800-viewport.html"); - - webViewImpl()->resize(IntSize(100, 200)); - - // Scroll main frame to the bottom of the document - webViewImpl()->setMainFrameScrollOffset(WebPoint(0, 400)); - EXPECT_POINT_EQ(IntPoint(0, 400), frame()->view()->scrollPosition()); - - webViewImpl()->setPageScaleFactor(2.0); - - // Scroll pinch viewport to the bottom of the main frame - PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); - pinchViewport.setLocation(FloatPoint(0, 300)); - EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 300), pinchViewport.location()); - - // Verify the initial size of the pinch viewport in the CSS pixels - EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), pinchViewport.visibleRect().size()); - - // Perform the resizing - webViewImpl()->resize(IntSize(200, 100)); - - // After resizing the scale changes 2.0 -> 4.0 - EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), pinchViewport.visibleRect().size()); - - EXPECT_POINT_EQ(IntPoint(0, 625), frame()->view()->scrollPosition()); - EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 75), pinchViewport.location()); -} - -// Test that the PinchViewport works as expected in case if a scaled -// and scrolled viewport - scroll right. -TEST_F(PinchViewportTest, TestResizeAfterHorizontalScroll) -{ - /* - 200 200 - ---------------o----- ---------------o----- - | | | | 25| | - | | | | -----| - | 100| | |100 50 | - | | | | | - | ---- | |-------------------| - | | | | - | | | | - | | | | - | | | | - | | | | - |400 | ---------> | | - | | | | - | | | | - | | | | - | | | | - | | | | - | | | | - | | | | - | | | | - |-------------------| | | - | | | | - - */ - - initializeWithAndroidSettings(); - - registerMockedHttpURLLoad("200-by-800-viewport.html"); - navigateTo(m_baseURL + "200-by-800-viewport.html"); - - webViewImpl()->resize(IntSize(100, 200)); - - // Outer viewport takes the whole width of the document. - - webViewImpl()->setPageScaleFactor(2.0); - - // Scroll pinch viewport to the right edge of the frame - PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); - pinchViewport.setLocation(FloatPoint(150, 0)); - EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), pinchViewport.location()); - - // Verify the initial size of the pinch viewport in the CSS pixels - EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), pinchViewport.visibleRect().size()); - - webViewImpl()->resize(IntSize(200, 100)); - - // After resizing the scale changes 2.0 -> 4.0 - EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), pinchViewport.visibleRect().size()); - - EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); - EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 0), pinchViewport.location()); -} - static void disableAcceleratedCompositing(WebSettings* settings) { PinchViewportTest::configureSettings(settings); diff --git a/Source/web/tests/data/200-by-800-viewport.html b/Source/web/tests/data/200-by-800-viewport.html deleted file mode 100644 index 67df179b7b6..00000000000 --- a/Source/web/tests/data/200-by-800-viewport.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - -
a
- - -