[framework] make HitTestEntry generic (#97175)

This commit is contained in:
Jonah Williams 2022-01-26 13:10:20 -08:00 committed by GitHub
parent f085e1a9cd
commit 8c1d9d7627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 14 deletions

View File

@ -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)';

View File

@ -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 {
: 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;

View File

@ -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;

View File

@ -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 {
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]

View File

@ -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);