<commit_before>// Copyright 2018-2020, University of Colorado Boulder

/**
 * Pointer type for managing accessibility, in particular the focus in the display.
 * Tracks the state of accessible focus.
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */

import Focus from '../accessibility/Focus.js';
import PDOMInstance from '../accessibility/pdom/PDOMInstance.js';
import Display from '../display/Display.js';
import scenery from '../scenery.js';
import Trail from '../util/Trail.js';
import Pointer from './Pointer.js'; // inherits from Pointer

class PDOMPointer extends Pointer {

  /**
   * @param {Display} display
   */
  constructor( display ) {
    super( null, false, 'a11y' );

    // @private
    this.display = display;

    this.initializeListeners();

    // @public (scenery-internal) - Prevent any "trusted" events from being dispatched to the KeyStateTracker. When
    // true, only scripted events are passed to the keyStateTracker. Otherwise, the modeled keyboard state when using
    // fuzzBoard will appear broken as both user and KeyboardFuzzer interact with display.
    this.blockTrustedEvents = false;

    // @private {Node|null} - target of a user event, if focus changes in response to keydown listeners, listeners
    // on keyup are prevented because the key press was not intended for the newly focused node.
    // TODO: Can we do this for more than keydown/keyup? See https://github.com/phetsims/scenery/issues/942
    this.keydownTargetNode = null;

    sceneryLog && sceneryLog.Pointer && sceneryLog.Pointer( 'Created ' + this.toString() );
  }

  /**
   * Set up listeners, attaching blur and focus listeners to the pointer once this PDOMPointer has been attached
   * to a display.
   * @private
   */
  initializeListeners() {

    this.addInputListener( {
      focus: () => {
        assert && assert( this.trail, 'trail should have been calculated for the focused node' );

        // NOTE: The "root" peer can't be focused (so it doesn't matter if it doesn't have a node).
        if ( this.trail.lastNode().focusable ) {
          Display.focus = new Focus( this.display, PDOMInstance.guessVisualTrail( this.trail, this.display.rootNode ) );
          this.display.pointerFocus = null;
        }
      },
      blur: event => {
        Display.focus = null;
        this.keydownTargetNode = null;
      },
      keydown: event => {
        if ( this.blockTrustedEvents && event.domEvent.isTrusted ) {
          return;
        }

        // set the target to potentially block keyup events
        this.keydownTargetNode = event.target;
      },
      keyup: event => {<commit_msg>remove unused lint of code, https://github.com/phetsims/scenery/issues/1148<commit_after>// Copyright 2018-2020, University of Colorado Boulder

/**
 * Pointer type for managing accessibility, in particular the focus in the display.
 * Tracks the state of accessible focus.
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */

import Focus from '../accessibility/Focus.js';
import PDOMInstance from '../accessibility/pdom/PDOMInstance.js';
import Display from '../display/Display.js';
import scenery from '../scenery.js';
import Trail from '../util/Trail.js';
import Pointer from './Pointer.js'; // inherits from Pointer

class PDOMPointer extends Pointer {

  /**
   * @param {Display} display
   */
  constructor( display ) {
    super( null, false, 'a11y' );

    // @private
    this.display = display;

    this.initializeListeners();

    // @public (scenery-internal) - Prevent any "trusted" events from being dispatched to the KeyStateTracker. When
    // true, only scripted events are passed to the keyStateTracker. Otherwise, the modeled keyboard state when using
    // fuzzBoard will appear broken as both user and KeyboardFuzzer interact with display.
    this.blockTrustedEvents = false;

    // @private {Node|null} - target of a user event, if focus changes in response to keydown listeners, listeners
    // on keyup are prevented because the key press was not intended for the newly focused node.
    // TODO: Can we do this for more than keydown/keyup? See https://github.com/phetsims/scenery/issues/942
    this.keydownTargetNode = null;

    sceneryLog && sceneryLog.Pointer && sceneryLog.Pointer( 'Created ' + this.toString() );
  }

  /**
   * Set up listeners, attaching blur and focus listeners to the pointer once this PDOMPointer has been attached
   * to a display.
   * @private
   */
  initializeListeners() {

    this.addInputListener( {
      focus: () => {
        assert && assert( this.trail, 'trail should have been calculated for the focused node' );

        // NOTE: The "root" peer can't be focused (so it doesn't matter if it doesn't have a node).
        if ( this.trail.lastNode().focusable ) {
          Display.focus = new Focus( this.display, PDOMInstance.guessVisualTrail( this.trail, this.display.rootNode ) );
        }
      },
      blur: event => {
        Display.focus = null;
        this.keydownTargetNode = null;
      },
      keydown: event => {
        if ( this.blockTrustedEvents && event.domEvent.isTrusted ) {
          return;
        }

        // set the target to potentially block keyup events
        this.keydownTargetNode = event.target;
      },
      keyup: event => {
{'fraction_non_alphanumeric': 0.10621279761904762, 'fraction_numerical': 0.005580357142857143, 'mean_word_length': 2.907703488372093, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4476401', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1465, 'n_words': 523}