OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 7000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7011 | 7011 |
7012 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { | 7012 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { |
7013 SetupScrollAndContentsLayers(gfx::Size(100, 100)) | 7013 SetupScrollAndContentsLayers(gfx::Size(100, 100)) |
7014 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); | 7014 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); |
7015 host_impl_->DidChangeTopControlsPosition(); | 7015 host_impl_->DidChangeTopControlsPosition(); |
7016 EXPECT_TRUE(did_request_animate_); | 7016 EXPECT_TRUE(did_request_animate_); |
7017 EXPECT_TRUE(did_request_redraw_); | 7017 EXPECT_TRUE(did_request_redraw_); |
7018 } | 7018 } |
7019 | 7019 |
7020 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { | 7020 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
| 7021 InputHandlerScrollResult result; |
7021 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 7022 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
7022 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 7023 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
7023 host_impl_->top_controls_manager()->UpdateTopControlsState( | 7024 host_impl_->top_controls_manager()->UpdateTopControlsState( |
7024 BOTH, SHOWN, false); | 7025 BOTH, SHOWN, false); |
7025 DrawFrame(); | 7026 DrawFrame(); |
7026 | 7027 |
7027 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 7028 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
7028 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 7029 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
7029 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7030 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
7030 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7031 EXPECT_EQ(gfx::Vector2dF().ToString(), |
7031 scroll_layer->CurrentScrollOffset().ToString()); | 7032 scroll_layer->CurrentScrollOffset().ToString()); |
7032 | 7033 |
7033 // Scroll just the top controls and verify that the scroll succeeds. | 7034 // Scroll just the top controls and verify that the scroll succeeds. |
7034 const float residue = 10; | 7035 const float residue = 10; |
7035 float offset = top_controls_height_ - residue; | 7036 float offset = top_controls_height_ - residue; |
7036 EXPECT_TRUE( | 7037 result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)); |
7037 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); | 7038 EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
| 7039 EXPECT_TRUE(result.did_scroll); |
7038 EXPECT_FLOAT_EQ(-offset, | 7040 EXPECT_FLOAT_EQ(-offset, |
7039 host_impl_->top_controls_manager()->ControlsTopOffset()); | 7041 host_impl_->top_controls_manager()->ControlsTopOffset()); |
7040 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7042 EXPECT_EQ(gfx::Vector2dF().ToString(), |
7041 scroll_layer->CurrentScrollOffset().ToString()); | 7043 scroll_layer->CurrentScrollOffset().ToString()); |
7042 | 7044 |
7043 // Scroll across the boundary | 7045 // Scroll across the boundary |
7044 const float content_scroll = 20; | 7046 const float content_scroll = 20; |
7045 offset = residue + content_scroll; | 7047 offset = residue + content_scroll; |
7046 EXPECT_TRUE( | 7048 result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)); |
7047 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); | 7049 EXPECT_TRUE(result.did_scroll); |
| 7050 EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
7048 EXPECT_EQ(-top_controls_height_, | 7051 EXPECT_EQ(-top_controls_height_, |
7049 host_impl_->top_controls_manager()->ControlsTopOffset()); | 7052 host_impl_->top_controls_manager()->ControlsTopOffset()); |
7050 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), | 7053 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
7051 scroll_layer->CurrentScrollOffset().ToString()); | 7054 scroll_layer->CurrentScrollOffset().ToString()); |
7052 | 7055 |
7053 // Now scroll back to the top of the content | 7056 // Now scroll back to the top of the content |
7054 offset = -content_scroll; | 7057 offset = -content_scroll; |
7055 EXPECT_TRUE( | 7058 result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)); |
7056 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); | 7059 EXPECT_TRUE(result.did_scroll); |
| 7060 EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
7057 EXPECT_EQ(-top_controls_height_, | 7061 EXPECT_EQ(-top_controls_height_, |
7058 host_impl_->top_controls_manager()->ControlsTopOffset()); | 7062 host_impl_->top_controls_manager()->ControlsTopOffset()); |
7059 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7063 EXPECT_EQ(gfx::Vector2dF().ToString(), |
7060 scroll_layer->CurrentScrollOffset().ToString()); | 7064 scroll_layer->CurrentScrollOffset().ToString()); |
7061 | 7065 |
7062 // And scroll the top controls completely into view | 7066 // And scroll the top controls completely into view |
7063 offset = -top_controls_height_; | 7067 offset = -top_controls_height_; |
7064 EXPECT_TRUE( | 7068 result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)); |
7065 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); | 7069 EXPECT_TRUE(result.did_scroll); |
| 7070 EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
7066 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7071 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
7067 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7072 EXPECT_EQ(gfx::Vector2dF().ToString(), |
7068 scroll_layer->CurrentScrollOffset().ToString()); | 7073 scroll_layer->CurrentScrollOffset().ToString()); |
7069 | 7074 |
7070 // And attempt to scroll past the end | 7075 // And attempt to scroll past the end |
7071 EXPECT_FALSE( | 7076 result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)); |
7072 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); | 7077 EXPECT_FALSE(result.did_scroll); |
| 7078 EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, -50)); |
7073 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7079 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
7074 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7080 EXPECT_EQ(gfx::Vector2dF().ToString(), |
7075 scroll_layer->CurrentScrollOffset().ToString()); | 7081 scroll_layer->CurrentScrollOffset().ToString()); |
7076 | 7082 |
7077 host_impl_->ScrollEnd(); | 7083 host_impl_->ScrollEnd(); |
7078 } | 7084 } |
7079 | 7085 |
7080 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { | 7086 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
7081 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 7087 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
7082 host_impl_->SetViewportSize(gfx::Size(100, 200)); | 7088 host_impl_->SetViewportSize(gfx::Size(100, 200)); |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8193 // Hold an unowned pointer to the output surface to use for mock expectations. | 8199 // Hold an unowned pointer to the output surface to use for mock expectations. |
8194 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); | 8200 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
8195 | 8201 |
8196 CreateHostImpl(DefaultSettings(), output_surface.Pass()); | 8202 CreateHostImpl(DefaultSettings(), output_surface.Pass()); |
8197 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); | 8203 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
8198 host_impl_->BeginCommit(); | 8204 host_impl_->BeginCommit(); |
8199 } | 8205 } |
8200 | 8206 |
8201 } // namespace | 8207 } // namespace |
8202 } // namespace cc | 8208 } // namespace cc |
OLD | NEW |