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_->SetTopControlsLayoutHeight(settings_.top_controls_height); | 2128 host_impl_->SetTopControlsLayoutHeight( |
| 2129 settings_.top_controls_height); |
2129 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2130 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
2130 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); | 2131 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); |
| 2132 |
| 2133 host_impl_->CreatePendingTree(); |
| 2134 root = |
| 2135 LayerImpl::Create(host_impl_->sync_tree(), 1); |
| 2136 root_clip = |
| 2137 LayerImpl::Create(host_impl_->sync_tree(), 2); |
| 2138 root_clip->SetBounds(clip_size_); |
| 2139 root->SetScrollClipLayer(root_clip->id()); |
| 2140 root->SetBounds(layer_size_); |
| 2141 root->SetContentBounds(layer_size_); |
| 2142 root->SetPosition(gfx::PointF()); |
| 2143 root->SetDrawsContent(false); |
| 2144 root->SetIsContainerForFixedPositionLayers(true); |
| 2145 inner_viewport_scroll_layer_id = root->id(); |
| 2146 page_scale_layer_id = root_clip->id(); |
| 2147 root_clip->AddChild(root.Pass()); |
| 2148 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass()); |
| 2149 host_impl_->sync_tree()->SetViewportLayersFromIds( |
| 2150 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); |
| 2151 // Set a viewport size that is large enough to contain both the top controls |
| 2152 // and some content. |
| 2153 host_impl_->SetViewportSize(viewport_size_); |
| 2154 host_impl_->sync_tree()->set_top_controls_layout_height( |
| 2155 settings_.top_controls_height); |
| 2156 root_clip_ptr = host_impl_->sync_tree()->root_layer(); |
| 2157 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); |
2131 } | 2158 } |
2132 | 2159 |
2133 protected: | 2160 protected: |
2134 gfx::Size layer_size_; | 2161 gfx::Size layer_size_; |
2135 gfx::Size clip_size_; | 2162 gfx::Size clip_size_; |
2136 gfx::Size viewport_size_; | 2163 gfx::Size viewport_size_; |
2137 | 2164 |
2138 LayerTreeSettings settings_; | 2165 LayerTreeSettings settings_; |
2139 }; // class LayerTreeHostImplTopControlsTest | 2166 }; // class LayerTreeHostImplTopControlsTest |
2140 | 2167 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 | 2212 |
2186 // Use a tolerance that requires the container size delta to be within 0.01 | 2213 // Use a tolerance that requires the container size delta to be within 0.01 |
2187 // pixels. | 2214 // pixels. |
2188 double tolerance = 0.0001; | 2215 double tolerance = 0.0001; |
2189 EXPECT_LT( | 2216 EXPECT_LT( |
2190 (expected_container_size_delta - | 2217 (expected_container_size_delta - |
2191 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), | 2218 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), |
2192 tolerance); | 2219 tolerance); |
2193 } | 2220 } |
2194 | 2221 |
| 2222 // Ensure setting the top controls position explicitly using the setters on the |
| 2223 // TreeImpl correctly affects the top controls manager and viewport bounds. |
| 2224 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
| 2225 SetupTopControlsAndScrollLayer(); |
| 2226 DrawFrame(); |
| 2227 |
| 2228 host_impl_->active_tree()->set_top_controls_top_offset(-20.f); |
| 2229 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2230 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 2231 |
| 2232 host_impl_->active_tree()->set_top_controls_delta(-30.f); |
| 2233 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2234 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 2235 |
| 2236 host_impl_->DidChangeTopControlsPosition(); |
| 2237 |
| 2238 // Now that top controls have moved, expect the clip to resize. |
| 2239 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2240 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2241 } |
| 2242 |
| 2243 // Test that the top_controls delta and sent delta are appropriately |
| 2244 // applied on sync tree activation. The total top controls offset shouldn't |
| 2245 // change after the activation. |
| 2246 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { |
| 2247 SetupTopControlsAndScrollLayer(); |
| 2248 DrawFrame(); |
| 2249 |
| 2250 host_impl_->sync_tree()->set_top_controls_top_offset(-35.f); |
| 2251 |
| 2252 host_impl_->active_tree()->set_top_controls_top_offset(-30.f); |
| 2253 host_impl_->active_tree()->set_top_controls_delta(-20.f); |
| 2254 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); |
| 2255 |
| 2256 host_impl_->DidChangeTopControlsPosition(); |
| 2257 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2258 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2259 |
| 2260 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2261 |
| 2262 host_impl_->ActivateSyncTree(); |
| 2263 |
| 2264 root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2265 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2266 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2267 |
| 2268 EXPECT_EQ(0.f, host_impl_->active_tree()->sent_top_controls_delta()); |
| 2269 EXPECT_EQ(-15.f, host_impl_->active_tree()->top_controls_delta()); |
| 2270 EXPECT_EQ(-35.f, host_impl_->active_tree()->top_controls_top_offset()); |
| 2271 } |
| 2272 |
| 2273 // Test that changing the top controls layout height is correctly applied to |
| 2274 // the inner viewport container bounds. That is, the top controls layout |
| 2275 // height is the amount that the inner viewport container was shrunk outside |
| 2276 // the compositor to accommodate the top controls. |
| 2277 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { |
| 2278 SetupTopControlsAndScrollLayer(); |
| 2279 DrawFrame(); |
| 2280 |
| 2281 host_impl_->sync_tree()->set_top_controls_top_offset(-35.f); |
| 2282 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); |
| 2283 |
| 2284 host_impl_->active_tree()->set_top_controls_top_offset(-30.f); |
| 2285 host_impl_->active_tree()->set_top_controls_delta(-20.f); |
| 2286 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); |
| 2287 |
| 2288 host_impl_->DidChangeTopControlsPosition(); |
| 2289 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2290 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2291 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2292 |
| 2293 host_impl_->sync_tree()->root_layer()->SetBounds( |
| 2294 gfx::Size(root_clip_ptr->bounds().width(), |
| 2295 root_clip_ptr->bounds().height() - 15.f)); |
| 2296 |
| 2297 host_impl_->ActivateSyncTree(); |
| 2298 |
| 2299 root_clip_ptr = host_impl_->active_tree()->root_layer(); |
| 2300 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2301 |
| 2302 // The total bounds should remain unchanged since the bounds delta should |
| 2303 // account for the difference between the layout height and the current |
| 2304 // top controls offset. |
| 2305 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
| 2306 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 15.f), root_clip_ptr->bounds_delta()); |
| 2307 |
| 2308 host_impl_->active_tree()->set_top_controls_delta(0.f); |
| 2309 host_impl_->DidChangeTopControlsPosition(); |
| 2310 |
| 2311 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2312 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); |
| 2313 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f), |
| 2314 root_clip_ptr->bounds()); |
| 2315 } |
| 2316 |
2195 TEST_F(LayerTreeHostImplTopControlsTest, | 2317 TEST_F(LayerTreeHostImplTopControlsTest, |
2196 ScrollNonScrollableRootWithTopControls) { | 2318 ScrollNonScrollableRootWithTopControls) { |
2197 SetupTopControlsAndScrollLayer(); | 2319 SetupTopControlsAndScrollLayer(); |
2198 DrawFrame(); | 2320 DrawFrame(); |
2199 | 2321 |
2200 EXPECT_EQ(InputHandler::ScrollStarted, | 2322 EXPECT_EQ(InputHandler::ScrollStarted, |
2201 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2323 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
2202 | 2324 |
2203 host_impl_->top_controls_manager()->ScrollBegin(); | 2325 host_impl_->top_controls_manager()->ScrollBegin(); |
2204 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); | 2326 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
2205 host_impl_->top_controls_manager()->ScrollEnd(); | 2327 host_impl_->top_controls_manager()->ScrollEnd(); |
2206 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->content_top_offset()); | 2328 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
2207 // Now that top controls have moved, expect the clip to resize. | 2329 // Now that top controls have moved, expect the clip to resize. |
2208 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); | 2330 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); |
2209 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); | 2331 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); |
2210 | 2332 |
2211 host_impl_->ScrollEnd(); | 2333 host_impl_->ScrollEnd(); |
2212 | 2334 |
2213 EXPECT_EQ(InputHandler::ScrollStarted, | 2335 EXPECT_EQ(InputHandler::ScrollStarted, |
2214 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2336 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
2215 | 2337 |
2216 float scroll_increment_y = -25.f; | 2338 float scroll_increment_y = -25.f; |
2217 host_impl_->top_controls_manager()->ScrollBegin(); | 2339 host_impl_->top_controls_manager()->ScrollBegin(); |
2218 host_impl_->top_controls_manager()->ScrollBy( | 2340 host_impl_->top_controls_manager()->ScrollBy( |
2219 gfx::Vector2dF(0.f, scroll_increment_y)); | 2341 gfx::Vector2dF(0.f, scroll_increment_y)); |
2220 EXPECT_EQ(-scroll_increment_y, | 2342 EXPECT_EQ(-scroll_increment_y, |
2221 host_impl_->top_controls_manager()->content_top_offset()); | 2343 host_impl_->top_controls_manager()->ContentTopOffset()); |
2222 // Now that top controls have moved, expect the clip to resize. | 2344 // Now that top controls have moved, expect the clip to resize. |
2223 EXPECT_EQ(gfx::Size(viewport_size_.width(), | 2345 EXPECT_EQ(gfx::Size(viewport_size_.width(), |
2224 viewport_size_.height() + scroll_increment_y), | 2346 viewport_size_.height() + scroll_increment_y), |
2225 root_clip_ptr->bounds()); | 2347 root_clip_ptr->bounds()); |
2226 | 2348 |
2227 host_impl_->top_controls_manager()->ScrollBy( | 2349 host_impl_->top_controls_manager()->ScrollBy( |
2228 gfx::Vector2dF(0.f, scroll_increment_y)); | 2350 gfx::Vector2dF(0.f, scroll_increment_y)); |
2229 host_impl_->top_controls_manager()->ScrollEnd(); | 2351 host_impl_->top_controls_manager()->ScrollEnd(); |
2230 EXPECT_EQ(-2 * scroll_increment_y, | 2352 EXPECT_EQ(-2 * scroll_increment_y, |
2231 host_impl_->top_controls_manager()->content_top_offset()); | 2353 host_impl_->top_controls_manager()->ContentTopOffset()); |
2232 // Now that top controls have moved, expect the clip to resize. | 2354 // Now that top controls have moved, expect the clip to resize. |
2233 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); | 2355 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); |
2234 | 2356 |
2235 host_impl_->ScrollEnd(); | 2357 host_impl_->ScrollEnd(); |
2236 | 2358 |
2237 // Verify the layer is once-again non-scrollable. | 2359 // Verify the layer is once-again non-scrollable. |
2238 EXPECT_EQ( | 2360 EXPECT_EQ( |
2239 gfx::Vector2d(), | 2361 gfx::Vector2d(), |
2240 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); | 2362 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); |
2241 | 2363 |
(...skipping 4248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6490 EXPECT_TRUE(did_request_redraw_); | 6612 EXPECT_TRUE(did_request_redraw_); |
6491 } | 6613 } |
6492 | 6614 |
6493 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { | 6615 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
6494 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6616 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
6495 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 6617 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
6496 DrawFrame(); | 6618 DrawFrame(); |
6497 | 6619 |
6498 EXPECT_EQ(InputHandler::ScrollStarted, | 6620 EXPECT_EQ(InputHandler::ScrollStarted, |
6499 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6621 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
6500 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6622 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6501 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6623 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6502 scroll_layer->TotalScrollOffset().ToString()); | 6624 scroll_layer->TotalScrollOffset().ToString()); |
6503 | 6625 |
6504 // Scroll just the top controls and verify that the scroll succeeds. | 6626 // Scroll just the top controls and verify that the scroll succeeds. |
6505 const float residue = 10; | 6627 const float residue = 10; |
6506 float offset = top_controls_height_ - residue; | 6628 float offset = top_controls_height_ - residue; |
6507 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6629 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6508 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); | 6630 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6509 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6631 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6510 scroll_layer->TotalScrollOffset().ToString()); | 6632 scroll_layer->TotalScrollOffset().ToString()); |
6511 | 6633 |
6512 // Scroll across the boundary | 6634 // Scroll across the boundary |
6513 const float content_scroll = 20; | 6635 const float content_scroll = 20; |
6514 offset = residue + content_scroll; | 6636 offset = residue + content_scroll; |
6515 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6637 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6516 EXPECT_EQ(-top_controls_height_, | 6638 EXPECT_EQ(-top_controls_height_, |
6517 host_impl_->top_controls_manager()->controls_top_offset()); | 6639 host_impl_->top_controls_manager()->ControlsTopOffset()); |
6518 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), | 6640 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
6519 scroll_layer->TotalScrollOffset().ToString()); | 6641 scroll_layer->TotalScrollOffset().ToString()); |
6520 | 6642 |
6521 // Now scroll back to the top of the content | 6643 // Now scroll back to the top of the content |
6522 offset = -content_scroll; | 6644 offset = -content_scroll; |
6523 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6645 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6524 EXPECT_EQ(-top_controls_height_, | 6646 EXPECT_EQ(-top_controls_height_, |
6525 host_impl_->top_controls_manager()->controls_top_offset()); | 6647 host_impl_->top_controls_manager()->ControlsTopOffset()); |
6526 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6648 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6527 scroll_layer->TotalScrollOffset().ToString()); | 6649 scroll_layer->TotalScrollOffset().ToString()); |
6528 | 6650 |
6529 // And scroll the top controls completely into view | 6651 // And scroll the top controls completely into view |
6530 offset = -top_controls_height_; | 6652 offset = -top_controls_height_; |
6531 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6653 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6532 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6654 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6533 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6655 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6534 scroll_layer->TotalScrollOffset().ToString()); | 6656 scroll_layer->TotalScrollOffset().ToString()); |
6535 | 6657 |
6536 // And attempt to scroll past the end | 6658 // And attempt to scroll past the end |
6537 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6659 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6538 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6660 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6539 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6661 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6540 scroll_layer->TotalScrollOffset().ToString()); | 6662 scroll_layer->TotalScrollOffset().ToString()); |
6541 | 6663 |
6542 host_impl_->ScrollEnd(); | 6664 host_impl_->ScrollEnd(); |
6543 } | 6665 } |
6544 | 6666 |
6545 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { | 6667 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
6546 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6668 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
6547 host_impl_->SetViewportSize(gfx::Size(100, 200)); | 6669 host_impl_->SetViewportSize(gfx::Size(100, 200)); |
6548 DrawFrame(); | 6670 DrawFrame(); |
6549 | 6671 |
6550 EXPECT_EQ(InputHandler::ScrollStarted, | 6672 EXPECT_EQ(InputHandler::ScrollStarted, |
6551 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6673 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
6552 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6674 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6553 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6675 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6554 scroll_layer->TotalScrollOffset().ToString()); | 6676 scroll_layer->TotalScrollOffset().ToString()); |
6555 | 6677 |
6556 // Scroll the top controls partially. | 6678 // Scroll the top controls partially. |
6557 const float residue = 35; | 6679 const float residue = 35; |
6558 float offset = top_controls_height_ - residue; | 6680 float offset = top_controls_height_ - residue; |
6559 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6681 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6560 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); | 6682 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6561 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6683 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6562 scroll_layer->TotalScrollOffset().ToString()); | 6684 scroll_layer->TotalScrollOffset().ToString()); |
6563 | 6685 |
6564 did_request_redraw_ = false; | 6686 did_request_redraw_ = false; |
6565 did_request_animate_ = false; | 6687 did_request_animate_ = false; |
6566 did_request_commit_ = false; | 6688 did_request_commit_ = false; |
6567 | 6689 |
6568 // End the scroll while the controls are still offset from their limit. | 6690 // End the scroll while the controls are still offset from their limit. |
6569 host_impl_->ScrollEnd(); | 6691 host_impl_->ScrollEnd(); |
6570 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); | 6692 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); |
6571 EXPECT_TRUE(did_request_animate_); | 6693 EXPECT_TRUE(did_request_animate_); |
6572 EXPECT_TRUE(did_request_redraw_); | 6694 EXPECT_TRUE(did_request_redraw_); |
6573 EXPECT_FALSE(did_request_commit_); | 6695 EXPECT_FALSE(did_request_commit_); |
6574 | 6696 |
6575 // The top controls should properly animate until finished, despite the scroll | 6697 // The top controls should properly animate until finished, despite the scroll |
6576 // offset being at the origin. | 6698 // offset being at the origin. |
6577 base::TimeTicks animation_time = gfx::FrameTime::Now(); | 6699 base::TimeTicks animation_time = gfx::FrameTime::Now(); |
6578 while (did_request_animate_) { | 6700 while (did_request_animate_) { |
6579 did_request_redraw_ = false; | 6701 did_request_redraw_ = false; |
6580 did_request_animate_ = false; | 6702 did_request_animate_ = false; |
6581 did_request_commit_ = false; | 6703 did_request_commit_ = false; |
6582 | 6704 |
6583 float old_offset = | 6705 float old_offset = |
6584 host_impl_->top_controls_manager()->controls_top_offset(); | 6706 host_impl_->top_controls_manager()->ControlsTopOffset(); |
6585 | 6707 |
6586 animation_time += base::TimeDelta::FromMilliseconds(5); | 6708 animation_time += base::TimeDelta::FromMilliseconds(5); |
6587 host_impl_->Animate(animation_time); | 6709 host_impl_->Animate(animation_time); |
6588 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6710 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6589 scroll_layer->TotalScrollOffset().ToString()); | 6711 scroll_layer->TotalScrollOffset().ToString()); |
6590 | 6712 |
6591 float new_offset = | 6713 float new_offset = |
6592 host_impl_->top_controls_manager()->controls_top_offset(); | 6714 host_impl_->top_controls_manager()->ControlsTopOffset(); |
6593 | 6715 |
6594 // No commit is needed as the controls are animating the content offset, | 6716 // No commit is needed as the controls are animating the content offset, |
6595 // not the scroll offset. | 6717 // not the scroll offset. |
6596 EXPECT_FALSE(did_request_commit_); | 6718 EXPECT_FALSE(did_request_commit_); |
6597 | 6719 |
6598 if (new_offset != old_offset) | 6720 if (new_offset != old_offset) |
6599 EXPECT_TRUE(did_request_redraw_); | 6721 EXPECT_TRUE(did_request_redraw_); |
6600 | 6722 |
6601 if (new_offset != 0) { | 6723 if (new_offset != 0) { |
6602 EXPECT_TRUE(host_impl_->top_controls_manager()->animation()); | 6724 EXPECT_TRUE(host_impl_->top_controls_manager()->animation()); |
6603 EXPECT_TRUE(did_request_animate_); | 6725 EXPECT_TRUE(did_request_animate_); |
6604 } | 6726 } |
6605 } | 6727 } |
6606 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 6728 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
6607 } | 6729 } |
6608 | 6730 |
6609 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { | 6731 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { |
6610 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 6732 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
6611 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 6733 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
6612 float initial_scroll_offset = 50; | 6734 float initial_scroll_offset = 50; |
6613 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); | 6735 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); |
6614 DrawFrame(); | 6736 DrawFrame(); |
6615 | 6737 |
6616 EXPECT_EQ(InputHandler::ScrollStarted, | 6738 EXPECT_EQ(InputHandler::ScrollStarted, |
6617 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6739 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
6618 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6740 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6619 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), | 6741 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
6620 scroll_layer->TotalScrollOffset().ToString()); | 6742 scroll_layer->TotalScrollOffset().ToString()); |
6621 | 6743 |
6622 // Scroll the top controls partially. | 6744 // Scroll the top controls partially. |
6623 const float residue = 15; | 6745 const float residue = 15; |
6624 float offset = top_controls_height_ - residue; | 6746 float offset = top_controls_height_ - residue; |
6625 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6747 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6626 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); | 6748 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
6627 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), | 6749 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
6628 scroll_layer->TotalScrollOffset().ToString()); | 6750 scroll_layer->TotalScrollOffset().ToString()); |
6629 | 6751 |
6630 did_request_redraw_ = false; | 6752 did_request_redraw_ = false; |
6631 did_request_animate_ = false; | 6753 did_request_animate_ = false; |
6632 did_request_commit_ = false; | 6754 did_request_commit_ = false; |
6633 | 6755 |
6634 // End the scroll while the controls are still offset from the limit. | 6756 // End the scroll while the controls are still offset from the limit. |
6635 host_impl_->ScrollEnd(); | 6757 host_impl_->ScrollEnd(); |
6636 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); | 6758 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); |
6637 EXPECT_TRUE(did_request_animate_); | 6759 EXPECT_TRUE(did_request_animate_); |
6638 EXPECT_TRUE(did_request_redraw_); | 6760 EXPECT_TRUE(did_request_redraw_); |
6639 EXPECT_FALSE(did_request_commit_); | 6761 EXPECT_FALSE(did_request_commit_); |
6640 | 6762 |
6641 // Animate the top controls to the limit. | 6763 // Animate the top controls to the limit. |
6642 base::TimeTicks animation_time = gfx::FrameTime::Now(); | 6764 base::TimeTicks animation_time = gfx::FrameTime::Now(); |
6643 while (did_request_animate_) { | 6765 while (did_request_animate_) { |
6644 did_request_redraw_ = false; | 6766 did_request_redraw_ = false; |
6645 did_request_animate_ = false; | 6767 did_request_animate_ = false; |
6646 did_request_commit_ = false; | 6768 did_request_commit_ = false; |
6647 | 6769 |
6648 float old_offset = | 6770 float old_offset = |
6649 host_impl_->top_controls_manager()->controls_top_offset(); | 6771 host_impl_->top_controls_manager()->ControlsTopOffset(); |
6650 | 6772 |
6651 animation_time += base::TimeDelta::FromMilliseconds(5); | 6773 animation_time += base::TimeDelta::FromMilliseconds(5); |
6652 host_impl_->Animate(animation_time); | 6774 host_impl_->Animate(animation_time); |
6653 | 6775 |
6654 float new_offset = | 6776 float new_offset = |
6655 host_impl_->top_controls_manager()->controls_top_offset(); | 6777 host_impl_->top_controls_manager()->ControlsTopOffset(); |
6656 | 6778 |
6657 if (new_offset != old_offset) { | 6779 if (new_offset != old_offset) { |
6658 EXPECT_TRUE(did_request_redraw_); | 6780 EXPECT_TRUE(did_request_redraw_); |
6659 EXPECT_TRUE(did_request_commit_); | 6781 EXPECT_TRUE(did_request_commit_); |
6660 } | 6782 } |
6661 } | 6783 } |
6662 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 6784 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
6663 } | 6785 } |
6664 | 6786 |
6665 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 6787 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6979 // surface. | 7101 // surface. |
6980 EXPECT_EQ(0, num_lost_surfaces_); | 7102 EXPECT_EQ(0, num_lost_surfaces_); |
6981 host_impl_->DidLoseOutputSurface(); | 7103 host_impl_->DidLoseOutputSurface(); |
6982 EXPECT_EQ(1, num_lost_surfaces_); | 7104 EXPECT_EQ(1, num_lost_surfaces_); |
6983 host_impl_->DidLoseOutputSurface(); | 7105 host_impl_->DidLoseOutputSurface(); |
6984 EXPECT_LE(1, num_lost_surfaces_); | 7106 EXPECT_LE(1, num_lost_surfaces_); |
6985 } | 7107 } |
6986 | 7108 |
6987 } // namespace | 7109 } // namespace |
6988 } // namespace cc | 7110 } // namespace cc |
OLD | NEW |