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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 WebInspector.settings.overrideCSSMedia.addChangeListener(this._cssMediaChang ed, this); | 55 WebInspector.settings.overrideCSSMedia.addChangeListener(this._cssMediaChang ed, this); |
| 56 WebInspector.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChang ed, this); | 56 WebInspector.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChang ed, this); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * @constructor | 60 * @constructor |
| 61 * @param {number} width | 61 * @param {number} width |
| 62 * @param {number} height | 62 * @param {number} height |
| 63 * @param {number} deviceScaleFactor | 63 * @param {number} deviceScaleFactor |
| 64 * @param {boolean} textAutosizing | |
| 64 */ | 65 */ |
| 65 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor) | 66 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor, textAutosizing) |
| 66 { | 67 { |
| 67 this.width = width; | 68 this.width = width; |
| 68 this.height = height; | 69 this.height = height; |
| 69 this.deviceScaleFactor = deviceScaleFactor; | 70 this.deviceScaleFactor = deviceScaleFactor; |
| 71 this.textAutosizing = textAutosizing; | |
| 70 } | 72 } |
| 71 | 73 |
| 72 /** | 74 /** |
| 73 * @return {WebInspector.OverridesSupport.DeviceMetrics} | 75 * @return {WebInspector.OverridesSupport.DeviceMetrics} |
| 74 */ | 76 */ |
| 75 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) | 77 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) |
| 76 { | 78 { |
| 77 if (value) { | 79 if (value) { |
| 78 var splitMetrics = value.split("x"); | 80 var splitMetrics = value.split("x"); |
| 79 if (splitMetrics.length === 3) | 81 if (splitMetrics.length === 4) |
| 80 return new WebInspector.OverridesSupport.DeviceMetrics(parseInt(spli tMetrics[0], 10), parseInt(splitMetrics[1], 10), parseFloat(splitMetrics[2])); | 82 return new WebInspector.OverridesSupport.DeviceMetrics(parseInt(spli tMetrics[0], 10), parseInt(splitMetrics[1], 10), parseFloat(splitMetrics[2]), sp litMetrics[3] == 1); |
|
skobes
2013/10/16 19:38:09
This would be a lot more readable with each ctor a
pdr.
2013/10/18 01:28:44
Agreed, I refactored this a bit to clean it up.
| |
| 81 } | 83 } |
| 82 return new WebInspector.OverridesSupport.DeviceMetrics(0, 0, 1); | 84 return new WebInspector.OverridesSupport.DeviceMetrics(0, 0, 1, false); |
| 83 } | 85 } |
| 84 | 86 |
| 85 /** | 87 /** |
| 86 * @return {?WebInspector.OverridesSupport.DeviceMetrics} | 88 * @return {?WebInspector.OverridesSupport.DeviceMetrics} |
| 87 */ | 89 */ |
| 88 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString) | 90 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing) |
| 89 { | 91 { |
| 90 function isUserInputValid(value, isInteger) | 92 function isUserInputValid(value, isInteger) |
| 91 { | 93 { |
| 92 if (!value) | 94 if (!value) |
| 93 return true; | 95 return true; |
| 94 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); | 96 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); |
| 95 } | 97 } |
| 96 | 98 |
| 97 if (!widthString ^ !heightString) | 99 if (!widthString ^ !heightString) |
| 98 return null; | 100 return null; |
| 99 | 101 |
| 100 var isWidthValid = isUserInputValid(widthString, true); | 102 var isWidthValid = isUserInputValid(widthString, true); |
| 101 var isHeightValid = isUserInputValid(heightString, true); | 103 var isHeightValid = isUserInputValid(heightString, true); |
| 102 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); | 104 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); |
| 103 | 105 |
| 104 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) | 106 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) |
| 105 return null; | 107 return null; |
| 106 | 108 |
| 107 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; | 109 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; |
| 108 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; | 110 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; |
| 109 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; | 111 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; |
| 110 | 112 |
| 111 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor); | 113 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); |
| 112 } | 114 } |
| 113 | 115 |
| 114 WebInspector.OverridesSupport.DeviceMetrics.prototype = { | 116 WebInspector.OverridesSupport.DeviceMetrics.prototype = { |
| 115 /** | 117 /** |
| 116 * @return {boolean} | 118 * @return {boolean} |
| 117 */ | 119 */ |
| 118 isValid: function() | 120 isValid: function() |
| 119 { | 121 { |
| 120 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); | 122 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); |
| 121 }, | 123 }, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * @return {boolean} | 142 * @return {boolean} |
| 141 */ | 143 */ |
| 142 isDeviceScaleFactorValid: function() | 144 isDeviceScaleFactorValid: function() |
| 143 { | 145 { |
| 144 return this.deviceScaleFactor > 0; | 146 return this.deviceScaleFactor > 0; |
| 145 }, | 147 }, |
| 146 | 148 |
| 147 /** | 149 /** |
| 150 * @return {boolean} | |
| 151 */ | |
| 152 isTextAutosizingValid: function() | |
| 153 { | |
| 154 return true; | |
| 155 }, | |
| 156 | |
| 157 /** | |
| 148 * @return {string} | 158 * @return {string} |
| 149 */ | 159 */ |
| 150 toSetting: function() | 160 toSetting: function() |
| 151 { | 161 { |
| 152 if (!this.isValid()) | 162 if (!this.isValid()) |
| 153 return ""; | 163 return ""; |
| 154 | 164 |
| 155 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor : ""; | 165 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.textAutosizing ? "1" : "0") : ""; |
| 156 }, | 166 }, |
| 157 | 167 |
| 158 /** | 168 /** |
| 159 * @return {string} | 169 * @return {string} |
| 160 */ | 170 */ |
| 161 widthToInput: function() | 171 widthToInput: function() |
| 162 { | 172 { |
| 163 return this.isWidthValid() && this.width ? String(this.width) : ""; | 173 return this.isWidthValid() && this.width ? String(this.width) : ""; |
| 164 }, | 174 }, |
| 165 | 175 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : ""); | 354 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : ""); |
| 345 }, | 355 }, |
| 346 | 356 |
| 347 _deviceMetricsChanged: function() | 357 _deviceMetricsChanged: function() |
| 348 { | 358 { |
| 349 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : ""); | 359 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : ""); |
| 350 if (metrics.isValid()) { | 360 if (metrics.isValid()) { |
| 351 var active = metrics.width > 0 && metrics.height > 0; | 361 var active = metrics.width > 0 && metrics.height > 0; |
| 352 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ; | 362 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ; |
| 353 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r); | 363 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r); |
| 354 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get()); | 364 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get(), metrics.textAutosizi ng); |
| 355 if (active != this._deviceMetricsOverridesActive) { | 365 if (active != this._deviceMetricsOverridesActive) { |
| 356 PageAgent.reload(false); | 366 PageAgent.reload(false); |
| 357 this._deviceMetricsOverridesActive = active; | 367 this._deviceMetricsOverridesActive = active; |
| 358 } | 368 } |
| 359 } | 369 } |
| 360 }, | 370 }, |
| 361 | 371 |
| 362 _geolocationPositionChanged: function() | 372 _geolocationPositionChanged: function() |
| 363 { | 373 { |
| 364 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) { | 374 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 392 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : ""); | 402 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : ""); |
| 393 WebInspector.cssModel.mediaQueryResultChanged(); | 403 WebInspector.cssModel.mediaQueryResultChanged(); |
| 394 } | 404 } |
| 395 } | 405 } |
| 396 | 406 |
| 397 | 407 |
| 398 /** | 408 /** |
| 399 * @type {WebInspector.OverridesSupport} | 409 * @type {WebInspector.OverridesSupport} |
| 400 */ | 410 */ |
| 401 WebInspector.overridesSupport; | 411 WebInspector.overridesSupport; |
| OLD | NEW |