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

Unified Diff: Source/web/WebViewImpl.cpp

Issue 882683003: Normalize top controls offset to (0, 1), Blink-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rename to shownratio Created 5 years, 10 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
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('j') | 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 06e1c3efd3a9d6a137123b869811287b1502407b..743982ad6e7dd52141de44a20178acf9df8b8bb2 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -412,8 +412,10 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
, m_backgroundColorOverride(Color::transparent)
, m_zoomFactorOverride(0)
, m_userGestureObserved(false)
- , m_topControlsContentOffset(0)
- , m_topControlsLayoutHeight(0)
+ , m_topControlsShownRatio(0)
+ , m_topControlsHeight(0)
+ , m_topControlsShrinkLayoutSize(true)
+ , m_topControlsOffsetIsNormalized(true)
{
Page::PageClients pageClients;
pageClients.chromeClient = &m_chromeClientImpl;
@@ -1717,16 +1719,27 @@ void WebViewImpl::performResize()
}
}
-void WebViewImpl::setTopControlsContentOffset(float offset)
+void WebViewImpl::setTopControlsShownRatio(float offset)
{
- m_topControlsContentOffset = offset;
+ m_topControlsShownRatio = offset;
+ // TODO(aelias): Rename this to ShownRatio after CC side lands.
m_layerTreeView->setTopControlsContentOffset(offset);
didUpdateTopControls();
}
void WebViewImpl::setTopControlsLayoutHeight(float height)
{
- m_topControlsLayoutHeight = height;
+ m_topControlsOffsetIsNormalized = false;
+ setTopControlsHeight(height, true);
+}
+
+void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayoutSize)
+{
+ if (m_topControlsHeight == height && m_topControlsShrinkLayoutSize == topControlsShrinkLayoutSize)
+ return;
+
+ m_topControlsHeight = height;
+ m_topControlsShrinkLayoutSize = topControlsShrinkLayoutSize;
didUpdateTopControls();
}
@@ -1740,7 +1753,11 @@ void WebViewImpl::didUpdateTopControls()
if (!view)
return;
- float topControlsViewportAdjustment = m_topControlsLayoutHeight - m_topControlsContentOffset;
+ float topControlsViewportAdjustment = 0;
+ if (m_topControlsShrinkLayoutSize)
+ topControlsViewportAdjustment += m_topControlsHeight;
+ topControlsViewportAdjustment -= m_topControlsShownRatio * (m_topControlsOffsetIsNormalized ? m_topControlsHeight : 1);
+
if (!pinchVirtualViewportEnabled()) {
// The viewport bounds were adjusted on the compositor by this much due to top controls. Tell
// the FrameView about it so it can make correct scroll offset clamping decisions during compositor
@@ -1756,13 +1773,13 @@ void WebViewImpl::didUpdateTopControls()
// On ChromeOS the pinch viewport can change size independent of the layout viewport due to the
// on screen keyboard so we should only set the FrameView adjustment on Android.
-#if OS(ANDROID)
- // Shrink the FrameView by the amount that will maintain the aspect-ratio with the PinchViewport.
- float aspectRatio = pinchViewport.visibleRect().width() / pinchViewport.visibleRect().height();
- float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars).width() / aspectRatio;
- float adjustment = newHeight - view->unscaledVisibleContentSize(ExcludeScrollbars).height();
- view->setTopControlsViewportAdjustment(adjustment);
-#endif
+ if (settings() && settings()->mainFrameResizesAreOrientationChanges()) {
+ // Shrink the FrameView by the amount that will maintain the aspect-ratio with the PinchViewport.
+ float aspectRatio = pinchViewport.visibleRect().width() / pinchViewport.visibleRect().height();
+ float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars).width() / aspectRatio;
+ float adjustment = newHeight - view->unscaledVisibleContentSize(ExcludeScrollbars).height();
+ view->setTopControlsViewportAdjustment(adjustment);
+ }
}
}
@@ -4388,14 +4405,14 @@ void WebViewImpl::applyViewportDeltas(
const WebSize& outerViewportDelta,
const WebFloatSize& elasticOverscrollDelta,
float pageScaleDelta,
- float topControlsDelta)
+ float topControlsShownRatioDelta)
{
applyViewportDeltas(
WebFloatSize(pinchViewportDelta.width, pinchViewportDelta.height),
WebFloatSize(outerViewportDelta.width, outerViewportDelta.height),
elasticOverscrollDelta,
pageScaleDelta,
- topControlsDelta);
+ topControlsShownRatioDelta);
}
void WebViewImpl::applyViewportDeltas(
@@ -4403,7 +4420,7 @@ void WebViewImpl::applyViewportDeltas(
const WebFloatSize& outerViewportDelta,
const WebFloatSize& elasticOverscrollDelta,
float pageScaleDelta,
- float topControlsDelta)
+ float topControlsShownRatioDelta)
{
ASSERT(pinchVirtualViewportEnabled());
@@ -4413,7 +4430,7 @@ void WebViewImpl::applyViewportDeltas(
if (!frameView)
return;
- setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta);
+ setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelta);
FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visibleRect().location();
pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height);
@@ -4428,12 +4445,12 @@ void WebViewImpl::applyViewportDeltas(
DoubleSize(outerViewportDelta.width, outerViewportDelta.height), /* programmaticScroll */ false);
}
-void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScaleDelta, float topControlsDelta)
+void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScaleDelta, float topControlsShownRatioDelta)
{
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
- setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta);
+ setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelta);
if (pageScaleDelta == 1) {
TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollBy", "x", scrollDelta.width, "y", scrollDelta.height);
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698