Commit 59379b09 authored by bokan's avatar bokan Committed by Commit bot

Made double-tap zoom work in pinch virtual viewport mode (Chromium-side).

On the Blink side:
The clamping method used by computeScaleAndScrollForBlockRect now
uses a new method PinchViewport::clampDocumentOffsetAtScale to clamp
the requested viewport offset taking into account the inner and outer
viewports.

Also added an overload of applyViewportDeltas, called in virtual
viewport mode only, that applies the inner and outer deltas along
page scale in one shot. This makes the viewport layers a special case
again in that their scroll offsets are set through this call, rather
than the standard 'did_scroll' callback of most layers. This is needed
since the scroll offsets may be invalid until the page scale is
applied so this is handled in one method to prevent unintended
clamping.

On the Compositor side:
Calls the appropriate applyViewportDeltas based on which pinch mode
we're running in. The page scale animation now prefers to scroll the
inner viewport first, scrolling the outer only when the inner has
reached its scroll extent.

Blink-side: https://codereview.chromium.org/584833003

BUG=364106

Review URL: https://codereview.chromium.org/585063002

Cr-Commit-Position: refs/heads/master@{#297167}
parent c4e4aaaf
......@@ -43,6 +43,10 @@ class HardwareRenderer : public cc::LayerTreeHostClient,
virtual void DidBeginMainFrame() OVERRIDE;
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE {}
virtual void Layout() OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
......
......@@ -34,6 +34,10 @@ class FakeLayerTreeHostClient : public LayerTreeHostClient,
virtual void DidBeginMainFrame() OVERRIDE {}
virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE {}
virtual void Layout() OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
......
......@@ -280,6 +280,15 @@ class LayerTreeHostClientForTesting : public LayerTreeHostClient,
virtual void Layout() OVERRIDE { test_hooks_->Layout(); }
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {
test_hooks_->ApplyViewportDeltas(inner_delta,
outer_delta,
page_scale,
top_controls_delta);
}
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float scale,
float top_controls_delta) OVERRIDE {
......
......@@ -58,6 +58,10 @@ class TestHooks : public AnimationDelegate {
bool has_unfinished_animation) {}
virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl,
base::TimeTicks monotonic_time) {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float scale,
float top_controls_delta) {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float scale,
float top_controls_delta) {}
......
......@@ -1097,11 +1097,11 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
// SetScrollOffsetFromImplSide above could have destroyed the tree,
// so re-get this layer before doing anything to it.
DCHECK(inner_viewport_scroll_layer_.get()); // We should always have this.
// Preemptively apply the scroll offset and scale delta here before sending
// it to the client. If the client comes back and sets it to the same
// value, then the layer can early out without needing a full commit.
DCHECK(inner_viewport_scroll_layer_.get()); // We should always have this.
inner_viewport_scroll_layer_->SetScrollOffsetFromImplSide(
inner_viewport_scroll_layer_->scroll_offset() +
inner_viewport_scroll_delta);
......@@ -1110,12 +1110,20 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
outer_viewport_scroll_layer_->scroll_offset() +
outer_viewport_scroll_delta);
}
ApplyPageScaleDeltaFromImplSide(info->page_scale_delta);
client_->ApplyViewportDeltas(
inner_viewport_scroll_delta + outer_viewport_scroll_delta,
info->page_scale_delta,
info->top_controls_delta);
ApplyPageScaleDeltaFromImplSide(info->page_scale_delta);
if (!outer_viewport_scroll_layer_.get()) {
client_->ApplyViewportDeltas(
inner_viewport_scroll_delta + outer_viewport_scroll_delta,
info->page_scale_delta,
info->top_controls_delta);
} else {
client_->ApplyViewportDeltas(
inner_viewport_scroll_delta,
outer_viewport_scroll_delta,
info->page_scale_delta,
info->top_controls_delta);
}
}
}
......
......@@ -27,6 +27,10 @@ class LayerTreeHostClient {
virtual void BeginMainFrame(const BeginFrameArgs& args) = 0;
virtual void DidBeginMainFrame() = 0;
virtual void Layout() = 0;
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) = 0;
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) = 0;
......
......@@ -2961,6 +2961,15 @@ void LayerTreeHostImpl::SetFullRootLayerDamage() {
SetViewportDamage(gfx::Rect(DrawViewportSize()));
}
void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) {
DCHECK(InnerViewportScrollLayer());
LayerImpl* scroll_layer = InnerViewportScrollLayer();
gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta);
if (!unused_delta.IsZero() && OuterViewportScrollLayer())
OuterViewportScrollLayer()->ScrollBy(unused_delta);
}
void LayerTreeHostImpl::ScrollViewportBy(gfx::Vector2dF scroll_delta) {
DCHECK(InnerViewportScrollLayer());
LayerImpl* scroll_layer = OuterViewportScrollLayer()
......@@ -2988,7 +2997,7 @@ void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) {
gfx::Vector2dF next_scroll =
page_scale_animation_->ScrollOffsetAtTime(monotonic_time);
ScrollViewportBy(next_scroll - scroll_total);
ScrollViewportInnerFirst(next_scroll - scroll_total);
SetNeedsRedraw();
if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) {
......
......@@ -522,7 +522,12 @@ class CC_EXPORT LayerTreeHostImpl
bool UseZeroCopyRasterizer() const;
bool UseOneCopyRasterizer() const;
// Scroll by preferring to move the outer viewport first, only moving the
// inner if the outer is at its scroll extents.
void ScrollViewportBy(gfx::Vector2dF scroll_delta);
// Scroll by preferring to move the inner viewport first, only moving the
// outer if the inner is at its scroll extents.
void ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta);
void AnimatePageScale(base::TimeTicks monotonic_time);
void AnimateScrollbars(base::TimeTicks monotonic_time);
void AnimateTopControls(base::TimeTicks monotonic_time);
......
......@@ -57,6 +57,10 @@ class LayerTreeHostNoMessageLoopTest
virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE {}
virtual void DidBeginMainFrame() OVERRIDE {}
virtual void Layout() OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
......
......@@ -74,6 +74,11 @@ class CONTENT_EXPORT CompositorImpl
virtual void DidBeginMainFrame() OVERRIDE {}
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE {}
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(
const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
virtual void ApplyViewportDeltas(
const gfx::Vector2d& scroll_delta,
float page_scale,
......
......@@ -786,6 +786,18 @@ void RenderWidgetCompositor::Layout() {
widget_->webwidget()->layout();
}
void RenderWidgetCompositor::ApplyViewportDeltas(
const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) {
widget_->webwidget()->applyViewportDeltas(
inner_delta,
outer_delta,
page_scale,
top_controls_delta);
}
void RenderWidgetCompositor::ApplyViewportDeltas(
const gfx::Vector2d& scroll_delta,
float page_scale,
......
......@@ -132,6 +132,10 @@ class CONTENT_EXPORT RenderWidgetCompositor
virtual void DidBeginMainFrame() OVERRIDE;
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
......
......@@ -137,6 +137,12 @@ void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) {
void WebLayerTreeViewImplForTesting::Layout() {
}
void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) {}
void WebLayerTreeViewImplForTesting::ApplyViewportDeltas(
const gfx::Vector2d& scroll_delta,
float page_scale,
......
......@@ -69,6 +69,10 @@ class WebLayerTreeViewImplForTesting
virtual void DidBeginMainFrame() OVERRIDE {}
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE {}
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
......
......@@ -72,6 +72,10 @@ void CompositorHost::BeginMainFrame(const cc::BeginFrameArgs& args) {
}
void CompositorHost::Layout() {}
void CompositorHost::ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) {}
void CompositorHost::ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) {}
......
......@@ -33,6 +33,10 @@ class CompositorHost : public cc::LayerTreeHostClient {
virtual void DidBeginMainFrame() OVERRIDE;
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
......
......@@ -72,6 +72,18 @@ void WebLayerTreeViewImpl::Layout() {
widget_->layout();
}
void WebLayerTreeViewImpl::ApplyViewportDeltas(
const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) {
widget_->applyViewportDeltas(
inner_delta,
outer_delta,
page_scale,
top_controls_delta);
}
void WebLayerTreeViewImpl::ApplyViewportDeltas(
const gfx::Vector2d& scroll_delta,
float page_scale,
......
......@@ -48,6 +48,10 @@ class WebLayerTreeViewImpl : public blink::WebLayerTreeView,
virtual void DidBeginMainFrame() OVERRIDE;
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
float page_scale,
float top_controls_delta) OVERRIDE;
......
......@@ -232,6 +232,11 @@ class COMPOSITOR_EXPORT Compositor
virtual void DidBeginMainFrame() OVERRIDE {}
virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void ApplyViewportDeltas(
const gfx::Vector2d& inner_delta,
const gfx::Vector2d& outer_delta,
float page_scale,
float top_controls_delta) OVERRIDE {}
virtual void ApplyViewportDeltas(
const gfx::Vector2d& scroll_delta,
float page_scale,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment