MCPcopy Create free account
hub / github.com/ampproject/amphtml / constructor

Method constructor

src/input.js:23–79  ·  view source on GitHub ↗

* @param {!Window} win

(win)

Source from the content-addressed store, hash-verified

21 * @param {!Window} win
22 */
23 constructor(win) {
24 /** @const {!Window} */
25 this.win = win;
26
27 /** @private {!Function} */
28 this.boundOnKeyDown_ = this.onKeyDown_.bind(this);
29
30 /** @private {!Function} */
31 this.boundOnMouseDown_ = this.onMouseDown_.bind(this);
32
33 /** @private {?function(!Event)} */
34 this.boundOnMouseMove_ = null;
35
36 /** @private {?Function} */
37 this.boundMouseCanceled_ = null;
38
39 /** @private {?Function} */
40 this.boundMouseConfirmed_ = null;
41
42 /** @private {boolean} */
43 this.hasTouch_ =
44 'ontouchstart' in win ||
45 (win.navigator['maxTouchPoints'] !== undefined &&
46 win.navigator['maxTouchPoints'] > 0) ||
47 win['DocumentTouch'] !== undefined;
48 dev().fine(TAG_, 'touch detected:', this.hasTouch_);
49
50 /** @private {boolean} */
51 this.keyboardActive_ = false;
52 this.win.document.addEventListener('keydown', this.boundOnKeyDown_);
53 this.win.document.addEventListener('mousedown', this.boundOnMouseDown_);
54
55 /** @private {boolean} */
56 this.hasMouse_ = true;
57
58 /** @private {number} */
59 this.mouseConfirmAttemptCount_ = 0;
60
61 /** @private {!Observable<boolean>} */
62 this.touchDetectedObservable_ = new Observable();
63
64 /** @private {!Observable<boolean>} */
65 this.mouseDetectedObservable_ = new Observable();
66
67 /** @private {!Observable<boolean>} */
68 this.keyboardStateObservable_ = new Observable();
69
70 // If touch available, temporarily set hasMouse to false and wait for
71 // mouse events.
72 if (this.hasTouch_) {
73 this.hasMouse_ = !this.hasTouch_;
74 this.boundOnMouseMove_ = /** @type {function(!Event)} */ (
75 this.onMouseMove_.bind(this)
76 );
77 listenOnce(win.document, 'mousemove', this.boundOnMouseMove_);
78 }
79 }
80

Callers

nothing calls this directly

Calls 4

devFunction · 0.90
listenOnceFunction · 0.90
fineMethod · 0.80
addEventListenerMethod · 0.45

Tested by

no test coverage detected