@@ -111,13 +111,7 @@ public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDisp
111
111
112
112
if (!supportsHover ) {
113
113
dispatchNonBubblingEventForPathWhenListened (
114
- EVENT .ENTER ,
115
- EVENT .ENTER_CAPTURE ,
116
- hitPath ,
117
- eventDispatcher ,
118
- surfaceId ,
119
- motionEvent ,
120
- false );
114
+ EVENT .ENTER , EVENT .ENTER_CAPTURE , hitPath , eventDispatcher , surfaceId , motionEvent );
121
115
}
122
116
123
117
boolean listeningForDown =
@@ -202,13 +196,7 @@ public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDisp
202
196
203
197
if (!supportsHover ) {
204
198
dispatchNonBubblingEventForPathWhenListened (
205
- EVENT .LEAVE ,
206
- EVENT .LEAVE_CAPTURE ,
207
- hitPath ,
208
- eventDispatcher ,
209
- surfaceId ,
210
- motionEvent ,
211
- false );
199
+ EVENT .LEAVE , EVENT .LEAVE_CAPTURE , hitPath , eventDispatcher , surfaceId , motionEvent );
212
200
}
213
201
return ;
214
202
}
@@ -239,28 +227,22 @@ private static boolean isAnyoneListeningForBubblingEvent(
239
227
return false ;
240
228
}
241
229
242
- /**
243
- * Dispatch event only if ancestor is listening to relevant capture event. This should only be
244
- * relevant for ENTER/LEAVE events that need to be dispatched along every relevant view in the hit
245
- * path.
246
- *
247
- * @param pointerEventType - Should only be ENTER/LEAVE events
248
- * @param hitPath - ViewTargets ordered from target -> root
249
- * @param dispatcher
250
- * @param surfaceId
251
- * @param motionEvent
252
- * @param forceDispatch - Ignore if ancestor is listening and force the event to be dispatched
230
+ /*
231
+ Dispatch event only if ancestor is listening to relevant event.
232
+ This should only be relevant for ENTER/LEAVE events.
233
+ @param hitPath - ordered from inner target to root
253
234
*/
235
+
236
+ /** Dispatch non-bubbling event along the hit path only when relevant listeners */
254
237
private static void dispatchNonBubblingEventForPathWhenListened (
255
238
EVENT event ,
256
239
EVENT captureEvent ,
257
240
List <ViewTarget > hitPath ,
258
241
EventDispatcher dispatcher ,
259
242
int surfaceId ,
260
- MotionEvent motionEvent ,
261
- boolean forceDispatch ) {
243
+ MotionEvent motionEvent ) {
262
244
263
- boolean ancestorListening = forceDispatch ;
245
+ boolean ancestorListening = false ;
264
246
String eventName = PointerEventHelper .getDispatchableEventName (event );
265
247
if (eventName == null ) {
266
248
return ;
@@ -330,72 +312,54 @@ private void handleHoverEvent(
330
312
// hitState is list ordered from inner child -> parent tag
331
313
// Traverse hitState back-to-front to find the first divergence with mLastHitState
332
314
// FIXME: this may generate incorrect events when view collapsing changes the hierarchy
333
- boolean nonDivergentListeningToEnter = false ;
334
- boolean nonDivergentListeningToLeave = false ;
335
- int firstDivergentIndexFromBack = 0 ;
336
- while (firstDivergentIndexFromBack < Math .min (hitPath .size (), mLastHitPath .size ())
315
+ int firstDivergentIndex = 0 ;
316
+ while (firstDivergentIndex < Math .min (hitPath .size (), mLastHitPath .size ())
337
317
&& hitPath
338
- .get (hitPath .size () - 1 - firstDivergentIndexFromBack )
339
- .equals (mLastHitPath .get (mLastHitPath .size () - 1 - firstDivergentIndexFromBack ))) {
340
-
341
- // Track if any non-diverging views are listening to enter/leave
342
- View nonDivergentViewTargetView =
343
- hitPath .get (hitPath .size () - 1 - firstDivergentIndexFromBack ).getView ();
344
- if (!nonDivergentListeningToEnter
345
- && PointerEventHelper .isListening (nonDivergentViewTargetView , EVENT .ENTER_CAPTURE )) {
346
- nonDivergentListeningToEnter = true ;
347
- }
348
- if (!nonDivergentListeningToLeave
349
- && PointerEventHelper .isListening (nonDivergentViewTargetView , EVENT .LEAVE_CAPTURE )) {
350
- nonDivergentListeningToLeave = true ;
351
- }
352
-
353
- firstDivergentIndexFromBack ++;
318
+ .get (hitPath .size () - 1 - firstDivergentIndex )
319
+ .equals (mLastHitPath .get (mLastHitPath .size () - 1 - firstDivergentIndex ))) {
320
+ firstDivergentIndex ++;
354
321
}
355
322
356
- boolean hasDiverged =
357
- firstDivergentIndexFromBack < Math .max (hitPath .size (), mLastHitPath .size ());
323
+ boolean hasDiverged = firstDivergentIndex < Math .max (hitPath .size (), mLastHitPath .size ());
358
324
325
+ // Fire all relevant enter events
359
326
if (hasDiverged ) {
360
327
// If something has changed in either enter/exit, let's start a new coalescing key
361
328
mTouchEventCoalescingKeyHelper .incrementCoalescingKey (mHoverInteractionKey );
362
329
363
- List <ViewTarget > enterViewTargets =
364
- hitPath .subList (0 , hitPath .size () - firstDivergentIndexFromBack );
330
+ List <ViewTarget > enterViewTargets = hitPath .subList (0 , hitPath .size () - firstDivergentIndex );
365
331
if (enterViewTargets .size () > 0 ) {
366
- dispatchNonBubblingEventForPathWhenListened (
367
- EVENT .ENTER ,
368
- EVENT .ENTER_CAPTURE ,
369
- enterViewTargets ,
370
- eventDispatcher ,
371
- surfaceId ,
372
- motionEvent ,
373
- nonDivergentListeningToEnter );
332
+ // root -> child
333
+ for (int i = enterViewTargets .size (); i -- > 0 ; ) {
334
+ eventDispatcher .dispatchEvent (
335
+ PointerEvent .obtain (
336
+ PointerEventHelper .POINTER_ENTER ,
337
+ surfaceId ,
338
+ enterViewTargets .get (i ).getViewId (),
339
+ motionEvent ));
340
+ }
374
341
}
375
342
343
+ // Fire all relevant exit events
376
344
List <ViewTarget > exitViewTargets =
377
- mLastHitPath .subList (0 , mLastHitPath .size () - firstDivergentIndexFromBack );
345
+ mLastHitPath .subList (0 , mLastHitPath .size () - firstDivergentIndex );
378
346
if (exitViewTargets .size () > 0 ) {
379
347
// child -> root
380
- dispatchNonBubblingEventForPathWhenListened (
381
- EVENT . LEAVE ,
382
- EVENT . LEAVE_CAPTURE ,
383
- enterViewTargets ,
384
- eventDispatcher ,
385
- surfaceId ,
386
- motionEvent ,
387
- nonDivergentListeningToLeave );
348
+ for ( ViewTarget exitViewTarget : exitViewTargets ) {
349
+ eventDispatcher . dispatchEvent (
350
+ PointerEvent . obtain (
351
+ PointerEventHelper . POINTER_LEAVE ,
352
+ surfaceId ,
353
+ exitViewTarget . getViewId () ,
354
+ motionEvent ));
355
+ }
388
356
}
389
357
}
390
358
391
359
int coalescingKey = mTouchEventCoalescingKeyHelper .getCoalescingKey (mHoverInteractionKey );
392
- boolean listeningToMove =
393
- isAnyoneListeningForBubblingEvent (hitPath , EVENT .MOVE , EVENT .MOVE_CAPTURE );
394
- if (listeningToMove ) {
395
- eventDispatcher .dispatchEvent (
396
- PointerEvent .obtain (
397
- PointerEventHelper .POINTER_MOVE , surfaceId , targetTag , motionEvent , coalescingKey ));
398
- }
360
+ eventDispatcher .dispatchEvent (
361
+ PointerEvent .obtain (
362
+ PointerEventHelper .POINTER_MOVE , surfaceId , targetTag , motionEvent , coalescingKey ));
399
363
400
364
mLastHitPath = hitPath ;
401
365
mLastEventCoordinates [0 ] = x ;
@@ -425,13 +389,7 @@ private void dispatchCancelEvent(
425
389
}
426
390
427
391
dispatchNonBubblingEventForPathWhenListened (
428
- EVENT .LEAVE ,
429
- EVENT .LEAVE_CAPTURE ,
430
- hitPath ,
431
- eventDispatcher ,
432
- surfaceId ,
433
- motionEvent ,
434
- false );
392
+ EVENT .LEAVE , EVENT .LEAVE_CAPTURE , hitPath , eventDispatcher , surfaceId , motionEvent );
435
393
436
394
mTouchEventCoalescingKeyHelper .removeCoalescingKey (mDownStartTime );
437
395
mDownStartTime = TouchEvent .UNSET ;
0 commit comments