Commit 16471d92 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #353 from Hixie/hit-testing-cleanup

Hit Testing Cleanup
parents 876459e8 92b9d91a
...@@ -31,14 +31,6 @@ int _hammingWeight(int value) { ...@@ -31,14 +31,6 @@ int _hammingWeight(int value) {
return weight; return weight;
} }
/// A hit test entry used by [FlutterBinding]
class BindingHitTestEntry extends HitTestEntry {
const BindingHitTestEntry(HitTestTarget target, this.result) : super(target);
/// The result of the hit test
final HitTestResult result;
}
/// State used in converting PointerPackets to PointerInputEvents /// State used in converting PointerPackets to PointerInputEvents
class _PointerState { class _PointerState {
_PointerState({ this.pointer, this.lastPosition }); _PointerState({ this.pointer, this.lastPosition });
...@@ -269,7 +261,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -269,7 +261,7 @@ class FlutterBinding extends HitTestTarget {
HitTestResult hitTest(Point position) { HitTestResult hitTest(Point position) {
HitTestResult result = new HitTestResult(); HitTestResult result = new HitTestResult();
_renderView.hitTest(result, position: position); _renderView.hitTest(result, position: position);
result.add(new BindingHitTestEntry(this, result)); result.add(new HitTestEntry(this));
return result; return result;
} }
...@@ -280,7 +272,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -280,7 +272,7 @@ class FlutterBinding extends HitTestTarget {
entry.target.handleEvent(event, entry); entry.target.handleEvent(event, entry);
} }
void handleEvent(InputEvent e, BindingHitTestEntry entry) { void handleEvent(InputEvent e, HitTestEntry entry) {
if (e is PointerInputEvent) { if (e is PointerInputEvent) {
PointerInputEvent event = e; PointerInputEvent event = e;
pointerRouter.route(event); pointerRouter.route(event);
......
...@@ -275,10 +275,14 @@ class BoxConstraints extends Constraints { ...@@ -275,10 +275,14 @@ class BoxConstraints extends Constraints {
/// A hit test entry used by [RenderBox] /// A hit test entry used by [RenderBox]
class BoxHitTestEntry extends HitTestEntry { class BoxHitTestEntry extends HitTestEntry {
const BoxHitTestEntry(HitTestTarget target, this.localPosition) : super(target); const BoxHitTestEntry(RenderBox target, this.localPosition) : super(target);
RenderBox get target => super.target;
/// The position of the hit test in the local coordinates of [target] /// The position of the hit test in the local coordinates of [target]
final Point localPosition; final Point localPosition;
String toString() => '${target.runtimeType}@$localPosition';
} }
/// Parent data used by [RenderBox] and its subclasses /// Parent data used by [RenderBox] and its subclasses
......
...@@ -19,12 +19,14 @@ class HitTestEntry { ...@@ -19,12 +19,14 @@ class HitTestEntry {
/// The [HitTestTarget] encountered during the hit test. /// The [HitTestTarget] encountered during the hit test.
final HitTestTarget target; final HitTestTarget target;
String toString() => '$target';
} }
/// The result of performing a hit test. /// The result of performing a hit test.
class HitTestResult { class HitTestResult {
HitTestResult({ List<HitTestEntry> path }) HitTestResult({ List<HitTestEntry> path })
: path = path != null ? path : new List<HitTestEntry>(); : path = path ?? <HitTestEntry>[];
/// The list of [HitTestEntry] objects recorded during the hit test. /// The list of [HitTestEntry] objects recorded during the hit test.
/// ///
...@@ -36,9 +38,11 @@ class HitTestResult { ...@@ -36,9 +38,11 @@ class HitTestResult {
/// Add a [HitTestEntry] to the path. /// Add a [HitTestEntry] to the path.
/// ///
/// The new entry is added at the end of the path, which means entries should /// The new entry is added at the end of the path, which means entries should
/// be added in order from most specific to least specific, typically during a /// be added in order from most specific to least specific, typically during an
/// upward walk in the tree being hit tested. /// upward walk of the tree being hit tested.
void add(HitTestEntry entry) { void add(HitTestEntry entry) {
path.add(entry); path.add(entry);
} }
String toString() => 'HitTestResult(${path.isEmpty ? "<empty path>" : path.join(", ")})';
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment