Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a4f7a0df
Unverified
Commit
a4f7a0df
authored
Dec 09, 2019
by
Tong Mu
Committed by
GitHub
Dec 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert changes to TestPointer; MouseTracker no longer relies on Add events (#46285)
* Revert test pointer * Synthesize new state
parent
5406f2b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
59 deletions
+21
-59
mouse_tracking.dart
packages/flutter/lib/src/gestures/mouse_tracking.dart
+13
-10
test_pointer.dart
packages/flutter_test/lib/src/test_pointer.dart
+8
-49
No files found.
packages/flutter/lib/src/gestures/mouse_tracking.dart
View file @
a4f7a0df
...
...
@@ -145,7 +145,7 @@ typedef _UpdatedDeviceHandler = void Function(_MouseState mouseState, LinkedHash
// Various states of a connected mouse device used by [MouseTracker].
class
_MouseState
{
_MouseState
({
@required
Pointer
Added
Event
initialEvent
,
@required
PointerEvent
initialEvent
,
})
:
assert
(
initialEvent
!=
null
),
_latestEvent
=
initialEvent
;
...
...
@@ -289,6 +289,7 @@ class MouseTracker extends ChangeNotifier {
return
;
final
PointerEvent
previousEvent
=
existingState
?.
latestEvent
;
final
Offset
lastHoverPosition
=
previousEvent
is
!
PointerHoverEvent
?
null
:
previousEvent
.
position
;
_updateDevices
(
targetEvent:
event
,
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
...
...
@@ -296,7 +297,7 @@ class MouseTracker extends ChangeNotifier {
_dispatchDeviceCallbacks
(
lastAnnotations:
previousAnnotations
,
nextAnnotations:
mouseState
.
annotations
,
handledEvent:
previousEvent
,
lastHoverPosition:
lastHoverPosition
,
unhandledEvent:
event
,
trackedAnnotations:
_trackedAnnotations
,
);
...
...
@@ -327,10 +328,12 @@ class MouseTracker extends ChangeNotifier {
void
_updateAllDevices
()
{
_updateDevices
(
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
final
PointerEvent
latestEvent
=
mouseState
.
latestEvent
;
final
Offset
lastHoverPosition
=
latestEvent
is
PointerHoverEvent
?
latestEvent
.
position
:
null
;
_dispatchDeviceCallbacks
(
lastAnnotations:
previousAnnotations
,
nextAnnotations:
mouseState
.
annotations
,
handledEvent:
mouseState
.
latestEvent
,
lastHoverPosition:
lastHoverPosition
,
unhandledEvent:
mouseState
.
latestEvent
,
trackedAnnotations:
_trackedAnnotations
,
);
...
...
@@ -385,11 +388,11 @@ class MouseTracker extends ChangeNotifier {
_MouseState
targetState
;
if
(
targetEvent
!=
null
)
{
targetState
=
_mouseStates
[
targetEvent
.
device
];
assert
((
targetState
==
null
)
==
(
targetEvent
is
PointerAddedEvent
));
if
(
targetEvent
is
PointerAddedEvent
)
{
if
(
targetState
==
null
)
{
targetState
=
_MouseState
(
initialEvent:
targetEvent
);
_mouseStates
[
targetState
.
device
]
=
targetState
;
}
else
{
assert
(
targetEvent
is
!
PointerAddedEvent
);
targetState
.
latestEvent
=
targetEvent
;
// Update mouseState to the latest devices that have not been removed,
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
...
...
@@ -424,17 +427,18 @@ class MouseTracker extends ChangeNotifier {
// Dispatch callbacks related to a device after all necessary information
// has been collected.
//
// The `unhandledEvent` can be null. Other arguments must not be null.
// The `lastHoverPosition` can be null, which means the last event is not a
// hover. Other arguments must not be null.
static
void
_dispatchDeviceCallbacks
({
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
lastAnnotations
,
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
nextAnnotations
,
@required
PointerEvent
handledEvent
,
@required
Offset
lastHoverPosition
,
@required
PointerEvent
unhandledEvent
,
@required
Set
<
MouseTrackerAnnotation
>
trackedAnnotations
,
})
{
assert
(
lastAnnotations
!=
null
);
assert
(
nextAnnotations
!=
null
);
//
handledEvent
can be null
//
lastHoverPosition
can be null
assert
(
unhandledEvent
!=
null
);
assert
(
trackedAnnotations
!=
null
);
// Order is important for mouse event callbacks. The `findAnnotations`
...
...
@@ -477,8 +481,7 @@ class MouseTracker extends ChangeNotifier {
// or the position has changed
assert
(
trackedAnnotations
.
contains
(
annotation
));
if
(!
lastAnnotations
.
contains
(
annotation
)
||
handledEvent
is
!
PointerHoverEvent
||
handledEvent
.
position
!=
unhandledEvent
.
position
)
{
||
lastHoverPosition
!=
unhandledEvent
.
position
)
{
if
(
annotation
.
onHover
!=
null
)
{
annotation
.
onHover
(
unhandledEvent
);
}
...
...
packages/flutter_test/lib/src/test_pointer.dart
View file @
a4f7a0df
...
...
@@ -337,16 +337,12 @@ class TestGesture {
_dispatcher
=
dispatcher
,
_hitTester
=
hitTester
,
_pointer
=
TestPointer
(
pointer
,
kind
,
device
,
buttons
),
_added
=
false
,
_result
=
null
;
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// hit test result.
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
down
(
Offset
downLocation
)
{
Future
<
void
>
down
(
Offset
downLocation
)
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
(
location:
downLocation
);
_result
=
_hitTester
(
downLocation
);
return
_dispatcher
(
_pointer
.
down
(
downLocation
),
_result
);
});
...
...
@@ -354,12 +350,9 @@ class TestGesture {
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// hit test result with a custom down event.
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
downWithCustomEvent
(
Offset
downLocation
,
PointerDownEvent
event
)
{
Future
<
void
>
downWithCustomEvent
(
Offset
downLocation
,
PointerDownEvent
event
)
async
{
_pointer
.
setDownInfo
(
event
,
downLocation
);
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
(
location:
downLocation
);
_pointer
.
setDownInfo
(
event
,
downLocation
);
_result
=
_hitTester
(
downLocation
);
return
_dispatcher
(
event
,
_result
);
});
...
...
@@ -369,22 +362,10 @@ class TestGesture {
final
HitTester
_hitTester
;
final
TestPointer
_pointer
;
HitTestResult
_result
;
bool
_added
;
Future
<
void
>
_ensureAdded
({
Offset
location
})
async
{
if
(!
_added
)
{
await
addPointer
(
location:
location
??
_pointer
.
location
);
}
}
/// In a test, send a move event that moves the pointer by the given offset.
///
/// If the pointer has not been added, and the subject event is not an added
/// event, an added event will be dispatched first.
@visibleForTesting
Future
<
void
>
updateWithCustomEvent
(
PointerEvent
event
,
{
Duration
timeStamp
=
Duration
.
zero
})
async
{
if
(
event
is
!
PointerAddedEvent
)
await
_ensureAdded
(
location:
event
.
position
);
Future
<
void
>
updateWithCustomEvent
(
PointerEvent
event
,
{
Duration
timeStamp
=
Duration
.
zero
})
{
_pointer
.
setDownInfo
(
event
,
event
.
position
);
return
TestAsyncUtils
.
guard
<
void
>(()
{
return
_dispatcher
(
event
,
_result
);
...
...
@@ -392,34 +373,21 @@ class TestGesture {
}
/// In a test, send a pointer add event for this pointer.
///
/// If a pointer has been added, the pointer will be removed first.
Future
<
void
>
addPointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
if
(
_added
)
{
await
removePointer
(
timeStamp:
timeStamp
);
}
_added
=
true
;
return
TestAsyncUtils
.
guard
<
void
>(()
{
return
_dispatcher
(
_pointer
.
addPointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
});
}
/// In a test, send a pointer remove event for this pointer.
///
/// If no pointer has been added, the call will be a no-op.
Future
<
void
>
removePointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
if
(!
_added
)
return
;
_added
=
false
;
await
_dispatcher
(
_pointer
.
removePointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
return
TestAsyncUtils
.
guard
<
void
>(()
{
return
_dispatcher
(
_pointer
.
removePointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
});
}
/// Send a move event moving the pointer by the given offset.
///
/// If the pointer has not been added, an added event will be dispatched first.
///
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// up, then a hover event is dispatched. Touch devices are not able to send
/// hover events.
...
...
@@ -429,14 +397,11 @@ class TestGesture {
/// Send a move event moving the pointer to the given location.
///
/// If the pointer has not been added, an added event will be dispatched first.
///
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// up, then a hover event is dispatched. Touch devices are not able to send
/// hover events.
Future
<
void
>
moveTo
(
Offset
location
,
{
Duration
timeStamp
=
Duration
.
zero
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
(
location:
location
);
return
TestAsyncUtils
.
guard
<
void
>(()
{
if
(
_pointer
.
_isDown
)
{
assert
(
_result
!=
null
,
'Move events with the pointer down must be preceded by a down '
...
...
@@ -451,11 +416,8 @@ class TestGesture {
}
/// End the gesture by releasing the pointer.
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
up
()
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
();
assert
(
_pointer
.
_isDown
);
await
_dispatcher
(
_pointer
.
up
(),
_result
);
assert
(!
_pointer
.
_isDown
);
...
...
@@ -466,11 +428,8 @@ class TestGesture {
/// End the gesture by canceling the pointer (as would happen if the
/// system showed a modal dialog on top of the Flutter application,
/// for instance).
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
cancel
()
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
();
assert
(
_pointer
.
_isDown
);
await
_dispatcher
(
_pointer
.
cancel
(),
_result
);
assert
(!
_pointer
.
_isDown
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment