| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 root->SetIsContainerForFixedPositionLayers(true); | 2118 root->SetIsContainerForFixedPositionLayers(true); |
| 2119 int inner_viewport_scroll_layer_id = root->id(); | 2119 int inner_viewport_scroll_layer_id = root->id(); |
| 2120 int page_scale_layer_id = root_clip->id(); | 2120 int page_scale_layer_id = root_clip->id(); |
| 2121 root_clip->AddChild(root.Pass()); | 2121 root_clip->AddChild(root.Pass()); |
| 2122 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); | 2122 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2123 host_impl_->active_tree()->SetViewportLayersFromIds( | 2123 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 2124 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); | 2124 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); |
| 2125 // Set a viewport size that is large enough to contain both the top controls | 2125 // Set a viewport size that is large enough to contain both the top controls |
| 2126 // and some content. | 2126 // and some content. |
| 2127 host_impl_->SetViewportSize(viewport_size_); | 2127 host_impl_->SetViewportSize(viewport_size_); |
| 2128 host_impl_->active_tree()->set_top_controls_content_offset( |
| 2129 settings_.top_controls_height); |
| 2128 host_impl_->SetTopControlsLayoutHeight( | 2130 host_impl_->SetTopControlsLayoutHeight( |
| 2129 settings_.top_controls_height); | 2131 settings_.top_controls_height); |
| 2130 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2132 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2131 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); | 2133 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); |
| 2132 | 2134 |
| 2133 host_impl_->CreatePendingTree(); | 2135 host_impl_->CreatePendingTree(); |
| 2134 root = | 2136 root = |
| 2135 LayerImpl::Create(host_impl_->sync_tree(), 1); | 2137 LayerImpl::Create(host_impl_->sync_tree(), 1); |
| 2136 root_clip = | 2138 root_clip = |
| 2137 LayerImpl::Create(host_impl_->sync_tree(), 2); | 2139 LayerImpl::Create(host_impl_->sync_tree(), 2); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2218 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), | 2220 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), |
| 2219 tolerance); | 2221 tolerance); |
| 2220 } | 2222 } |
| 2221 | 2223 |
| 2222 // Ensure setting the top controls position explicitly using the setters on the | 2224 // Ensure setting the top controls position explicitly using the setters on the |
| 2223 // TreeImpl correctly affects the top controls manager and viewport bounds. | 2225 // TreeImpl correctly affects the top controls manager and viewport bounds. |
| 2224 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { | 2226 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
| 2225 SetupTopControlsAndScrollLayer(); | 2227 SetupTopControlsAndScrollLayer(); |
| 2226 DrawFrame(); | 2228 DrawFrame(); |
| 2227 | 2229 |
| 2228 host_impl_->active_tree()->set_top_controls_top_offset(-20.f); | 2230 host_impl_->active_tree()->set_top_controls_content_offset(30.f); |
| 2229 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2231 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2230 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); | 2232 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 2231 | 2233 |
| 2232 host_impl_->active_tree()->set_top_controls_delta(-30.f); | 2234 host_impl_->active_tree()->set_top_controls_delta(-30.f); |
| 2233 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2235 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2234 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); | 2236 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 2235 | 2237 |
| 2236 host_impl_->DidChangeTopControlsPosition(); | 2238 host_impl_->DidChangeTopControlsPosition(); |
| 2237 | 2239 |
| 2238 // Now that top controls have moved, expect the clip to resize. | 2240 // Now that top controls have moved, expect the clip to resize. |
| 2239 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2241 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2240 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); | 2242 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2241 } | 2243 } |
| 2242 | 2244 |
| 2243 // Test that the top_controls delta and sent delta are appropriately | 2245 // Test that the top_controls delta and sent delta are appropriately |
| 2244 // applied on sync tree activation. The total top controls offset shouldn't | 2246 // applied on sync tree activation. The total top controls offset shouldn't |
| 2245 // change after the activation. | 2247 // change after the activation. |
| 2246 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { | 2248 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { |
| 2247 SetupTopControlsAndScrollLayer(); | 2249 SetupTopControlsAndScrollLayer(); |
| 2248 DrawFrame(); | 2250 DrawFrame(); |
| 2249 | 2251 |
| 2250 host_impl_->sync_tree()->set_top_controls_top_offset(-35.f); | 2252 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); |
| 2251 | 2253 |
| 2252 host_impl_->active_tree()->set_top_controls_top_offset(-30.f); | 2254 host_impl_->active_tree()->set_top_controls_content_offset(20.f); |
| 2253 host_impl_->active_tree()->set_top_controls_delta(-20.f); | 2255 host_impl_->active_tree()->set_top_controls_delta(-20.f); |
| 2254 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); | 2256 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); |
| 2255 | 2257 |
| 2256 host_impl_->DidChangeTopControlsPosition(); | 2258 host_impl_->DidChangeTopControlsPosition(); |
| 2257 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2259 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2258 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); | 2260 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2259 | |
| 2260 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2261 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2262 EXPECT_EQ(0.f, |
| 2263 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2261 | 2264 |
| 2262 host_impl_->ActivateSyncTree(); | 2265 host_impl_->ActivateSyncTree(); |
| 2263 | 2266 |
| 2264 root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2267 root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2265 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2268 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2266 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); | 2269 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2267 | 2270 |
| 2268 EXPECT_EQ(0.f, host_impl_->active_tree()->sent_top_controls_delta()); | 2271 EXPECT_EQ(0.f, host_impl_->active_tree()->sent_top_controls_delta()); |
| 2269 EXPECT_EQ(-15.f, host_impl_->active_tree()->top_controls_delta()); | 2272 EXPECT_EQ(-15.f, host_impl_->active_tree()->top_controls_delta()); |
| 2270 EXPECT_EQ(-35.f, host_impl_->active_tree()->top_controls_top_offset()); | 2273 EXPECT_EQ(15.f, host_impl_->active_tree()->top_controls_content_offset()); |
| 2274 EXPECT_EQ(0.f, |
| 2275 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2271 } | 2276 } |
| 2272 | 2277 |
| 2273 // Test that changing the top controls layout height is correctly applied to | 2278 // Test that changing the top controls layout height is correctly applied to |
| 2274 // the inner viewport container bounds. That is, the top controls layout | 2279 // the inner viewport container bounds. That is, the top controls layout |
| 2275 // height is the amount that the inner viewport container was shrunk outside | 2280 // height is the amount that the inner viewport container was shrunk outside |
| 2276 // the compositor to accommodate the top controls. | 2281 // the compositor to accommodate the top controls. |
| 2277 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { | 2282 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { |
| 2278 SetupTopControlsAndScrollLayer(); | 2283 SetupTopControlsAndScrollLayer(); |
| 2279 DrawFrame(); | 2284 DrawFrame(); |
| 2280 | 2285 |
| 2281 host_impl_->sync_tree()->set_top_controls_top_offset(-35.f); | 2286 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); |
| 2282 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); | 2287 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); |
| 2283 | 2288 |
| 2284 host_impl_->active_tree()->set_top_controls_top_offset(-30.f); | 2289 host_impl_->active_tree()->set_top_controls_content_offset(20.f); |
| 2285 host_impl_->active_tree()->set_top_controls_delta(-20.f); | 2290 host_impl_->active_tree()->set_top_controls_delta(-20.f); |
| 2286 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); | 2291 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); |
| 2287 | 2292 |
| 2288 host_impl_->DidChangeTopControlsPosition(); | 2293 host_impl_->DidChangeTopControlsPosition(); |
| 2289 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2294 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2290 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); | 2295 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2291 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2296 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2292 | 2297 |
| 2293 host_impl_->sync_tree()->root_layer()->SetBounds( | 2298 host_impl_->sync_tree()->root_layer()->SetBounds( |
| 2294 gfx::Size(root_clip_ptr->bounds().width(), | 2299 gfx::Size(root_clip_ptr->bounds().width(), |
| (...skipping 4313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6608 SetupScrollAndContentsLayers(gfx::Size(100, 100)) | 6613 SetupScrollAndContentsLayers(gfx::Size(100, 100)) |
| 6609 ->SetScrollOffset(gfx::Vector2d(0, 10)); | 6614 ->SetScrollOffset(gfx::Vector2d(0, 10)); |
| 6610 host_impl_->DidChangeTopControlsPosition(); | 6615 host_impl_->DidChangeTopControlsPosition(); |
| 6611 EXPECT_TRUE(did_request_animate_); | 6616 EXPECT_TRUE(did_request_animate_); |
| 6612 EXPECT_TRUE(did_request_redraw_); | 6617 EXPECT_TRUE(did_request_redraw_); |
| 6613 } | 6618 } |
| 6614 | 6619 |
| 6615 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { | 6620 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
| 6616 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6621 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 6617 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 6622 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 6623 host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 6624 BOTH, SHOWN, false); |
| 6618 DrawFrame(); | 6625 DrawFrame(); |
| 6619 | 6626 |
| 6620 EXPECT_EQ(InputHandler::ScrollStarted, | 6627 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6621 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6628 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6622 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 6629 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 6623 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6630 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6624 scroll_layer->TotalScrollOffset().ToString()); | 6631 scroll_layer->TotalScrollOffset().ToString()); |
| 6625 | 6632 |
| 6626 // Scroll just the top controls and verify that the scroll succeeds. | 6633 // Scroll just the top controls and verify that the scroll succeeds. |
| 6627 const float residue = 10; | 6634 const float residue = 10; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6660 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 6667 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 6661 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6668 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6662 scroll_layer->TotalScrollOffset().ToString()); | 6669 scroll_layer->TotalScrollOffset().ToString()); |
| 6663 | 6670 |
| 6664 host_impl_->ScrollEnd(); | 6671 host_impl_->ScrollEnd(); |
| 6665 } | 6672 } |
| 6666 | 6673 |
| 6667 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { | 6674 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
| 6668 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6675 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 6669 host_impl_->SetViewportSize(gfx::Size(100, 200)); | 6676 host_impl_->SetViewportSize(gfx::Size(100, 200)); |
| 6677 host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 6678 BOTH, SHOWN, false); |
| 6670 DrawFrame(); | 6679 DrawFrame(); |
| 6671 | 6680 |
| 6672 EXPECT_EQ(InputHandler::ScrollStarted, | 6681 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6673 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6682 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6674 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 6683 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 6675 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6684 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6676 scroll_layer->TotalScrollOffset().ToString()); | 6685 scroll_layer->TotalScrollOffset().ToString()); |
| 6677 | 6686 |
| 6678 // Scroll the top controls partially. | 6687 // Scroll the top controls partially. |
| 6679 const float residue = 35; | 6688 const float residue = 35; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6724 EXPECT_TRUE(host_impl_->top_controls_manager()->animation()); | 6733 EXPECT_TRUE(host_impl_->top_controls_manager()->animation()); |
| 6725 EXPECT_TRUE(did_request_animate_); | 6734 EXPECT_TRUE(did_request_animate_); |
| 6726 } | 6735 } |
| 6727 } | 6736 } |
| 6728 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 6737 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 6729 } | 6738 } |
| 6730 | 6739 |
| 6731 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { | 6740 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { |
| 6732 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6741 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 6733 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 6742 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 6743 host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 6744 BOTH, SHOWN, false); |
| 6734 float initial_scroll_offset = 50; | 6745 float initial_scroll_offset = 50; |
| 6735 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); | 6746 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); |
| 6736 DrawFrame(); | 6747 DrawFrame(); |
| 6737 | 6748 |
| 6738 EXPECT_EQ(InputHandler::ScrollStarted, | 6749 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6739 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6750 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6740 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 6751 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 6741 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), | 6752 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 6742 scroll_layer->TotalScrollOffset().ToString()); | 6753 scroll_layer->TotalScrollOffset().ToString()); |
| 6743 | 6754 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7101 // surface. | 7112 // surface. |
| 7102 EXPECT_EQ(0, num_lost_surfaces_); | 7113 EXPECT_EQ(0, num_lost_surfaces_); |
| 7103 host_impl_->DidLoseOutputSurface(); | 7114 host_impl_->DidLoseOutputSurface(); |
| 7104 EXPECT_EQ(1, num_lost_surfaces_); | 7115 EXPECT_EQ(1, num_lost_surfaces_); |
| 7105 host_impl_->DidLoseOutputSurface(); | 7116 host_impl_->DidLoseOutputSurface(); |
| 7106 EXPECT_LE(1, num_lost_surfaces_); | 7117 EXPECT_LE(1, num_lost_surfaces_); |
| 7107 } | 7118 } |
| 7108 | 7119 |
| 7109 } // namespace | 7120 } // namespace |
| 7110 } // namespace cc | 7121 } // namespace cc |
| OLD | NEW |