#include "cc/animation/scrollbar_animation_controller_thinning.h"
#include "cc/base/latency_info_swap_promise.h"
#include "cc/base/math_util.h"
+#include "cc/input/page_scale_animation.h"
#include "cc/input/top_controls_manager.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/delegated_renderer_layer_impl.h"
EXPECT_TRUE(did_request_commit_);
}
+TEST_F(LayerTreeHostImplTest, ScrollActiveOnlyAfterScrollMovement) {
+ SetupScrollAndContentsLayers(gfx::Size(100, 100));
+ host_impl_->SetViewportSize(gfx::Size(50, 50));
+ DrawFrame();
+
+ EXPECT_EQ(InputHandler::ScrollStarted,
+ host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
+ EXPECT_FALSE(host_impl_->IsActivelyScrolling());
+ host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
+ EXPECT_TRUE(host_impl_->IsActivelyScrolling());
+ host_impl_->ScrollEnd();
+ EXPECT_FALSE(host_impl_->IsActivelyScrolling());
+}
+
TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) {
// We should not crash when trying to scroll an empty layer tree.
EXPECT_EQ(InputHandler::ScrollIgnored,
did_request_redraw_ = false;
did_request_animate_ = false;
- host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration);
+ host_impl_->active_tree()->SetPageScaleAnimation(
+ gfx::Vector2d(), false, 2.f, duration);
+ host_impl_->ActivateSyncTree();
EXPECT_FALSE(did_request_redraw_);
EXPECT_TRUE(did_request_animate_);
did_request_redraw_ = false;
did_request_animate_ = false;
- host_impl_->StartPageScaleAnimation(
+ host_impl_->active_tree()->SetPageScaleAnimation(
gfx::Vector2d(25, 25), true, min_page_scale, duration);
+ host_impl_->ActivateSyncTree();
EXPECT_FALSE(did_request_redraw_);
EXPECT_TRUE(did_request_animate_);
max_page_scale);
scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
- host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration);
+ host_impl_->active_tree()->SetPageScaleAnimation(
+ gfx::Vector2d(), true, 1.f, duration);
+ host_impl_->ActivateSyncTree();
host_impl_->Animate(start_time);
host_impl_->Animate(halfway_through_animation);
EXPECT_TRUE(did_request_redraw_);
}
}
+TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) {
+ host_impl_->CreatePendingTree();
+ CreateScrollAndContentsLayers(host_impl_->pending_tree(),
+ gfx::Size(100, 100));
+ host_impl_->ActivateSyncTree();
+ DrawFrame();
+
+ LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer();
+ DCHECK(scroll_layer);
+
+ float min_page_scale = 0.5f;
+ float max_page_scale = 4.f;
+ host_impl_->sync_tree()->SetPageScaleFactorAndLimits(
+ 1.f, min_page_scale, max_page_scale);
+ host_impl_->ActivateSyncTree();
+
+ base::TimeTicks start_time =
+ base::TimeTicks() + base::TimeDelta::FromSeconds(1);
+ base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
+ base::TimeTicks third_through_animation = start_time + duration / 3;
+ base::TimeTicks halfway_through_animation = start_time + duration / 2;
+ base::TimeTicks end_time = start_time + duration;
+ float target_scale = 2.f;
+
+ scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50));
+
+ // Make sure TakePageScaleAnimation works properly.
+ host_impl_->sync_tree()->SetPageScaleAnimation(
+ gfx::Vector2d(), false, target_scale, duration);
+ scoped_ptr<PageScaleAnimation> psa =
+ host_impl_->sync_tree()->TakePageScaleAnimation();
+ EXPECT_EQ(target_scale, psa->target_page_scale_factor());
+ EXPECT_EQ(duration, psa->duration());
+ EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation());
+
+ // Recreate the PSA. Nothing should happen here since the tree containing the
+ // PSA hasn't been activated yet.
+ did_request_redraw_ = false;
+ did_request_animate_ = false;
+ host_impl_->sync_tree()->SetPageScaleAnimation(
+ gfx::Vector2d(), false, target_scale, duration);
+ host_impl_->Animate(halfway_through_animation);
+ EXPECT_FALSE(did_request_animate_);
+ EXPECT_FALSE(did_request_redraw_);
+
+ // Activate the sync tree. This should cause the animation to become enabled.
+ // It should also clear the pointer on the sync tree.
+ host_impl_->ActivateSyncTree();
+ EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation().get());
+ EXPECT_FALSE(did_request_redraw_);
+ EXPECT_TRUE(did_request_animate_);
+
+ // From here on, make sure the animation runs as normal.
+ did_request_redraw_ = false;
+ did_request_animate_ = false;
+ host_impl_->Animate(start_time);
+ EXPECT_TRUE(did_request_redraw_);
+ EXPECT_TRUE(did_request_animate_);
+
+ did_request_redraw_ = false;
+ did_request_animate_ = false;
+ host_impl_->Animate(third_through_animation);
+ EXPECT_TRUE(did_request_redraw_);
+ EXPECT_TRUE(did_request_animate_);
+
+ // Another activation shouldn't have any effect on the animation.
+ host_impl_->ActivateSyncTree();
+
+ did_request_redraw_ = false;
+ did_request_animate_ = false;
+ host_impl_->Animate(halfway_through_animation);
+ EXPECT_TRUE(did_request_redraw_);
+ EXPECT_TRUE(did_request_animate_);
+
+ did_request_redraw_ = false;
+ did_request_animate_ = false;
+ did_request_commit_ = false;
+ host_impl_->Animate(end_time);
+ EXPECT_TRUE(did_request_commit_);
+ EXPECT_FALSE(did_request_animate_);
+
+ scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
+ EXPECT_EQ(scroll_info->page_scale_delta, target_scale);
+ ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
+}
+
class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl {
public:
LayerTreeHostImplOverridePhysicalTime(
}
void SetupTopControlsAndScrollLayer() {
- CreateHostImpl(settings_, CreateOutputSurface());
-
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_->active_tree(), 1);
scoped_ptr<LayerImpl> root_clip =
host_impl_->SetViewportSize(viewport_size_);
host_impl_->SetTopControlsLayoutHeight(
settings_.top_controls_height);
- LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
- EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
host_impl_->CreatePendingTree();
root =
host_impl_->SetViewportSize(viewport_size_);
host_impl_->sync_tree()->set_top_controls_layout_height(
settings_.top_controls_height);
- root_clip_ptr = host_impl_->sync_tree()->root_layer();
- EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
}
protected:
}; // class LayerTreeHostImplTopControlsTest
TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();
}
TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();
// Ensure setting the top controls position explicitly using the setters on the
// TreeImpl correctly affects the top controls manager and viewport bounds.
TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();
// applied on sync tree activation. The total top controls offset shouldn't
// change after the activation.
TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();
// height is the amount that the inner viewport container was shrunk outside
// the compositor to accommodate the top controls.
TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();
TEST_F(LayerTreeHostImplTopControlsTest,
ScrollNonScrollableRootWithTopControls) {
+ CreateHostImpl(settings_, CreateOutputSurface());
SetupTopControlsAndScrollLayer();
DrawFrame();