Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/events/browserfeature.js
4115 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Browser capability checks for the events package.
9
*/
10
11
goog.module('goog.events.BrowserFeature');
12
goog.module.declareLegacyNamespace();
13
14
15
/**
16
* Tricks Closure Compiler into believing that a function is pure. The compiler
17
* assumes that any `valueOf` function is pure, without analyzing its contents.
18
*
19
* @param {function(): T} fn
20
* @return {T}
21
* @template T
22
*/
23
const purify = (fn) => {
24
return ({valueOf: fn}).valueOf();
25
};
26
27
28
/**
29
* Enum of browser capabilities.
30
* @enum {boolean}
31
*/
32
exports = {
33
/**
34
* Whether touch is enabled in the browser.
35
*/
36
TOUCH_ENABLED:
37
('ontouchstart' in goog.global ||
38
!!(goog.global['document'] && document.documentElement &&
39
'ontouchstart' in document.documentElement) ||
40
// IE10 uses non-standard touch events, so it has a different check.
41
!!(goog.global['navigator'] &&
42
(goog.global['navigator']['maxTouchPoints'] ||
43
goog.global['navigator']['msMaxTouchPoints']))),
44
45
/**
46
* Whether addEventListener supports W3C standard pointer events.
47
* http://www.w3.org/TR/pointerevents/
48
*/
49
POINTER_EVENTS: ('PointerEvent' in goog.global),
50
51
/**
52
* Whether addEventListener supports MSPointer events (only used in IE10).
53
* http://msdn.microsoft.com/en-us/library/ie/hh772103(v=vs.85).aspx
54
* http://msdn.microsoft.com/library/hh673557(v=vs.85).aspx
55
*/
56
MSPOINTER_EVENTS: false,
57
58
/**
59
* Whether addEventListener supports {passive: true}.
60
* https://developers.google.com/web/updates/2016/06/passive-event-listeners
61
*/
62
PASSIVE_EVENTS: purify(function() {
63
// If we're in a web worker or other custom environment, we can't tell.
64
if (!goog.global.addEventListener || !Object.defineProperty) { // IE 8
65
return false;
66
}
67
68
var passive = false;
69
var options = Object.defineProperty({}, 'passive', {
70
get: function() {
71
passive = true;
72
}
73
});
74
try {
75
const nullFunction = () => {};
76
goog.global.addEventListener('test', nullFunction, options);
77
goog.global.removeEventListener('test', nullFunction, options);
78
} catch (e) {
79
}
80
81
return passive;
82
})
83
};
84
85