From 7d52672a31997ddf9f8d8f3dac9b236bbdd558e7 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 12 Aug 2015 16:37:56 -0700 Subject: [PATCH] RenderBox.hitTest should do the bounds check Previously we were doing the bounds testing for hit tests in the parent, but that doesn't work if the child paints at a location other than 0.0, 0.0. Now we do the bounds check in the child. This also simplifies Scaffold's hit testing. Fixes #558 --- sky/packages/sky/lib/rendering/box.dart | 39 ++++++++++------------ sky/packages/sky/lib/widgets/scaffold.dart | 28 ++-------------- 2 files changed, 20 insertions(+), 47 deletions(-) diff --git a/sky/packages/sky/lib/rendering/box.dart b/sky/packages/sky/lib/rendering/box.dart index b9f729b3db9..c1068927461 100644 --- a/sky/packages/sky/lib/rendering/box.dart +++ b/sky/packages/sky/lib/rendering/box.dart @@ -414,9 +414,13 @@ abstract class RenderBox extends RenderObject { } bool hitTest(HitTestResult result, { Point position }) { - hitTestChildren(result, position: position); - result.add(new BoxHitTestEntry(this, position)); - return true; + if (position.x >= 0.0 && position.x < _size.width && + position.y >= 0.0 && position.y < _size.height) { + hitTestChildren(result, position: position); + result.add(new BoxHitTestEntry(this, position)); + return true; + } + return false; } void hitTestChildren(HitTestResult result, { Point position }) { } @@ -1008,11 +1012,8 @@ abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi void hitTestChildren(HitTestResult result, { Point position }) { if (child != null) { assert(child.parentData is BoxParentData); - Rect childBounds = child.parentData.position & child.size; - if (childBounds.contains(position)) { - child.hitTest(result, position: new Point(position.x - child.parentData.position.x, - position.y - child.parentData.position.y)); - } + child.hitTest(result, position: new Point(position.x - child.parentData.position.x, + position.y - child.parentData.position.y)); } } @@ -1319,10 +1320,8 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin