<commit_before>/**
 * Copyright 2013 Google, Inc. All Rights Reserved.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/**
 * @fileoverview Navigation of events in graphics replay.
 *
 * @author <EMAIL> (<NAME>)
 */

goog.provide('wtf.replay.graphics.ui.EventNavigator');

goog.require('goog.soy');
goog.require('wtf.replay.graphics.Playback');
goog.require('wtf.replay.graphics.ui.EventNavigatorTableSource');
goog.require('wtf.replay.graphics.ui.eventNavigator');
goog.require('wtf.ui.Control');
goog.require('wtf.ui.VirtualTable');



/**
 * Navigation of events control.
 *
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @param {!Element} parentElement Element to display in.
 * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper.
 * @constructor
 * @extends {wtf.ui.Control}
 */
wtf.replay.graphics.ui.EventNavigator = function(
    playback, parentElement, opt_domHelper) {
  goog.base(this, parentElement, opt_domHelper);

  /**
   * Source of table.
   * @type {!wtf.replay.graphics.ui.EventNavigatorTableSource}
   * @private
   */
  this.tableSource_ =
      new wtf.replay.graphics.ui.EventNavigatorTableSource(playback);
  this.registerDisposable(this.tableSource_);

  /**
   * Results table.
   * @type {!wtf.ui.VirtualTable}
   * @private
   */
  this.table_ = new wtf.ui.VirtualTable(
      this.getChildElement(
          goog.getCssName('replayGraphicsEventNavigatorTable')),
      this.getDom());
  this.registerDisposable(this.table_);
  this.table_.setSource(this.tableSource_);

  // Listen to changes in step.
  this.listenToStepUpdates_(playback);
};
goog.inherits(wtf.replay.graphics.ui.EventNavigator, wtf.ui.Control);


/**
 * @override
 */
wtf.replay.graphics.ui.EventNavigator.prototype.createDom = function(dom) {
  return /** @type {!Element} */ (goog.soy.renderAsFragment(
      wtf.replay.graphics.ui.eventNavigator.controller,
      undefined, undefined, dom));
};


/**
 * Changes the layout of elements to fit the container.
 */
wtf.replay.graphics.ui.EventNavigator.prototype.layout = function() {
  this.table_.layout();
};


/**
 * Ensures that the event table updates when the step changes.
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @private
 */
wtf.replay.graphics.ui.EventNavigator.prototype.listenToStepUpdates_ =
    function(playback) {
  playback.addListener(
      wtf.replay.graphics.Playback.EventType.STEP_CHANGED,
      function() {
        this.tableSource_.invalidate();
      }, this);
};<commit_msg>Stopped event updates when playing. Fixes #375.<commit_after>/**
 * Copyright 2013 Google, Inc. All Rights Reserved.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/**
 * @fileoverview Navigation of events in graphics replay.
 *
 * @author <EMAIL> (<NAME>)
 */

goog.provide('wtf.replay.graphics.ui.EventNavigator');

goog.require('goog.soy');
goog.require('wtf.replay.graphics.Playback');
goog.require('wtf.replay.graphics.ui.EventNavigatorTableSource');
goog.require('wtf.replay.graphics.ui.eventNavigator');
goog.require('wtf.ui.Control');
goog.require('wtf.ui.VirtualTable');



/**
 * Navigation of events control.
 *
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @param {!Element} parentElement Element to display in.
 * @param {goog.dom.DomHelper=} opt_domHelper The DOM helper.
 * @constructor
 * @extends {wtf.ui.Control}
 */
wtf.replay.graphics.ui.EventNavigator = function(
    playback, parentElement, opt_domHelper) {
  goog.base(this, parentElement, opt_domHelper);

  /**
   * Source of table.
   * @type {!wtf.replay.graphics.ui.EventNavigatorTableSource}
   * @private
   */
  this.tableSource_ =
      new wtf.replay.graphics.ui.EventNavigatorTableSource(playback);
  this.registerDisposable(this.tableSource_);

  /**
   * Results table.
   * @type {!wtf.ui.VirtualTable}
   * @private
   */
  this.table_ = new wtf.ui.VirtualTable(
      this.getChildElement(
          goog.getCssName('replayGraphicsEventNavigatorTable')),
      this.getDom());
  this.registerDisposable(this.table_);
  this.table_.setSource(this.tableSource_);

  // Listen to changes in step.
  this.listenToStepUpdates_(playback);

  // Stop listening to changes in step after playing begins. Start listening
  // again when playing stops.
  this.listenToPlayUpdates_(playback);
};
goog.inherits(wtf.replay.graphics.ui.EventNavigator, wtf.ui.Control);


/**
 * @override
 */
wtf.replay.graphics.ui.EventNavigator.prototype.createDom = function(dom) {
  return /** @type {!Element} */ (goog.soy.renderAsFragment(
      wtf.replay.graphics.ui.eventNavigator.controller,
      undefined, undefined, dom));
};


/**
 * Changes the layout of elements to fit the container.
 */
wtf.replay.graphics.ui.EventNavigator.prototype.layout = function() {
  this.table_.layout();
};


/**
 * Listens to play updates to determine if the event navigator should update
 * if the step changes.
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @private
 */
wtf.replay.graphics.ui.EventNavigator.prototype.listenToPlayUpdates_ =
    function(playback) {
  // After playing begins, do not update the table events upon step change.
  playback.addListener(
      wtf.replay.graphics.Playback.EventType.PLAY_BEGAN,
      function() {
        this.unListenToStepUpdates_(playback);
        this.table_.setSource(null);
      }, this);

  // After playing stops, update the table events upon step change.
  playback.addListener(
      wtf.replay.graphics.Playback.EventType.PLAY_STOPPED,
      function() {
        this.listenToStepUpdates_(playback);
        this.table_.setSource(this.tableSource_);
      }, this);
};


/**
 * Ensures that the event table updates when the step changes.
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @private
 */
wtf.replay.graphics.ui.EventNavigator.prototype.listenToStepUpdates_ =
    function(playback) {
  playback.addListener(
      wtf.replay.graphics.Playback.EventType.STEP_CHANGED,
      this.tableSource_.invalidate, this.tableSource_);
};


/**
 * Stops updating the event table based on changes in step.
 * @param {!wtf.replay.graphics.Playback} playback The playback.
 * @private
 */
wtf.replay.graphics.ui.EventNavigator.prototype.unListenToStepUpdates_ =
    function(playback) {
  playback.removeListener(
      wtf.replay.graphics.Playback.EventType.STEP_CHANGED,
      this.tableSource_.invalidate, this.tableSource_);
};
{'fraction_non_alphanumeric': 0.13313971262610821, 'fraction_numerical': 0.001681442983797004, 'mean_word_length': 3.8828358208955223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '7579878', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2077, 'n_words': 409}