OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 height = parseInt(splitMetrics[1], 10); | 111 height = parseInt(splitMetrics[1], 10); |
112 deviceScaleFactor = parseFloat(splitMetrics[2]); | 112 deviceScaleFactor = parseFloat(splitMetrics[2]); |
113 if (splitMetrics.length == 4) | 113 if (splitMetrics.length == 4) |
114 textAutosizing = splitMetrics[3] == 1; | 114 textAutosizing = splitMetrics[3] == 1; |
115 } | 115 } |
116 } | 116 } |
117 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); | 117 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); |
118 } | 118 } |
119 | 119 |
120 /** | 120 /** |
121 * @return {?WebInspector.OverridesSupport.DeviceMetrics} | |
122 */ | |
123 WebInspector.OverridesSupport.DeviceMetrics._parseUserInput = function(widthStri ng, heightString, deviceScaleFactorString, textAutosizing) | |
124 { | |
125 function isUserInputValid(value, isInteger) | |
126 { | |
127 if (!value) | |
128 return true; | |
129 return isInteger ? /^[\d]+$/.test(value) : /^[\d]+(\.\d+)?|\.\d+$/.test( value); | |
130 } | |
131 | |
132 if (!widthString ^ !heightString) | |
133 return null; | |
134 | |
135 var isWidthValid = isUserInputValid(widthString, true); | |
136 var isHeightValid = isUserInputValid(heightString, true); | |
137 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); | |
138 | |
139 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) | |
140 return null; | |
141 | |
142 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; | |
143 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; | |
144 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; | |
145 | |
146 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); | |
147 } | |
148 | |
149 /** | |
150 * @param {!Element} widthInput | |
151 * @param {!Element} heightInput | |
152 * @param {!Element} deviceScaleFactorInput | |
153 * @param {!Element} textAutosizingInput | |
154 */ | |
155 WebInspector.OverridesSupport.DeviceMetrics.applyOverrides = function(widthInput , heightInput, deviceScaleFactorInput, textAutosizingInput) | |
156 { | |
157 if (WebInspector.OverridesSupport.DeviceMetrics._applyOverridesTimer) | |
158 clearTimeout(WebInspector.OverridesSupport.DeviceMetrics._applyOverrides Timer); | |
159 WebInspector.OverridesSupport.DeviceMetrics._applyOverridesTimer = setTimeou t(onTimer, 50); | |
160 | |
161 function onTimer() | |
162 { | |
163 delete WebInspector.OverridesSupport.DeviceMetrics._applyOverridesTimer; | |
164 var metrics = WebInspector.OverridesSupport.DeviceMetrics._parseUserInpu t(widthInput.value.trim(), heightInput.value.trim(), deviceScaleFactorInput.valu e.trim(), textAutosizingInput.checked); | |
165 | |
166 function setValid(condition, element) | |
167 { | |
168 if (condition) | |
169 element.classList.remove("error-input"); | |
170 else | |
171 element.classList.add("error-input"); | |
172 } | |
173 | |
174 setValid(metrics && metrics.isWidthValid(), widthInput); | |
175 setValid(metrics && metrics.isHeightValid(), heightInput); | |
176 setValid(metrics && metrics.isDeviceScaleFactorValid(), deviceScaleFacto rInput); | |
177 | |
178 if (!metrics) | |
179 return; | |
180 | |
181 if (metrics.isValid()) { | |
182 var value = metrics.toSetting(); | |
183 if (value !== WebInspector.overridesSupport.settings.deviceMetrics.g et()) | |
184 WebInspector.overridesSupport.settings.deviceMetrics.set(value); | |
185 } | |
186 } | |
187 } | |
188 | |
189 WebInspector.OverridesSupport.DeviceMetrics.prototype = { | |
190 /** | |
191 * @return {boolean} | |
192 */ | |
193 isValid: function() | |
194 { | |
195 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); | |
196 }, | |
197 | |
198 /** | |
199 * @return {boolean} | |
200 */ | |
201 isWidthValid: function() | |
202 { | |
203 return this.width >= 0; | |
204 }, | |
205 | |
206 /** | |
207 * @return {boolean} | |
208 */ | |
209 isHeightValid: function() | |
210 { | |
211 return this.height >= 0; | |
212 }, | |
213 | |
214 /** | |
215 * @return {boolean} | |
216 */ | |
217 isDeviceScaleFactorValid: function() | |
218 { | |
219 return this.deviceScaleFactor >= 0; | |
220 }, | |
221 | |
222 /** | |
223 * @return {string} | |
224 */ | |
225 toSetting: function() | |
226 { | |
227 if (!this.isValid()) | |
228 return ""; | |
229 | |
230 return this.width + "x" + this.height + "x" + this.deviceScaleFactor + " x" + (this.textAutosizing ? "1" : "0"); | |
231 }, | |
232 | |
233 /** | |
234 * @return {string} | |
235 */ | |
236 widthToInput: function() | |
237 { | |
238 return this.isWidthValid() ? String(this.width) : ""; | |
239 }, | |
240 | |
241 /** | |
242 * @return {string} | |
243 */ | |
244 heightToInput: function() | |
245 { | |
246 return this.isHeightValid() ? String(this.height) : ""; | |
247 }, | |
248 | |
249 /** | |
250 * @return {string} | |
251 */ | |
252 deviceScaleFactorToInput: function() | |
253 { | |
254 return this.isDeviceScaleFactorValid() ? String(this.deviceScaleFactor) : ""; | |
255 }, | |
256 | |
257 /** | |
258 * Compute the font scale factor. | |
259 * | |
260 * Chromium on Android uses a device scale adjustment for fonts used in text autosizing for | |
261 * improved legibility. This function computes this adjusted value for text autosizing. | |
262 * | |
263 * For a description of the Android device scale adjustment algorithm, see: | |
264 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) | |
265 * | |
266 * @return {number} font scale factor. | |
267 */ | |
268 fontScaleFactor: function() | |
269 { | |
270 if (this.isValid()) { | |
271 // FIXME: this works bad with zero width/height. Create utility func tion with parameters instead. | |
272 var minWidth = Math.min(this.width, this.height) / (this.deviceScale Factor || 1); | |
273 | |
274 var kMinFSM = 1.05; | |
275 var kWidthForMinFSM = 320; | |
276 var kMaxFSM = 1.3; | |
277 var kWidthForMaxFSM = 800; | |
278 | |
279 if (minWidth <= kWidthForMinFSM) | |
280 return kMinFSM; | |
281 if (minWidth >= kWidthForMaxFSM) | |
282 return kMaxFSM; | |
283 | |
284 // The font scale multiplier varies linearly between kMinFSM and kMa xFSM. | |
285 var ratio = (minWidth - kWidthForMinFSM) / (kWidthForMaxFSM - kWidth ForMinFSM); | |
286 | |
287 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | |
288 } | |
289 | |
290 return 1; | |
291 } | |
292 } | |
293 | |
294 /** | |
295 * @constructor | 121 * @constructor |
296 * @param {number} latitude | 122 * @param {number} latitude |
297 * @param {number} longitude | 123 * @param {number} longitude |
298 */ | 124 */ |
299 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error) | 125 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error) |
300 { | 126 { |
301 this.latitude = latitude; | 127 this.latitude = latitude; |
302 this.longitude = longitude; | 128 this.longitude = longitude; |
303 this.error = error; | 129 this.error = error; |
304 } | 130 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 } | 277 } |
452 this._deviceMetricsChanged(); | 278 this._deviceMetricsChanged(); |
453 }, | 279 }, |
454 | 280 |
455 /** | 281 /** |
456 * @param {string} deviceMetrics | 282 * @param {string} deviceMetrics |
457 * @param {string} userAgent | 283 * @param {string} userAgent |
458 */ | 284 */ |
459 emulateDevice: function(deviceMetrics, userAgent) | 285 emulateDevice: function(deviceMetrics, userAgent) |
460 { | 286 { |
287 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d eviceMetrics) | |
dgozman
2014/05/28 09:39:10
nit: semicolon missing
pfeldman
2014/05/28 15:07:45
Done.
| |
461 this._deviceMetricsChangedListenerMuted = true; | 288 this._deviceMetricsChangedListenerMuted = true; |
462 this._userAgentChangedListenerMuted = true; | 289 this._userAgentChangedListenerMuted = true; |
463 this.settings.deviceMetrics.set(deviceMetrics); | |
464 this.settings.userAgent.set(userAgent); | 290 this.settings.userAgent.set(userAgent); |
465 this.settings.overrideDeviceMetrics.set(true); | 291 this.settings.overrideDeviceResolution.set(true); |
292 this.settings.deviceWidth.set(metrics.width); | |
293 this.settings.deviceHeight.set(metrics.height); | |
294 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); | |
295 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); | |
466 this.settings.overrideUserAgent.set(true); | 296 this.settings.overrideUserAgent.set(true); |
467 this.settings.emulateTouchEvents.set(true); | 297 this.settings.emulateTouchEvents.set(true); |
468 this.settings.emulateViewport.set(true); | 298 this.settings.emulateViewport.set(true); |
469 delete this._deviceMetricsChangedListenerMuted; | 299 delete this._deviceMetricsChangedListenerMuted; |
470 delete this._userAgentChangedListenerMuted; | 300 delete this._userAgentChangedListenerMuted; |
471 this._deviceMetricsChanged(); | 301 this._deviceMetricsChanged(); |
472 this._userAgentChanged(); | 302 this._userAgentChanged(); |
473 }, | 303 }, |
474 | 304 |
475 reset: function() | 305 reset: function() |
476 { | 306 { |
477 this._deviceMetricsChangedListenerMuted = true; | 307 this._deviceMetricsChangedListenerMuted = true; |
478 this._userAgentChangedListenerMuted = true; | 308 this._userAgentChangedListenerMuted = true; |
479 this.settings.overrideDeviceMetrics.set(false); | 309 this.settings.overrideDeviceResolution.set(false); |
480 this.settings.overrideUserAgent.set(false); | 310 this.settings.overrideUserAgent.set(false); |
481 this.settings.emulateTouchEvents.set(false); | 311 this.settings.emulateTouchEvents.set(false); |
482 this.settings.overrideDeviceOrientation.set(false); | 312 this.settings.overrideDeviceOrientation.set(false); |
483 this.settings.overrideGeolocation.set(false); | 313 this.settings.overrideGeolocation.set(false); |
484 this.settings.overrideCSSMedia.set(false); | 314 this.settings.overrideCSSMedia.set(false); |
485 this.settings.emulateViewport.set(false); | 315 this.settings.emulateViewport.set(false); |
486 this.settings.deviceMetrics.set(""); | |
487 delete this._deviceMetricsChangedListenerMuted; | 316 delete this._deviceMetricsChangedListenerMuted; |
488 delete this._userAgentChangedListenerMuted; | 317 delete this._userAgentChangedListenerMuted; |
489 this._deviceMetricsChanged(); | 318 this._deviceMetricsChanged(); |
490 this._userAgentChanged(); | 319 this._userAgentChanged(); |
491 }, | 320 }, |
492 | 321 |
493 applyInitialOverrides: function() | 322 applyInitialOverrides: function() |
494 { | 323 { |
495 if (!this._target) { | 324 if (!this._target) { |
496 this._applyInitialOverridesOnTargetAdded = true; | 325 this._applyInitialOverridesOnTargetAdded = true; |
497 return; | 326 return; |
498 } | 327 } |
499 | 328 |
500 if (this.settings.overrideDeviceOrientation.get()) | 329 if (this.settings.overrideDeviceOrientation.get()) |
501 this._deviceOrientationChanged(); | 330 this._deviceOrientationChanged(); |
502 | 331 |
503 if (this.settings.overrideGeolocation.get()) | 332 if (this.settings.overrideGeolocation.get()) |
504 this._geolocationPositionChanged(); | 333 this._geolocationPositionChanged(); |
505 | 334 |
506 if (this.settings.emulateTouchEvents.get()) | 335 if (this.settings.emulateTouchEvents.get()) |
507 this._emulateTouchEventsChanged(); | 336 this._emulateTouchEventsChanged(); |
508 | 337 |
509 if (this.settings.overrideCSSMedia.get()) | 338 if (this.settings.overrideCSSMedia.get()) |
510 this._cssMediaChanged(); | 339 this._cssMediaChanged(); |
511 | 340 |
512 if (this.settings.overrideDeviceMetrics.get()) | 341 if (this.settings.overrideDeviceResolution.get() || this.settings.emulat eViewport.get()) |
513 this._deviceMetricsChanged(); | 342 this._deviceMetricsChanged(); |
514 | 343 |
515 if (this.settings.overrideUserAgent.get()) | 344 if (this.settings.overrideUserAgent.get()) |
516 this._userAgentChanged(); | 345 this._userAgentChanged(); |
517 | 346 |
518 this._showRulersChanged(); | 347 this._showRulersChanged(); |
519 }, | 348 }, |
520 | 349 |
521 _userAgentChanged: function() | 350 _userAgentChanged: function() |
522 { | 351 { |
523 if (this._userAgentChangedListenerMuted) | 352 if (this._userAgentChangedListenerMuted) |
524 return; | 353 return; |
525 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; | 354 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; |
526 NetworkAgent.setUserAgentOverride(userAgent); | 355 NetworkAgent.setUserAgentOverride(userAgent); |
527 this._updateUserAgentWarningMessage(this._userAgent !== userAgent ? WebI nspector.UIString("You might need to reload the page for proper user agent spoof ing and viewport rendering.") : ""); | 356 this._updateUserAgentWarningMessage(this._userAgent !== userAgent ? WebI nspector.UIString("You might need to reload the page for proper user agent spoof ing and viewport rendering.") : ""); |
528 this._userAgent = userAgent; | 357 this._userAgent = userAgent; |
529 this.maybeHasActiveOverridesChanged(); | 358 this.maybeHasActiveOverridesChanged(); |
530 }, | 359 }, |
531 | 360 |
532 _onPageResizerAvailableSizeChanged: function() | 361 _onPageResizerAvailableSizeChanged: function() |
533 { | 362 { |
534 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his.settings.deviceMetrics.get()); | |
535 if (!metrics.isValid()) | |
536 return; | |
537 | |
538 var available = this._pageResizer.availableDipSize(); | 363 var available = this._pageResizer.availableDipSize(); |
539 if (available.width > metrics.width && available.height > metrics.height ) | 364 if (available.width > this.settings.deviceWidth.get() && available.heigh t > this.settings.deviceHeight.get()) |
540 return; | 365 return; |
541 | 366 |
542 this._deviceMetricsChanged(); | 367 this._deviceMetricsChanged(); |
543 }, | 368 }, |
544 | 369 |
545 _onPageResizerResizeRequested: function(event) | 370 _onPageResizerResizeRequested: function(event) |
546 { | 371 { |
547 if (!this.settings.overrideDeviceMetrics.get()) | |
548 return; | |
549 | |
550 var size = /** @type {!Size} */ (event.data); | 372 var size = /** @type {!Size} */ (event.data); |
551 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his.settings.deviceMetrics.get()); | 373 this.settings.deviceWidth.set(size.width); |
dgozman
2014/05/28 09:39:10
We should have a 'change multiple settings at once
pfeldman
2014/05/28 15:07:45
Agreed. But apart from that, I'll make sure it onl
| |
552 if (!metrics.isValid()) | 374 this.settings.deviceHeight.set(size.height); |
553 return; | |
554 | |
555 metrics.width = size.width; | |
556 metrics.height = size.height; | |
557 var value = metrics.toSetting(); | |
558 if (this.settings.deviceMetrics.get() === value) | |
559 return; | |
560 | |
561 this.settings.deviceMetrics.set(metrics.toSetting()); | |
562 }, | 375 }, |
563 | 376 |
564 _deviceMetricsChanged: function() | 377 _deviceMetricsChanged: function() |
565 { | 378 { |
566 this._showRulersChanged(); | 379 this._showRulersChanged(); |
567 | 380 |
568 if (this._deviceMetricsChangedListenerMuted) | 381 if (this._deviceMetricsChangedListenerMuted) |
569 return; | 382 return; |
570 | 383 |
571 var metricsOverrideEnabled = this.settings.overrideDeviceMetrics.get(); | 384 var overrideDeviceResolution = this.settings.overrideDeviceResolution.ge t(); |
572 if (!metricsOverrideEnabled) { | 385 if (!overrideDeviceResolution && !this.settings.emulateViewport.get()) { |
573 if (this._pageResizer) | 386 if (this._pageResizer) |
574 this._pageResizer.disable(); | 387 this._pageResizer.disable(); |
575 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this)); | 388 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this)); |
576 this.maybeHasActiveOverridesChanged(); | 389 this.maybeHasActiveOverridesChanged(); |
577 return; | 390 return; |
578 } | 391 } |
579 | 392 |
580 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his.settings.deviceMetrics.get()); | 393 var dipWidth = this.settings.deviceWidth.get(); |
581 if (!metrics.isValid()) | 394 var dipHeight = this.settings.deviceHeight.get(); |
582 return; | |
583 | |
584 var dipWidth = Math.round(metrics.width); | |
585 var dipHeight = Math.round(metrics.height); | |
586 | 395 |
587 // Disable override without checks. | 396 // Disable override without checks. |
588 if (this.isInspectingDevice()) | 397 if (this.isInspectingDevice()) |
589 return; | 398 return; |
590 | 399 |
591 var overrideWidth = dipWidth; | 400 var overrideWidth = overrideDeviceResolution ? dipWidth : 0; |
592 var overrideHeight = dipHeight; | 401 var overrideHeight = overrideDeviceResolution ? dipHeight : 0; |
593 if (this._pageResizer) { | 402 if (this._pageResizer) { |
594 var available = this._pageResizer.availableDipSize(); | 403 var available = this._pageResizer.availableDipSize(); |
595 if (available.width >= dipWidth && available.height >= dipHeight) { | 404 if (available.width >= dipWidth && available.height >= dipHeight) { |
596 this._pageResizer.enable(dipWidth, dipHeight, 0); | 405 this._pageResizer.enable(dipWidth, dipHeight, 0); |
597 // When we have enough space, no page size override is required. This will speed things up and remove lag. | 406 // When we have enough space, no page size override is required. This will speed things up and remove lag. |
598 overrideWidth = 0; | 407 overrideWidth = 0; |
599 overrideHeight = 0; | 408 overrideHeight = 0; |
600 } else { | 409 } else if (overrideDeviceResolution) { |
dgozman
2014/05/28 09:39:10
Adding this means it's possible to have |available
pfeldman
2014/05/28 15:07:45
Done.
| |
601 this._pageResizer.enable(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0); | 410 this._pageResizer.enable(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0); |
602 } | 411 } |
603 } | 412 } |
604 | 413 |
605 // Do not emulate resolution more often than 10Hz. | 414 // Do not emulate resolution more often than 10Hz. |
606 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1; | 415 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1; |
607 if (overrideWidth || overrideHeight) | 416 if (overrideWidth || overrideHeight) |
608 setTimeout(setDeviceMetricsOverride.bind(this), 100); | 417 setTimeout(setDeviceMetricsOverride.bind(this), 100); |
609 else | 418 else |
610 setDeviceMetricsOverride.call(this); | 419 setDeviceMetricsOverride.call(this); |
611 | 420 |
612 /** | 421 /** |
613 * @this {WebInspector.OverridesSupport} | 422 * @this {WebInspector.OverridesSupport} |
614 */ | 423 */ |
615 function setDeviceMetricsOverride() | 424 function setDeviceMetricsOverride() |
616 { | 425 { |
617 // Drop heavy intermediate commands. | 426 // Drop heavy intermediate commands. |
618 this._setDeviceMetricsTimers--; | 427 this._setDeviceMetricsTimers--; |
619 var isExpensive = overrideWidth || overrideHeight; | 428 var isExpensive = overrideWidth || overrideHeight; |
620 if (isExpensive && this._setDeviceMetricsTimers) { | 429 if (isExpensive && this._setDeviceMetricsTimers) { |
621 var commandThreshold = 100; | 430 var commandThreshold = 100; |
622 var time = window.performance.now(); | 431 var time = window.performance.now(); |
623 if (time - this._lastExpensivePageAgentCommandTime < commandThre shold) | 432 if (time - this._lastExpensivePageAgentCommandTime < commandThre shold) |
624 return; | 433 return; |
625 this._lastExpensivePageAgentCommandTime = time; | 434 this._lastExpensivePageAgentCommandTime = time; |
626 } | 435 } |
627 | 436 |
628 PageAgent.setDeviceMetricsOverride( | 437 PageAgent.setDeviceMetricsOverride( |
629 overrideWidth, overrideHeight, metrics.deviceScaleFactor, | 438 overrideWidth, overrideHeight, this.settings.deviceScaleFactor.g et(), |
630 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(), | 439 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(), |
631 metrics.textAutosizing, metrics.fontScaleFactor(), | 440 this.settings.deviceTextAutosizing.get(), this._fontScaleFactor( ), |
632 apiCallback.bind(this)); | 441 apiCallback.bind(this)); |
633 } | 442 } |
634 | 443 |
635 this.maybeHasActiveOverridesChanged(); | 444 this.maybeHasActiveOverridesChanged(); |
636 | 445 |
637 /** | 446 /** |
638 * @param {?Protocol.Error} error | 447 * @param {?Protocol.Error} error |
639 * @this {WebInspector.OverridesSupport} | 448 * @this {WebInspector.OverridesSupport} |
640 */ | 449 */ |
641 function apiCallback(error) | 450 function apiCallback(error) |
642 { | 451 { |
643 if (error) { | 452 if (error) { |
644 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page.")); | 453 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page.")); |
645 if (this._pageResizer) | 454 if (this._pageResizer) |
646 this._pageResizer.disable(); | 455 this._pageResizer.disable(); |
647 return; | 456 return; |
648 } | 457 } |
649 | 458 |
650 var viewportEnabled = this.settings.emulateViewport.get(); | 459 var overrideDeviceResolution = this.settings.overrideDeviceResolutio n.get(); |
651 this._updateDeviceMetricsWarningMessage(this._deviceMetricsOverrideE nabled !== metricsOverrideEnabled || (metricsOverrideEnabled && this._emulateVie wportEnabled != viewportEnabled) ? | 460 var viewportEnabled = this.settings.emulateViewport.get(); |
461 this._updateDeviceMetricsWarningMessage(this._overrideDeviceResoluti on !== overrideDeviceResolution || this._emulateViewportEnabled != viewportEnabl ed ? | |
652 WebInspector.UIString("You might need to reload the page for pro per user agent spoofing and viewport rendering.") : ""); | 462 WebInspector.UIString("You might need to reload the page for pro per user agent spoofing and viewport rendering.") : ""); |
653 this._deviceMetricsOverrideEnabled = metricsOverrideEnabled; | 463 this._overrideDeviceResolution = overrideDeviceResolution; |
654 this._emulateViewportEnabled = viewportEnabled; | 464 this._emulateViewportEnabled = viewportEnabled; |
655 this._deviceMetricsOverrideAppliedForTest(); | 465 this._deviceMetricsOverrideAppliedForTest(); |
656 } | 466 } |
657 }, | 467 }, |
658 | 468 |
659 _deviceMetricsOverrideAppliedForTest: function() | 469 _deviceMetricsOverrideAppliedForTest: function() |
660 { | 470 { |
661 // Used for sniffing in tests. | 471 // Used for sniffing in tests. |
662 }, | 472 }, |
663 | 473 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 for (var i = 0; i < targets.length; ++i) | 519 for (var i = 0; i < targets.length; ++i) |
710 targets[i].cssModel.mediaQueryResultChanged(); | 520 targets[i].cssModel.mediaQueryResultChanged(); |
711 this.maybeHasActiveOverridesChanged(); | 521 this.maybeHasActiveOverridesChanged(); |
712 }, | 522 }, |
713 | 523 |
714 /** | 524 /** |
715 * @return {boolean} | 525 * @return {boolean} |
716 */ | 526 */ |
717 showMetricsRulers: function() | 527 showMetricsRulers: function() |
718 { | 528 { |
719 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceMetrics.get(); | 529 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceResolution.get(); |
720 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; | 530 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; |
721 }, | 531 }, |
722 | 532 |
723 _showRulersChanged: function() | 533 _showRulersChanged: function() |
724 { | 534 { |
725 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | 535 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
726 return; | 536 return; |
727 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 537 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
728 }, | 538 }, |
729 | 539 |
730 /** | 540 /** |
731 * @return {boolean} | 541 * @return {boolean} |
732 */ | 542 */ |
733 hasActiveOverrides: function() | 543 hasActiveOverrides: function() |
734 { | 544 { |
735 return this._hasActiveOverrides; | 545 return this._hasActiveOverrides; |
736 }, | 546 }, |
737 | 547 |
738 maybeHasActiveOverridesChanged: function() | 548 maybeHasActiveOverridesChanged: function() |
739 { | 549 { |
740 var hasActiveOverrides = | 550 var hasActiveOverrides = |
741 this.settings.overrideUserAgent.get() || | 551 this.settings.overrideUserAgent.get() || |
742 (this.settings.overrideDeviceMetrics.get() && !this.isInspectingDevi ce()) || | 552 ((this.settings.overrideDeviceResolution.get() || this.settings.emul ateViewport.get()) && !this.isInspectingDevice()) || |
743 this.settings.overrideGeolocation.get() || | 553 this.settings.overrideGeolocation.get() || |
744 this.settings.overrideDeviceOrientation.get() || | 554 this.settings.overrideDeviceOrientation.get() || |
745 (this.settings.emulateTouchEvents.get() && !this.hasTouchInputs()) | | | 555 (this.settings.emulateTouchEvents.get() && !this.hasTouchInputs()) | | |
746 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; | 556 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; |
747 if (this._hasActiveOverrides !== hasActiveOverrides) { | 557 if (this._hasActiveOverrides !== hasActiveOverrides) { |
748 this._hasActiveOverrides = hasActiveOverrides; | 558 this._hasActiveOverrides = hasActiveOverrides; |
749 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); | 559 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); |
750 } | 560 } |
751 }, | 561 }, |
752 | 562 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 targetAdded: function(target) | 598 targetAdded: function(target) |
789 { | 599 { |
790 // FIXME: adapt this to multiple targets. | 600 // FIXME: adapt this to multiple targets. |
791 if (this._target) | 601 if (this._target) |
792 return; | 602 return; |
793 this._target = target; | 603 this._target = target; |
794 | 604 |
795 this.settings = {}; | 605 this.settings = {}; |
796 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o verrideUserAgent", false); | 606 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o verrideUserAgent", false); |
797 this.settings.userAgent = WebInspector.settings.createSetting("userAgent ", ""); | 607 this.settings.userAgent = WebInspector.settings.createSetting("userAgent ", ""); |
798 this.settings.overrideDeviceMetrics = WebInspector.settings.createSettin g("overrideDeviceMetrics", false); | 608 |
799 this.settings.deviceMetrics = WebInspector.settings.createSetting("devic eMetrics", ""); | 609 this.settings.overrideDeviceResolution = WebInspector.settings.createSet ting("overrideDeviceResolution", false); |
610 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW idth", 800); | |
611 this.settings.deviceHeight = WebInspector.settings.createSetting("device Height", 600); | |
612 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d eviceScaleFactor", 1); | |
dgozman
2014/05/28 09:39:10
I'd use window.devicePixelRatio as a default value
pfeldman
2014/05/28 15:07:45
Done.
| |
613 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting ("deviceTextAutosizing", true); | |
614 | |
800 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev iceFitWindow", true); | 615 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev iceFitWindow", true); |
801 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); | 616 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); |
802 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); | 617 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); |
803 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); | 618 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); |
804 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); | 619 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); |
805 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); | 620 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); |
806 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); | 621 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); |
807 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); | 622 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); |
808 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); | 623 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); |
809 | 624 |
810 this.maybeHasActiveOverridesChanged(); | 625 this.maybeHasActiveOverridesChanged(); |
811 | 626 |
812 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged , this); | 627 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged , this); |
813 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 628 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
814 | 629 |
815 this.settings.overrideDeviceMetrics.addChangeListener(this._deviceMetric sChanged, this); | 630 this.settings.overrideDeviceResolution.addChangeListener(this._deviceMet ricsChanged, this); |
816 this.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged , this); | 631 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged, this); |
632 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged, this); | |
633 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha nged, this); | |
634 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics Changed, this); | |
817 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); | 635 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); |
818 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); | 636 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); |
819 | 637 |
820 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); | 638 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); |
821 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); | 639 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); |
822 | 640 |
823 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); | 641 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); |
824 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); | 642 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); |
825 | 643 |
826 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); | 644 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); |
827 | 645 |
828 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); | 646 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); |
829 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); | 647 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); |
830 | 648 |
831 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); | 649 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); |
832 | 650 |
833 if (this._applyInitialOverridesOnTargetAdded) { | 651 if (this._applyInitialOverridesOnTargetAdded) { |
834 delete this._applyInitialOverridesOnTargetAdded; | 652 delete this._applyInitialOverridesOnTargetAdded; |
835 this.applyInitialOverrides(); | 653 this.applyInitialOverrides(); |
836 } | 654 } |
837 }, | 655 }, |
838 | 656 |
657 swapDimensions: function() | |
658 { | |
659 var width = WebInspector.OverridesSupport.settings.deviceWidth.get(); | |
dgozman
2014/05/28 09:39:10
Use WebInspector.overridesSupport instance, not a
pfeldman
2014/05/28 15:07:45
Done.
| |
660 var height = WebInspector.OverridesSupport.settings.deviceHeight.get(); | |
661 WebInspector.OverridesSupport.settings.deviceWidth.set(height); | |
662 WebInspector.OverridesSupport.settings.deviceHeight.set(width); | |
663 }, | |
664 | |
839 /** | 665 /** |
840 * @param {!WebInspector.Target} target | 666 * @param {!WebInspector.Target} target |
841 */ | 667 */ |
842 targetRemoved: function(target) | 668 targetRemoved: function(target) |
843 { | 669 { |
844 // FIXME: adapt this to multiple targets. | 670 // FIXME: adapt this to multiple targets. |
845 }, | 671 }, |
846 | 672 |
847 /** | 673 /** |
848 * @return {boolean} | 674 * @return {boolean} |
849 */ | 675 */ |
850 isInspectingDevice: function() | 676 isInspectingDevice: function() |
851 { | 677 { |
852 return !!this._target && this._target.isMobile(); | 678 return !!this._target && this._target.isMobile(); |
853 }, | 679 }, |
854 | 680 |
855 /** | 681 /** |
856 * @return {boolean} | 682 * @return {boolean} |
857 */ | 683 */ |
858 hasTouchInputs: function() | 684 hasTouchInputs: function() |
859 { | 685 { |
860 return !!this._target && this._target.hasTouchInputs; | 686 return !!this._target && this._target.hasTouchInputs; |
861 }, | 687 }, |
862 | 688 |
689 /** | |
690 * Compute the font scale factor. | |
691 * | |
692 * Chromium on Android uses a device scale adjustment for fonts used in text autosizing for | |
693 * improved legibility. This function computes this adjusted value for text autosizing. | |
694 * | |
695 * For a description of the Android device scale adjustment algorithm, see: | |
696 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) | |
697 * | |
698 * @return {number} font scale factor. | |
699 */ | |
700 _fontScaleFactor: function() | |
701 { | |
702 if (!this.settings.overrideDeviceResolution.get()) | |
703 return 1; | |
704 | |
705 var width = this.settings.deviceWidth.get(); | |
706 var height = this.settings.deviceWidth.get(); | |
707 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); | |
708 | |
709 // FIXME: this works bad with zero width/height. Create utility function with parameters instead. | |
dgozman
2014/05/28 09:39:10
You can easily fix this TODO by passing (overrideW
pfeldman
2014/05/28 15:07:45
Done.
| |
710 var minWidth = Math.min(width, height) / deviceScaleFactor; | |
711 | |
712 var kMinFSM = 1.05; | |
713 var kWidthForMinFSM = 320; | |
714 var kMaxFSM = 1.3; | |
715 var kWidthForMaxFSM = 800; | |
716 | |
717 if (minWidth <= kWidthForMinFSM) | |
718 return kMinFSM; | |
719 if (minWidth >= kWidthForMaxFSM) | |
720 return kMaxFSM; | |
721 | |
722 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM . | |
723 var ratio = (minWidth - kWidthForMinFSM) / (kWidthForMaxFSM - kWidthForM inFSM); | |
724 | |
725 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | |
726 }, | |
727 | |
863 __proto__: WebInspector.Object.prototype | 728 __proto__: WebInspector.Object.prototype |
864 } | 729 } |
865 | 730 |
866 | 731 |
867 /** | 732 /** |
868 * @type {!WebInspector.OverridesSupport} | 733 * @type {!WebInspector.OverridesSupport} |
869 */ | 734 */ |
870 WebInspector.overridesSupport; | 735 WebInspector.overridesSupport; |
OLD | NEW |