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

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

Issue 27119002: Add text autosizing override in the inspector. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {number} textAutosizing (index into WebInspector.OverridesSupport.Devi ceMetrics.TextAutosizingTypes).
64 */ 65 */
65 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor) 66 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor, textAutosizingOverride)
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.textAutosizingOverride = textAutosizingOverride;
70 } 72 }
71 73
74 WebInspector.OverridesSupport.DeviceMetrics.TextAutosizingTypes = ["Default", "E nabled", "Disabled"];
75
72 /** 76 /**
73 * @return {WebInspector.OverridesSupport.DeviceMetrics} 77 * @return {WebInspector.OverridesSupport.DeviceMetrics}
74 */ 78 */
75 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) 79 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value)
76 { 80 {
81 var width = 0;
82 var height = 0;
83 var deviceScaleFactor = 1;
84 var textAutosizingOverride = 0;
77 if (value) { 85 if (value) {
78 var splitMetrics = value.split("x"); 86 var splitMetrics = value.split("x");
79 if (splitMetrics.length === 3) 87 if (splitMetrics.length === 4) {
80 return new WebInspector.OverridesSupport.DeviceMetrics(parseInt(spli tMetrics[0], 10), parseInt(splitMetrics[1], 10), parseFloat(splitMetrics[2])); 88 width = parseInt(splitMetrics[0], 10);
89 height = parseInt(splitMetrics[1], 10);
90 deviceScaleFactor = parseFloat(splitMetrics[2]);
91 textAutosizingOverride = parseInt(splitMetrics[3], 10);
92 }
81 } 93 }
82 return new WebInspector.OverridesSupport.DeviceMetrics(0, 0, 1); 94 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizingOverride);
83 } 95 }
84 96
85 /** 97 /**
86 * @return {?WebInspector.OverridesSupport.DeviceMetrics} 98 * @return {?WebInspector.OverridesSupport.DeviceMetrics}
87 */ 99 */
88 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString) 100 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizingOverrideIndex)
89 { 101 {
90 function isUserInputValid(value, isInteger) 102 function isUserInputValid(value, isInteger)
91 { 103 {
92 if (!value) 104 if (!value)
93 return true; 105 return true;
94 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); 106 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value);
95 } 107 }
96 108
97 if (!widthString ^ !heightString) 109 if (!widthString ^ !heightString)
98 return null; 110 return null;
99 111
100 var isWidthValid = isUserInputValid(widthString, true); 112 var isWidthValid = isUserInputValid(widthString, true);
101 var isHeightValid = isUserInputValid(heightString, true); 113 var isHeightValid = isUserInputValid(heightString, true);
102 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); 114 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se);
115 var isTextAutosizingOverrideValid = WebInspector.OverridesSupport.DeviceMetr ics.TextAutosizingTypes[textAutosizingOverrideIndex] !== undefined;
103 116
104 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) 117 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid && !isTextA utosizingOverrideValid)
105 return null; 118 return null;
106 119
107 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; 120 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1;
108 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; 121 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1;
109 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; 122 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1;
123 var textAutosizingOverride = isTextAutosizingOverrideValid ? textAutosizingO verrideIndex : 0;
110 124
111 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor); 125 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizingOverride);
112 } 126 }
113 127
114 WebInspector.OverridesSupport.DeviceMetrics.prototype = { 128 WebInspector.OverridesSupport.DeviceMetrics.prototype = {
115 /** 129 /**
116 * @return {boolean} 130 * @return {boolean}
117 */ 131 */
118 isValid: function() 132 isValid: function()
119 { 133 {
120 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); 134 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid();
121 }, 135 },
(...skipping 16 matching lines...) Expand all
138 152
139 /** 153 /**
140 * @return {boolean} 154 * @return {boolean}
141 */ 155 */
142 isDeviceScaleFactorValid: function() 156 isDeviceScaleFactorValid: function()
143 { 157 {
144 return this.deviceScaleFactor > 0; 158 return this.deviceScaleFactor > 0;
145 }, 159 },
146 160
147 /** 161 /**
162 * @return {boolean}
163 */
164 isTextAutosizingOverrideValid: function()
165 {
166 return WebInspector.OverridesSupport.DeviceMetrics.TextAutosizingTypes[t his.textAutosizingOverride] !== undefined;
167 },
168
169 /**
148 * @return {string} 170 * @return {string}
149 */ 171 */
150 toSetting: function() 172 toSetting: function()
151 { 173 {
152 if (!this.isValid()) 174 if (!this.isValid())
153 return ""; 175 return "";
154 176 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + this.textAutosizingOverride : "";
155 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor : "";
156 }, 177 },
157 178
158 /** 179 /**
159 * @return {string} 180 * @return {string}
160 */ 181 */
161 widthToInput: function() 182 widthToInput: function()
162 { 183 {
163 return this.isWidthValid() && this.width ? String(this.width) : ""; 184 return this.isWidthValid() && this.width ? String(this.width) : "";
164 }, 185 },
165 186
166 /** 187 /**
167 * @return {string} 188 * @return {string}
168 */ 189 */
169 heightToInput: function() 190 heightToInput: function()
170 { 191 {
171 return this.isHeightValid() && this.height ? String(this.height) : ""; 192 return this.isHeightValid() && this.height ? String(this.height) : "";
172 }, 193 },
173 194
174 /** 195 /**
175 * @return {string} 196 * @return {string}
176 */ 197 */
177 deviceScaleFactorToInput: function() 198 deviceScaleFactorToInput: function()
178 { 199 {
179 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : ""; 200 return this.isDeviceScaleFactorValid() && this.deviceScaleFactor ? Strin g(this.deviceScaleFactor) : "";
201 },
202
203 /**
204 * @return {number}
205 */
206 textAutosizingOverrideToIndex: function()
207 {
208 return this.isTextAutosizingOverrideValid() ? this.textAutosizingOverrid e : 0;
180 } 209 }
181 } 210 }
182 211
183 /** 212 /**
184 * @constructor 213 * @constructor
185 * @param {number} latitude 214 * @param {number} latitude
186 * @param {number} longitude 215 * @param {number} longitude
187 */ 216 */
188 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error) 217 WebInspector.OverridesSupport.GeolocationPosition = function(latitude, longitude , error)
189 { 218 {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : ""); 373 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : "");
345 }, 374 },
346 375
347 _deviceMetricsChanged: function() 376 _deviceMetricsChanged: function()
348 { 377 {
349 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : ""); 378 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : "");
350 if (metrics.isValid()) { 379 if (metrics.isValid()) {
351 var active = metrics.width > 0 && metrics.height > 0; 380 var active = metrics.width > 0 && metrics.height > 0;
352 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ; 381 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ;
353 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r); 382 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r);
354 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get()); 383 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get(), metrics.textAutosizi ngOverride);
355 if (active != this._deviceMetricsOverridesActive) { 384 if (active != this._deviceMetricsOverridesActive) {
356 PageAgent.reload(false); 385 PageAgent.reload(false);
357 this._deviceMetricsOverridesActive = active; 386 this._deviceMetricsOverridesActive = active;
358 } 387 }
359 } 388 }
360 }, 389 },
361 390
362 _geolocationPositionChanged: function() 391 _geolocationPositionChanged: function()
363 { 392 {
364 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) { 393 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) {
(...skipping 27 matching lines...) Expand all
392 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : ""); 421 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : "");
393 WebInspector.cssModel.mediaQueryResultChanged(); 422 WebInspector.cssModel.mediaQueryResultChanged();
394 } 423 }
395 } 424 }
396 425
397 426
398 /** 427 /**
399 * @type {WebInspector.OverridesSupport} 428 * @type {WebInspector.OverridesSupport}
400 */ 429 */
401 WebInspector.overridesSupport; 430 WebInspector.overridesSupport;
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.cpp ('k') | Source/devtools/front_end/OverridesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698