summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/pdf/ui_manager.js
blob: f16535c81627a5a6e640a6fdc5d39ac2751c197b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';

var HIDE_TIMEOUT = 2000;

/**
 * Creates a UI Manager to handle transitioning of toolbars and panes.
 * @constructor
 * @param {Object} window The window containing the UI.
 * @param {Object} toolbar The toolbar element.
 * @param {Array} panes The panes that may be pulled in.
 */
function UiManager(window, toolbar, panes) {
  this.window_ = window;
  this.toolbar_ = toolbar;
  this.panes_ = panes;

  this.uiTimeout_ = null;

  var userInputs = ['click', 'keydown', 'mousemove', 'scroll'];
  for (var i = 0; i < userInputs.length; i++)
    this.window_.addEventListener(userInputs[i], this.showUi_.bind(this));
}

UiManager.prototype = {
  /**
   * @private
   * Display the toolbar and any pane that was previously opened.
   */
  showUi_: function() {
    this.toolbar_.show();
    for (var i = 0; i < this.panes_.length; i++)
      this.panes_[i].showIfOpenedByUser();

    this.hideUiAfterTimeout();
  },

  /**
   * @private
   * Hide the toolbar and any pane that was previously opened.
   */
  hideUi_: function() {
    this.toolbar_.hide();
    for (var i = 0; i < this.panes_.length; i++)
      this.panes_[i].hideIfOpenedByUser();
  },

  /**
   * Hide the toolbar after the HIDE_TIMEOUT has elapsed.
   */
  hideUiAfterTimeout: function() {
    if (this.uiTimeout_)
      clearTimeout(this.uiTimeout_);
    this.uiTimeout_ = setTimeout(this.hideUi_.bind(this), HIDE_TIMEOUT);
  }
};