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

Unified Diff: Source/web/WebViewImpl.cpp

Issue 556703005: Initial draft - modify ViewportAnchor to know about both inner and outer viewports. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« Source/web/ViewportAnchor.cpp ('K') | « Source/web/WebViewImpl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebViewImpl.cpp
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index a170b30c711d430597a550f8a410233e7b41e766..ce94184b7d05e807117039973402fb3b81655a55 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -1679,20 +1679,19 @@ void WebViewImpl::resize(const WebSize& newSize)
ViewportAnchor viewportAnchor(&localFrameRootTemporary()->frame()->eventHandler());
if (shouldAnchorAndRescaleViewport) {
- viewportAnchor.setAnchor(view->visibleContentRect(),
+ // TODO: should we pass FloatRects instead of IntRects?
+ viewportAnchor.setAnchor(visibleRectInDocument(), outerViewportRectInDocument(),
FloatSize(viewportAnchorXCoord, viewportAnchorYCoord));
}
// FIXME: TextAutosizer does not yet support out-of-process frames.
- if (mainFrameImpl() && mainFrameImpl()->frame()->isLocalFrame())
- {
+ if (mainFrameImpl() && mainFrameImpl()->frame()->isLocalFrame()) {
// Avoids unnecessary invalidations while various bits of state in TextAutosizer are updated.
TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
- performResize();
- } else {
- performResize();
}
+ performResize();
bokan 2014/09/10 15:03:59 Why did this get moved? TextAutosizer::DeferUpdate
timav 2014/09/10 18:22:40 Oops. Thank you, I did not catch that. Will undo.
+
if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) {
// Relayout immediately to recalculate the minimum scale limit.
if (view->needsLayout())
@@ -1700,15 +1699,40 @@ void WebViewImpl::resize(const WebSize& newSize)
if (shouldAnchorAndRescaleViewport) {
float newPageScaleFactor = oldPageScaleFactor / oldMinimumPageScaleFactor * minimumPageScaleFactor();
- IntSize scaledViewportSize = newSize;
- scaledViewportSize.scale(1 / newPageScaleFactor);
- setPageScaleFactor(newPageScaleFactor, viewportAnchor.computeOrigin(scaledViewportSize));
+ IntSize innerViewportSize = newSize;
+ innerViewportSize.scale(1 / newPageScaleFactor);
+
+ // in CSS pixel relative to the document
+ IntPoint innerOrigin = viewportAnchor.computeInnerViewportOrigin(innerViewportSize);
bokan 2014/09/10 15:03:59 Can you please rename as follows (here and other p
+
+ // in CSS pixel relative to the document
+ IntPoint outerOrigin = viewportAnchor.computeOuterViewportOrigin(
+ innerOrigin, outerViewportRectInDocument().size());
+
+ scrollAndRescaleViewports(newPageScaleFactor, innerOrigin, outerOrigin);
}
}
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();
+}
+
+IntRect WebViewImpl::outerViewportRectInDocument() const
aelias_OOO_until_Jul13 2014/09/10 01:46:25 This method doesn't seem to save much code duplica
timav 2014/09/10 18:22:40 Acknowledged.
+{
+ // Same as the inner viewport if the virtual viewport is disabled
+ return localFrameRootTemporary()->frameView()->visibleContentRect();
+}
+
void WebViewImpl::willEndLiveResize()
{
if (mainFrameImpl() && mainFrameImpl()->frameView())
@@ -2922,6 +2946,36 @@ void WebViewImpl::setMainFrameScrollOffset(const WebPoint& origin)
updateMainFrameScrollPosition(origin, false);
}
+void WebViewImpl::scrollAndRescaleViewports(float scaleFactor,
+ const IntPoint & innerViewportOrigin,
aelias_OOO_until_Jul13 2014/09/10 01:46:25 Please make these arguments: const IntPoint& outer
timav 2014/09/10 18:22:40 Acknowledged.
+ const IntPoint & outerViewportOrigin)
+{
+ // Old way
+ if (!pinchVirtualViewportEnabled()) {
+ setPageScaleFactor(scaleFactor, innerViewportOrigin);
+ return;
+ }
+
+ if (!page())
+ return;
+
+ if (!mainFrameImpl())
+ return;
+
+ FrameView * view = mainFrameImpl()->frameView();
+ if (!view)
+ return;
+
+ // Set outer viewport position.
+ view->scrollTo(toIntSize(outerViewportOrigin));
bokan 2014/09/10 15:03:58 Use WebViewImpl::updateMainFrameScrollPosition(Int
timav 2014/09/10 18:22:40 Yes, I missed that comment. The ScrollView::scroll
bokan 2014/09/10 18:26:40 Yup, highly easy to misuse. If you don't mind, go
+
+ // Set inner viewport position.
+ IntSize innerViewportInOuter = innerViewportOrigin - outerViewportOrigin;
+ page()->frameHost().pinchViewport().setLocation(IntPoint(innerViewportInOuter));
+
+ setPageScaleFactor(scaleFactor);
+}
+
void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin)
{
if (!page())
« Source/web/ViewportAnchor.cpp ('K') | « Source/web/WebViewImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698