Unverified Commit 8c1d9d76 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[framework] make HitTestEntry generic (#97175)

parent f085e1a9
......@@ -38,19 +38,20 @@ abstract class HitTestTarget {
HitTestTarget._();
/// Override this method to receive events.
void handleEvent(PointerEvent event, HitTestEntry entry);
void handleEvent(PointerEvent event, HitTestEntry<HitTestTarget> entry);
}
/// Data collected during a hit test about a specific [HitTestTarget].
///
/// Subclass this object to pass additional information from the hit test phase
/// to the event propagation phase.
class HitTestEntry {
@optionalTypeArgs
class HitTestEntry<T extends HitTestTarget> {
/// Creates a hit test entry.
HitTestEntry(this.target);
/// The [HitTestTarget] encountered during the hit test.
final HitTestTarget target;
final T target;
@override
String toString() => '${describeIdentity(this)}($target)';
......
......@@ -886,7 +886,7 @@ class BoxHitTestResult extends HitTestResult {
}
/// A hit test entry used by [RenderBox].
class BoxHitTestEntry extends HitTestEntry {
class BoxHitTestEntry extends HitTestEntry<RenderBox> {
/// Creates a box hit test entry.
///
/// The [localPosition] argument must not be null.
......@@ -894,9 +894,6 @@ class BoxHitTestEntry extends HitTestEntry {
: assert(localPosition != null),
super(target);
@override
RenderBox get target => super.target as RenderBox;
/// The position of the hit test in the local coordinates of [target].
final Offset localPosition;
......
......@@ -238,8 +238,9 @@ class MouseTracker extends ChangeNotifier {
assert(result != null);
final LinkedHashMap<MouseTrackerAnnotation, Matrix4> annotations = LinkedHashMap<MouseTrackerAnnotation, Matrix4>();
for (final HitTestEntry entry in result.path) {
if (entry.target is MouseTrackerAnnotation) {
annotations[entry.target as MouseTrackerAnnotation] = entry.transform!;
final Object target = entry.target;
if (target is MouseTrackerAnnotation) {
annotations[target] = entry.transform!;
}
}
return annotations;
......
......@@ -870,7 +870,7 @@ class SliverHitTestResult extends HitTestResult {
///
/// The coordinate system used by this hit test entry is relative to the
/// [AxisDirection] of the target sliver.
class SliverHitTestEntry extends HitTestEntry {
class SliverHitTestEntry extends HitTestEntry<RenderSliver> {
/// Creates a sliver hit test entry.
///
/// The [mainAxisPosition] and [crossAxisPosition] arguments must not be null.
......@@ -882,9 +882,6 @@ class SliverHitTestEntry extends HitTestEntry {
assert(crossAxisPosition != null),
super(target);
@override
RenderSliver get target => super.target as RenderSliver;
/// The distance in the [AxisDirection] from the edge of the sliver's painted
/// area (as given by the [SliverConstraints.scrollOffset]) to the hit point.
/// This can be an unusual direction, for example in the [AxisDirection.up]
......
......@@ -96,7 +96,7 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation
// A hit test entry that can be assigned with a [TestAnnotationTarget] and an
// optional transform matrix.
class TestAnnotationEntry extends HitTestEntry {
class TestAnnotationEntry extends HitTestEntry<TestAnnotationTarget> {
TestAnnotationEntry(TestAnnotationTarget target, [Matrix4? transform])
: transform = transform ?? Matrix4.identity(), super(target);
......
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