Path: blob/trunk/third_party/closure/goog/dom/browserfeature.js
4214 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Browser capability checks for the dom package.8*/91011goog.provide('goog.dom.BrowserFeature');1213goog.require('goog.userAgent');141516/**17* @define {boolean} Whether we know at compile time that the browser doesn't18* support OffscreenCanvas.19*/20goog.dom.BrowserFeature.ASSUME_NO_OFFSCREEN_CANVAS =21goog.define('goog.dom.ASSUME_NO_OFFSCREEN_CANVAS', false);2223/**24* @define {boolean} Whether we know at compile time that the browser supports25* all OffscreenCanvas contexts.26*/27// TODO(user): Eventually this should default to "FEATURESET_YEAR >= 202X".28goog.dom.BrowserFeature.ASSUME_OFFSCREEN_CANVAS =29goog.define('goog.dom.ASSUME_OFFSCREEN_CANVAS', false);3031/**32* Detects if a particular OffscreenCanvas context is supported.33* @param {string} contextName name of the context to test.34* @return {boolean} Whether the browser supports this OffscreenCanvas context.35* @private36*/37goog.dom.BrowserFeature.detectOffscreenCanvas_ = function(contextName) {38'use strict';39// This code only gets removed because we forced @nosideeffects on40// the functions. See: b/13880237641try {42return Boolean(new self.OffscreenCanvas(0, 0).getContext(contextName));43} catch (ex) {44}45return false;46};4748/**49* Whether the browser supports OffscreenCanvas 2D context.50* @const {boolean}51*/52goog.dom.BrowserFeature.OFFSCREEN_CANVAS_2D =53!goog.dom.BrowserFeature.ASSUME_NO_OFFSCREEN_CANVAS &&54(goog.dom.BrowserFeature.ASSUME_OFFSCREEN_CANVAS ||55goog.dom.BrowserFeature.detectOffscreenCanvas_('2d'));5657/**58* Whether attributes 'name' and 'type' can be added to an element after it's59* created. False in Internet Explorer prior to version 9.60* @const {boolean}61*/62goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES = true;6364/**65* Whether we can use element.children to access an element's Element66* children. Available since Gecko 1.9.1, IE 9. (IE<9 also includes comment67* nodes in the collection.)68* @const {boolean}69*/70goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE = true;7172/**73* Opera, Safari 3, and Internet Explorer 9 all support innerText but they74* include text nodes in script and style tags. Not document-mode-dependent.75* @const {boolean}76*/77goog.dom.BrowserFeature.CAN_USE_INNER_TEXT = false;7879/**80* MSIE, Opera, and Safari>=4 support element.parentElement to access an81* element's parent if it is an Element.82* @const {boolean}83*/84goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY =85goog.userAgent.IE || goog.userAgent.WEBKIT;8687/**88* Whether NoScope elements need a scoped element written before them in89* innerHTML.90* MSDN: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx#191* @const {boolean}92*/93goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT = goog.userAgent.IE;949596