B2G/gecko/testing/marionette/marionette-listener.js
/**
 * Function to emit touch events for each finger. e.g. finger=[['press', id], ['wait', 5], ['release']]
 * touchId represents the finger id, i keeps track of the current action of the chain 
 */
Function to emit touch events for each finger.
Function to emit touch events for each finger .
function actions(chain, touchId, command_id, i) {
  if (typeof i === "undefined") {
    i = 0;
  }
  if (i == chain.length) {
    sendResponse({value: touchId}, command_id);
    return;
  }
  let pack = chain[i];
  let command = pack[0];
  let el;
  let c;
  i++;
  if (command != 'press') {
    if (!(touchId in touchIds) && !mouseEventsOnly) {
      sendError("Element has not been pressed", 500, null, command_id);
      return;
    }
  }
  switch(command) {
    case 'press':
      if (lastCoordinates) {
        generateEvents('cancel', lastCoordinates[0], lastCoordinates[1], touchId);
        sendError("Invalid Command: press cannot follow an active touch event", 500, null, command_id);
        return;
      }
      el = elementManager.getKnownElement(pack[1], curWindow);
      if (!checkVisible(el)) {
         sendError("Element is not currently visible and may not be manipulated", 11, null, command_id);
         return;
      }
      c = coordinates(el, pack[2], pack[3]);
      touchId = generateEvents('press', c.x, c.y, null, el);
      actions(chain, touchId, command_id, i);
      break;
    case 'release':
      generateEvents('release', lastCoordinates[0], lastCoordinates[1], touchId);
      actions(chain, null, command_id, i);
      break;
    case 'move':
      el = elementManager.getKnownElement(pack[1], curWindow);
      c = coordinates(el);
      generateEvents('move', c.x, c.y, touchId);
      actions(chain, touchId, command_id, i);
      break;
    case 'moveByOffset':
      generateEvents('move', lastCoordinates[0] + pack[1], lastCoordinates[1] + pack[2], touchId);
      actions(chain, touchId, command_id, i);
      break;
    case 'wait':
      if (pack[1] != null ) {
        let time = pack[1]*1000;
        let standard = 750;
        try {
          standard = Services.prefs.getIntPref("ui.click_hold_context_menus.delay");
        }
        catch (e){}
        if (time >= standard && isTap) {
            chain.splice(i, 0, ['longPress'], ['wait', (time-standard)/1000]);
            time = standard;
        }
        checkTimer.initWithCallback(function(){actions(chain, touchId, command_id, i);}, time, Ci.nsITimer.TYPE_ONE_SHOT);
      }
      else {
        actions(chain, touchId, command_id, i);
      }
      break;
    case 'cancel':
      generateEvents('cancel', lastCoordinates[0], lastCoordinates[1], touchId);
      actions(chain, touchId, command_id, i);
      break;
    case 'longPress':
      generateEvents('contextmenu', lastCoordinates[0], lastCoordinates[1], touchId);
      actions(chain, touchId, command_id, i);
      break;
  }
}
function actions ( chain , touchId , command_id , i ) { if ( typeof i === "undefined" ) { i = 0 ; } if ( i == chain . length ) { sendResponse ( { value : touchId } , command_id ) ; return ; } let pack = chain [ i ] ; let command = pack [ 0 ] ; let el ; let c ; i ++ ; if ( command != 'press' ) { if ( ! ( touchId in touchIds ) && ! mouseEventsOnly ) { sendError ( "Element has not been pressed" , 500 , null , command_id ) ; return ; } } switch ( command ) { case 'press' : if ( lastCoordinates ) { generateEvents ( 'cancel' , lastCoordinates [ 0 ] , lastCoordinates [ 1 ] , touchId ) ; sendError ( "Invalid Command: press cannot follow an active touch event" , 500 , null , command_id ) ; return ; } el = elementManager . getKnownElement ( pack [ 1 ] , curWindow ) ; if ( ! checkVisible ( el ) ) { sendError ( "Element is not currently visible and may not be manipulated" , 11 , null , command_id ) ; return ; } c = coordinates ( el , pack [ 2 ] , pack [ 3 ] ) ; touchId = generateEvents ( 'press' , c . x , c . y , null , el ) ; actions ( chain , touchId , command_id , i ) ; break ; case 'release' : generateEvents ( 'release' , lastCoordinates [ 0 ] , lastCoordinates [ 1 ] , touchId ) ; actions ( chain , null , command_id , i ) ; break ; case 'move' : el = elementManager . getKnownElement ( pack [ 1 ] , curWindow ) ; c = coordinates ( el ) ; generateEvents ( 'move' , c . x , c . y , touchId ) ; actions ( chain , touchId , command_id , i ) ; break ; case 'moveByOffset' : generateEvents ( 'move' , lastCoordinates [ 0 ] + pack [ 1 ] , lastCoordinates [ 1 ] + pack [ 2 ] , touchId ) ; actions ( chain , touchId , command_id , i ) ; break ; case 'wait' : if ( pack [ 1 ] != null ) { let time = pack [ 1 ] * 1000 ; let standard = 750 ; try { standard = Services . prefs . getIntPref ( "ui.click_hold_context_menus.delay" ) ; } catch ( e ) { } if ( time >= standard && isTap ) { chain . splice ( i , 0 , [ 'longPress' ] , [ 'wait' , ( time - standard ) / 1000 ] ) ; time = standard ; } checkTimer . initWithCallback ( function ( ) { actions ( chain , touchId , command_id , i ) ; } , time , Ci . nsITimer . TYPE_ONE_SHOT ) ; } else { actions ( chain , touchId , command_id , i ) ; } break ; case 'cancel' : generateEvents ( 'cancel' , lastCoordinates [ 0 ] , lastCoordinates [ 1 ] , touchId ) ; actions ( chain , touchId , command_id , i ) ; break ; case 'longPress' : generateEvents ( 'contextmenu' , lastCoordinates [ 0 ] , lastCoordinates [ 1 ] , touchId ) ; actions ( chain , touchId , command_id , i ) ; break ; } }
Function to emit touch events for each finger.
Function to emit touch events for each finger .
//if mouseEventsOnly, then touchIds isn't used // standard waiting time to fire contextmenu