diff options
-rw-r--r-- | cc/surfaces/surface_hittest.cc | 5 | ||||
-rw-r--r-- | cc/surfaces/surface_hittest_delegate.h | 5 | ||||
-rw-r--r-- | cc/surfaces/surface_hittest_unittest.cc | 130 | ||||
-rw-r--r-- | cc/test/surface_hittest_test_helpers.cc | 33 | ||||
-rw-r--r-- | cc/test/surface_hittest_test_helpers.h | 17 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_input_event_router.cc | 9 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_input_event_router.h | 2 |
7 files changed, 126 insertions, 75 deletions
diff --git a/cc/surfaces/surface_hittest.cc b/cc/surfaces/surface_hittest.cc index 1f443d6..6db66e2 100644 --- a/cc/surfaces/surface_hittest.cc +++ b/cc/surfaces/surface_hittest.cc @@ -104,7 +104,10 @@ bool SurfaceHittest::GetTargetSurfaceAtPointInternal( gfx::Transform transform_to_child_space; if (GetTargetSurfaceAtPointInternal( surface_quad->surface_id, RenderPassId(), point_in_quad_space, - referenced_passes, out_surface_id, &transform_to_child_space)) { + referenced_passes, out_surface_id, &transform_to_child_space) || + (delegate_ && + delegate_->AcceptHitTarget(surface_quad, point_in_quad_space))) { + *out_surface_id = surface_quad->surface_id; *out_transform = transform_to_child_space * target_to_quad_transform * transform_from_root_target; return true; diff --git a/cc/surfaces/surface_hittest_delegate.h b/cc/surfaces/surface_hittest_delegate.h index 59095f8..f966b7c 100644 --- a/cc/surfaces/surface_hittest_delegate.h +++ b/cc/surfaces/surface_hittest_delegate.h @@ -21,6 +21,11 @@ class SurfaceHittestDelegate { // target. virtual bool RejectHitTarget(const SurfaceDrawQuad* surface_quad, const gfx::Point& point_in_quad_space) = 0; + + // Return true if this delegate accepts this |surface_quad| as a candidate hit + // target. + virtual bool AcceptHitTarget(const SurfaceDrawQuad* surface_quad, + const gfx::Point& point_in_quad_space) = 0; }; } // namespace cc diff --git a/cc/surfaces/surface_hittest_unittest.cc b/cc/surfaces/surface_hittest_unittest.cc index 5970d45..9c1309c4 100644 --- a/cc/surfaces/surface_hittest_unittest.cc +++ b/cc/surfaces/surface_hittest_unittest.cc @@ -505,10 +505,11 @@ TEST(SurfaceHittestTest, Hittest_SingleSurface_WithInsetsDelegate) { CreateCompositorFrame(child_rect, &child_pass); // Add a solid quad in the child surface. - gfx::Rect child_solid_quad_rect(200, 200); + gfx::Rect child_solid_quad_rect(190, 190); CreateSolidColorDrawQuad( child_pass, - gfx::Transform(), + gfx::Transform(1.0f, 0.0f, 0.0f, 5.0f, 0.0f, 1.0f, 0.0f, 5.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f), root_rect, child_solid_quad_rect); // Submit the frame. @@ -517,78 +518,81 @@ TEST(SurfaceHittestTest, Hittest_SingleSurface_WithInsetsDelegate) { SurfaceFactory::DrawCallback()); TestCase test_expectations_without_insets[] = { - { - root_surface_id, - gfx::Point(50, 50), - child_surface_id, - gfx::Point(0, 0) - }, - { - root_surface_id, - gfx::Point(60, 60), - child_surface_id, - gfx::Point(10, 10) - }, - { - root_surface_id, - gfx::Point(239, 239), - child_surface_id, - gfx::Point(189, 189) - }, - { - root_surface_id, - gfx::Point(249, 249), - child_surface_id, - gfx::Point(199, 199) - }, + {root_surface_id, gfx::Point(55, 55), child_surface_id, gfx::Point(5, 5)}, + {root_surface_id, gfx::Point(60, 60), child_surface_id, + gfx::Point(10, 10)}, + {root_surface_id, gfx::Point(239, 239), child_surface_id, + gfx::Point(189, 189)}, + {root_surface_id, gfx::Point(244, 244), child_surface_id, + gfx::Point(194, 194)}, + {root_surface_id, gfx::Point(50, 50), root_surface_id, + gfx::Point(50, 50)}, + {root_surface_id, gfx::Point(249, 249), root_surface_id, + gfx::Point(249, 249)}, }; - TestSurfaceHittestDelegate delegate; - RunTests(&delegate, &manager, test_expectations_without_insets, + TestSurfaceHittestDelegate empty_delegate; + RunTests(&empty_delegate, &manager, test_expectations_without_insets, arraysize(test_expectations_without_insets)); // Verify that insets have NOT affected hit targeting. - EXPECT_EQ(0, delegate.target_overrides()); + EXPECT_EQ(0, empty_delegate.reject_target_overrides()); + EXPECT_EQ(0, empty_delegate.accept_target_overrides()); + + TestCase test_expectations_with_reject_insets[] = { + // Point (55, 55) falls outside the child surface due to the insets + // introduced above. + {root_surface_id, gfx::Point(55, 55), root_surface_id, + gfx::Point(55, 55)}, + // These two points still fall within the child surface. + {root_surface_id, gfx::Point(60, 60), child_surface_id, + gfx::Point(10, 10)}, + {root_surface_id, gfx::Point(239, 239), child_surface_id, + gfx::Point(189, 189)}, + // Point (244, 244) falls outside the child surface due to the insets + // introduced above. + {root_surface_id, gfx::Point(244, 244), root_surface_id, + gfx::Point(244, 244)}, + // Next two points also fall within within the insets indroduced above. + {root_surface_id, gfx::Point(50, 50), root_surface_id, + gfx::Point(50, 50)}, + {root_surface_id, gfx::Point(249, 249), root_surface_id, + gfx::Point(249, 249)}, + }; - delegate.AddInsetsForSurface(child_surface_id, gfx::Insets(10, 10, 10, 10)); + TestSurfaceHittestDelegate reject_delegate; + reject_delegate.AddInsetsForRejectSurface(child_surface_id, + gfx::Insets(10, 10, 10, 10)); + RunTests(&reject_delegate, &manager, test_expectations_with_reject_insets, + arraysize(test_expectations_with_reject_insets)); - TestCase test_expectations_with_insets[] = { - // Point (50, 50) falls outside the child surface due to the insets - // introduced above. - { - root_surface_id, - gfx::Point(50, 50), - root_surface_id, - gfx::Point(50, 50) - }, - // These two points still fall within the child surface. - { - root_surface_id, - gfx::Point(60, 60), - child_surface_id, - gfx::Point(10, 10) - }, - { - root_surface_id, - gfx::Point(239, 239), - child_surface_id, - gfx::Point(189, 189) - }, - // Point (249, 249) falls outside the child surface due to the insets - // introduced above. - { - root_surface_id, - gfx::Point(249, 249), - root_surface_id, - gfx::Point(249, 249) - }, + // Verify that insets have affected hit targeting. + EXPECT_EQ(4, reject_delegate.reject_target_overrides()); + EXPECT_EQ(0, reject_delegate.accept_target_overrides()); + + TestCase test_expectations_with_accept_insets[] = { + {root_surface_id, gfx::Point(55, 55), child_surface_id, gfx::Point(5, 5)}, + {root_surface_id, gfx::Point(60, 60), child_surface_id, + gfx::Point(10, 10)}, + {root_surface_id, gfx::Point(239, 239), child_surface_id, + gfx::Point(189, 189)}, + {root_surface_id, gfx::Point(244, 244), child_surface_id, + gfx::Point(194, 194)}, + // Next two points fall within within the insets indroduced above. + {root_surface_id, gfx::Point(50, 50), child_surface_id, gfx::Point(0, 0)}, + {root_surface_id, gfx::Point(249, 249), child_surface_id, + gfx::Point(199, 199)}, }; - RunTests(&delegate, &manager, test_expectations_with_insets, - arraysize(test_expectations_with_insets)); + TestSurfaceHittestDelegate accept_delegate; + accept_delegate.AddInsetsForAcceptSurface(child_surface_id, + gfx::Insets(5, 5, 5, 5)); + RunTests(&accept_delegate, &manager, test_expectations_with_accept_insets, + arraysize(test_expectations_with_accept_insets)); // Verify that insets have affected hit targeting. - EXPECT_EQ(2, delegate.target_overrides()); + EXPECT_EQ(0, accept_delegate.reject_target_overrides()); + EXPECT_EQ(2, accept_delegate.accept_target_overrides()); factory.Destroy(root_surface_id); } diff --git a/cc/test/surface_hittest_test_helpers.cc b/cc/test/surface_hittest_test_helpers.cc index b83d6d4..5766273 100644 --- a/cc/test/surface_hittest_test_helpers.cc +++ b/cc/test/surface_hittest_test_helpers.cc @@ -93,27 +93,48 @@ scoped_ptr<CompositorFrame> CreateCompositorFrame(const gfx::Rect& root_rect, } TestSurfaceHittestDelegate::TestSurfaceHittestDelegate() - : target_overrides_(0) {} + : reject_target_overrides_(0), accept_target_overrides_(0) {} TestSurfaceHittestDelegate::~TestSurfaceHittestDelegate() {} -void TestSurfaceHittestDelegate::AddInsetsForSurface( +void TestSurfaceHittestDelegate::AddInsetsForRejectSurface( const SurfaceId& surface_id, const gfx::Insets& inset) { - insets_for_surface_.insert(std::make_pair(surface_id, inset)); + insets_for_reject_.insert(std::make_pair(surface_id, inset)); +} + +void TestSurfaceHittestDelegate::AddInsetsForAcceptSurface( + const SurfaceId& surface_id, + const gfx::Insets& inset) { + insets_for_accept_.insert(std::make_pair(surface_id, inset)); } bool TestSurfaceHittestDelegate::RejectHitTarget( const SurfaceDrawQuad* surface_quad, const gfx::Point& point_in_quad_space) { - if (!insets_for_surface_.count(surface_quad->surface_id)) + if (!insets_for_reject_.count(surface_quad->surface_id)) return false; gfx::Rect bounds(surface_quad->rect); - bounds.Inset(insets_for_surface_[surface_quad->surface_id]); + bounds.Inset(insets_for_reject_[surface_quad->surface_id]); // If the point provided falls outside the inset, then we skip this surface. if (!bounds.Contains(point_in_quad_space)) { if (surface_quad->rect.Contains(point_in_quad_space)) - ++target_overrides_; + ++reject_target_overrides_; + return true; + } + return false; +} + +bool TestSurfaceHittestDelegate::AcceptHitTarget( + const SurfaceDrawQuad* surface_quad, + const gfx::Point& point_in_quad_space) { + if (!insets_for_accept_.count(surface_quad->surface_id)) + return false; + gfx::Rect bounds(surface_quad->rect); + bounds.Inset(insets_for_accept_[surface_quad->surface_id]); + // If the point provided falls outside the inset, then we accept this surface. + if (!bounds.Contains(point_in_quad_space)) { + ++accept_target_overrides_; return true; } return false; diff --git a/cc/test/surface_hittest_test_helpers.h b/cc/test/surface_hittest_test_helpers.h index 4a27659..e3f8ff9 100644 --- a/cc/test/surface_hittest_test_helpers.h +++ b/cc/test/surface_hittest_test_helpers.h @@ -70,18 +70,25 @@ class TestSurfaceHittestDelegate : public SurfaceHittestDelegate { TestSurfaceHittestDelegate(); ~TestSurfaceHittestDelegate(); - int target_overrides() const { return target_overrides_; } + int reject_target_overrides() const { return reject_target_overrides_; } + int accept_target_overrides() const { return accept_target_overrides_; } - void AddInsetsForSurface(const SurfaceId& surface_id, - const gfx::Insets& inset); + void AddInsetsForRejectSurface(const SurfaceId& surface_id, + const gfx::Insets& inset); + void AddInsetsForAcceptSurface(const SurfaceId& surface_id, + const gfx::Insets& inset); // SurfaceHittestDelegate implementation. bool RejectHitTarget(const SurfaceDrawQuad* surface_quad, const gfx::Point& point_in_quad_space) override; + bool AcceptHitTarget(const SurfaceDrawQuad* surface_quad, + const gfx::Point& point_in_quad_space) override; private: - int target_overrides_; - std::map<SurfaceId, gfx::Insets> insets_for_surface_; + int reject_target_overrides_; + int accept_target_overrides_; + std::map<SurfaceId, gfx::Insets> insets_for_reject_; + std::map<SurfaceId, gfx::Insets> insets_for_accept_; DISALLOW_COPY_AND_ASSIGN(TestSurfaceHittestDelegate); }; diff --git a/content/browser/renderer_host/render_widget_host_input_event_router.cc b/content/browser/renderer_host/render_widget_host_input_event_router.cc index 67bbd4e..92b0766 100644 --- a/content/browser/renderer_host/render_widget_host_input_event_router.cc +++ b/content/browser/renderer_host/render_widget_host_input_event_router.cc @@ -27,6 +27,15 @@ bool RenderWidgetHostInputEventRouter::HittestDelegate::RejectHitTarget( return false; } +bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget( + const cc::SurfaceDrawQuad* surface_quad, + const gfx::Point& point_in_quad_space) { + auto it = hittest_data_.find(surface_quad->surface_id); + if (it != hittest_data_.end() && !it->second.ignored_for_hittest) + return true; + return false; +} + RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() : active_touches_(0) {} diff --git a/content/browser/renderer_host/render_widget_host_input_event_router.h b/content/browser/renderer_host/render_widget_host_input_event_router.h index ec45f15..abf5b7b 100644 --- a/content/browser/renderer_host/render_widget_host_input_event_router.h +++ b/content/browser/renderer_host/render_widget_host_input_event_router.h @@ -75,6 +75,8 @@ class CONTENT_EXPORT RenderWidgetHostInputEventRouter { hittest_data); bool RejectHitTarget(const cc::SurfaceDrawQuad* surface_quad, const gfx::Point& point_in_quad_space) override; + bool AcceptHitTarget(const cc::SurfaceDrawQuad* surface_quad, + const gfx::Point& point_in_quad_space) override; const std::unordered_map<cc::SurfaceId, HittestData, cc::SurfaceIdHash>& hittest_data_; |