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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 clip->AddChild(page_scale.Pass()); | 250 clip->AddChild(page_scale.Pass()); |
251 root->AddChild(clip.Pass()); | 251 root->AddChild(clip.Pass()); |
252 | 252 |
253 layer_tree_impl->SetRootLayer(root.Pass()); | 253 layer_tree_impl->SetRootLayer(root.Pass()); |
254 layer_tree_impl->SetViewportLayersFromIds( | 254 layer_tree_impl->SetViewportLayersFromIds( |
255 kPageScaleLayerId, kInnerViewportScrollLayerId, Layer::INVALID_ID); | 255 kPageScaleLayerId, kInnerViewportScrollLayerId, Layer::INVALID_ID); |
256 | 256 |
257 return scroll_layer; | 257 return scroll_layer; |
258 } | 258 } |
259 | 259 |
260 void SetupVirtualViewportLayers(const gfx::Size& content_size) { | |
danakj
2014/02/19 22:49:24
Can you make a subclass of this class to put the m
bokan
2014/02/20 16:30:49
Done.
| |
261 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | |
262 const int kOuterViewportClipLayerId = 6; | |
263 const int kOuterViewportScrollLayerId = 7; | |
264 const int kInnerViewportScrollLayerId = 2; | |
265 const int kInnerViewportClipLayerId = 4; | |
266 const int kPageScaleLayerId = 5; | |
267 | |
268 scoped_ptr<LayerImpl> inner_scroll = | |
269 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); | |
270 inner_scroll->SetIsContainerForFixedPositionLayers(true); | |
271 inner_scroll->SetScrollOffset(gfx::Vector2d()); | |
272 | |
273 scoped_ptr<LayerImpl> inner_clip = | |
274 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); | |
275 inner_clip->SetBounds( | |
276 gfx::Size(content_size.width() / 4, content_size.height() / 4)); | |
danakj
2014/02/19 22:49:24
can you make the content_size/4 and content_size/2
bokan
2014/02/20 16:30:49
Done.
| |
277 | |
278 scoped_ptr<LayerImpl> page_scale = | |
279 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); | |
280 | |
281 inner_scroll->SetScrollClipLayer(inner_clip->id()); | |
282 inner_scroll->SetBounds(gfx::Size( | |
283 content_size.width() / 2, content_size.height() / 2)); | |
284 inner_scroll->SetContentBounds(gfx::Size( | |
285 content_size.width() / 2, content_size.height() / 2)); | |
286 inner_scroll->SetPosition(gfx::PointF()); | |
287 inner_scroll->SetAnchorPoint(gfx::PointF()); | |
288 | |
289 scoped_ptr<LayerImpl> outer_clip = | |
290 LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); | |
291 outer_clip->SetBounds( | |
292 gfx::Size(content_size.width() / 2, content_size.height() / 2)); | |
293 outer_clip->SetIsContainerForFixedPositionLayers(true); | |
294 | |
295 scoped_ptr<LayerImpl> outer_scroll = | |
296 LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); | |
297 outer_scroll->SetScrollClipLayer(outer_clip->id()); | |
298 outer_scroll->SetScrollOffset(gfx::Vector2d()); | |
299 outer_scroll->SetBounds(content_size); | |
300 outer_scroll->SetContentBounds(content_size); | |
301 outer_scroll->SetPosition(gfx::PointF()); | |
302 outer_scroll->SetAnchorPoint(gfx::PointF()); | |
303 | |
304 scoped_ptr<LayerImpl> contents = | |
305 LayerImpl::Create(layer_tree_impl, 8); | |
306 contents->SetDrawsContent(true); | |
307 contents->SetBounds(content_size); | |
308 contents->SetContentBounds(content_size); | |
309 contents->SetPosition(gfx::PointF()); | |
310 contents->SetAnchorPoint(gfx::PointF()); | |
311 | |
312 outer_scroll->AddChild(contents.Pass()); | |
313 outer_clip->AddChild(outer_scroll.Pass()); | |
314 inner_scroll->AddChild(outer_clip.Pass()); | |
315 page_scale->AddChild(inner_scroll.Pass()); | |
316 inner_clip->AddChild(page_scale.Pass()); | |
317 | |
318 layer_tree_impl->SetRootLayer(inner_clip.Pass()); | |
319 layer_tree_impl->SetViewportLayersFromIds(kPageScaleLayerId, | |
320 kInnerViewportScrollLayerId, kOuterViewportScrollLayerId); | |
321 | |
322 host_impl_->active_tree()->DidBecomeActive(); | |
323 } | |
324 | |
260 LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { | 325 LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { |
261 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( | 326 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
262 host_impl_->active_tree(), content_size); | 327 host_impl_->active_tree(), content_size); |
263 host_impl_->active_tree()->DidBecomeActive(); | 328 host_impl_->active_tree()->DidBecomeActive(); |
264 return scroll_layer; | 329 return scroll_layer; |
265 } | 330 } |
266 | 331 |
267 // TODO(wjmaclean) Add clip-layer pointer to parameters. | 332 // TODO(wjmaclean) Add clip-layer pointer to parameters. |
268 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, | 333 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, |
269 const gfx::Size& size, | 334 const gfx::Size& size, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 DrawFrame(); | 550 DrawFrame(); |
486 | 551 |
487 EXPECT_EQ(InputHandler::ScrollStarted, | 552 EXPECT_EQ(InputHandler::ScrollStarted, |
488 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 553 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
489 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 554 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
490 host_impl_->ScrollEnd(); | 555 host_impl_->ScrollEnd(); |
491 EXPECT_TRUE(did_request_redraw_); | 556 EXPECT_TRUE(did_request_redraw_); |
492 EXPECT_TRUE(did_request_commit_); | 557 EXPECT_TRUE(did_request_commit_); |
493 } | 558 } |
494 | 559 |
560 TEST_F(LayerTreeHostImplTest, FlingScrollBubblesToInner) { | |
561 SetupVirtualViewportLayers(gfx::Size(100, 100)); | |
562 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); | |
563 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); | |
564 DrawFrame(); | |
565 { | |
566 // Make sure the fling goes to the outer viewport first | |
567 EXPECT_EQ(InputHandler::ScrollStarted, | |
568 host_impl_->ScrollBegin(gfx::Point(), | |
569 InputHandler::Gesture)); | |
570 EXPECT_EQ(InputHandler::ScrollStarted, | |
571 host_impl_->FlingScrollBegin()); | |
572 gfx::Vector2d scroll_delta(25, 25); | |
573 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | |
574 host_impl_->ScrollEnd(); | |
575 EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->TotalScrollOffset()); | |
576 EXPECT_VECTOR_EQ(gfx::Vector2dF(25, 25), outer_scroll->TotalScrollOffset()); | |
577 | |
578 // Fling past the outer viewport boundry, make sure inner viewport scrolls. | |
579 EXPECT_EQ(InputHandler::ScrollStarted, | |
580 host_impl_->ScrollBegin(gfx::Point(), | |
581 InputHandler::Gesture)); | |
582 EXPECT_EQ(InputHandler::ScrollStarted, | |
583 host_impl_->FlingScrollBegin()); | |
584 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | |
585 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | |
586 host_impl_->ScrollEnd(); | |
587 EXPECT_VECTOR_EQ(gfx::Vector2dF(25, 25), inner_scroll->TotalScrollOffset()); | |
wjmaclean
2014/02/10 14:31:47
In order to see the bubbling happening in a 'singl
bokan
2014/02/10 15:04:52
I think that each ScrollUpdate from a fling can on
| |
588 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), outer_scroll->TotalScrollOffset()); | |
589 } | |
590 } | |
591 | |
495 TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { | 592 TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { |
496 // We should not crash when trying to scroll an empty layer tree. | 593 // We should not crash when trying to scroll an empty layer tree. |
497 EXPECT_EQ(InputHandler::ScrollIgnored, | 594 EXPECT_EQ(InputHandler::ScrollIgnored, |
498 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 595 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
499 } | 596 } |
500 | 597 |
501 TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) { | 598 TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) { |
502 scoped_ptr<TestWebGraphicsContext3D> context_owned = | 599 scoped_ptr<TestWebGraphicsContext3D> context_owned = |
503 TestWebGraphicsContext3D::Create(); | 600 TestWebGraphicsContext3D::Create(); |
504 context_owned->set_context_lost(true); | 601 context_owned->set_context_lost(true); |
(...skipping 5263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5768 &set_needs_redraw_count)); | 5865 &set_needs_redraw_count)); |
5769 // Empty damage rect won't signal the monitor. | 5866 // Empty damage rect won't signal the monitor. |
5770 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 5867 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
5771 EXPECT_EQ(0, set_needs_commit_count); | 5868 EXPECT_EQ(0, set_needs_commit_count); |
5772 EXPECT_EQ(2, set_needs_redraw_count); | 5869 EXPECT_EQ(2, set_needs_redraw_count); |
5773 } | 5870 } |
5774 } | 5871 } |
5775 | 5872 |
5776 } // namespace | 5873 } // namespace |
5777 } // namespace cc | 5874 } // namespace cc |
OLD | NEW |