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

Side by Side Diff: Source/devtools/front_end/OverridesSupport.js

Issue 77723002: Remove the autosizing modes in favor of a dev site link. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase, address reviewer comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/devtools/front_end/OverridesView.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = true;
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 >= 3) {
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 if (splitMetrics.length == 4)
98 textAutosizing = splitMetrics[4] == 1; 95 textAutosizing = splitMetrics[3] == 1;
99 } 96 }
100 } 97 }
101 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing, useAndroidFontMetrics); 98 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing);
102 } 99 }
103 100
104 /** 101 /**
105 * @return {?WebInspector.OverridesSupport.DeviceMetrics} 102 * @return {?WebInspector.OverridesSupport.DeviceMetrics}
106 */ 103 */
107 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing, useAndroidFontMetrics) 104 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing)
108 { 105 {
109 function isUserInputValid(value, isInteger) 106 function isUserInputValid(value, isInteger)
110 { 107 {
111 if (!value) 108 if (!value)
112 return true; 109 return true;
113 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); 110 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value);
114 } 111 }
115 112
116 if (!widthString ^ !heightString) 113 if (!widthString ^ !heightString)
117 return null; 114 return null;
118 115
119 var isWidthValid = isUserInputValid(widthString, true); 116 var isWidthValid = isUserInputValid(widthString, true);
120 var isHeightValid = isUserInputValid(heightString, true); 117 var isHeightValid = isUserInputValid(heightString, true);
121 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); 118 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se);
122 119
123 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) 120 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid)
124 return null; 121 return null;
125 122
126 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; 123 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1;
127 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; 124 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1;
128 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; 125 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1;
129 126
130 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing, useAndroidFontMetrics); 127 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing);
131 } 128 }
132 129
133 WebInspector.OverridesSupport.DeviceMetrics.prototype = { 130 WebInspector.OverridesSupport.DeviceMetrics.prototype = {
134 /** 131 /**
135 * @return {boolean} 132 * @return {boolean}
136 */ 133 */
137 isValid: function() 134 isValid: function()
138 { 135 {
139 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); 136 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid();
140 }, 137 },
(...skipping 16 matching lines...) Expand all
157 154
158 /** 155 /**
159 * @return {boolean} 156 * @return {boolean}
160 */ 157 */
161 isDeviceScaleFactorValid: function() 158 isDeviceScaleFactorValid: function()
162 { 159 {
163 return this.deviceScaleFactor > 0; 160 return this.deviceScaleFactor > 0;
164 }, 161 },
165 162
166 /** 163 /**
167 * @return {boolean}
168 */
169 isUseAndroidFontMetricsDisabled: function()
170 {
171 return !this.textAutosizing;
172 },
173
174 /**
175 * @return {string} 164 * @return {string}
176 */ 165 */
177 toSetting: function() 166 toSetting: function()
178 { 167 {
179 if (!this.isValid()) 168 if (!this.isValid())
180 return ""; 169 return "";
181 170
182 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.useAndroidFontMetrics ? "1" : "0") + "x" + (this.textAutosizing ? "1" : "0") : ""; 171 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.textAutosizing ? "1" : "0") : "";
183 }, 172 },
184 173
185 /** 174 /**
186 * @return {string} 175 * @return {string}
187 */ 176 */
188 widthToInput: function() 177 widthToInput: function()
189 { 178 {
190 return this.isWidthValid() && this.width ? String(this.width) : ""; 179 return this.isWidthValid() && this.width ? String(this.width) : "";
191 }, 180 },
192 181
193 /** 182 /**
194 * @return {string} 183 * @return {string}
195 */ 184 */
196 heightToInput: function() 185 heightToInput: function()
197 { 186 {
198 return this.isHeightValid() && this.height ? String(this.height) : ""; 187 return this.isHeightValid() && this.height ? String(this.height) : "";
199 }, 188 },
200 189
201 /** 190 /**
202 * @return {string} 191 * @return {string}
203 */ 192 */
204 deviceScaleFactorToInput: function() 193 deviceScaleFactorToInput: function()
205 { 194 {
206 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : ""; 195 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : "";
207 }, 196 },
208 197
209 /** 198 /**
210 * Compute the font scale factor. 199 * Compute the font scale factor.
211 * 200 *
212 * Android uses a device scale adjustment for fonts used in text autosizing for improved 201 * Chromium on Android uses a device scale adjustment for fonts used in text autosizing for
213 * legibility. This function computes this adjusted value if useAndroidFontM etrics is true. 202 * improved legibility. This function computes this adjusted value for text autosizing.
214 * 203 *
215 * For a description of the Android device scale adjustment algorithm, see: 204 * For a description of the Android device scale adjustment algorithm, see:
216 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...) 205 * chrome/browser/chrome_content_browser_client.cc, GetFontScaleMultipli er(...)
217 * 206 *
218 * @return {number} font scale factor for Android if useAndroidFontMetrics, or 1. 207 * @return {number} font scale factor.
219 */ 208 */
220 fontScaleFactor: function() 209 fontScaleFactor: function()
221 { 210 {
222 if (this.useAndroidFontMetrics && this.isValid()) { 211 if (this.isValid()) {
223 var minWidth = Math.min(this.width, this.height) / this.deviceScaleF actor; 212 var minWidth = Math.min(this.width, this.height) / this.deviceScaleF actor;
224 213
225 var kMinFSM = 1.05; 214 var kMinFSM = 1.05;
226 var kWidthForMinFSM = 320; 215 var kWidthForMinFSM = 320;
227 var kMaxFSM = 1.3; 216 var kMaxFSM = 1.3;
228 var kWidthForMaxFSM = 800; 217 var kWidthForMaxFSM = 800;
229 218
230 if (minWidth <= kWidthForMinFSM) 219 if (minWidth <= kWidthForMinFSM)
231 return kMinFSM; 220 return kMinFSM;
232 if (minWidth >= kWidthForMaxFSM) 221 if (minWidth >= kWidthForMaxFSM)
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 }, 538 },
550 539
551 __proto__: WebInspector.Object.prototype 540 __proto__: WebInspector.Object.prototype
552 } 541 }
553 542
554 543
555 /** 544 /**
556 * @type {WebInspector.OverridesSupport} 545 * @type {WebInspector.OverridesSupport}
557 */ 546 */
558 WebInspector.overridesSupport; 547 WebInspector.overridesSupport;
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/OverridesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698