Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @implements {WebInspector.TargetManager.Observer} | 33 * @implements {WebInspector.TargetManager.Observer} |
| 34 * @extends {WebInspector.Object} | 34 * @extends {WebInspector.Object} |
| 35 */ | 35 */ |
| 36 WebInspector.OverridesSupport = function() | 36 WebInspector.OverridesSupport = function() |
| 37 { | 37 { |
| 38 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this); | 38 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.MainFrameNavigated, this._onMainFrameNavigated.bind(this), this); |
| 39 this._deviceMetricsOverrideEnabled = false; | 39 this._deviceMetricsOverrideEnabled = false; |
|
dgozman
2014/05/28 15:26:41
This field has changed.
pfeldman
2014/05/28 15:40:00
Done.
| |
| 40 this._emulateViewportEnabled = false; | 40 this._emulateViewportEnabled = false; |
| 41 this._userAgent = ""; | 41 this._userAgent = ""; |
| 42 this._pageResizer = null; | 42 this._pageResizer = null; |
| 43 WebInspector.targetManager.observeTargets(this); | 43 WebInspector.targetManager.observeTargets(this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebInspector.OverridesSupport.Events = { | 46 WebInspector.OverridesSupport.Events = { |
| 47 OverridesWarningUpdated: "OverridesWarningUpdated", | 47 OverridesWarningUpdated: "OverridesWarningUpdated", |
| 48 HasActiveOverridesChanged: "HasActiveOverridesChanged", | 48 HasActiveOverridesChanged: "HasActiveOverridesChanged", |
| 49 } | 49 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 WebInspector.OverridesSupport.PageResizer.prototype = { | 64 WebInspector.OverridesSupport.PageResizer.prototype = { |
| 65 /** | 65 /** |
| 66 * Zero width and height mean default size. | 66 * Zero width and height mean default size. |
| 67 * Scale should be applied to page-scale-dependent UI bits. Zero means no sc ale. | 67 * Scale should be applied to page-scale-dependent UI bits. Zero means no sc ale. |
| 68 * @param {number} dipWidth | 68 * @param {number} dipWidth |
| 69 * @param {number} dipHeight | 69 * @param {number} dipHeight |
| 70 * @param {number} scale | 70 * @param {number} scale |
| 71 */ | 71 */ |
| 72 enable: function(dipWidth, dipHeight, scale) { }, | 72 update: function(dipWidth, dipHeight, scale) { }, |
| 73 | |
| 74 disable: function() { }, | |
| 75 | 73 |
| 76 /** | 74 /** |
| 77 * Available size for the page. | 75 * Available size for the page. |
| 78 * @return {!Size} | 76 * @return {!Size} |
| 79 */ | 77 */ |
| 80 availableDipSize: function() { } | 78 availableDipSize: function() { } |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 /** | 81 /** |
| 84 * @constructor | 82 * @constructor |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 111 height = parseInt(splitMetrics[1], 10); | 109 height = parseInt(splitMetrics[1], 10); |
| 112 deviceScaleFactor = parseFloat(splitMetrics[2]); | 110 deviceScaleFactor = parseFloat(splitMetrics[2]); |
| 113 if (splitMetrics.length == 4) | 111 if (splitMetrics.length == 4) |
| 114 textAutosizing = splitMetrics[3] == 1; | 112 textAutosizing = splitMetrics[3] == 1; |
| 115 } | 113 } |
| 116 } | 114 } |
| 117 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); | 115 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); |
| 118 } | 116 } |
| 119 | 117 |
| 120 /** | 118 /** |
| 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 | 119 * @constructor |
| 296 * @param {number} latitude | 120 * @param {number} latitude |
| 297 * @param {number} longitude | 121 * @param {number} longitude |
| 298 */ | 122 */ |
| 299 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error) | 123 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error) |
| 300 { | 124 { |
| 301 this.latitude = latitude; | 125 this.latitude = latitude; |
| 302 this.longitude = longitude; | 126 this.longitude = longitude; |
| 303 this.error = error; | 127 this.error = error; |
| 304 } | 128 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 var gamma = isGammaValid ? parseFloat(gammaString) : -1; | 247 var gamma = isGammaValid ? parseFloat(gammaString) : -1; |
| 424 | 248 |
| 425 return new WebInspector.OverridesSupport.DeviceOrientation(alpha, beta, gamm a); | 249 return new WebInspector.OverridesSupport.DeviceOrientation(alpha, beta, gamm a); |
| 426 } | 250 } |
| 427 | 251 |
| 428 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride = function() | 252 WebInspector.OverridesSupport.DeviceOrientation.clearDeviceOrientationOverride = function() |
| 429 { | 253 { |
| 430 PageAgent.clearDeviceOrientationOverride(); | 254 PageAgent.clearDeviceOrientationOverride(); |
| 431 } | 255 } |
| 432 | 256 |
| 257 /** | |
| 258 * @param {string} value | |
| 259 */ | |
| 260 WebInspector.OverridesSupport.inputValidator = function(value) | |
| 261 { | |
| 262 if (value >= 0 && value <= 10000) | |
| 263 return ""; | |
| 264 return WebInspector.UIString("Value must be positive integer"); | |
|
dgozman
2014/05/28 15:26:41
non-negative?
pfeldman
2014/05/28 15:40:00
Done.
| |
| 265 } | |
| 266 | |
| 267 | |
| 433 WebInspector.OverridesSupport.prototype = { | 268 WebInspector.OverridesSupport.prototype = { |
| 434 /** | 269 /** |
| 435 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer | 270 * @param {?WebInspector.OverridesSupport.PageResizer} pageResizer |
| 436 */ | 271 */ |
| 437 setPageResizer: function(pageResizer) | 272 setPageResizer: function(pageResizer) |
| 438 { | 273 { |
| 439 if (pageResizer === this._pageResizer) | 274 if (pageResizer === this._pageResizer) |
| 440 return; | 275 return; |
| 441 | 276 |
| 442 if (this._pageResizer) { | 277 if (this._pageResizer) { |
| 443 this._pageResizer.disable(); | |
| 444 this._pageResizer.removeEventListener(WebInspector.OverridesSupport. PageResizer.Events.AvailableSizeChanged, this._onPageResizerAvailableSizeChanged , this); | 278 this._pageResizer.removeEventListener(WebInspector.OverridesSupport. PageResizer.Events.AvailableSizeChanged, this._onPageResizerAvailableSizeChanged , this); |
| 445 this._pageResizer.removeEventListener(WebInspector.OverridesSupport. PageResizer.Events.ResizeRequested, this._onPageResizerResizeRequested, this); | 279 this._pageResizer.removeEventListener(WebInspector.OverridesSupport. PageResizer.Events.ResizeRequested, this._onPageResizerResizeRequested, this); |
| 446 } | 280 } |
| 447 this._pageResizer = pageResizer; | 281 this._pageResizer = pageResizer; |
| 448 if (this._pageResizer) { | 282 if (this._pageResizer) { |
| 449 this._pageResizer.addEventListener(WebInspector.OverridesSupport.Pag eResizer.Events.AvailableSizeChanged, this._onPageResizerAvailableSizeChanged, t his); | 283 this._pageResizer.addEventListener(WebInspector.OverridesSupport.Pag eResizer.Events.AvailableSizeChanged, this._onPageResizerAvailableSizeChanged, t his); |
| 450 this._pageResizer.addEventListener(WebInspector.OverridesSupport.Pag eResizer.Events.ResizeRequested, this._onPageResizerResizeRequested, this); | 284 this._pageResizer.addEventListener(WebInspector.OverridesSupport.Pag eResizer.Events.ResizeRequested, this._onPageResizerResizeRequested, this); |
| 451 } | 285 } |
| 452 this._deviceMetricsChanged(); | 286 this._deviceMetricsChanged(); |
| 453 }, | 287 }, |
| 454 | 288 |
| 455 /** | 289 /** |
| 456 * @param {string} deviceMetrics | 290 * @param {string} deviceMetrics |
| 457 * @param {string} userAgent | 291 * @param {string} userAgent |
| 458 */ | 292 */ |
| 459 emulateDevice: function(deviceMetrics, userAgent) | 293 emulateDevice: function(deviceMetrics, userAgent) |
| 460 { | 294 { |
| 295 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(d eviceMetrics); | |
|
dgozman
2014/05/28 15:26:41
This looks like the only place using DeviceMetrics
pfeldman
2014/05/28 15:40:00
Sure :)
| |
| 461 this._deviceMetricsChangedListenerMuted = true; | 296 this._deviceMetricsChangedListenerMuted = true; |
| 462 this._userAgentChangedListenerMuted = true; | 297 this._userAgentChangedListenerMuted = true; |
| 463 this.settings.deviceMetrics.set(deviceMetrics); | |
| 464 this.settings.userAgent.set(userAgent); | 298 this.settings.userAgent.set(userAgent); |
| 465 this.settings.overrideDeviceMetrics.set(true); | 299 this.settings.overrideDeviceResolution.set(true); |
| 300 this.settings.deviceWidth.set(metrics.width); | |
| 301 this.settings.deviceHeight.set(metrics.height); | |
| 302 this.settings.deviceScaleFactor.set(metrics.deviceScaleFactor); | |
| 303 this.settings.deviceTextAutosizing.set(metrics.textAutosizing); | |
| 466 this.settings.overrideUserAgent.set(true); | 304 this.settings.overrideUserAgent.set(true); |
| 467 this.settings.emulateTouchEvents.set(true); | 305 this.settings.emulateTouchEvents.set(true); |
| 468 this.settings.emulateViewport.set(true); | 306 this.settings.emulateViewport.set(true); |
| 469 delete this._deviceMetricsChangedListenerMuted; | 307 delete this._deviceMetricsChangedListenerMuted; |
| 470 delete this._userAgentChangedListenerMuted; | 308 delete this._userAgentChangedListenerMuted; |
| 471 this._deviceMetricsChanged(); | 309 this._deviceMetricsChanged(); |
| 472 this._userAgentChanged(); | 310 this._userAgentChanged(); |
| 473 }, | 311 }, |
| 474 | 312 |
| 475 reset: function() | 313 reset: function() |
| 476 { | 314 { |
| 477 this._deviceMetricsChangedListenerMuted = true; | 315 this._deviceMetricsChangedListenerMuted = true; |
| 478 this._userAgentChangedListenerMuted = true; | 316 this._userAgentChangedListenerMuted = true; |
| 479 this.settings.overrideDeviceMetrics.set(false); | 317 this.settings.overrideDeviceResolution.set(false); |
| 480 this.settings.overrideUserAgent.set(false); | 318 this.settings.overrideUserAgent.set(false); |
| 481 this.settings.emulateTouchEvents.set(false); | 319 this.settings.emulateTouchEvents.set(false); |
| 482 this.settings.overrideDeviceOrientation.set(false); | 320 this.settings.overrideDeviceOrientation.set(false); |
| 483 this.settings.overrideGeolocation.set(false); | 321 this.settings.overrideGeolocation.set(false); |
| 484 this.settings.overrideCSSMedia.set(false); | 322 this.settings.overrideCSSMedia.set(false); |
| 485 this.settings.emulateViewport.set(false); | 323 this.settings.emulateViewport.set(false); |
| 486 this.settings.deviceMetrics.set(""); | |
| 487 delete this._deviceMetricsChangedListenerMuted; | 324 delete this._deviceMetricsChangedListenerMuted; |
| 488 delete this._userAgentChangedListenerMuted; | 325 delete this._userAgentChangedListenerMuted; |
| 489 this._deviceMetricsChanged(); | 326 this._deviceMetricsChanged(); |
| 490 this._userAgentChanged(); | 327 this._userAgentChanged(); |
| 491 }, | 328 }, |
| 492 | 329 |
| 493 applyInitialOverrides: function() | 330 applyInitialOverrides: function() |
| 494 { | 331 { |
| 495 if (!this._target) { | 332 if (!this._target) { |
| 496 this._applyInitialOverridesOnTargetAdded = true; | 333 this._applyInitialOverridesOnTargetAdded = true; |
| 497 return; | 334 return; |
| 498 } | 335 } |
| 499 | 336 |
| 500 if (this.settings.overrideDeviceOrientation.get()) | 337 if (this.settings.overrideDeviceOrientation.get()) |
| 501 this._deviceOrientationChanged(); | 338 this._deviceOrientationChanged(); |
| 502 | 339 |
| 503 if (this.settings.overrideGeolocation.get()) | 340 if (this.settings.overrideGeolocation.get()) |
| 504 this._geolocationPositionChanged(); | 341 this._geolocationPositionChanged(); |
| 505 | 342 |
| 506 if (this.settings.emulateTouchEvents.get()) | 343 if (this.settings.emulateTouchEvents.get()) |
| 507 this._emulateTouchEventsChanged(); | 344 this._emulateTouchEventsChanged(); |
| 508 | 345 |
| 509 if (this.settings.overrideCSSMedia.get()) | 346 if (this.settings.overrideCSSMedia.get()) |
| 510 this._cssMediaChanged(); | 347 this._cssMediaChanged(); |
| 511 | 348 |
| 512 if (this.settings.overrideDeviceMetrics.get()) | 349 if (this.settings.overrideDeviceResolution.get() || this.settings.emulat eViewport.get()) |
| 513 this._deviceMetricsChanged(); | 350 this._deviceMetricsChanged(); |
| 514 | 351 |
| 515 if (this.settings.overrideUserAgent.get()) | 352 if (this.settings.overrideUserAgent.get()) |
| 516 this._userAgentChanged(); | 353 this._userAgentChanged(); |
| 517 | 354 |
| 518 this._showRulersChanged(); | 355 this._showRulersChanged(); |
| 519 }, | 356 }, |
| 520 | 357 |
| 521 _userAgentChanged: function() | 358 _userAgentChanged: function() |
| 522 { | 359 { |
| 523 if (this._userAgentChangedListenerMuted) | 360 if (this._userAgentChangedListenerMuted) |
| 524 return; | 361 return; |
| 525 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; | 362 var userAgent = this.settings.overrideUserAgent.get() ? this.settings.us erAgent.get() : ""; |
| 526 NetworkAgent.setUserAgentOverride(userAgent); | 363 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.") : ""); | 364 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; | 365 this._userAgent = userAgent; |
| 529 this.maybeHasActiveOverridesChanged(); | 366 this.maybeHasActiveOverridesChanged(); |
| 530 }, | 367 }, |
| 531 | 368 |
| 532 _onPageResizerAvailableSizeChanged: function() | 369 _onPageResizerAvailableSizeChanged: function() |
| 533 { | 370 { |
| 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(); | 371 var available = this._pageResizer.availableDipSize(); |
| 539 if (available.width > metrics.width && available.height > metrics.height ) | 372 if (available.width > this.settings.deviceWidth.get() && available.heigh t > this.settings.deviceHeight.get()) |
|
dgozman
2014/05/28 15:26:41
This causes bugs when switching between bottom/rig
pfeldman
2014/05/28 15:40:00
Done.
| |
| 540 return; | 373 return; |
| 541 | 374 |
| 542 this._deviceMetricsChanged(); | 375 this._deviceMetricsChanged(); |
| 543 }, | 376 }, |
| 544 | 377 |
| 545 _onPageResizerResizeRequested: function(event) | 378 _onPageResizerResizeRequested: function(event) |
| 546 { | 379 { |
| 547 if (!this.settings.overrideDeviceMetrics.get()) | |
| 548 return; | |
| 549 | |
| 550 var size = /** @type {!Size} */ (event.data); | 380 var size = /** @type {!Size} */ (event.data); |
| 551 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his.settings.deviceMetrics.get()); | 381 if (size.width !== this.settings.deviceWidth.get()) |
| 552 if (!metrics.isValid()) | 382 this.settings.deviceWidth.set(size.width); |
| 553 return; | 383 if (size.height !== this.settings.deviceHeight.get()) |
| 554 | 384 this.settings.deviceHeight.set(size.height); |
| 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 }, | 385 }, |
| 563 | 386 |
| 564 _deviceMetricsChanged: function() | 387 _deviceMetricsChanged: function() |
| 565 { | 388 { |
| 566 this._showRulersChanged(); | 389 this._showRulersChanged(); |
| 567 | 390 |
| 568 if (this._deviceMetricsChangedListenerMuted) | 391 if (this._deviceMetricsChangedListenerMuted) |
| 569 return; | 392 return; |
| 570 | 393 |
| 571 var metricsOverrideEnabled = this.settings.overrideDeviceMetrics.get(); | 394 var overrideDeviceResolution = this.settings.overrideDeviceResolution.ge t(); |
| 572 if (!metricsOverrideEnabled) { | 395 if (!overrideDeviceResolution && !this.settings.emulateViewport.get()) { |
| 396 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this)); | |
| 573 if (this._pageResizer) | 397 if (this._pageResizer) |
| 574 this._pageResizer.disable(); | 398 this._pageResizer.update(0, 0, 0); |
| 575 PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this)); | |
| 576 this.maybeHasActiveOverridesChanged(); | 399 this.maybeHasActiveOverridesChanged(); |
| 577 return; | 400 return; |
| 578 } | 401 } |
| 579 | 402 |
| 580 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his.settings.deviceMetrics.get()); | 403 var dipWidth = overrideDeviceResolution ? this.settings.deviceWidth.get( ) : 0; |
| 581 if (!metrics.isValid()) | 404 var dipHeight = overrideDeviceResolution ? this.settings.deviceHeight.ge t() : 0; |
| 582 return; | |
| 583 | |
| 584 var dipWidth = Math.round(metrics.width); | |
| 585 var dipHeight = Math.round(metrics.height); | |
| 586 | 405 |
| 587 // Disable override without checks. | 406 // Disable override without checks. |
| 588 if (this.isInspectingDevice()) | 407 if (this.isInspectingDevice()) |
| 589 return; | 408 return; |
| 590 | 409 |
| 591 var overrideWidth = dipWidth; | 410 var overrideWidth = dipWidth; |
| 592 var overrideHeight = dipHeight; | 411 var overrideHeight = dipHeight; |
| 593 if (this._pageResizer) { | 412 if (this._pageResizer) { |
| 594 var available = this._pageResizer.availableDipSize(); | 413 var available = this._pageResizer.availableDipSize(); |
| 595 if (available.width >= dipWidth && available.height >= dipHeight) { | 414 if (available.width >= dipWidth && available.height >= dipHeight) { |
| 596 this._pageResizer.enable(dipWidth, dipHeight, 0); | 415 this._pageResizer.update(dipWidth, dipHeight, 0); |
| 597 // When we have enough space, no page size override is required. This will speed things up and remove lag. | 416 // When we have enough space, no page size override is required. This will speed things up and remove lag. |
| 598 overrideWidth = 0; | 417 overrideWidth = 0; |
| 599 overrideHeight = 0; | 418 overrideHeight = 0; |
| 600 } else { | 419 } else { |
| 601 this._pageResizer.enable(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0); | 420 this._pageResizer.update(Math.min(dipWidth, available.width), Ma th.min(dipHeight, available.height), 0); |
| 602 } | 421 } |
| 603 } | 422 } |
| 604 | 423 |
| 605 // Do not emulate resolution more often than 10Hz. | 424 // Do not emulate resolution more often than 10Hz. |
| 606 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1; | 425 this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1; |
| 607 if (overrideWidth || overrideHeight) | 426 if (overrideWidth || overrideHeight) |
| 608 setTimeout(setDeviceMetricsOverride.bind(this), 100); | 427 setTimeout(setDeviceMetricsOverride.bind(this), 100); |
| 609 else | 428 else |
| 610 setDeviceMetricsOverride.call(this); | 429 setDeviceMetricsOverride.call(this); |
| 611 | 430 |
| 612 /** | 431 /** |
| 613 * @this {WebInspector.OverridesSupport} | 432 * @this {WebInspector.OverridesSupport} |
| 614 */ | 433 */ |
| 615 function setDeviceMetricsOverride() | 434 function setDeviceMetricsOverride() |
| 616 { | 435 { |
| 617 // Drop heavy intermediate commands. | 436 // Drop heavy intermediate commands. |
| 618 this._setDeviceMetricsTimers--; | 437 this._setDeviceMetricsTimers--; |
| 619 var isExpensive = overrideWidth || overrideHeight; | 438 var isExpensive = overrideWidth || overrideHeight; |
| 620 if (isExpensive && this._setDeviceMetricsTimers) { | 439 if (isExpensive && this._setDeviceMetricsTimers) { |
| 621 var commandThreshold = 100; | 440 var commandThreshold = 100; |
| 622 var time = window.performance.now(); | 441 var time = window.performance.now(); |
| 623 if (time - this._lastExpensivePageAgentCommandTime < commandThre shold) | 442 if (time - this._lastExpensivePageAgentCommandTime < commandThre shold) |
| 624 return; | 443 return; |
| 625 this._lastExpensivePageAgentCommandTime = time; | 444 this._lastExpensivePageAgentCommandTime = time; |
| 626 } | 445 } |
| 627 | 446 |
| 628 PageAgent.setDeviceMetricsOverride( | 447 PageAgent.setDeviceMetricsOverride( |
| 629 overrideWidth, overrideHeight, metrics.deviceScaleFactor, | 448 overrideWidth, overrideHeight, this.settings.deviceScaleFactor.g et(), |
| 630 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(), | 449 this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(), |
| 631 metrics.textAutosizing, metrics.fontScaleFactor(), | 450 this.settings.deviceTextAutosizing.get(), this._fontScaleFactor( overrideWidth || dipWidth, overrideHeight || dipHeight), |
| 632 apiCallback.bind(this)); | 451 apiCallback.bind(this)); |
| 633 } | 452 } |
| 634 | 453 |
| 635 this.maybeHasActiveOverridesChanged(); | 454 this.maybeHasActiveOverridesChanged(); |
| 636 | 455 |
| 637 /** | 456 /** |
| 638 * @param {?Protocol.Error} error | 457 * @param {?Protocol.Error} error |
| 639 * @this {WebInspector.OverridesSupport} | 458 * @this {WebInspector.OverridesSupport} |
| 640 */ | 459 */ |
| 641 function apiCallback(error) | 460 function apiCallback(error) |
| 642 { | 461 { |
| 643 if (error) { | 462 if (error) { |
| 644 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page.")); | 463 this._updateDeviceMetricsWarningMessage(WebInspector.UIString("S creen emulation is not available on this page.")); |
| 645 if (this._pageResizer) | |
| 646 this._pageResizer.disable(); | |
| 647 return; | 464 return; |
| 648 } | 465 } |
| 649 | 466 |
| 650 var viewportEnabled = this.settings.emulateViewport.get(); | 467 var overrideDeviceResolution = this.settings.overrideDeviceResolutio n.get(); |
| 651 this._updateDeviceMetricsWarningMessage(this._deviceMetricsOverrideE nabled !== metricsOverrideEnabled || (metricsOverrideEnabled && this._emulateVie wportEnabled != viewportEnabled) ? | 468 var viewportEnabled = this.settings.emulateViewport.get(); |
| 469 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.") : ""); | 470 WebInspector.UIString("You might need to reload the page for pro per user agent spoofing and viewport rendering.") : ""); |
| 653 this._deviceMetricsOverrideEnabled = metricsOverrideEnabled; | 471 this._overrideDeviceResolution = overrideDeviceResolution; |
| 654 this._emulateViewportEnabled = viewportEnabled; | 472 this._emulateViewportEnabled = viewportEnabled; |
| 655 this._deviceMetricsOverrideAppliedForTest(); | 473 this._deviceMetricsOverrideAppliedForTest(); |
| 656 } | 474 } |
| 657 }, | 475 }, |
| 658 | 476 |
| 659 _deviceMetricsOverrideAppliedForTest: function() | 477 _deviceMetricsOverrideAppliedForTest: function() |
| 660 { | 478 { |
| 661 // Used for sniffing in tests. | 479 // Used for sniffing in tests. |
| 662 }, | 480 }, |
| 663 | 481 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 for (var i = 0; i < targets.length; ++i) | 527 for (var i = 0; i < targets.length; ++i) |
| 710 targets[i].cssModel.mediaQueryResultChanged(); | 528 targets[i].cssModel.mediaQueryResultChanged(); |
| 711 this.maybeHasActiveOverridesChanged(); | 529 this.maybeHasActiveOverridesChanged(); |
| 712 }, | 530 }, |
| 713 | 531 |
| 714 /** | 532 /** |
| 715 * @return {boolean} | 533 * @return {boolean} |
| 716 */ | 534 */ |
| 717 showMetricsRulers: function() | 535 showMetricsRulers: function() |
| 718 { | 536 { |
| 719 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceMetrics.get(); | 537 var rulersInPageResizer = this._pageResizer && this.settings.overrideDev iceResolution.get(); |
| 720 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; | 538 return WebInspector.settings.showMetricsRulers.get() && !rulersInPageRes izer; |
| 721 }, | 539 }, |
| 722 | 540 |
| 723 _showRulersChanged: function() | 541 _showRulersChanged: function() |
| 724 { | 542 { |
| 725 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) | 543 if (WebInspector.experimentsSettings.responsiveDesign.isEnabled()) |
| 726 return; | 544 return; |
| 727 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); | 545 PageAgent.setShowViewportSizeOnResize(true, this.showMetricsRulers()); |
| 728 }, | 546 }, |
| 729 | 547 |
| 730 /** | 548 /** |
| 731 * @return {boolean} | 549 * @return {boolean} |
| 732 */ | 550 */ |
| 733 hasActiveOverrides: function() | 551 hasActiveOverrides: function() |
| 734 { | 552 { |
| 735 return this._hasActiveOverrides; | 553 return this._hasActiveOverrides; |
| 736 }, | 554 }, |
| 737 | 555 |
| 738 maybeHasActiveOverridesChanged: function() | 556 maybeHasActiveOverridesChanged: function() |
| 739 { | 557 { |
| 740 var hasActiveOverrides = | 558 var hasActiveOverrides = |
| 741 this.settings.overrideUserAgent.get() || | 559 this.settings.overrideUserAgent.get() || |
| 742 (this.settings.overrideDeviceMetrics.get() && !this.isInspectingDevi ce()) || | 560 ((this.settings.overrideDeviceResolution.get() || this.settings.emul ateViewport.get()) && !this.isInspectingDevice()) || |
| 743 this.settings.overrideGeolocation.get() || | 561 this.settings.overrideGeolocation.get() || |
| 744 this.settings.overrideDeviceOrientation.get() || | 562 this.settings.overrideDeviceOrientation.get() || |
| 745 (this.settings.emulateTouchEvents.get() && !this.hasTouchInputs()) | | | 563 (this.settings.emulateTouchEvents.get() && !this.hasTouchInputs()) | | |
| 746 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; | 564 (this.settings.overrideCSSMedia.get() && !this.isInspectingDevice()) ; |
| 747 if (this._hasActiveOverrides !== hasActiveOverrides) { | 565 if (this._hasActiveOverrides !== hasActiveOverrides) { |
| 748 this._hasActiveOverrides = hasActiveOverrides; | 566 this._hasActiveOverrides = hasActiveOverrides; |
| 749 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); | 567 this.dispatchEventToListeners(WebInspector.OverridesSupport.Events.H asActiveOverridesChanged); |
| 750 } | 568 } |
| 751 }, | 569 }, |
| 752 | 570 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 targetAdded: function(target) | 606 targetAdded: function(target) |
| 789 { | 607 { |
| 790 // FIXME: adapt this to multiple targets. | 608 // FIXME: adapt this to multiple targets. |
| 791 if (this._target) | 609 if (this._target) |
| 792 return; | 610 return; |
| 793 this._target = target; | 611 this._target = target; |
| 794 | 612 |
| 795 this.settings = {}; | 613 this.settings = {}; |
| 796 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o verrideUserAgent", false); | 614 this.settings.overrideUserAgent = WebInspector.settings.createSetting("o verrideUserAgent", false); |
| 797 this.settings.userAgent = WebInspector.settings.createSetting("userAgent ", ""); | 615 this.settings.userAgent = WebInspector.settings.createSetting("userAgent ", ""); |
| 798 this.settings.overrideDeviceMetrics = WebInspector.settings.createSettin g("overrideDeviceMetrics", false); | 616 |
| 799 this.settings.deviceMetrics = WebInspector.settings.createSetting("devic eMetrics", ""); | 617 this.settings.overrideDeviceResolution = WebInspector.settings.createSet ting("overrideDeviceResolution", false); |
| 618 this.settings.deviceWidth = WebInspector.settings.createSetting("deviceW idth", 800); | |
| 619 this.settings.deviceHeight = WebInspector.settings.createSetting("device Height", 600); | |
| 620 this.settings.deviceScaleFactor = WebInspector.settings.createSetting("d eviceScaleFactor", window.devicePixelRatio); | |
| 621 this.settings.deviceTextAutosizing = WebInspector.settings.createSetting ("deviceTextAutosizing", true); | |
| 622 | |
| 800 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev iceFitWindow", true); | 623 this.settings.deviceFitWindow = WebInspector.settings.createSetting("dev iceFitWindow", true); |
| 801 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); | 624 this.settings.emulateViewport = WebInspector.settings.createSetting("emu lateViewport", false); |
| 802 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); | 625 this.settings.emulateTouchEvents = WebInspector.settings.createSetting(" emulateTouchEvents", false); |
| 803 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); | 626 this.settings.overrideGeolocation = WebInspector.settings.createSetting( "overrideGeolocation", false); |
| 804 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); | 627 this.settings.geolocationOverride = WebInspector.settings.createSetting( "geolocationOverride", ""); |
| 805 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); | 628 this.settings.overrideDeviceOrientation = WebInspector.settings.createSe tting("overrideDeviceOrientation", false); |
| 806 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); | 629 this.settings.deviceOrientationOverride = WebInspector.settings.createSe tting("deviceOrientationOverride", ""); |
| 807 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); | 630 this.settings.overrideCSSMedia = WebInspector.settings.createSetting("ov errideCSSMedia", false); |
| 808 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); | 631 this.settings.emulatedCSSMedia = WebInspector.settings.createSetting("em ulatedCSSMedia", "print"); |
| 809 | 632 |
| 810 this.maybeHasActiveOverridesChanged(); | 633 this.maybeHasActiveOverridesChanged(); |
| 811 | 634 |
| 812 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged , this); | 635 this.settings.overrideUserAgent.addChangeListener(this._userAgentChanged , this); |
| 813 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); | 636 this.settings.userAgent.addChangeListener(this._userAgentChanged, this); |
| 814 | 637 |
| 815 this.settings.overrideDeviceMetrics.addChangeListener(this._deviceMetric sChanged, this); | 638 this.settings.overrideDeviceResolution.addChangeListener(this._deviceMet ricsChanged, this); |
| 816 this.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged , this); | 639 this.settings.deviceWidth.addChangeListener(this._deviceMetricsChanged, this); |
| 640 this.settings.deviceHeight.addChangeListener(this._deviceMetricsChanged, this); | |
| 641 this.settings.deviceScaleFactor.addChangeListener(this._deviceMetricsCha nged, this); | |
| 642 this.settings.deviceTextAutosizing.addChangeListener(this._deviceMetrics Changed, this); | |
| 817 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); | 643 this.settings.emulateViewport.addChangeListener(this._deviceMetricsChang ed, this); |
| 818 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); | 644 this.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChang ed, this); |
| 819 | 645 |
| 820 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); | 646 this.settings.overrideGeolocation.addChangeListener(this._geolocationPos itionChanged, this); |
| 821 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); | 647 this.settings.geolocationOverride.addChangeListener(this._geolocationPos itionChanged, this); |
| 822 | 648 |
| 823 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); | 649 this.settings.overrideDeviceOrientation.addChangeListener(this._deviceOr ientationChanged, this); |
| 824 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); | 650 this.settings.deviceOrientationOverride.addChangeListener(this._deviceOr ientationChanged, this); |
| 825 | 651 |
| 826 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); | 652 this.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEve ntsChanged, this); |
| 827 | 653 |
| 828 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); | 654 this.settings.overrideCSSMedia.addChangeListener(this._cssMediaChanged, this); |
| 829 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); | 655 this.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChanged, this); |
| 830 | 656 |
| 831 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); | 657 WebInspector.settings.showMetricsRulers.addChangeListener(this._showRule rsChanged, this); |
| 832 | 658 |
| 833 if (this._applyInitialOverridesOnTargetAdded) { | 659 if (this._applyInitialOverridesOnTargetAdded) { |
| 834 delete this._applyInitialOverridesOnTargetAdded; | 660 delete this._applyInitialOverridesOnTargetAdded; |
| 835 this.applyInitialOverrides(); | 661 this.applyInitialOverrides(); |
| 836 } | 662 } |
| 837 }, | 663 }, |
| 838 | 664 |
| 665 swapDimensions: function() | |
| 666 { | |
| 667 var width = WebInspector.overridesSupport.settings.deviceWidth.get(); | |
| 668 var height = WebInspector.overridesSupport.settings.deviceHeight.get(); | |
| 669 WebInspector.overridesSupport.settings.deviceWidth.set(height); | |
| 670 WebInspector.overridesSupport.settings.deviceHeight.set(width); | |
| 671 }, | |
| 672 | |
| 839 /** | 673 /** |
| 840 * @param {!WebInspector.Target} target | 674 * @param {!WebInspector.Target} target |
| 841 */ | 675 */ |
| 842 targetRemoved: function(target) | 676 targetRemoved: function(target) |
| 843 { | 677 { |
| 844 // FIXME: adapt this to multiple targets. | 678 // FIXME: adapt this to multiple targets. |
| 845 }, | 679 }, |
| 846 | 680 |
| 847 /** | 681 /** |
| 848 * @return {boolean} | 682 * @return {boolean} |
| 849 */ | 683 */ |
| 850 isInspectingDevice: function() | 684 isInspectingDevice: function() |
| 851 { | 685 { |
| 852 return !!this._target && this._target.isMobile(); | 686 return !!this._target && this._target.isMobile(); |
| 853 }, | 687 }, |
| 854 | 688 |
| 855 /** | 689 /** |
| 856 * @return {boolean} | 690 * @return {boolean} |
| 857 */ | 691 */ |
| 858 hasTouchInputs: function() | 692 hasTouchInputs: function() |
| 859 { | 693 { |
| 860 return !!this._target && this._target.hasTouchInputs; | 694 return !!this._target && this._target.hasTouchInputs; |
| 861 }, | 695 }, |
| 862 | 696 |
| 697 /** | |
| 698 * Compute the font scale factor. | |
| 699 * | |
| 700 * Chromium on Android uses a device scale adjustment for fonts used in text autosizing for | |
| 701 * improved legibility. This function computes this adjusted value for text autosizing. | |
| 702 * | |
| 703 * For a description of the Android device scale adjustment algorithm, see: | |
| 704 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) | |
| 705 * | |
| 706 * @param {number} width | |
| 707 * @param {number} height | |
| 708 * @return {number} font scale factor. | |
| 709 */ | |
| 710 _fontScaleFactor: function(width, height) | |
| 711 { | |
| 712 if (!this.settings.overrideDeviceResolution.get()) | |
| 713 return 1; | |
| 714 | |
| 715 var deviceScaleFactor = this.settings.deviceScaleFactor.get(); | |
| 716 | |
| 717 // FIXME: this works bad with zero width/height. Create utility function with parameters instead. | |
|
dgozman
2014/05/28 15:26:41
Remove FIXME.
pfeldman
2014/05/28 15:40:00
Done.
| |
| 718 var minWidth = Math.min(width, height) / deviceScaleFactor; | |
| 719 | |
| 720 var kMinFSM = 1.05; | |
| 721 var kWidthForMinFSM = 320; | |
| 722 var kMaxFSM = 1.3; | |
| 723 var kWidthForMaxFSM = 800; | |
| 724 | |
| 725 if (minWidth <= kWidthForMinFSM) | |
| 726 return kMinFSM; | |
| 727 if (minWidth >= kWidthForMaxFSM) | |
| 728 return kMaxFSM; | |
| 729 | |
| 730 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM . | |
| 731 var ratio = (minWidth - kWidthForMinFSM) / (kWidthForMaxFSM - kWidthForM inFSM); | |
| 732 | |
| 733 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | |
| 734 }, | |
| 735 | |
| 863 __proto__: WebInspector.Object.prototype | 736 __proto__: WebInspector.Object.prototype |
| 864 } | 737 } |
| 865 | 738 |
| 866 | 739 |
| 867 /** | 740 /** |
| 868 * @type {!WebInspector.OverridesSupport} | 741 * @type {!WebInspector.OverridesSupport} |
| 869 */ | 742 */ |
| 870 WebInspector.overridesSupport; | 743 WebInspector.overridesSupport; |
| OLD | NEW |