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

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

Issue 26929003: Add text autosizing override in the inspector. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address reviewer comments 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 WebInspector.settings.overrideCSSMedia.addChangeListener(this._cssMediaChang ed, this); 56 WebInspector.settings.overrideCSSMedia.addChangeListener(this._cssMediaChang ed, this);
57 WebInspector.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChang ed, this); 57 WebInspector.settings.emulatedCSSMedia.addChangeListener(this._cssMediaChang ed, this);
58 } 58 }
59 59
60 /** 60 /**
61 * @constructor 61 * @constructor
62 * @param {number} width 62 * @param {number} width
63 * @param {number} height 63 * @param {number} height
64 * @param {number} deviceScaleFactor 64 * @param {number} deviceScaleFactor
65 * @param {boolean} textAutosizing
65 */ 66 */
66 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor) 67 WebInspector.OverridesSupport.DeviceMetrics = function(width, height, deviceScal eFactor, textAutosizing)
67 { 68 {
68 this.width = width; 69 this.width = width;
69 this.height = height; 70 this.height = height;
70 this.deviceScaleFactor = deviceScaleFactor; 71 this.deviceScaleFactor = deviceScaleFactor;
72 this.textAutosizing = textAutosizing;
71 } 73 }
72 74
73 /** 75 /**
74 * @return {WebInspector.OverridesSupport.DeviceMetrics} 76 * @return {WebInspector.OverridesSupport.DeviceMetrics}
75 */ 77 */
76 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value) 78 WebInspector.OverridesSupport.DeviceMetrics.parseSetting = function(value)
77 { 79 {
80 var width = 0;
81 var height = 0;
82 var deviceScaleFactor = 1;
83 var textAutosizing = false;
78 if (value) { 84 if (value) {
79 var splitMetrics = value.split("x"); 85 var splitMetrics = value.split("x");
80 if (splitMetrics.length === 3) 86 if (splitMetrics.length === 4) {
81 return new WebInspector.OverridesSupport.DeviceMetrics(parseInt(spli tMetrics[0], 10), parseInt(splitMetrics[1], 10), parseFloat(splitMetrics[2])); 87 width = parseInt(splitMetrics[0], 10);
88 height = parseInt(splitMetrics[1], 10);
89 deviceScaleFactor = parseFloat(splitMetrics[2]);
90 textAutosizing = splitMetrics[3] == 1;
91 }
82 } 92 }
83 return new WebInspector.OverridesSupport.DeviceMetrics(0, 0, 1); 93 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing);
84 } 94 }
85 95
86 /** 96 /**
87 * @return {?WebInspector.OverridesSupport.DeviceMetrics} 97 * @return {?WebInspector.OverridesSupport.DeviceMetrics}
88 */ 98 */
89 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString) 99 WebInspector.OverridesSupport.DeviceMetrics.parseUserInput = function(widthStrin g, heightString, deviceScaleFactorString, textAutosizing)
90 { 100 {
91 function isUserInputValid(value, isInteger) 101 function isUserInputValid(value, isInteger)
92 { 102 {
93 if (!value) 103 if (!value)
94 return true; 104 return true;
95 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value); 105 return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\. \d+)?|\.\d+)$/.test(value);
96 } 106 }
97 107
98 if (!widthString ^ !heightString) 108 if (!widthString ^ !heightString)
99 return null; 109 return null;
100 110
101 var isWidthValid = isUserInputValid(widthString, true); 111 var isWidthValid = isUserInputValid(widthString, true);
102 var isHeightValid = isUserInputValid(heightString, true); 112 var isHeightValid = isUserInputValid(heightString, true);
103 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se); 113 var isDeviceScaleFactorValid = isUserInputValid(deviceScaleFactorString, fal se);
104 114
105 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid) 115 if (!isWidthValid && !isHeightValid && !isDeviceScaleFactorValid)
106 return null; 116 return null;
107 117
108 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1; 118 var width = isWidthValid ? parseInt(widthString || "0", 10) : -1;
109 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1; 119 var height = isHeightValid ? parseInt(heightString || "0", 10) : -1;
110 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1; 120 var deviceScaleFactor = isDeviceScaleFactorValid ? parseFloat(deviceScaleFac torString) : -1;
111 121
112 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor); 122 return new WebInspector.OverridesSupport.DeviceMetrics(width, height, device ScaleFactor, textAutosizing);
113 } 123 }
114 124
115 WebInspector.OverridesSupport.DeviceMetrics.prototype = { 125 WebInspector.OverridesSupport.DeviceMetrics.prototype = {
116 /** 126 /**
117 * @return {boolean} 127 * @return {boolean}
118 */ 128 */
119 isValid: function() 129 isValid: function()
120 { 130 {
121 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid(); 131 return this.isWidthValid() && this.isHeightValid() && this.isDeviceScale FactorValid();
122 }, 132 },
(...skipping 16 matching lines...) Expand all
139 149
140 /** 150 /**
141 * @return {boolean} 151 * @return {boolean}
142 */ 152 */
143 isDeviceScaleFactorValid: function() 153 isDeviceScaleFactorValid: function()
144 { 154 {
145 return this.deviceScaleFactor > 0; 155 return this.deviceScaleFactor > 0;
146 }, 156 },
147 157
148 /** 158 /**
159 * @return {boolean}
160 */
161 isTextAutosizingValid: function()
162 {
163 return true;
164 },
165
166 /**
149 * @return {string} 167 * @return {string}
150 */ 168 */
151 toSetting: function() 169 toSetting: function()
152 { 170 {
153 if (!this.isValid()) 171 if (!this.isValid())
154 return ""; 172 return "";
155 173
156 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor : ""; 174 return this.width && this.height ? this.width + "x" + this.height + "x" + this.deviceScaleFactor + "x" + (this.textAutosizing ? "1" : "0") : "";
157 }, 175 },
158 176
159 /** 177 /**
160 * @return {string} 178 * @return {string}
161 */ 179 */
162 widthToInput: function() 180 widthToInput: function()
163 { 181 {
164 return this.isWidthValid() && this.width ? String(this.width) : ""; 182 return this.isWidthValid() && this.width ? String(this.width) : "";
165 }, 183 },
166 184
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : ""); 363 NetworkAgent.setUserAgentOverride(this._overridesActive && WebInspector. settings.overrideUserAgent.get() ? WebInspector.settings.userAgent.get() : "");
346 }, 364 },
347 365
348 _deviceMetricsChanged: function() 366 _deviceMetricsChanged: function()
349 { 367 {
350 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : ""); 368 var metrics = WebInspector.OverridesSupport.DeviceMetrics.parseSetting(t his._overridesActive && WebInspector.settings.overrideDeviceMetrics.get() ? WebI nspector.settings.deviceMetrics.get() : "");
351 if (metrics.isValid()) { 369 if (metrics.isValid()) {
352 var active = metrics.width > 0 && metrics.height > 0; 370 var active = metrics.width > 0 && metrics.height > 0;
353 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ; 371 var dipWidth = Math.round(metrics.width / metrics.deviceScaleFactor) ;
354 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r); 372 var dipHeight = Math.round(metrics.height / metrics.deviceScaleFacto r);
355 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get()); 373 PageAgent.setDeviceMetricsOverride(dipWidth, dipHeight, metrics.devi ceScaleFactor, WebInspector.settings.deviceFitWindow.get(), metrics.textAutosizi ng);
356 if (active != this._deviceMetricsOverridesActive) { 374 if (active != this._deviceMetricsOverridesActive) {
357 PageAgent.reload(false); 375 PageAgent.reload(false);
358 this._deviceMetricsOverridesActive = active; 376 this._deviceMetricsOverridesActive = active;
359 } 377 }
360 } 378 }
361 }, 379 },
362 380
363 _geolocationPositionChanged: function() 381 _geolocationPositionChanged: function()
364 { 382 {
365 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) { 383 if (!this._overridesActive || !WebInspector.settings.overrideGeolocation .get()) {
(...skipping 27 matching lines...) Expand all
393 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : ""); 411 PageAgent.setEmulatedMedia(this._overridesActive && WebInspector.setting s.overrideCSSMedia.get() ? WebInspector.settings.emulatedCSSMedia.get() : "");
394 WebInspector.cssModel.mediaQueryResultChanged(); 412 WebInspector.cssModel.mediaQueryResultChanged();
395 } 413 }
396 } 414 }
397 415
398 416
399 /** 417 /**
400 * @type {WebInspector.OverridesSupport} 418 * @type {WebInspector.OverridesSupport}
401 */ 419 */
402 WebInspector.overridesSupport; 420 WebInspector.overridesSupport;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698