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