Index: third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js b/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js |
index b30dbd998b54af4c732f8d0a0fc10c081ebede01..0c9aea551cc31513bb8eb130048f00596504a98b 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js |
+++ b/third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js |
@@ -1,149 +1,141 @@ |
// Copyright 2016 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. |
- |
/** |
- * @constructor |
* @implements {WebInspector.TargetManager.Observer} |
+ * @unrestricted |
*/ |
-WebInspector.MultitargetTouchModel = function() |
-{ |
+WebInspector.MultitargetTouchModel = class { |
+ constructor() { |
this._touchEnabled = false; |
this._touchMobile = false; |
this._customTouchEnabled = false; |
WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capability.Browser); |
-}; |
- |
-WebInspector.MultitargetTouchModel._symbol = Symbol("MultitargetTouchModel.symbol"); |
- |
-WebInspector.MultitargetTouchModel.prototype = { |
- /** |
- * @param {boolean} enabled |
- * @param {boolean} mobile |
- */ |
- setTouchEnabled: function(enabled, mobile) |
- { |
- this._touchEnabled = enabled; |
- this._touchMobile = mobile; |
- this._updateAllTargets(); |
- }, |
+ } |
- /** |
- * @param {boolean} enabled |
- */ |
- setCustomTouchEnabled: function(enabled) |
- { |
- this._customTouchEnabled = enabled; |
- this._updateAllTargets(); |
- }, |
- |
- _updateAllTargets: function() |
- { |
- for (var target of WebInspector.targetManager.targets(WebInspector.Target.Capability.Browser)) |
- this._applyToTarget(target); |
- }, |
+ /** |
+ * @return {!WebInspector.MultitargetTouchModel} |
+ */ |
+ static instance() { |
+ if (!WebInspector.MultitargetTouchModel._instance) |
+ WebInspector.MultitargetTouchModel._instance = new WebInspector.MultitargetTouchModel(); |
+ return /** @type {!WebInspector.MultitargetTouchModel} */ (WebInspector.MultitargetTouchModel._instance); |
+ } |
+ |
+ /** |
+ * @param {boolean} enabled |
+ * @param {boolean} mobile |
+ */ |
+ setTouchEnabled(enabled, mobile) { |
+ this._touchEnabled = enabled; |
+ this._touchMobile = mobile; |
+ this._updateAllTargets(); |
+ } |
+ |
+ /** |
+ * @param {boolean} enabled |
+ */ |
+ setCustomTouchEnabled(enabled) { |
+ this._customTouchEnabled = enabled; |
+ this._updateAllTargets(); |
+ } |
+ |
+ _updateAllTargets() { |
+ for (var target of WebInspector.targetManager.targets(WebInspector.Target.Capability.Browser)) |
+ this._applyToTarget(target); |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.Target} target |
+ */ |
+ _applyToTarget(target) { |
+ var current = {enabled: this._touchEnabled, configuration: this._touchMobile ? 'mobile' : 'desktop'}; |
+ if (this._customTouchEnabled) |
+ current = {enabled: true, configuration: 'mobile'}; |
+ |
+ var domModel = WebInspector.DOMModel.fromTarget(target); |
+ var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false; |
+ if (inspectModeEnabled) |
+ current = {enabled: false, configuration: 'mobile'}; |
/** |
- * @param {!WebInspector.Target} target |
+ * @suppressGlobalPropertiesCheck |
*/ |
- _applyToTarget: function(target) |
- { |
- var current = {enabled: this._touchEnabled, configuration : this._touchMobile ? "mobile" : "desktop"}; |
- if (this._customTouchEnabled) |
- current = {enabled: true, configuration: "mobile"}; |
- |
- var domModel = WebInspector.DOMModel.fromTarget(target); |
- var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false; |
- if (inspectModeEnabled) |
- current = {enabled: false, configuration: "mobile"}; |
- |
- /** |
- * @suppressGlobalPropertiesCheck |
- */ |
- const injectedFunction = function() { |
- const touchEvents = ["ontouchstart", "ontouchend", "ontouchmove", "ontouchcancel"]; |
- var recepients = [window.__proto__, document.__proto__]; |
- for (var i = 0; i < touchEvents.length; ++i) { |
- for (var j = 0; j < recepients.length; ++j) { |
- if (!(touchEvents[i] in recepients[j])) |
- Object.defineProperty(recepients[j], touchEvents[i], { value: null, writable: true, configurable: true, enumerable: true }); |
- } |
- } |
- }; |
- |
- var symbol = WebInspector.MultitargetTouchModel._symbol; |
- var previous = target[symbol] || {enabled: false, configuration: "mobile", scriptId: ""}; |
- |
- if (previous.enabled === current.enabled && (!current.enabled || previous.configuration === current.configuration)) |
- return; |
- |
- if (previous.scriptId) { |
- target.pageAgent().removeScriptToEvaluateOnLoad(previous.scriptId); |
- target[symbol].scriptId = ""; |
+ const injectedFunction = function() { |
+ const touchEvents = ['ontouchstart', 'ontouchend', 'ontouchmove', 'ontouchcancel']; |
+ var recepients = [window.__proto__, document.__proto__]; |
+ for (var i = 0; i < touchEvents.length; ++i) { |
+ for (var j = 0; j < recepients.length; ++j) { |
+ if (!(touchEvents[i] in recepients[j])) |
+ Object.defineProperty( |
+ recepients[j], touchEvents[i], {value: null, writable: true, configurable: true, enumerable: true}); |
} |
+ } |
+ }; |
- target[symbol] = current; |
- target[symbol].scriptId = ""; |
- |
- if (current.enabled) |
- target.pageAgent().addScriptToEvaluateOnLoad("(" + injectedFunction.toString() + ")()", scriptAddedCallback); |
+ var symbol = WebInspector.MultitargetTouchModel._symbol; |
+ var previous = target[symbol] || {enabled: false, configuration: 'mobile', scriptId: ''}; |
- /** |
- * @param {?Protocol.Error} error |
- * @param {string} scriptId |
- */ |
- function scriptAddedCallback(error, scriptId) |
- { |
- (target[symbol] || {}).scriptId = error ? "" : scriptId; |
- } |
+ if (previous.enabled === current.enabled && (!current.enabled || previous.configuration === current.configuration)) |
+ return; |
- target.emulationAgent().setTouchEmulationEnabled(current.enabled, current.configuration); |
- }, |
+ if (previous.scriptId) { |
+ target.pageAgent().removeScriptToEvaluateOnLoad(previous.scriptId); |
+ target[symbol].scriptId = ''; |
+ } |
- /** |
- * @param {!WebInspector.Event} event |
- */ |
- _inspectModeToggled: function(event) |
- { |
- var domModel = /** @type {!WebInspector.DOMModel} */ (event.target); |
- this._applyToTarget(domModel.target()); |
- }, |
+ target[symbol] = current; |
+ target[symbol].scriptId = ''; |
- /** |
- * @override |
- * @param {!WebInspector.Target} target |
- */ |
- targetAdded: function(target) |
- { |
- var domModel = WebInspector.DOMModel.fromTarget(target); |
- if (domModel) |
- domModel.addEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); |
- this._applyToTarget(target); |
- }, |
+ if (current.enabled) |
+ target.pageAgent().addScriptToEvaluateOnLoad('(' + injectedFunction.toString() + ')()', scriptAddedCallback); |
/** |
- * @override |
- * @param {!WebInspector.Target} target |
+ * @param {?Protocol.Error} error |
+ * @param {string} scriptId |
*/ |
- targetRemoved: function(target) |
- { |
- var domModel = WebInspector.DOMModel.fromTarget(target); |
- if (domModel) |
- domModel.removeEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); |
+ function scriptAddedCallback(error, scriptId) { |
+ (target[symbol] || {}).scriptId = error ? '' : scriptId; |
} |
+ |
+ target.emulationAgent().setTouchEmulationEnabled(current.enabled, current.configuration); |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.Event} event |
+ */ |
+ _inspectModeToggled(event) { |
+ var domModel = /** @type {!WebInspector.DOMModel} */ (event.target); |
+ this._applyToTarget(domModel.target()); |
+ } |
+ |
+ /** |
+ * @override |
+ * @param {!WebInspector.Target} target |
+ */ |
+ targetAdded(target) { |
+ var domModel = WebInspector.DOMModel.fromTarget(target); |
+ if (domModel) |
+ domModel.addEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); |
+ this._applyToTarget(target); |
+ } |
+ |
+ /** |
+ * @override |
+ * @param {!WebInspector.Target} target |
+ */ |
+ targetRemoved(target) { |
+ var domModel = WebInspector.DOMModel.fromTarget(target); |
+ if (domModel) |
+ domModel.removeEventListener( |
+ WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled, this); |
+ } |
}; |
+WebInspector.MultitargetTouchModel._symbol = Symbol('MultitargetTouchModel.symbol'); |
/** @type {?WebInspector.MultitargetTouchModel} */ |
WebInspector.MultitargetTouchModel._instance = null; |
-/** |
- * @return {!WebInspector.MultitargetTouchModel} |
- */ |
-WebInspector.MultitargetTouchModel.instance = function() |
-{ |
- if (!WebInspector.MultitargetTouchModel._instance) |
- WebInspector.MultitargetTouchModel._instance = new WebInspector.MultitargetTouchModel(); |
- return /** @type {!WebInspector.MultitargetTouchModel} */ (WebInspector.MultitargetTouchModel._instance); |
-}; |
+ |