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
314eb3ba
Unverified
Commit
314eb3ba
authored
Nov 20, 2019
by
chunhtai
Committed by
GitHub
Nov 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving pointer event sanitizing to engine. (#44217)
parent
f8cafd9d
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
419 deletions
+57
-419
converter.dart
packages/flutter/lib/src/gestures/converter.dart
+49
-322
gesture_binding_test.dart
packages/flutter/test/gestures/gesture_binding_test.dart
+3
-88
mouse_tracking_test.dart
packages/flutter/test/gestures/mouse_tracking_test.dart
+5
-7
binding.dart
packages/flutter_test/lib/src/binding.dart
+0
-2
No files found.
packages/flutter/lib/src/gestures/converter.dart
View file @
314eb3ba
This diff is collapsed.
Click to expand it.
packages/flutter/test/gestures/gesture_binding_test.dart
View file @
314eb3ba
...
@@ -26,7 +26,6 @@ TestGestureFlutterBinding _binding = TestGestureFlutterBinding();
...
@@ -26,7 +26,6 @@ TestGestureFlutterBinding _binding = TestGestureFlutterBinding();
void
ensureTestGestureBinding
(
)
{
void
ensureTestGestureBinding
(
)
{
_binding
??=
TestGestureFlutterBinding
();
_binding
??=
TestGestureFlutterBinding
();
PointerEventConverter
.
clearPointers
();
assert
(
GestureBinding
.
instance
!=
null
);
assert
(
GestureBinding
.
instance
!=
null
);
}
}
...
@@ -72,9 +71,11 @@ void main() {
...
@@ -72,9 +71,11 @@ void main() {
test
(
'Pointer hover events'
,
()
{
test
(
'Pointer hover events'
,
()
{
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
data:
<
ui
.
PointerData
>[
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
remove
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
remove
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
),
],
],
);
);
...
@@ -97,33 +98,6 @@ void main() {
...
@@ -97,33 +98,6 @@ void main() {
expect
(
pointerRouterEvents
[
5
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
pointerRouterEvents
[
5
].
runtimeType
,
equals
(
PointerHoverEvent
));
});
});
test
(
'Synthetic move events'
,
()
{
final
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
ui
.
PointerData
(
change:
ui
.
PointerChange
.
down
,
physicalX:
1.0
*
ui
.
window
.
devicePixelRatio
,
physicalY:
3.0
*
ui
.
window
.
devicePixelRatio
,
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
up
,
physicalX:
10.0
*
ui
.
window
.
devicePixelRatio
,
physicalY:
15.0
*
ui
.
window
.
devicePixelRatio
,
),
],
);
final
List
<
PointerEvent
>
events
=
<
PointerEvent
>[];
_binding
.
callback
=
events
.
add
;
ui
.
window
.
onPointerDataPacket
(
packet
);
expect
(
events
.
length
,
3
);
expect
(
events
[
0
].
runtimeType
,
equals
(
PointerDownEvent
));
expect
(
events
[
1
].
runtimeType
,
equals
(
PointerMoveEvent
));
expect
(
events
[
1
].
delta
,
equals
(
const
Offset
(
9.0
,
12.0
)));
expect
(
events
[
2
].
runtimeType
,
equals
(
PointerUpEvent
));
});
test
(
'Pointer cancel events'
,
()
{
test
(
'Pointer cancel events'
,
()
{
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
data:
<
ui
.
PointerData
>[
...
@@ -168,6 +142,7 @@ void main() {
...
@@ -168,6 +142,7 @@ void main() {
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
remove
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
remove
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
device:
24
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
device:
24
),
],
],
);
);
...
@@ -183,28 +158,6 @@ void main() {
...
@@ -183,28 +158,6 @@ void main() {
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerHoverEvent
));
});
});
test
(
'Synthetic hover and cancel for misplaced down and remove'
,
()
{
final
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
,
device:
25
,
physicalX:
10.0
*
ui
.
window
.
devicePixelRatio
,
physicalY:
10.0
*
ui
.
window
.
devicePixelRatio
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
down
,
device:
25
,
physicalX:
15.0
*
ui
.
window
.
devicePixelRatio
,
physicalY:
17.0
*
ui
.
window
.
devicePixelRatio
),
const
ui
.
PointerData
(
change:
ui
.
PointerChange
.
remove
,
device:
25
),
],
);
final
List
<
PointerEvent
>
events
=
PointerEventConverter
.
expand
(
packet
.
data
,
ui
.
window
.
devicePixelRatio
).
toList
();
expect
(
events
.
length
,
6
);
expect
(
events
[
0
].
runtimeType
,
equals
(
PointerAddedEvent
));
expect
(
events
[
1
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
events
[
1
].
delta
,
equals
(
const
Offset
(
5.0
,
7.0
)));
expect
(
events
[
2
].
runtimeType
,
equals
(
PointerDownEvent
));
expect
(
events
[
3
].
runtimeType
,
equals
(
PointerCancelEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
events
[
5
].
runtimeType
,
equals
(
PointerRemovedEvent
));
});
test
(
'Can expand pointer scroll events'
,
()
{
test
(
'Can expand pointer scroll events'
,
()
{
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
const
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
data:
<
ui
.
PointerData
>[
...
@@ -221,36 +174,6 @@ void main() {
...
@@ -221,36 +174,6 @@ void main() {
expect
(
events
[
1
].
runtimeType
,
equals
(
PointerScrollEvent
));
expect
(
events
[
1
].
runtimeType
,
equals
(
PointerScrollEvent
));
});
});
test
(
'Synthetic hover/move for misplaced scrolls'
,
()
{
final
Offset
lastLocation
=
const
Offset
(
10.0
,
10.0
)
*
ui
.
window
.
devicePixelRatio
;
const
Offset
unexpectedOffset
=
Offset
(
5.0
,
7.0
);
final
Offset
scrollLocation
=
lastLocation
+
unexpectedOffset
*
ui
.
window
.
devicePixelRatio
;
final
ui
.
PointerDataPacket
packet
=
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
ui
.
PointerData
(
change:
ui
.
PointerChange
.
add
,
physicalX:
lastLocation
.
dx
,
physicalY:
lastLocation
.
dy
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
physicalX:
scrollLocation
.
dx
,
physicalY:
scrollLocation
.
dy
,
signalKind:
ui
.
PointerSignalKind
.
scroll
),
// Move back to starting location, click, and repeat to test mouse-down version.
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
physicalX:
lastLocation
.
dx
,
physicalY:
lastLocation
.
dy
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
down
,
physicalX:
lastLocation
.
dx
,
physicalY:
lastLocation
.
dy
),
ui
.
PointerData
(
change:
ui
.
PointerChange
.
hover
,
physicalX:
scrollLocation
.
dx
,
physicalY:
scrollLocation
.
dy
,
signalKind:
ui
.
PointerSignalKind
.
scroll
),
],
);
final
List
<
PointerEvent
>
events
=
PointerEventConverter
.
expand
(
packet
.
data
,
ui
.
window
.
devicePixelRatio
).
toList
();
expect
(
events
.
length
,
7
);
expect
(
events
[
0
].
runtimeType
,
equals
(
PointerAddedEvent
));
expect
(
events
[
1
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
events
[
1
].
delta
,
equals
(
unexpectedOffset
));
expect
(
events
[
2
].
runtimeType
,
equals
(
PointerScrollEvent
));
expect
(
events
[
3
].
runtimeType
,
equals
(
PointerHoverEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerDownEvent
));
expect
(
events
[
5
].
runtimeType
,
equals
(
PointerMoveEvent
));
expect
(
events
[
5
].
delta
,
equals
(
unexpectedOffset
));
expect
(
events
[
6
].
runtimeType
,
equals
(
PointerScrollEvent
));
});
test
(
'Should synthesize kPrimaryButton for touch'
,
()
{
test
(
'Should synthesize kPrimaryButton for touch'
,
()
{
final
Offset
location
=
const
Offset
(
10.0
,
10.0
)
*
ui
.
window
.
devicePixelRatio
;
final
Offset
location
=
const
Offset
(
10.0
,
10.0
)
*
ui
.
window
.
devicePixelRatio
;
const
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
;
const
PointerDeviceKind
kind
=
PointerDeviceKind
.
touch
;
...
@@ -278,8 +201,6 @@ void main() {
...
@@ -278,8 +201,6 @@ void main() {
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
));
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
PointerEventConverter
.
clearPointers
();
});
});
test
(
'Should synthesize kPrimaryButton for stylus'
,
()
{
test
(
'Should synthesize kPrimaryButton for stylus'
,
()
{
...
@@ -313,8 +234,6 @@ void main() {
...
@@ -313,8 +234,6 @@ void main() {
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
|
kSecondaryStylusButton
));
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
|
kSecondaryStylusButton
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
PointerEventConverter
.
clearPointers
();
}
}
});
});
...
@@ -345,8 +264,6 @@ void main() {
...
@@ -345,8 +264,6 @@ void main() {
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
));
expect
(
events
[
3
].
buttons
,
equals
(
kPrimaryButton
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
PointerEventConverter
.
clearPointers
();
});
});
test
(
'Should not synthesize kPrimaryButton for mouse'
,
()
{
test
(
'Should not synthesize kPrimaryButton for mouse'
,
()
{
...
@@ -378,8 +295,6 @@ void main() {
...
@@ -378,8 +295,6 @@ void main() {
expect
(
events
[
3
].
buttons
,
equals
(
kMiddleMouseButton
|
kSecondaryMouseButton
));
expect
(
events
[
3
].
buttons
,
equals
(
kMiddleMouseButton
|
kSecondaryMouseButton
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
runtimeType
,
equals
(
PointerUpEvent
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
expect
(
events
[
4
].
buttons
,
equals
(
0
));
PointerEventConverter
.
clearPointers
();
}
}
});
});
}
}
packages/flutter/test/gestures/mouse_tracking_test.dart
View file @
314eb3ba
...
@@ -77,7 +77,6 @@ void main() {
...
@@ -77,7 +77,6 @@ void main() {
setUp
(()
{
setUp
(()
{
_ensureTestGestureBinding
();
_ensureTestGestureBinding
();
_binding
.
postFrameCallbacks
.
clear
();
_binding
.
postFrameCallbacks
.
clear
();
PointerEventConverter
.
clearPointers
();
});
});
test
(
'MouseTrackerAnnotation has correct toString'
,
()
{
test
(
'MouseTrackerAnnotation has correct toString'
,
()
{
...
@@ -134,11 +133,10 @@ void main() {
...
@@ -134,11 +133,10 @@ void main() {
// Remove
// Remove
ui
.
window
.
onPointerDataPacket
(
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
ui
.
window
.
onPointerDataPacket
(
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
_pointerData
(
PointerChange
.
remove
,
const
Offset
(
1.0
,
2
01.0
)),
_pointerData
(
PointerChange
.
remove
,
const
Offset
(
1.0
,
1
01.0
)),
]));
]));
expect
(
events
,
_equalToEventsOnCriticalFields
(<
PointerEvent
>[
expect
(
events
,
_equalToEventsOnCriticalFields
(<
PointerEvent
>[
const
PointerHoverEvent
(
position:
Offset
(
1.0
,
201.0
)),
const
PointerExitEvent
(
position:
Offset
(
1.0
,
101.0
)),
const
PointerExitEvent
(
position:
Offset
(
1.0
,
201.0
)),
]));
]));
expect
(
listenerLogs
,
<
bool
>[
false
]);
expect
(
listenerLogs
,
<
bool
>[
false
]);
events
.
clear
();
events
.
clear
();
...
@@ -286,12 +284,12 @@ void main() {
...
@@ -286,12 +284,12 @@ void main() {
_setUpWithOneAnnotation
(
logEvents:
events
);
_setUpWithOneAnnotation
(
logEvents:
events
);
ui
.
window
.
onPointerDataPacket
(
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
ui
.
window
.
onPointerDataPacket
(
ui
.
PointerDataPacket
(
data:
<
ui
.
PointerData
>[
_pointerData
(
PointerChange
.
add
,
const
Offset
(
0.0
,
101.0
)),
_pointerData
(
PointerChange
.
down
,
const
Offset
(
0.0
,
101.0
)),
_pointerData
(
PointerChange
.
down
,
const
Offset
(
0.0
,
101.0
)),
]));
]));
expect
(
events
,
_equalToEventsOnCriticalFields
(<
PointerEvent
>[
expect
(
events
,
_equalToEventsOnCriticalFields
(<
PointerEvent
>[
// This Enter event is triggered by the [PointerAddedEvent] that was
// This Enter event is triggered by the [PointerAddedEvent] The
// synthesized during the event normalization of pointer event converter.
// [PointerDownEvent] is ignored by [MouseTracker].
// The [PointerDownEvent] is ignored by [MouseTracker].
const
PointerEnterEvent
(
position:
Offset
(
0.0
,
101.0
)),
const
PointerEnterEvent
(
position:
Offset
(
0.0
,
101.0
)),
]));
]));
events
.
clear
();
events
.
clear
();
...
...
packages/flutter_test/lib/src/binding.dart
View file @
314eb3ba
...
@@ -808,8 +808,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
...
@@ -808,8 +808,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
'active mouse gesture to remove the mouse pointer.'
);
'active mouse gesture to remove the mouse pointer.'
);
// ignore: invalid_use_of_visible_for_testing_member
// ignore: invalid_use_of_visible_for_testing_member
RendererBinding
.
instance
.
initMouseTracker
();
RendererBinding
.
instance
.
initMouseTracker
();
// ignore: invalid_use_of_visible_for_testing_member
PointerEventConverter
.
clearPointers
();
}
}
}
}
...
...
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