 Chromium Code Reviews
 Chromium Code Reviews Issue 77723002:
  Remove the autosizing modes in favor of a dev site link.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 77723002:
  Remove the autosizing modes in favor of a dev site link.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 WebInspector.OverridesSupport.Events = { | 60 WebInspector.OverridesSupport.Events = { | 
| 61 OverridesWarningUpdated: "OverridesWarningUpdated", | 61 OverridesWarningUpdated: "OverridesWarningUpdated", | 
| 62 } | 62 } | 
| 63 | 63 | 
| 64 /** | 64 /** | 
| 65 * @constructor | 65 * @constructor | 
| 66 * @param {number} width | 66 * @param {number} width | 
| 67 * @param {number} height | 67 * @param {number} height | 
| 68 * @param {number} deviceScaleFactor | 68 * @param {number} deviceScaleFactor | 
| 69 * @param {boolean} textAutosizing | 69 * @param {boolean} textAutosizing | 
| 70 * @param {boolean} useAndroidFontMetrics | |
| 71 */ | 70 */ | 
| 72 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor, textAutosizing, useAndroidFontMetrics) | 71 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor, textAutosizing) | 
| 73 { | 72 { | 
| 74 this.width = width; | 73 this.width = width; | 
| 75 this.height = height; | 74 this.height = height; | 
| 76 this.deviceScaleFactor = deviceScaleFactor; | 75 this.deviceScaleFactor = deviceScaleFactor; | 
| 77 this.textAutosizing = textAutosizing; | 76 this.textAutosizing = textAutosizing; | 
| 78 this.useAndroidFontMetrics = useAndroidFontMetrics; | |
| 79 } | 77 } | 
| 80 | 78 | 
| 81 /** | 79 /** | 
| 82 * @return {WebInspector.OverridesSupport.DeviceMetrics} | 80 * @return {WebInspector.OverridesSupport.DeviceMetrics} | 
| 83 */ | 81 */ | 
| 84 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) | 82 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) | 
| 85 { | 83 { | 
| 86 var width = 0; | 84 var width = 0; | 
| 87 var height = 0; | 85 var height = 0; | 
| 88 var deviceScaleFactor = 1; | 86 var deviceScaleFactor = 1; | 
| 89 var textAutosizing = false; | 87 var textAutosizing = false; | 
| 90 var useAndroidFontMetrics = false; | |
| 91 if (value) { | 88 if (value) { | 
| 92 var splitMetrics = value.split("x"); | 89 var splitMetrics = value.split("x"); | 
| 93 if (splitMetrics.length === 5) { | 90 if (splitMetrics.length === 4) { | 
| 94 width = parseInt(splitMetrics[0], 10); | 91 width = parseInt(splitMetrics[0], 10); | 
| 95 height = parseInt(splitMetrics[1], 10); | 92 height = parseInt(splitMetrics[1], 10); | 
| 96 deviceScaleFactor = parseFloat(splitMetrics[2]); | 93 deviceScaleFactor = parseFloat(splitMetrics[2]); | 
| 97 useAndroidFontMetrics = splitMetrics[3] == 1; | 94 textAutosizing = splitMetrics[3] == 1; | 
| 98 textAutosizing = splitMetrics[4] == 1; | |
| 99 } | 95 } | 
| 100 } | 96 } | 
| 101 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing, useAndroidFontMetrics); | 97 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); | 
| 102 } | 98 } | 
| 103 | 99 | 
| 104 /** | 100 /** | 
| 105 * @return {?WebInspector.OverridesSupport.DeviceMetrics} | 101 * @return {?WebInspector.OverridesSupport.DeviceMetrics} | 
| 106 */ | 102 */ | 
| 107 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing, useAndroidFontMetrics) | 103 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing) | 
| 108 { | 104 { | 
| 109 function isUserInputValid(value, isInteger) | 105 function isUserInputValid(value, isInteger) | 
| 110 { | 106 { | 
| 111 if (!value) | 107 if (!value) | 
| 112 return true; | 108 return true; | 
| 113 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); | 109 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); | 
| 114 } | 110 } | 
| 115 | 111 | 
| 116 if (!widthString ^ !heightString) | 112 if (!widthString ^ !heightString) | 
| 117 return null; | 113 return null; | 
| 118 | 114 | 
| 119 var isWidthValid = isUserInputValid(widthString, true); | 115 var isWidthValid = isUserInputValid(widthString, true); | 
| 120 var isHeightValid = isUserInputValid(heightString, true); | 116 var isHeightValid = isUserInputValid(heightString, true); | 
| 121 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); | 117 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); | 
| 122 | 118 | 
| 123 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) | 119 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) | 
| 124 return null; | 120 return null; | 
| 125 | 121 | 
| 126 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; | 122 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; | 
| 127 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; | 123 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; | 
| 128 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; | 124 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; | 
| 129 | 125 | 
| 130 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing, useAndroidFontMetrics); | 126 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing); | 
| 131 } | 127 } | 
| 132 | 128 | 
| 133 WebInspector.OverridesSupport.DeviceMetrics.prototype = { | 129 WebInspector.OverridesSupport.DeviceMetrics.prototype = { | 
| 134 /** | 130 /** | 
| 135 * @return {boolean} | 131 * @return {boolean} | 
| 136 */ | 132 */ | 
| 137 isValid: function() | 133 isValid: function() | 
| 138 { | 134 { | 
| 139 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); | 135 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); | 
| 140 }, | 136 }, | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 157 | 153 | 
| 158 /** | 154 /** | 
| 159 * @return {boolean} | 155 * @return {boolean} | 
| 160 */ | 156 */ | 
| 161 isDeviceScaleFactorValid: function() | 157 isDeviceScaleFactorValid: function() | 
| 162 { | 158 { | 
| 163 return this.deviceScaleFactor > 0; | 159 return this.deviceScaleFactor > 0; | 
| 164 }, | 160 }, | 
| 165 | 161 | 
| 166 /** | 162 /** | 
| 167 * @return {boolean} | |
| 168 */ | |
| 169 isUseAndroidFontMetricsDisabled: function() | |
| 170 { | |
| 171 return !this.textAutosizing; | |
| 172 }, | |
| 173 | |
| 174 /** | |
| 175 * @return {string} | 163 * @return {string} | 
| 176 */ | 164 */ | 
| 177 toSetting: function() | 165 toSetting: function() | 
| 178 { | 166 { | 
| 179 if (!this.isValid()) | 167 if (!this.isValid()) | 
| 180 return ""; | 168 return ""; | 
| 181 | 169 | 
| 182 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.useAndroidFontMetrics ? "1" : "0") + "x" + (this.textAutosizing ? "1" : "0") : ""; | 170 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.textAutosizing ? "1" : "0") : ""; | 
| 183 }, | 171 }, | 
| 184 | 172 | 
| 185 /** | 173 /** | 
| 186 * @return {string} | 174 * @return {string} | 
| 187 */ | 175 */ | 
| 188 widthToInput: function() | 176 widthToInput: function() | 
| 189 { | 177 { | 
| 190 return this.isWidthValid() && this.width ? String(this.width) : ""; | 178 return this.isWidthValid() && this.width ? String(this.width) : ""; | 
| 191 }, | 179 }, | 
| 192 | 180 | 
| 193 /** | 181 /** | 
| 194 * @return {string} | 182 * @return {string} | 
| 195 */ | 183 */ | 
| 196 heightToInput: function() | 184 heightToInput: function() | 
| 197 { | 185 { | 
| 198 return this.isHeightValid() && this.height ? String(this.height) : ""; | 186 return this.isHeightValid() && this.height ? String(this.height) : ""; | 
| 199 }, | 187 }, | 
| 200 | 188 | 
| 201 /** | 189 /** | 
| 202 * @return {string} | 190 * @return {string} | 
| 203 */ | 191 */ | 
| 204 deviceScaleFactorToInput: function() | 192 deviceScaleFactorToInput: function() | 
| 205 { | 193 { | 
| 206 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : ""; | 194 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : ""; | 
| 207 }, | 195 }, | 
| 208 | 196 | 
| 209 /** | 197 /** | 
| 210 * Compute the font scale factor. | 198 * Compute the font scale factor. | 
| 211 * | 199 * | 
| 212 * Android uses a device scale adjustment for fonts used in text autosizing for improved | 200 * Chromium on mobile uses a device scale adjustment for fonts used in text autosizing for | 
| 
skobes
2013/11/20 20:06:41
I would leave this comment as "Android", since it
 | |
| 213 * legibility. This function computes this adjusted value if useAndroidFontM etrics is true. | 201 * improved legibility. This function computes this adjusted value for text autosizing. | 
| 214 * | 202 * | 
| 215 * For a description of the Android device scale adjustment algorithm, see: | 203 * For a description of the Android device scale adjustment algorithm, see: | 
| 216 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) | 204 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) | 
| 217 * | 205 * | 
| 218 * @return {number} font scale factor for Android if useAndroidFontMetrics, or 1. | 206 * @return {number} font scale factor. | 
| 219 */ | 207 */ | 
| 220 fontScaleFactor: function() | 208 fontScaleFactor: function() | 
| 221 { | 209 { | 
| 222 if (this.useAndroidFontMetrics && this.isValid()) { | 210 if (this.isValid()) { | 
| 223 var minWidth = Math.min(this.width, this.height) / this.deviceScaleF actor; | 211 var minWidth = Math.min(this.width, this.height) / this.deviceScaleF actor; | 
| 224 | 212 | 
| 225 var kMinFSM = 1.05; | 213 var kMinFSM = 1.05; | 
| 226 var kWidthForMinFSM = 320; | 214 var kWidthForMinFSM = 320; | 
| 227 var kMaxFSM = 1.3; | 215 var kMaxFSM = 1.3; | 
| 228 var kWidthForMaxFSM = 800; | 216 var kWidthForMaxFSM = 800; | 
| 229 | 217 | 
| 230 if (minWidth <= kWidthForMinFSM) | 218 if (minWidth <= kWidthForMinFSM) | 
| 231 return kMinFSM; | 219 return kMinFSM; | 
| 232 if (minWidth >= kWidthForMaxFSM) | 220 if (minWidth >= kWidthForMaxFSM) | 
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 }, | 537 }, | 
| 550 | 538 | 
| 551 __proto__: WebInspector.Object.prototype | 539 __proto__: WebInspector.Object.prototype | 
| 552 } | 540 } | 
| 553 | 541 | 
| 554 | 542 | 
| 555 /** | 543 /** | 
| 556 * @type {WebInspector.OverridesSupport} | 544 * @type {WebInspector.OverridesSupport} | 
| 557 */ | 545 */ | 
| 558 WebInspector.overridesSupport; | 546 WebInspector.overridesSupport; | 
| OLD | NEW |