Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 10140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10151 last_on_draw_frame_.reset(); | 10151 last_on_draw_frame_.reset(); |
| 10152 | 10152 |
| 10153 // Different draw params does swap. | 10153 // Different draw params does swap. |
| 10154 did_request_redraw_ = false; | 10154 did_request_redraw_ = false; |
| 10155 host_impl_->OnDraw(draw_transform, draw_viewport2, | 10155 host_impl_->OnDraw(draw_transform, draw_viewport2, |
| 10156 resourceless_software_draw); | 10156 resourceless_software_draw); |
| 10157 EXPECT_TRUE(did_request_redraw_); | 10157 EXPECT_TRUE(did_request_redraw_); |
| 10158 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); | 10158 EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 10159 } | 10159 } |
| 10160 | 10160 |
| 10161 // We will force the touch event handler to be passive if we touch on a | 10161 // We will force the touch event handler to be passive if we touch on a layer |
| 10162 // layer which is the current scrolling layer or its descendant. | 10162 // which is the current scrolling layer. |
| 10163 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) { | 10163 TEST_F(LayerTreeHostImplTest, TouchInsideFlingLayer) { |
| 10164 gfx::Size surface_size(100, 100); | 10164 gfx::Size surface_size(100, 100); |
| 10165 gfx::Size inner_size(50, 50); | 10165 gfx::Size content_size(200, 200); |
| 10166 | 10166 |
| 10167 LayerImpl* root = | 10167 LayerImpl* root = |
| 10168 CreateBasicVirtualViewportLayers(surface_size, surface_size); | 10168 CreateBasicVirtualViewportLayers(surface_size, surface_size); |
| 10169 root->test_properties()->force_render_surface = true; | 10169 root->test_properties()->force_render_surface = true; |
| 10170 | 10170 |
| 10171 // A div layer which has an event handler. | |
| 10171 std::unique_ptr<LayerImpl> child = | 10172 std::unique_ptr<LayerImpl> child = |
| 10172 CreateScrollableLayer(26, surface_size, root); | 10173 CreateScrollableLayer(26, surface_size, root); |
| 10173 LayerImpl* child_layer = child.get(); | 10174 LayerImpl* child_layer = child.get(); |
| 10174 | 10175 |
| 10176 // The layer tree should create a layer for the div layer, which is the | |
| 10177 // actual scrolling layer. | |
| 10175 std::unique_ptr<LayerImpl> grand_child = | 10178 std::unique_ptr<LayerImpl> grand_child = |
| 10176 CreateScrollableLayer(27, inner_size, root); | 10179 CreateScrollableLayer(27, content_size, root); |
| 10177 LayerImpl* grand_child_layer = grand_child.get(); | 10180 LayerImpl* grand_child_layer = grand_child.get(); |
| 10181 | |
| 10178 child->test_properties()->AddChild(std::move(grand_child)); | 10182 child->test_properties()->AddChild(std::move(grand_child)); |
| 10179 root->test_properties()->AddChild(std::move(child)); | 10183 root->test_properties()->AddChild(std::move(child)); |
| 10180 | 10184 |
| 10185 host_impl_->SetViewportSize(surface_size); | |
| 10181 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 10186 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 10182 host_impl_->active_tree()->DidBecomeActive(); | 10187 host_impl_->active_tree()->DidBecomeActive(); |
| 10183 DrawFrame(); | 10188 DrawFrame(); |
| 10184 | 10189 |
| 10185 { | 10190 { |
| 10186 // Touch on a layer which does not have a handler will return kNone. | 10191 // Touch on a layer which does not have a handler will return kNone. |
| 10187 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER, | 10192 EXPECT_EQ(InputHandler::TouchStartEventListenerType::NO_HANDLER, |
| 10188 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); | 10193 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); |
| 10189 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | 10194 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 10190 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | |
| 10191 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, | 10195 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, |
| 10192 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); | 10196 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(10, 10))); |
| 10193 // Flinging the child layer. | 10197 // Flinging the grand_child layer. |
| 10194 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 10198 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10195 host_impl_ | 10199 host_impl_ |
| 10196 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(), | 10200 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(), |
| 10201 InputHandler::TOUCHSCREEN) | |
| 10202 .thread); | |
| 10203 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | |
| 10204 host_impl_->FlingScrollBegin().thread); | |
| 10205 EXPECT_EQ(grand_child_layer->scroll_tree_index(), | |
| 10206 host_impl_->CurrentlyScrollingNode()->id); | |
| 10207 // Touch on the grand_child layer, which is an active fling layer, the touch | |
| 10208 // event handler will force to be passive. | |
| 10209 EXPECT_EQ( | |
| 10210 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, | |
| 10211 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80))); | |
| 10212 } | |
| 10213 } | |
| 10214 | |
| 10215 // We will force the touch event handler to be passive if we touch on a layer | |
| 10216 // which is a descendant of the current scrolling layer. If we touch on its | |
| 10217 // ancestor, then the touch event handler will still be blocked. | |
| 10218 TEST_F(LayerTreeHostImplTest, TouchInsideOrOutsideFlingLayer) { | |
| 10219 gfx::Size surface_size(100, 100); | |
| 10220 gfx::Size content_size(200, 200); | |
| 10221 gfx::Size inner_size(50, 50); | |
| 10222 | |
| 10223 LayerImpl* root = | |
| 10224 CreateBasicVirtualViewportLayers(surface_size, surface_size); | |
| 10225 root->test_properties()->force_render_surface = true; | |
| 10226 | |
| 10227 // A div layer which has an event handler. | |
| 10228 std::unique_ptr<LayerImpl> child = | |
|
weiliangc
2017/03/22 18:11:31
Could pdr@ confirm that this is what the "layer tr
| |
| 10229 CreateScrollableLayer(26, surface_size, root); | |
| 10230 LayerImpl* child_layer = child.get(); | |
| 10231 | |
| 10232 // The layer tree should create a layer for the div layer, which is the | |
| 10233 // actual scrolling layer. | |
| 10234 std::unique_ptr<LayerImpl> grand_child = | |
| 10235 CreateScrollableLayer(27, content_size, root); | |
| 10236 LayerImpl* grand_child_layer = grand_child.get(); | |
| 10237 | |
| 10238 // A child scrollable layer inside grand_child_layer. | |
| 10239 std::unique_ptr<LayerImpl> great_grand_child = | |
| 10240 CreateScrollableLayer(28, inner_size, root); | |
| 10241 LayerImpl* great_grand_child_layer = great_grand_child.get(); | |
| 10242 | |
| 10243 grand_child->test_properties()->AddChild(std::move(great_grand_child)); | |
| 10244 child->test_properties()->AddChild(std::move(grand_child)); | |
| 10245 root->test_properties()->AddChild(std::move(child)); | |
| 10246 | |
| 10247 host_impl_->SetViewportSize(surface_size); | |
| 10248 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | |
| 10249 host_impl_->active_tree()->DidBecomeActive(); | |
| 10250 DrawFrame(); | |
| 10251 | |
| 10252 { | |
| 10253 child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | |
| 10254 grand_child_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); | |
| 10255 // Flinging the grand_child layer. | |
| 10256 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | |
| 10257 host_impl_ | |
| 10258 ->ScrollBegin(BeginState(gfx::Point(60, 60)).get(), | |
| 10197 InputHandler::TOUCHSCREEN) | 10259 InputHandler::TOUCHSCREEN) |
| 10198 .thread); | 10260 .thread); |
| 10199 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 10261 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10200 host_impl_->FlingScrollBegin().thread); | 10262 host_impl_->FlingScrollBegin().thread); |
| 10201 EXPECT_EQ(child_layer->scroll_tree_index(), | 10263 EXPECT_EQ(grand_child_layer->scroll_tree_index(), |
| 10202 host_impl_->CurrentlyScrollingNode()->id); | 10264 host_impl_->CurrentlyScrollingNode()->id); |
| 10203 // Touch on the child layer, which is an active fling layer, the touch | 10265 // Touch on the grand_child layer, which is an active fling layer, the touch |
| 10204 // event handler will force to be passive. | 10266 // event handler will force to be passive. |
| 10205 EXPECT_EQ( | 10267 EXPECT_EQ( |
| 10206 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, | 10268 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, |
| 10207 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80))); | 10269 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(70, 80))); |
| 10208 // Touch on the grand child layer, which is a descendant of an active fling | 10270 // Touch on the great_grand_child_layer layer, which is the child of the |
| 10209 // layer, the touch event handler will force to be passive. | 10271 // active fling layer, the touch event handler will force to be passive. |
| 10210 EXPECT_EQ( | 10272 EXPECT_EQ( |
| 10211 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, | 10273 InputHandler::TouchStartEventListenerType::HANDLER_ON_SCROLLING_LAYER, |
| 10212 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30))); | 10274 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(20, 30))); |
| 10213 | 10275 |
| 10214 // Now flinging on the grand child layer. | 10276 // Now flinging on the great_grand_child_layer. |
| 10215 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 10277 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10216 host_impl_ | 10278 host_impl_ |
| 10217 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), | 10279 ->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 10218 InputHandler::TOUCHSCREEN) | 10280 InputHandler::TOUCHSCREEN) |
| 10219 .thread); | 10281 .thread); |
| 10220 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 10282 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10221 host_impl_->FlingScrollBegin().thread); | 10283 host_impl_->FlingScrollBegin().thread); |
| 10222 EXPECT_EQ(grand_child_layer->scroll_tree_index(), | 10284 EXPECT_EQ(great_grand_child_layer->scroll_tree_index(), |
| 10223 host_impl_->CurrentlyScrollingNode()->id); | 10285 host_impl_->CurrentlyScrollingNode()->id); |
| 10224 // Touch on the child layer, the touch event handler will still be blocking. | 10286 // Touch on the child layer, the touch event handler will be blocked. |
| 10225 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, | 10287 EXPECT_EQ(InputHandler::TouchStartEventListenerType::HANDLER, |
| 10226 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60))); | 10288 host_impl_->EventListenerTypeForTouchStartAt(gfx::Point(60, 60))); |
| 10227 } | 10289 } |
| 10228 } | 10290 } |
| 10229 | 10291 |
| 10230 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { | 10292 class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 10231 protected: | 10293 protected: |
| 10232 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { | 10294 std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { |
| 10233 return FakeCompositorFrameSink::Create3d(); | 10295 return FakeCompositorFrameSink::Create3d(); |
| 10234 } | 10296 } |
| (...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12064 else | 12126 else |
| 12065 EXPECT_FALSE(tile->HasRasterTask()); | 12127 EXPECT_FALSE(tile->HasRasterTask()); |
| 12066 } | 12128 } |
| 12067 Region expected_invalidation( | 12129 Region expected_invalidation( |
| 12068 raster_source->GetRectForImage(checkerable_image->uniqueID())); | 12130 raster_source->GetRectForImage(checkerable_image->uniqueID())); |
| 12069 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); | 12131 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); |
| 12070 } | 12132 } |
| 12071 | 12133 |
| 12072 } // namespace | 12134 } // namespace |
| 12073 } // namespace cc | 12135 } // namespace cc |
| OLD | NEW |