Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 737943002: Update from https://crrev.com/304715 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_pixeltest_masks.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2312 host_impl_->SetViewportSize(viewport_size_); 2312 host_impl_->SetViewportSize(viewport_size_);
2313 host_impl_->sync_tree()->set_top_controls_layout_height( 2313 host_impl_->sync_tree()->set_top_controls_layout_height(
2314 settings_.top_controls_height); 2314 settings_.top_controls_height);
2315 } 2315 }
2316 2316
2317 void SetupTopControlsAndScrollLayerWithVirtualViewport( 2317 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2318 const gfx::Size& inner_viewport_size, 2318 const gfx::Size& inner_viewport_size,
2319 const gfx::Size& outer_viewport_size, 2319 const gfx::Size& outer_viewport_size,
2320 const gfx::Size& scroll_layer_size) { 2320 const gfx::Size& scroll_layer_size) {
2321 CreateHostImpl(settings_, CreateOutputSurface()); 2321 CreateHostImpl(settings_, CreateOutputSurface());
2322 host_impl_->SetTopControlsLayoutHeight(
2323 settings_.top_controls_height);
2322 2324
2323 scoped_ptr<LayerImpl> root = 2325 scoped_ptr<LayerImpl> root =
2324 LayerImpl::Create(host_impl_->active_tree(), 1); 2326 LayerImpl::Create(host_impl_->active_tree(), 1);
2325 scoped_ptr<LayerImpl> root_clip = 2327 scoped_ptr<LayerImpl> root_clip =
2326 LayerImpl::Create(host_impl_->active_tree(), 2); 2328 LayerImpl::Create(host_impl_->active_tree(), 2);
2327 scoped_ptr<LayerImpl> page_scale = 2329 scoped_ptr<LayerImpl> page_scale =
2328 LayerImpl::Create(host_impl_->active_tree(), 3); 2330 LayerImpl::Create(host_impl_->active_tree(), 3);
2329 2331
2330 scoped_ptr<LayerImpl> outer_scroll = 2332 scoped_ptr<LayerImpl> outer_scroll =
2331 LayerImpl::Create(host_impl_->active_tree(), 4); 2333 LayerImpl::Create(host_impl_->active_tree(), 4);
(...skipping 25 matching lines...) Expand all
2357 page_scale->AddChild(root.Pass()); 2359 page_scale->AddChild(root.Pass());
2358 root_clip->AddChild(page_scale.Pass()); 2360 root_clip->AddChild(page_scale.Pass());
2359 2361
2360 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 2362 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
2361 host_impl_->active_tree()->SetViewportLayersFromIds( 2363 host_impl_->active_tree()->SetViewportLayersFromIds(
2362 page_scale_layer_id, 2364 page_scale_layer_id,
2363 inner_viewport_scroll_layer_id, 2365 inner_viewport_scroll_layer_id,
2364 outer_viewport_scroll_layer_id); 2366 outer_viewport_scroll_layer_id);
2365 2367
2366 host_impl_->SetViewportSize(inner_viewport_size); 2368 host_impl_->SetViewportSize(inner_viewport_size);
2367 host_impl_->SetTopControlsLayoutHeight(
2368 settings_.top_controls_height);
2369 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2369 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2370 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); 2370 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds());
2371 } 2371 }
2372 2372
2373 protected: 2373 protected:
2374 gfx::Size layer_size_; 2374 gfx::Size layer_size_;
2375 gfx::Size clip_size_; 2375 gfx::Size clip_size_;
2376 gfx::Size viewport_size_; 2376 gfx::Size viewport_size_;
2377 2377
2378 LayerTreeSettings settings_; 2378 LayerTreeSettings settings_;
(...skipping 16 matching lines...) Expand all
2395 host_impl_->top_controls_manager()->ScrollEnd(); 2395 host_impl_->top_controls_manager()->ScrollEnd();
2396 2396
2397 LayerImpl* inner_viewport_scroll_layer = 2397 LayerImpl* inner_viewport_scroll_layer =
2398 host_impl_->active_tree()->InnerViewportScrollLayer(); 2398 host_impl_->active_tree()->InnerViewportScrollLayer();
2399 DCHECK(inner_viewport_scroll_layer); 2399 DCHECK(inner_viewport_scroll_layer);
2400 host_impl_->ScrollEnd(); 2400 host_impl_->ScrollEnd();
2401 EXPECT_EQ(top_controls_scroll_delta, 2401 EXPECT_EQ(top_controls_scroll_delta,
2402 inner_viewport_scroll_layer->FixedContainerSizeDelta()); 2402 inner_viewport_scroll_layer->FixedContainerSizeDelta());
2403 } 2403 }
2404 2404
2405 // In this test, the outer viewport is initially unscrollable. We test that a
2406 // scroll initiated on the inner viewport, causing the top controls to show and
2407 // thus making the outer viewport scrollable, still scrolls the outer viewport.
2408 TEST_F(LayerTreeHostImplTopControlsTest,
2409 TopControlsOuterViewportBecomesScrollable) {
2410 SetupTopControlsAndScrollLayerWithVirtualViewport(
2411 gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100));
2412 DrawFrame();
2413
2414 LayerImpl *inner_scroll =
2415 host_impl_->active_tree()->InnerViewportScrollLayer();
2416 LayerImpl *inner_container =
2417 host_impl_->active_tree()->InnerViewportContainerLayer();
2418 LayerImpl *outer_scroll =
2419 host_impl_->active_tree()->OuterViewportScrollLayer();
2420 LayerImpl *outer_container =
2421 host_impl_->active_tree()->OuterViewportContainerLayer();
2422
2423 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer.
2424 outer_scroll->SetDrawsContent(true);
2425 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 1.f, 2.f);
2426
2427 EXPECT_EQ(InputHandler::ScrollStarted,
2428 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2429 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f));
2430
2431 // The entire scroll delta should have been used to hide the top controls.
2432 // The viewport layers should be resized back to their full sizes.
2433 EXPECT_EQ(0.f,
2434 host_impl_->active_tree()->total_top_controls_content_offset());
2435 EXPECT_EQ(0.f, inner_scroll->TotalScrollOffset().y());
2436 EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height());
2437 EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height());
2438
2439 // The inner viewport should be scrollable by 50px * page_scale.
2440 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 100.f));
2441 EXPECT_EQ(50.f, inner_scroll->TotalScrollOffset().y());
2442 EXPECT_EQ(0.f, outer_scroll->TotalScrollOffset().y());
2443 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset());
2444
2445 host_impl_->ScrollEnd();
2446
2447 EXPECT_EQ(InputHandler::ScrollStarted,
2448 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2449 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll);
2450
2451 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f));
2452
2453 // The entire scroll delta should have been used to show the top controls.
2454 // The outer viewport should be resized to accomodate and scrolled to the
2455 // bottom of the document to keep the viewport in place.
2456 EXPECT_EQ(50.f,
2457 host_impl_->active_tree()->total_top_controls_content_offset());
2458 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height());
2459 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height());
2460 EXPECT_EQ(25.f, outer_scroll->TotalScrollOffset().y());
2461 EXPECT_EQ(25.f, inner_scroll->TotalScrollOffset().y());
2462
2463 // Now when we continue scrolling, make sure the outer viewport gets scrolled
2464 // since it wasn't scrollable when the scroll began.
2465 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -20.f));
2466 EXPECT_EQ(15.f, outer_scroll->TotalScrollOffset().y());
2467 EXPECT_EQ(25.f, inner_scroll->TotalScrollOffset().y());
2468
2469 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -30.f));
2470 EXPECT_EQ(0.f, outer_scroll->TotalScrollOffset().y());
2471 EXPECT_EQ(25.f, inner_scroll->TotalScrollOffset().y());
2472
2473 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f));
2474 host_impl_->ScrollEnd();
2475
2476 EXPECT_EQ(0.f, outer_scroll->TotalScrollOffset().y());
2477 EXPECT_EQ(0.f, inner_scroll->TotalScrollOffset().y());
2478 }
2479
2405 // Test that the fixed position container delta is appropriately adjusted 2480 // Test that the fixed position container delta is appropriately adjusted
2406 // by the top controls showing/hiding and page scale doesn't affect it. 2481 // by the top controls showing/hiding and page scale doesn't affect it.
2407 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { 2482 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) {
2408 SetupTopControlsAndScrollLayerWithVirtualViewport( 2483 SetupTopControlsAndScrollLayerWithVirtualViewport(
2409 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); 2484 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100));
2410 DrawFrame(); 2485 DrawFrame();
2411 2486
2412 float page_scale = 1.5f; 2487 float page_scale = 1.5f;
2413 float top_controls_height = settings_.top_controls_height; 2488 float top_controls_height = settings_.top_controls_height;
2414 LayerImpl* outer_viewport_scroll_layer = 2489 LayerImpl* outer_viewport_scroll_layer =
(...skipping 5259 matching lines...) Expand 10 before | Expand all | Expand 10 after
7674 // surface. 7749 // surface.
7675 EXPECT_EQ(0, num_lost_surfaces_); 7750 EXPECT_EQ(0, num_lost_surfaces_);
7676 host_impl_->DidLoseOutputSurface(); 7751 host_impl_->DidLoseOutputSurface();
7677 EXPECT_EQ(1, num_lost_surfaces_); 7752 EXPECT_EQ(1, num_lost_surfaces_);
7678 host_impl_->DidLoseOutputSurface(); 7753 host_impl_->DidLoseOutputSurface();
7679 EXPECT_LE(1, num_lost_surfaces_); 7754 EXPECT_LE(1, num_lost_surfaces_);
7680 } 7755 }
7681 7756
7682 } // namespace 7757 } // namespace
7683 } // namespace cc 7758 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_pixeltest_masks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698