Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/TouchModel.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @implements {WebInspector.TargetManager.Observer} 5 * @implements {SDK.TargetManager.Observer}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 WebInspector.MultitargetTouchModel = class { 8 Emulation.MultitargetTouchModel = class {
9 constructor() { 9 constructor() {
10 this._touchEnabled = false; 10 this._touchEnabled = false;
11 this._touchMobile = false; 11 this._touchMobile = false;
12 this._customTouchEnabled = false; 12 this._customTouchEnabled = false;
13 13
14 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.Browser); 14 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
15 } 15 }
16 16
17 /** 17 /**
18 * @return {!WebInspector.MultitargetTouchModel} 18 * @return {!Emulation.MultitargetTouchModel}
19 */ 19 */
20 static instance() { 20 static instance() {
21 if (!WebInspector.MultitargetTouchModel._instance) 21 if (!Emulation.MultitargetTouchModel._instance)
22 WebInspector.MultitargetTouchModel._instance = new WebInspector.Multitarge tTouchModel(); 22 Emulation.MultitargetTouchModel._instance = new Emulation.MultitargetTouch Model();
23 return /** @type {!WebInspector.MultitargetTouchModel} */ (WebInspector.Mult itargetTouchModel._instance); 23 return /** @type {!Emulation.MultitargetTouchModel} */ (Emulation.Multitarge tTouchModel._instance);
24 } 24 }
25 25
26 /** 26 /**
27 * @param {boolean} enabled 27 * @param {boolean} enabled
28 * @param {boolean} mobile 28 * @param {boolean} mobile
29 */ 29 */
30 setTouchEnabled(enabled, mobile) { 30 setTouchEnabled(enabled, mobile) {
31 this._touchEnabled = enabled; 31 this._touchEnabled = enabled;
32 this._touchMobile = mobile; 32 this._touchMobile = mobile;
33 this._updateAllTargets(); 33 this._updateAllTargets();
34 } 34 }
35 35
36 /** 36 /**
37 * @param {boolean} enabled 37 * @param {boolean} enabled
38 */ 38 */
39 setCustomTouchEnabled(enabled) { 39 setCustomTouchEnabled(enabled) {
40 this._customTouchEnabled = enabled; 40 this._customTouchEnabled = enabled;
41 this._updateAllTargets(); 41 this._updateAllTargets();
42 } 42 }
43 43
44 _updateAllTargets() { 44 _updateAllTargets() {
45 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca pability.Browser)) 45 for (var target of SDK.targetManager.targets(SDK.Target.Capability.Browser))
46 this._applyToTarget(target); 46 this._applyToTarget(target);
47 } 47 }
48 48
49 /** 49 /**
50 * @param {!WebInspector.Target} target 50 * @param {!SDK.Target} target
51 */ 51 */
52 _applyToTarget(target) { 52 _applyToTarget(target) {
53 var current = {enabled: this._touchEnabled, configuration: this._touchMobile ? 'mobile' : 'desktop'}; 53 var current = {enabled: this._touchEnabled, configuration: this._touchMobile ? 'mobile' : 'desktop'};
54 if (this._customTouchEnabled) 54 if (this._customTouchEnabled)
55 current = {enabled: true, configuration: 'mobile'}; 55 current = {enabled: true, configuration: 'mobile'};
56 56
57 var domModel = WebInspector.DOMModel.fromTarget(target); 57 var domModel = SDK.DOMModel.fromTarget(target);
58 var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false; 58 var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false;
59 if (inspectModeEnabled) 59 if (inspectModeEnabled)
60 current = {enabled: false, configuration: 'mobile'}; 60 current = {enabled: false, configuration: 'mobile'};
61 61
62 /** 62 /**
63 * @suppressGlobalPropertiesCheck 63 * @suppressGlobalPropertiesCheck
64 */ 64 */
65 const injectedFunction = function() { 65 const injectedFunction = function() {
66 const touchEvents = ['ontouchstart', 'ontouchend', 'ontouchmove', 'ontouch cancel']; 66 const touchEvents = ['ontouchstart', 'ontouchend', 'ontouchmove', 'ontouch cancel'];
67 var recepients = [window.__proto__, document.__proto__]; 67 var recepients = [window.__proto__, document.__proto__];
68 for (var i = 0; i < touchEvents.length; ++i) { 68 for (var i = 0; i < touchEvents.length; ++i) {
69 for (var j = 0; j < recepients.length; ++j) { 69 for (var j = 0; j < recepients.length; ++j) {
70 if (!(touchEvents[i] in recepients[j])) 70 if (!(touchEvents[i] in recepients[j]))
71 Object.defineProperty( 71 Object.defineProperty(
72 recepients[j], touchEvents[i], {value: null, writable: true, con figurable: true, enumerable: true}); 72 recepients[j], touchEvents[i], {value: null, writable: true, con figurable: true, enumerable: true});
73 } 73 }
74 } 74 }
75 }; 75 };
76 76
77 var symbol = WebInspector.MultitargetTouchModel._symbol; 77 var symbol = Emulation.MultitargetTouchModel._symbol;
78 var previous = target[symbol] || {enabled: false, configuration: 'mobile', s criptId: ''}; 78 var previous = target[symbol] || {enabled: false, configuration: 'mobile', s criptId: ''};
79 79
80 if (previous.enabled === current.enabled && (!current.enabled || previous.co nfiguration === current.configuration)) 80 if (previous.enabled === current.enabled && (!current.enabled || previous.co nfiguration === current.configuration))
81 return; 81 return;
82 82
83 if (previous.scriptId) { 83 if (previous.scriptId) {
84 target.pageAgent().removeScriptToEvaluateOnLoad(previous.scriptId); 84 target.pageAgent().removeScriptToEvaluateOnLoad(previous.scriptId);
85 target[symbol].scriptId = ''; 85 target[symbol].scriptId = '';
86 } 86 }
87 87
88 target[symbol] = current; 88 target[symbol] = current;
89 target[symbol].scriptId = ''; 89 target[symbol].scriptId = '';
90 90
91 if (current.enabled) 91 if (current.enabled)
92 target.pageAgent().addScriptToEvaluateOnLoad('(' + injectedFunction.toStri ng() + ')()', scriptAddedCallback); 92 target.pageAgent().addScriptToEvaluateOnLoad('(' + injectedFunction.toStri ng() + ')()', scriptAddedCallback);
93 93
94 /** 94 /**
95 * @param {?Protocol.Error} error 95 * @param {?Protocol.Error} error
96 * @param {string} scriptId 96 * @param {string} scriptId
97 */ 97 */
98 function scriptAddedCallback(error, scriptId) { 98 function scriptAddedCallback(error, scriptId) {
99 (target[symbol] || {}).scriptId = error ? '' : scriptId; 99 (target[symbol] || {}).scriptId = error ? '' : scriptId;
100 } 100 }
101 101
102 target.emulationAgent().setTouchEmulationEnabled(current.enabled, current.co nfiguration); 102 target.emulationAgent().setTouchEmulationEnabled(current.enabled, current.co nfiguration);
103 } 103 }
104 104
105 /** 105 /**
106 * @param {!WebInspector.Event} event 106 * @param {!Common.Event} event
107 */ 107 */
108 _inspectModeToggled(event) { 108 _inspectModeToggled(event) {
109 var domModel = /** @type {!WebInspector.DOMModel} */ (event.target); 109 var domModel = /** @type {!SDK.DOMModel} */ (event.target);
110 this._applyToTarget(domModel.target()); 110 this._applyToTarget(domModel.target());
111 } 111 }
112 112
113 /** 113 /**
114 * @override 114 * @override
115 * @param {!WebInspector.Target} target 115 * @param {!SDK.Target} target
116 */ 116 */
117 targetAdded(target) { 117 targetAdded(target) {
118 var domModel = WebInspector.DOMModel.fromTarget(target); 118 var domModel = SDK.DOMModel.fromTarget(target);
119 if (domModel) 119 if (domModel)
120 domModel.addEventListener(WebInspector.DOMModel.Events.InspectModeWillBeTo ggled, this._inspectModeToggled, this); 120 domModel.addEventListener(SDK.DOMModel.Events.InspectModeWillBeToggled, th is._inspectModeToggled, this);
121 this._applyToTarget(target); 121 this._applyToTarget(target);
122 } 122 }
123 123
124 /** 124 /**
125 * @override 125 * @override
126 * @param {!WebInspector.Target} target 126 * @param {!SDK.Target} target
127 */ 127 */
128 targetRemoved(target) { 128 targetRemoved(target) {
129 var domModel = WebInspector.DOMModel.fromTarget(target); 129 var domModel = SDK.DOMModel.fromTarget(target);
130 if (domModel) 130 if (domModel)
131 domModel.removeEventListener( 131 domModel.removeEventListener(
132 WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectMo deToggled, this); 132 SDK.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeToggled , this);
133 } 133 }
134 }; 134 };
135 135
136 WebInspector.MultitargetTouchModel._symbol = Symbol('MultitargetTouchModel.symbo l'); 136 Emulation.MultitargetTouchModel._symbol = Symbol('MultitargetTouchModel.symbol') ;
137 137
138 /** @type {?WebInspector.MultitargetTouchModel} */ 138 /** @type {?Emulation.MultitargetTouchModel} */
139 WebInspector.MultitargetTouchModel._instance = null; 139 Emulation.MultitargetTouchModel._instance = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698