Commit 8273d966 authored by bokan's avatar bokan Committed by Commit bot

Don't scale fixed container adjustment in pinch virtual viewport.

In the current method of pinch-zoom, position: fixed elements stick to
the visual viewport (i.e. the screen). This means when the user pinch
zooms in, the viewport gets smaller so the fixed layers attached to the
right and bottom need an adjustment to keep them fixed to the screen.

In the new virtual viewport mode, the fixed elements stick to the layout
viewport, which doesn't change under scale so we no longer need to scale
this adjustment. Additionally, the adjustment that previously came from
pinch zooming is not needed at all.

BUG=420277

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

Cr-Commit-Position: refs/heads/master@{#300625}
parent ced73ad0
...@@ -625,6 +625,13 @@ gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const { ...@@ -625,6 +625,13 @@ gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
float scale = layer_tree_impl()->page_scale_factor(); float scale = layer_tree_impl()->page_scale_factor();
gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta(); gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
// In virtual-viewport mode, we don't need to compensate for pinch zoom or
// scale since the fixed container is the outer viewport, which sits below
// the page scale.
if (layer_tree_impl()->settings().use_pinch_virtual_viewport)
return delta_from_scroll;
delta_from_scroll.Scale(1.f / scale); delta_from_scroll.Scale(1.f / scale);
// The delta-from-pinch component requires some explanation: A viewport of // The delta-from-pinch component requires some explanation: A viewport of
......
...@@ -906,19 +906,10 @@ TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { ...@@ -906,19 +906,10 @@ TEST_F(LayerTreeHostImplTest, ImplPinchZoom) {
scroll_layer->SetScrollDelta(gfx::Vector2d()); scroll_layer->SetScrollDelta(gfx::Vector2d());
float page_scale_delta = 2.f; float page_scale_delta = 2.f;
gfx::Vector2dF expected_container_size_delta(
container_layer->bounds().width(), container_layer->bounds().height());
expected_container_size_delta.Scale((1.f - page_scale_delta) /
(page_scale_factor * page_scale_delta));
host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
host_impl_->PinchGestureBegin(); host_impl_->PinchGestureBegin();
host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
// While the gesture is still active, the scroll layer should have a
// container size delta = container->bounds() * ((1.f -
// page_scale_delta)/())
EXPECT_EQ(expected_container_size_delta,
scroll_layer->FixedContainerSizeDelta());
host_impl_->PinchGestureEnd(); host_impl_->PinchGestureEnd();
host_impl_->ScrollEnd(); host_impl_->ScrollEnd();
EXPECT_FALSE(did_request_animate_); EXPECT_FALSE(did_request_animate_);
...@@ -2249,6 +2240,7 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { ...@@ -2249,6 +2240,7 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
clip_size_(layer_size_) { clip_size_(layer_size_) {
settings_.calculate_top_controls_position = true; settings_.calculate_top_controls_position = true;
settings_.top_controls_height = 50; settings_.top_controls_height = 50;
settings_.use_pinch_virtual_viewport = true;
viewport_size_ = viewport_size_ =
gfx::Size(clip_size_.width(), gfx::Size(clip_size_.width(),
...@@ -2391,8 +2383,8 @@ TEST_F(LayerTreeHostImplTopControlsTest, ...@@ -2391,8 +2383,8 @@ TEST_F(LayerTreeHostImplTopControlsTest,
} }
TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
CreateHostImpl(settings_, CreateOutputSurface()); SetupTopControlsAndScrollLayerWithVirtualViewport(
SetupTopControlsAndScrollLayer(); gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10));
DrawFrame(); DrawFrame();
EXPECT_EQ(InputHandler::ScrollStarted, EXPECT_EQ(InputHandler::ScrollStarted,
...@@ -2414,36 +2406,56 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { ...@@ -2414,36 +2406,56 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
inner_viewport_scroll_layer->FixedContainerSizeDelta()); inner_viewport_scroll_layer->FixedContainerSizeDelta());
} }
TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) { // Test that the fixed position container delta is appropriately adjusted
CreateHostImpl(settings_, CreateOutputSurface()); // by the top controls showing/hiding and page scale doesn't affect it.
SetupTopControlsAndScrollLayer(); TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) {
SetupTopControlsAndScrollLayerWithVirtualViewport(
gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100));
DrawFrame(); DrawFrame();
EXPECT_EQ(InputHandler::ScrollStarted,
host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
float page_scale = 1.5f; float page_scale = 1.5f;
float top_controls_height = settings_.top_controls_height;
LayerImpl* outer_viewport_scroll_layer =
host_impl_->active_tree()->OuterViewportScrollLayer();
// Zoom in, since the fixed container is the outer viewport, the delta should
// not be scaled.
host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f);
gfx::Vector2dF top_controls_scroll_delta(0.f, 5.f); EXPECT_EQ(InputHandler::ScrollStarted,
gfx::Vector2dF expected_container_size_delta = host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
ScaleVector2d(top_controls_scroll_delta, 1.f / page_scale);
// Scroll down, the top controls hiding should expand the viewport size so
// the delta should be equal to the scroll distance.
gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
host_impl_->top_controls_manager()->ScrollBegin(); host_impl_->top_controls_manager()->ScrollBegin();
host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
host_impl_->top_controls_manager()->ScrollEnd(); EXPECT_EQ(top_controls_height - top_controls_scroll_delta.y(),
host_impl_->top_controls_manager()->ContentTopOffset());
EXPECT_VECTOR_EQ(top_controls_scroll_delta,
outer_viewport_scroll_layer->FixedContainerSizeDelta());
host_impl_->ScrollEnd();
LayerImpl* inner_viewport_scroll_layer = // Scroll past the maximum extent. The delta shouldn't be greater than the
host_impl_->active_tree()->InnerViewportScrollLayer(); // top controls height.
DCHECK(inner_viewport_scroll_layer); host_impl_->top_controls_manager()->ScrollBegin();
host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height),
outer_viewport_scroll_layer->FixedContainerSizeDelta());
host_impl_->ScrollEnd(); host_impl_->ScrollEnd();
// Use a tolerance that requires the container size delta to be within 0.01 // Scroll in the direction to make the top controls show.
// pixels. host_impl_->top_controls_manager()->ScrollBegin();
double tolerance = 0.0001; host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta);
EXPECT_LT( EXPECT_EQ(top_controls_scroll_delta.y(),
(expected_container_size_delta - host_impl_->top_controls_manager()->ContentTopOffset());
inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), EXPECT_VECTOR_EQ(
tolerance); gfx::Vector2dF(0, top_controls_height - top_controls_scroll_delta.y()),
outer_viewport_scroll_layer->FixedContainerSizeDelta());
host_impl_->top_controls_manager()->ScrollEnd();
} }
// Ensure setting the top controls position explicitly using the setters on the // Ensure setting the top controls position explicitly using the setters on the
......
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