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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.DeviceModeModel = class { 8 Emulation.DeviceModeModel = class {
9 /** 9 /**
10 * @param {function()} updateCallback 10 * @param {function()} updateCallback
11 */ 11 */
12 constructor(updateCallback) { 12 constructor(updateCallback) {
13 this._updateCallback = updateCallback; 13 this._updateCallback = updateCallback;
14 this._screenRect = new WebInspector.Rect(0, 0, 1, 1); 14 this._screenRect = new Common.Rect(0, 0, 1, 1);
15 this._visiblePageRect = new WebInspector.Rect(0, 0, 1, 1); 15 this._visiblePageRect = new Common.Rect(0, 0, 1, 1);
16 this._availableSize = new Size(1, 1); 16 this._availableSize = new Size(1, 1);
17 this._preferredSize = new Size(1, 1); 17 this._preferredSize = new Size(1, 1);
18 this._initialized = false; 18 this._initialized = false;
19 this._deviceMetricsThrottler = new WebInspector.Throttler(0); 19 this._deviceMetricsThrottler = new Common.Throttler(0);
20 this._appliedDeviceSize = new Size(1, 1); 20 this._appliedDeviceSize = new Size(1, 1);
21 this._appliedDeviceScaleFactor = window.devicePixelRatio; 21 this._appliedDeviceScaleFactor = window.devicePixelRatio;
22 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop; 22 this._appliedUserAgentType = Emulation.DeviceModeModel.UA.Desktop;
23 23
24 this._scaleSetting = WebInspector.settings.createSetting('emulation.deviceSc ale', 1); 24 this._scaleSetting = Common.settings.createSetting('emulation.deviceScale', 1);
25 // We've used to allow zero before. 25 // We've used to allow zero before.
26 if (!this._scaleSetting.get()) 26 if (!this._scaleSetting.get())
27 this._scaleSetting.set(1); 27 this._scaleSetting.set(1);
28 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this); 28 this._scaleSetting.addChangeListener(this._scaleSettingChanged, this);
29 29
30 this._widthSetting = WebInspector.settings.createSetting('emulation.deviceWi dth', 400); 30 this._widthSetting = Common.settings.createSetting('emulation.deviceWidth', 400);
31 if (this._widthSetting.get() < WebInspector.DeviceModeModel.MinDeviceSize) 31 if (this._widthSetting.get() < Emulation.DeviceModeModel.MinDeviceSize)
32 this._widthSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); 32 this._widthSetting.set(Emulation.DeviceModeModel.MinDeviceSize);
33 if (this._widthSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) 33 if (this._widthSetting.get() > Emulation.DeviceModeModel.MaxDeviceSize)
34 this._widthSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); 34 this._widthSetting.set(Emulation.DeviceModeModel.MaxDeviceSize);
35 this._widthSetting.addChangeListener(this._widthSettingChanged, this); 35 this._widthSetting.addChangeListener(this._widthSettingChanged, this);
36 36
37 this._heightSetting = WebInspector.settings.createSetting('emulation.deviceH eight', 0); 37 this._heightSetting = Common.settings.createSetting('emulation.deviceHeight' , 0);
38 if (this._heightSetting.get() && this._heightSetting.get() < WebInspector.De viceModeModel.MinDeviceSize) 38 if (this._heightSetting.get() && this._heightSetting.get() < Emulation.Devic eModeModel.MinDeviceSize)
39 this._heightSetting.set(WebInspector.DeviceModeModel.MinDeviceSize); 39 this._heightSetting.set(Emulation.DeviceModeModel.MinDeviceSize);
40 if (this._heightSetting.get() > WebInspector.DeviceModeModel.MaxDeviceSize) 40 if (this._heightSetting.get() > Emulation.DeviceModeModel.MaxDeviceSize)
41 this._heightSetting.set(WebInspector.DeviceModeModel.MaxDeviceSize); 41 this._heightSetting.set(Emulation.DeviceModeModel.MaxDeviceSize);
42 this._heightSetting.addChangeListener(this._heightSettingChanged, this); 42 this._heightSetting.addChangeListener(this._heightSettingChanged, this);
43 43
44 this._uaSetting = WebInspector.settings.createSetting('emulation.deviceUA', WebInspector.DeviceModeModel.UA.Mobile); 44 this._uaSetting = Common.settings.createSetting('emulation.deviceUA', Emulat ion.DeviceModeModel.UA.Mobile);
45 this._uaSetting.addChangeListener(this._uaSettingChanged, this); 45 this._uaSetting.addChangeListener(this._uaSettingChanged, this);
46 this._deviceScaleFactorSetting = WebInspector.settings.createSetting('emulat ion.deviceScaleFactor', 0); 46 this._deviceScaleFactorSetting = Common.settings.createSetting('emulation.de viceScaleFactor', 0);
47 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett ingChanged, this); 47 this._deviceScaleFactorSetting.addChangeListener(this._deviceScaleFactorSett ingChanged, this);
48 48
49 this._deviceOutlineSetting = WebInspector.settings.moduleSetting('emulation. showDeviceOutline'); 49 this._deviceOutlineSetting = Common.settings.moduleSetting('emulation.showDe viceOutline');
50 this._deviceOutlineSetting.addChangeListener(this._deviceOutlineSettingChang ed, this); 50 this._deviceOutlineSetting.addChangeListener(this._deviceOutlineSettingChang ed, this);
51 51
52 /** @type {!WebInspector.DeviceModeModel.Type} */ 52 /** @type {!Emulation.DeviceModeModel.Type} */
53 this._type = WebInspector.DeviceModeModel.Type.None; 53 this._type = Emulation.DeviceModeModel.Type.None;
54 /** @type {?WebInspector.EmulatedDevice} */ 54 /** @type {?Emulation.EmulatedDevice} */
55 this._device = null; 55 this._device = null;
56 /** @type {?WebInspector.EmulatedDevice.Mode} */ 56 /** @type {?Emulation.EmulatedDevice.Mode} */
57 this._mode = null; 57 this._mode = null;
58 /** @type {number} */ 58 /** @type {number} */
59 this._fitScale = 1; 59 this._fitScale = 1;
60 60
61 /** @type {?WebInspector.Target} */ 61 /** @type {?SDK.Target} */
62 this._target = null; 62 this._target = null;
63 /** @type {?function()} */ 63 /** @type {?function()} */
64 this._onTargetAvailable = null; 64 this._onTargetAvailable = null;
65 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.Browser); 65 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
66 } 66 }
67 67
68 /** 68 /**
69 * @param {string} value 69 * @param {string} value
70 * @return {boolean} 70 * @return {boolean}
71 */ 71 */
72 static deviceSizeValidator(value) { 72 static deviceSizeValidator(value) {
73 if (/^[\d]+$/.test(value) && value >= WebInspector.DeviceModeModel.MinDevice Size && 73 if (/^[\d]+$/.test(value) && value >= Emulation.DeviceModeModel.MinDeviceSiz e &&
74 value <= WebInspector.DeviceModeModel.MaxDeviceSize) 74 value <= Emulation.DeviceModeModel.MaxDeviceSize)
75 return true; 75 return true;
76 return false; 76 return false;
77 } 77 }
78 78
79 /** 79 /**
80 * @param {string} value 80 * @param {string} value
81 * @return {boolean} 81 * @return {boolean}
82 */ 82 */
83 static deviceScaleFactorValidator(value) { 83 static deviceScaleFactorValidator(value) {
84 if (!value || (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10)) 84 if (!value || (/^[\d]+(\.\d+)?|\.\d+$/.test(value) && value >= 0 && value <= 10))
85 return true; 85 return true;
86 return false; 86 return false;
87 } 87 }
88 88
89 /** 89 /**
90 * @param {!Size} availableSize 90 * @param {!Size} availableSize
91 * @param {!Size} preferredSize 91 * @param {!Size} preferredSize
92 */ 92 */
93 setAvailableSize(availableSize, preferredSize) { 93 setAvailableSize(availableSize, preferredSize) {
94 this._availableSize = availableSize; 94 this._availableSize = availableSize;
95 this._preferredSize = preferredSize; 95 this._preferredSize = preferredSize;
96 this._initialized = true; 96 this._initialized = true;
97 this._calculateAndEmulate(false); 97 this._calculateAndEmulate(false);
98 } 98 }
99 99
100 /** 100 /**
101 * @param {!WebInspector.DeviceModeModel.Type} type 101 * @param {!Emulation.DeviceModeModel.Type} type
102 * @param {?WebInspector.EmulatedDevice} device 102 * @param {?Emulation.EmulatedDevice} device
103 * @param {?WebInspector.EmulatedDevice.Mode} mode 103 * @param {?Emulation.EmulatedDevice.Mode} mode
104 * @param {number=} scale 104 * @param {number=} scale
105 */ 105 */
106 emulate(type, device, mode, scale) { 106 emulate(type, device, mode, scale) {
107 var resetPageScaleFactor = this._type !== type || this._device !== device || this._mode !== mode; 107 var resetPageScaleFactor = this._type !== type || this._device !== device || this._mode !== mode;
108 this._type = type; 108 this._type = type;
109 109
110 if (type === WebInspector.DeviceModeModel.Type.Device) { 110 if (type === Emulation.DeviceModeModel.Type.Device) {
111 console.assert(device && mode, 'Must pass device and mode for device emula tion'); 111 console.assert(device && mode, 'Must pass device and mode for device emula tion');
112 this._mode = mode; 112 this._mode = mode;
113 this._device = device; 113 this._device = device;
114 if (this._initialized) { 114 if (this._initialized) {
115 var orientation = device.orientationByName(mode.orientation); 115 var orientation = device.orientationByName(mode.orientation);
116 this._scaleSetting.set( 116 this._scaleSetting.set(
117 scale || 117 scale ||
118 this._calculateFitScale( 118 this._calculateFitScale(
119 orientation.width, orientation.height, this._currentOutline(), t his._currentInsets())); 119 orientation.width, orientation.height, this._currentOutline(), t his._currentInsets()));
120 } 120 }
121 } else { 121 } else {
122 this._device = null; 122 this._device = null;
123 this._mode = null; 123 this._mode = null;
124 } 124 }
125 125
126 if (type !== WebInspector.DeviceModeModel.Type.None) 126 if (type !== Emulation.DeviceModeModel.Type.None)
127 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Devic eModeEnabled); 127 Host.userMetrics.actionTaken(Host.UserMetrics.Action.DeviceModeEnabled);
128 this._calculateAndEmulate(resetPageScaleFactor); 128 this._calculateAndEmulate(resetPageScaleFactor);
129 } 129 }
130 130
131 /** 131 /**
132 * @param {number} width 132 * @param {number} width
133 */ 133 */
134 setWidth(width) { 134 setWidth(width) {
135 var max = Math.min(WebInspector.DeviceModeModel.MaxDeviceSize, this._preferr edScaledWidth()); 135 var max = Math.min(Emulation.DeviceModeModel.MaxDeviceSize, this._preferredS caledWidth());
136 width = Math.max(Math.min(width, max), 1); 136 width = Math.max(Math.min(width, max), 1);
137 this._widthSetting.set(width); 137 this._widthSetting.set(width);
138 } 138 }
139 139
140 /** 140 /**
141 * @param {number} width 141 * @param {number} width
142 */ 142 */
143 setWidthAndScaleToFit(width) { 143 setWidthAndScaleToFit(width) {
144 width = Math.max(Math.min(width, WebInspector.DeviceModeModel.MaxDeviceSize) , 1); 144 width = Math.max(Math.min(width, Emulation.DeviceModeModel.MaxDeviceSize), 1 );
145 this._scaleSetting.set(this._calculateFitScale(width, this._heightSetting.ge t())); 145 this._scaleSetting.set(this._calculateFitScale(width, this._heightSetting.ge t()));
146 this._widthSetting.set(width); 146 this._widthSetting.set(width);
147 } 147 }
148 148
149 /** 149 /**
150 * @param {number} height 150 * @param {number} height
151 */ 151 */
152 setHeight(height) { 152 setHeight(height) {
153 var max = Math.min(WebInspector.DeviceModeModel.MaxDeviceSize, this._preferr edScaledHeight()); 153 var max = Math.min(Emulation.DeviceModeModel.MaxDeviceSize, this._preferredS caledHeight());
154 height = Math.max(Math.min(height, max), 0); 154 height = Math.max(Math.min(height, max), 0);
155 if (height === this._preferredScaledHeight()) 155 if (height === this._preferredScaledHeight())
156 height = 0; 156 height = 0;
157 this._heightSetting.set(height); 157 this._heightSetting.set(height);
158 } 158 }
159 159
160 /** 160 /**
161 * @param {number} height 161 * @param {number} height
162 */ 162 */
163 setHeightAndScaleToFit(height) { 163 setHeightAndScaleToFit(height) {
164 height = Math.max(Math.min(height, WebInspector.DeviceModeModel.MaxDeviceSiz e), 0); 164 height = Math.max(Math.min(height, Emulation.DeviceModeModel.MaxDeviceSize), 0);
165 this._scaleSetting.set(this._calculateFitScale(this._widthSetting.get(), hei ght)); 165 this._scaleSetting.set(this._calculateFitScale(this._widthSetting.get(), hei ght));
166 this._heightSetting.set(height); 166 this._heightSetting.set(height);
167 } 167 }
168 168
169 /** 169 /**
170 * @param {number} scale 170 * @param {number} scale
171 */ 171 */
172 setScale(scale) { 172 setScale(scale) {
173 this._scaleSetting.set(scale); 173 this._scaleSetting.set(scale);
174 } 174 }
175 175
176 /** 176 /**
177 * @return {?WebInspector.EmulatedDevice} 177 * @return {?Emulation.EmulatedDevice}
178 */ 178 */
179 device() { 179 device() {
180 return this._device; 180 return this._device;
181 } 181 }
182 182
183 /** 183 /**
184 * @return {?WebInspector.EmulatedDevice.Mode} 184 * @return {?Emulation.EmulatedDevice.Mode}
185 */ 185 */
186 mode() { 186 mode() {
187 return this._mode; 187 return this._mode;
188 } 188 }
189 189
190 /** 190 /**
191 * @return {!WebInspector.DeviceModeModel.Type} 191 * @return {!Emulation.DeviceModeModel.Type}
192 */ 192 */
193 type() { 193 type() {
194 return this._type; 194 return this._type;
195 } 195 }
196 196
197 /** 197 /**
198 * @return {string} 198 * @return {string}
199 */ 199 */
200 screenImage() { 200 screenImage() {
201 return (this._device && this._mode) ? this._device.modeImage(this._mode) : ' '; 201 return (this._device && this._mode) ? this._device.modeImage(this._mode) : ' ';
202 } 202 }
203 203
204 /** 204 /**
205 * @return {string} 205 * @return {string}
206 */ 206 */
207 outlineImage() { 207 outlineImage() {
208 return (this._device && this._mode && this._deviceOutlineSetting.get()) ? th is._device.outlineImage(this._mode) : 208 return (this._device && this._mode && this._deviceOutlineSetting.get()) ? th is._device.outlineImage(this._mode) :
209 '' ; 209 '' ;
210 } 210 }
211 211
212 /** 212 /**
213 * @return {!WebInspector.Rect} 213 * @return {!Common.Rect}
214 */ 214 */
215 outlineRect() { 215 outlineRect() {
216 return this._outlineRect; 216 return this._outlineRect;
217 } 217 }
218 218
219 /** 219 /**
220 * @return {!WebInspector.Rect} 220 * @return {!Common.Rect}
221 */ 221 */
222 screenRect() { 222 screenRect() {
223 return this._screenRect; 223 return this._screenRect;
224 } 224 }
225 225
226 /** 226 /**
227 * @return {!WebInspector.Rect} 227 * @return {!Common.Rect}
228 */ 228 */
229 visiblePageRect() { 229 visiblePageRect() {
230 return this._visiblePageRect; 230 return this._visiblePageRect;
231 } 231 }
232 232
233 /** 233 /**
234 * @return {number} 234 * @return {number}
235 */ 235 */
236 scale() { 236 scale() {
237 return this._scale; 237 return this._scale;
(...skipping 14 matching lines...) Expand all
252 } 252 }
253 253
254 /** 254 /**
255 * @return {number} 255 * @return {number}
256 */ 256 */
257 appliedDeviceScaleFactor() { 257 appliedDeviceScaleFactor() {
258 return this._appliedDeviceScaleFactor; 258 return this._appliedDeviceScaleFactor;
259 } 259 }
260 260
261 /** 261 /**
262 * @return {!WebInspector.DeviceModeModel.UA} 262 * @return {!Emulation.DeviceModeModel.UA}
263 */ 263 */
264 appliedUserAgentType() { 264 appliedUserAgentType() {
265 return this._appliedUserAgentType; 265 return this._appliedUserAgentType;
266 } 266 }
267 267
268 /** 268 /**
269 * @return {boolean} 269 * @return {boolean}
270 */ 270 */
271 isFullHeight() { 271 isFullHeight() {
272 return !this._heightSetting.get(); 272 return !this._heightSetting.get();
273 } 273 }
274 274
275 /** 275 /**
276 * @return {!WebInspector.Setting} 276 * @return {!Common.Setting}
277 */ 277 */
278 scaleSetting() { 278 scaleSetting() {
279 return this._scaleSetting; 279 return this._scaleSetting;
280 } 280 }
281 281
282 /** 282 /**
283 * @return {!WebInspector.Setting} 283 * @return {!Common.Setting}
284 */ 284 */
285 uaSetting() { 285 uaSetting() {
286 return this._uaSetting; 286 return this._uaSetting;
287 } 287 }
288 288
289 /** 289 /**
290 * @return {!WebInspector.Setting} 290 * @return {!Common.Setting}
291 */ 291 */
292 deviceScaleFactorSetting() { 292 deviceScaleFactorSetting() {
293 return this._deviceScaleFactorSetting; 293 return this._deviceScaleFactorSetting;
294 } 294 }
295 295
296 /** 296 /**
297 * @return {!WebInspector.Setting} 297 * @return {!Common.Setting}
298 */ 298 */
299 deviceOutlineSetting() { 299 deviceOutlineSetting() {
300 return this._deviceOutlineSetting; 300 return this._deviceOutlineSetting;
301 } 301 }
302 302
303 reset() { 303 reset() {
304 this._deviceScaleFactorSetting.set(0); 304 this._deviceScaleFactorSetting.set(0);
305 this._scaleSetting.set(1); 305 this._scaleSetting.set(1);
306 this.setWidth(400); 306 this.setWidth(400);
307 this.setHeight(0); 307 this.setHeight(0);
308 this._uaSetting.set(WebInspector.DeviceModeModel.UA.Mobile); 308 this._uaSetting.set(Emulation.DeviceModeModel.UA.Mobile);
309 } 309 }
310 310
311 /** 311 /**
312 * @override 312 * @override
313 * @param {!WebInspector.Target} target 313 * @param {!SDK.Target} target
314 */ 314 */
315 targetAdded(target) { 315 targetAdded(target) {
316 if (!this._target) { 316 if (!this._target) {
317 this._target = target; 317 this._target = target;
318 if (this._onTargetAvailable) { 318 if (this._onTargetAvailable) {
319 var callback = this._onTargetAvailable; 319 var callback = this._onTargetAvailable;
320 this._onTargetAvailable = null; 320 this._onTargetAvailable = null;
321 callback(); 321 callback();
322 } 322 }
323 } 323 }
324 } 324 }
325 325
326 /** 326 /**
327 * @override 327 * @override
328 * @param {!WebInspector.Target} target 328 * @param {!SDK.Target} target
329 */ 329 */
330 targetRemoved(target) { 330 targetRemoved(target) {
331 if (this._target === target) 331 if (this._target === target)
332 this._target = null; 332 this._target = null;
333 } 333 }
334 334
335 _scaleSettingChanged() { 335 _scaleSettingChanged() {
336 this._calculateAndEmulate(false); 336 this._calculateAndEmulate(false);
337 } 337 }
338 338
(...skipping 29 matching lines...) Expand all
368 */ 368 */
369 _preferredScaledHeight() { 369 _preferredScaledHeight() {
370 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1)); 370 return Math.floor(this._preferredSize.height / (this._scaleSetting.get() || 1));
371 } 371 }
372 372
373 /** 373 /**
374 * @return {!Insets} 374 * @return {!Insets}
375 */ 375 */
376 _currentOutline() { 376 _currentOutline() {
377 var outline = new Insets(0, 0, 0, 0); 377 var outline = new Insets(0, 0, 0, 0);
378 if (this._type !== WebInspector.DeviceModeModel.Type.Device) 378 if (this._type !== Emulation.DeviceModeModel.Type.Device)
379 return outline; 379 return outline;
380 var orientation = this._device.orientationByName(this._mode.orientation); 380 var orientation = this._device.orientationByName(this._mode.orientation);
381 if (this._deviceOutlineSetting.get()) 381 if (this._deviceOutlineSetting.get())
382 outline = orientation.outlineInsets || outline; 382 outline = orientation.outlineInsets || outline;
383 return outline; 383 return outline;
384 } 384 }
385 385
386 /** 386 /**
387 * @return {!Insets} 387 * @return {!Insets}
388 */ 388 */
389 _currentInsets() { 389 _currentInsets() {
390 if (this._type !== WebInspector.DeviceModeModel.Type.Device) 390 if (this._type !== Emulation.DeviceModeModel.Type.Device)
391 return new Insets(0, 0, 0, 0); 391 return new Insets(0, 0, 0, 0);
392 return this._mode.insets; 392 return this._mode.insets;
393 } 393 }
394 394
395 /** 395 /**
396 * @param {boolean} resetPageScaleFactor 396 * @param {boolean} resetPageScaleFactor
397 */ 397 */
398 _calculateAndEmulate(resetPageScaleFactor) { 398 _calculateAndEmulate(resetPageScaleFactor) {
399 if (!this._target) 399 if (!this._target)
400 this._onTargetAvailable = this._calculateAndEmulate.bind(this, resetPageSc aleFactor); 400 this._onTargetAvailable = this._calculateAndEmulate.bind(this, resetPageSc aleFactor);
401 401
402 if (this._type === WebInspector.DeviceModeModel.Type.Device) { 402 if (this._type === Emulation.DeviceModeModel.Type.Device) {
403 var orientation = this._device.orientationByName(this._mode.orientation); 403 var orientation = this._device.orientationByName(this._mode.orientation);
404 var outline = this._currentOutline(); 404 var outline = this._currentOutline();
405 var insets = this._currentInsets(); 405 var insets = this._currentInsets();
406 this._fitScale = this._calculateFitScale(orientation.width, orientation.he ight, outline, insets); 406 this._fitScale = this._calculateFitScale(orientation.width, orientation.he ight, outline, insets);
407 if (this._device.mobile()) 407 if (this._device.mobile())
408 this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceM odeModel.UA.Mobile : 408 this._appliedUserAgentType = this._device.touch() ? Emulation.DeviceMode Model.UA.Mobile :
409 WebInspector.DeviceM odeModel.UA.MobileNoTouch; 409 Emulation.DeviceMode Model.UA.MobileNoTouch;
410 else 410 else
411 this._appliedUserAgentType = this._device.touch() ? WebInspector.DeviceM odeModel.UA.DesktopTouch : 411 this._appliedUserAgentType = this._device.touch() ? Emulation.DeviceMode Model.UA.DesktopTouch :
412 WebInspector.DeviceM odeModel.UA.Desktop; 412 Emulation.DeviceMode Model.UA.Desktop;
413 this._applyDeviceMetrics( 413 this._applyDeviceMetrics(
414 new Size(orientation.width, orientation.height), insets, outline, this ._scaleSetting.get(), 414 new Size(orientation.width, orientation.height), insets, outline, this ._scaleSetting.get(),
415 this._device.deviceScaleFactor, this._device.mobile(), 415 this._device.deviceScaleFactor, this._device.mobile(),
416 this._mode.orientation === WebInspector.EmulatedDevice.Horizontal ? 'l andscapePrimary' : 'portraitPrimary', 416 this._mode.orientation === Emulation.EmulatedDevice.Horizontal ? 'land scapePrimary' : 'portraitPrimary',
417 resetPageScaleFactor); 417 resetPageScaleFactor);
418 this._applyUserAgent(this._device.userAgent); 418 this._applyUserAgent(this._device.userAgent);
419 this._applyTouch(this._device.touch(), this._device.mobile()); 419 this._applyTouch(this._device.touch(), this._device.mobile());
420 } else if (this._type === WebInspector.DeviceModeModel.Type.None) { 420 } else if (this._type === Emulation.DeviceModeModel.Type.None) {
421 this._fitScale = this._calculateFitScale(this._availableSize.width, this._ availableSize.height); 421 this._fitScale = this._calculateFitScale(this._availableSize.width, this._ availableSize.height);
422 this._appliedUserAgentType = WebInspector.DeviceModeModel.UA.Desktop; 422 this._appliedUserAgentType = Emulation.DeviceModeModel.UA.Desktop;
423 this._applyDeviceMetrics( 423 this._applyDeviceMetrics(
424 this._availableSize, new Insets(0, 0, 0, 0), new Insets(0, 0, 0, 0), 1 , 0, false, '', resetPageScaleFactor); 424 this._availableSize, new Insets(0, 0, 0, 0), new Insets(0, 0, 0, 0), 1 , 0, false, '', resetPageScaleFactor);
425 this._applyUserAgent(''); 425 this._applyUserAgent('');
426 this._applyTouch(false, false); 426 this._applyTouch(false, false);
427 } else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) { 427 } else if (this._type === Emulation.DeviceModeModel.Type.Responsive) {
428 var screenWidth = this._widthSetting.get(); 428 var screenWidth = this._widthSetting.get();
429 if (!screenWidth || screenWidth > this._preferredScaledWidth()) 429 if (!screenWidth || screenWidth > this._preferredScaledWidth())
430 screenWidth = this._preferredScaledWidth(); 430 screenWidth = this._preferredScaledWidth();
431 var screenHeight = this._heightSetting.get(); 431 var screenHeight = this._heightSetting.get();
432 if (!screenHeight || screenHeight > this._preferredScaledHeight()) 432 if (!screenHeight || screenHeight > this._preferredScaledHeight())
433 screenHeight = this._preferredScaledHeight(); 433 screenHeight = this._preferredScaledHeight();
434 var mobile = this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mob ile || 434 var mobile = this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile ||
435 this._uaSetting.get() === WebInspector.DeviceModeModel.UA.MobileNoTouc h; 435 this._uaSetting.get() === Emulation.DeviceModeModel.UA.MobileNoTouch;
436 var defaultDeviceScaleFactor = mobile ? WebInspector.DeviceModeModel.defau ltMobileScaleFactor : 0; 436 var defaultDeviceScaleFactor = mobile ? Emulation.DeviceModeModel.defaultM obileScaleFactor : 0;
437 this._fitScale = this._calculateFitScale(this._widthSetting.get(), this._h eightSetting.get()); 437 this._fitScale = this._calculateFitScale(this._widthSetting.get(), this._h eightSetting.get());
438 this._appliedUserAgentType = this._uaSetting.get(); 438 this._appliedUserAgentType = this._uaSetting.get();
439 this._applyDeviceMetrics( 439 this._applyDeviceMetrics(
440 new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), new Inset s(0, 0, 0, 0), this._scaleSetting.get(), 440 new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), new Inset s(0, 0, 0, 0), this._scaleSetting.get(),
441 this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobi le, 441 this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobi le,
442 screenHeight >= screenWidth ? 'portraitPrimary' : 'landscapePrimary', resetPageScaleFactor); 442 screenHeight >= screenWidth ? 'portraitPrimary' : 'landscapePrimary', resetPageScaleFactor);
443 this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultMobileU serAgent : ''); 443 this._applyUserAgent(mobile ? Emulation.DeviceModeModel._defaultMobileUser Agent : '');
444 this._applyTouch( 444 this._applyTouch(
445 this._uaSetting.get() === WebInspector.DeviceModeModel.UA.DesktopTouch || 445 this._uaSetting.get() === Emulation.DeviceModeModel.UA.DesktopTouch ||
446 this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile, 446 this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile,
447 this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile); 447 this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile);
448 } 448 }
449 if (this._target) 449 if (this._target)
450 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === W ebInspector.DeviceModeModel.Type.None); 450 this._target.renderingAgent().setShowViewportSizeOnResize(this._type === E mulation.DeviceModeModel.Type.None);
451 this._updateCallback.call(null); 451 this._updateCallback.call(null);
452 } 452 }
453 453
454 /** 454 /**
455 * @param {number} screenWidth 455 * @param {number} screenWidth
456 * @param {number} screenHeight 456 * @param {number} screenHeight
457 * @param {!Insets=} outline 457 * @param {!Insets=} outline
458 * @param {!Insets=} insets 458 * @param {!Insets=} insets
459 * @return {number} 459 * @return {number}
460 */ 460 */
(...skipping 27 matching lines...) Expand all
488 */ 488 */
489 setSizeAndScaleToFit(width, height) { 489 setSizeAndScaleToFit(width, height) {
490 this._scaleSetting.set(this._calculateFitScale(width, height)); 490 this._scaleSetting.set(this._calculateFitScale(width, height));
491 this.setWidth(width); 491 this.setWidth(width);
492 } 492 }
493 493
494 /** 494 /**
495 * @param {string} userAgent 495 * @param {string} userAgent
496 */ 496 */
497 _applyUserAgent(userAgent) { 497 _applyUserAgent(userAgent) {
498 WebInspector.multitargetNetworkManager.setUserAgentOverride(userAgent); 498 SDK.multitargetNetworkManager.setUserAgentOverride(userAgent);
499 } 499 }
500 500
501 /** 501 /**
502 * @param {!Size} screenSize 502 * @param {!Size} screenSize
503 * @param {!Insets} insets 503 * @param {!Insets} insets
504 * @param {!Insets} outline 504 * @param {!Insets} outline
505 * @param {number} scale 505 * @param {number} scale
506 * @param {number} deviceScaleFactor 506 * @param {number} deviceScaleFactor
507 * @param {boolean} mobile 507 * @param {boolean} mobile
508 * @param {string} screenOrientation 508 * @param {string} screenOrientation
(...skipping 13 matching lines...) Expand all
522 522
523 var pageWidth = screenSize.width - insets.left - insets.right; 523 var pageWidth = screenSize.width - insets.left - insets.right;
524 var pageHeight = screenSize.height - insets.top - insets.bottom; 524 var pageHeight = screenSize.height - insets.top - insets.bottom;
525 525
526 var positionX = insets.left; 526 var positionX = insets.left;
527 var positionY = insets.top; 527 var positionY = insets.top;
528 var screenOrientationAngle = screenOrientation === 'landscapePrimary' ? 90 : 0; 528 var screenOrientationAngle = screenOrientation === 'landscapePrimary' ? 90 : 0;
529 529
530 this._appliedDeviceSize = screenSize; 530 this._appliedDeviceSize = screenSize;
531 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixelRati o; 531 this._appliedDeviceScaleFactor = deviceScaleFactor || window.devicePixelRati o;
532 this._screenRect = new WebInspector.Rect( 532 this._screenRect = new Common.Rect(
533 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), outline.top * scale, 533 Math.max(0, (this._availableSize.width - screenSize.width * scale) / 2), outline.top * scale,
534 screenSize.width * scale, screenSize.height * scale); 534 screenSize.width * scale, screenSize.height * scale);
535 this._outlineRect = new WebInspector.Rect( 535 this._outlineRect = new Common.Rect(
536 this._screenRect.left - outline.left * scale, 0, (outline.left + screenS ize.width + outline.right) * scale, 536 this._screenRect.left - outline.left * scale, 0, (outline.left + screenS ize.width + outline.right) * scale,
537 (outline.top + screenSize.height + outline.bottom) * scale); 537 (outline.top + screenSize.height + outline.bottom) * scale);
538 this._visiblePageRect = new WebInspector.Rect( 538 this._visiblePageRect = new Common.Rect(
539 positionX * scale, positionY * scale, 539 positionX * scale, positionY * scale,
540 Math.min(pageWidth * scale, this._availableSize.width - this._screenRect .left - positionX * scale), 540 Math.min(pageWidth * scale, this._availableSize.width - this._screenRect .left - positionX * scale),
541 Math.min(pageHeight * scale, this._availableSize.height - this._screenRe ct.top - positionY * scale)); 541 Math.min(pageHeight * scale, this._availableSize.height - this._screenRe ct.top - positionY * scale));
542 this._scale = scale; 542 this._scale = scale;
543 543
544 if (scale === 1 && this._availableSize.width >= screenSize.width && 544 if (scale === 1 && this._availableSize.width >= screenSize.width &&
545 this._availableSize.height >= screenSize.height) { 545 this._availableSize.height >= screenSize.height) {
546 // When we have enough space, no page size override is required. This will speed things up and remove lag. 546 // When we have enough space, no page size override is required. This will speed things up and remove lag.
547 pageWidth = 0; 547 pageWidth = 0;
548 pageHeight = 0; 548 pageHeight = 0;
549 } 549 }
550 if (this._visiblePageRect.width === pageWidth * scale && this._visiblePageRe ct.height === pageHeight * scale && 550 if (this._visiblePageRect.width === pageWidth * scale && this._visiblePageRe ct.height === pageHeight * scale &&
551 Number.isInteger(pageWidth * scale) && Number.isInteger(pageHeight * sca le)) { 551 Number.isInteger(pageWidth * scale) && Number.isInteger(pageHeight * sca le)) {
552 // When we only have to apply scale, do not resize the page. This will spe ed things up and remove lag. 552 // When we only have to apply scale, do not resize the page. This will spe ed things up and remove lag.
553 pageWidth = 0; 553 pageWidth = 0;
554 pageHeight = 0; 554 pageHeight = 0;
555 } 555 }
556 556
557 this._deviceMetricsThrottler.schedule(setDeviceMetricsOverride.bind(this)); 557 this._deviceMetricsThrottler.schedule(setDeviceMetricsOverride.bind(this));
558 558
559 /** 559 /**
560 * @this {WebInspector.DeviceModeModel} 560 * @this {Emulation.DeviceModeModel}
561 * @return {!Promise.<?>} 561 * @return {!Promise.<?>}
562 */ 562 */
563 function setDeviceMetricsOverride() { 563 function setDeviceMetricsOverride() {
564 if (!this._target) 564 if (!this._target)
565 return Promise.resolve(); 565 return Promise.resolve();
566 566
567 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation; 567 var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation;
568 var allPromises = []; 568 var allPromises = [];
569 if (resetPageScaleFactor) 569 if (resetPageScaleFactor)
570 allPromises.push(this._target.emulationAgent().resetPageScaleFactor()); 570 allPromises.push(this._target.emulationAgent().resetPageScaleFactor());
(...skipping 26 matching lines...) Expand all
597 597
598 _deviceMetricsOverrideAppliedForTest() { 598 _deviceMetricsOverrideAppliedForTest() {
599 // Used for sniffing in tests. 599 // Used for sniffing in tests.
600 } 600 }
601 601
602 /** 602 /**
603 * @param {boolean} touchEnabled 603 * @param {boolean} touchEnabled
604 * @param {boolean} mobile 604 * @param {boolean} mobile
605 */ 605 */
606 _applyTouch(touchEnabled, mobile) { 606 _applyTouch(touchEnabled, mobile) {
607 WebInspector.MultitargetTouchModel.instance().setTouchEnabled(touchEnabled, mobile); 607 Emulation.MultitargetTouchModel.instance().setTouchEnabled(touchEnabled, mob ile);
608 } 608 }
609 }; 609 };
610 610
611 /** @enum {string} */ 611 /** @enum {string} */
612 WebInspector.DeviceModeModel.Type = { 612 Emulation.DeviceModeModel.Type = {
613 None: 'None', 613 None: 'None',
614 Responsive: 'Responsive', 614 Responsive: 'Responsive',
615 Device: 'Device' 615 Device: 'Device'
616 }; 616 };
617 617
618 /** @enum {string} */ 618 /** @enum {string} */
619 WebInspector.DeviceModeModel.UA = { 619 Emulation.DeviceModeModel.UA = {
620 Mobile: WebInspector.UIString('Mobile'), 620 Mobile: Common.UIString('Mobile'),
621 MobileNoTouch: WebInspector.UIString('Mobile (no touch)'), 621 MobileNoTouch: Common.UIString('Mobile (no touch)'),
622 Desktop: WebInspector.UIString('Desktop'), 622 Desktop: Common.UIString('Desktop'),
623 DesktopTouch: WebInspector.UIString('Desktop (touch)') 623 DesktopTouch: Common.UIString('Desktop (touch)')
624 }; 624 };
625 625
626 WebInspector.DeviceModeModel.MinDeviceSize = 50; 626 Emulation.DeviceModeModel.MinDeviceSize = 50;
627 WebInspector.DeviceModeModel.MaxDeviceSize = 9999; 627 Emulation.DeviceModeModel.MaxDeviceSize = 9999;
628 628
629 629
630 WebInspector.DeviceModeModel._defaultMobileUserAgent = 630 Emulation.DeviceModeModel._defaultMobileUserAgent =
631 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/%s Mobile Safari/537.36'; 631 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/%s Mobile Safari/537.36';
632 WebInspector.DeviceModeModel._defaultMobileUserAgent = 632 Emulation.DeviceModeModel._defaultMobileUserAgent =
633 WebInspector.MultitargetNetworkManager.patchUserAgentWithChromeVersion( 633 SDK.MultitargetNetworkManager.patchUserAgentWithChromeVersion(
634 WebInspector.DeviceModeModel._defaultMobileUserAgent); 634 Emulation.DeviceModeModel._defaultMobileUserAgent);
635 WebInspector.DeviceModeModel.defaultMobileScaleFactor = 2; 635 Emulation.DeviceModeModel.defaultMobileScaleFactor = 2;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698