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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/DevicesSettingsTab.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
5 /** 4 /**
6 * @constructor
7 * @extends {WebInspector.VBox}
8 * @implements {WebInspector.ListWidget.Delegate} 5 * @implements {WebInspector.ListWidget.Delegate}
6 * @unrestricted
9 */ 7 */
10 WebInspector.DevicesSettingsTab = function() 8 WebInspector.DevicesSettingsTab = class extends WebInspector.VBox {
11 { 9 constructor() {
12 WebInspector.VBox.call(this); 10 super();
13 this.element.classList.add("settings-tab-container"); 11 this.element.classList.add('settings-tab-container');
14 this.element.classList.add("devices-settings-tab"); 12 this.element.classList.add('devices-settings-tab');
15 this.registerRequiredCSS("emulation/devicesSettingsTab.css"); 13 this.registerRequiredCSS('emulation/devicesSettingsTab.css');
16 14
17 var header = this.element.createChild("header"); 15 var header = this.element.createChild('header');
18 header.createChild("h3").createTextChild(WebInspector.UIString("Emulated Dev ices")); 16 header.createChild('h3').createTextChild(WebInspector.UIString('Emulated Dev ices'));
19 this.containerElement = this.element.createChild("div", "help-container-wrap per").createChild("div", "settings-tab help-content help-container"); 17 this.containerElement = this.element.createChild('div', 'help-container-wrap per')
20 18 .createChild('div', 'settings-tab help-content h elp-container');
21 var buttonsRow = this.containerElement.createChild("div", "devices-button-ro w"); 19
22 this._addCustomButton = createTextButton(WebInspector.UIString("Add custom d evice..."), this._addCustomDevice.bind(this)); 20 var buttonsRow = this.containerElement.createChild('div', 'devices-button-ro w');
21 this._addCustomButton =
22 createTextButton(WebInspector.UIString('Add custom device...'), this._ad dCustomDevice.bind(this));
23 buttonsRow.appendChild(this._addCustomButton); 23 buttonsRow.appendChild(this._addCustomButton);
24 24
25 this._list = new WebInspector.ListWidget(this); 25 this._list = new WebInspector.ListWidget(this);
26 this._list.registerRequiredCSS("emulation/devicesSettingsTab.css"); 26 this._list.registerRequiredCSS('emulation/devicesSettingsTab.css');
27 this._list.element.classList.add("devices-list"); 27 this._list.element.classList.add('devices-list');
28 this._list.show(this.containerElement); 28 this._list.show(this.containerElement);
29 29
30 this._muteUpdate = false; 30 this._muteUpdate = false;
31 this._emulatedDevicesList = WebInspector.EmulatedDevicesList.instance(); 31 this._emulatedDevicesList = WebInspector.EmulatedDevicesList.instance();
32 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.CustomDevicesUpdated, this._devicesUpdated, this); 32 this._emulatedDevicesList.addEventListener(
33 this._emulatedDevicesList.addEventListener(WebInspector.EmulatedDevicesList. Events.StandardDevicesUpdated, this._devicesUpdated, this); 33 WebInspector.EmulatedDevicesList.Events.CustomDevicesUpdated, this._devi cesUpdated, this);
34 this._emulatedDevicesList.addEventListener(
35 WebInspector.EmulatedDevicesList.Events.StandardDevicesUpdated, this._de vicesUpdated, this);
34 36
35 this.setDefaultFocusedElement(this._addCustomButton); 37 this.setDefaultFocusedElement(this._addCustomButton);
36 }; 38 }
37 39
38 WebInspector.DevicesSettingsTab.prototype = { 40 /**
39 wasShown: function() 41 * @override
40 { 42 */
41 WebInspector.VBox.prototype.wasShown.call(this); 43 wasShown() {
42 this._devicesUpdated(); 44 super.wasShown();
43 }, 45 this._devicesUpdated();
44 46 }
45 _devicesUpdated: function() 47
46 { 48 _devicesUpdated() {
47 if (this._muteUpdate) 49 if (this._muteUpdate)
48 return; 50 return;
49 51
50 this._list.clear(); 52 this._list.clear();
51 53
52 var devices = this._emulatedDevicesList.custom().slice(); 54 var devices = this._emulatedDevicesList.custom().slice();
53 for (var i = 0; i < devices.length; ++i) 55 for (var i = 0; i < devices.length; ++i)
54 this._list.appendItem(devices[i], true); 56 this._list.appendItem(devices[i], true);
55 57
56 this._list.appendSeparator(); 58 this._list.appendSeparator();
57 59
58 devices = this._emulatedDevicesList.standard().slice(); 60 devices = this._emulatedDevicesList.standard().slice();
59 devices.sort(WebInspector.EmulatedDevice.deviceComparator); 61 devices.sort(WebInspector.EmulatedDevice.deviceComparator);
60 for (var i = 0; i < devices.length; ++i) 62 for (var i = 0; i < devices.length; ++i)
61 this._list.appendItem(devices[i], false); 63 this._list.appendItem(devices[i], false);
62 }, 64 }
63 65
64 /** 66 /**
65 * @param {boolean} custom 67 * @param {boolean} custom
66 */ 68 */
67 _muteAndSaveDeviceList: function(custom) 69 _muteAndSaveDeviceList(custom) {
68 { 70 this._muteUpdate = true;
69 this._muteUpdate = true; 71 if (custom)
70 if (custom) 72 this._emulatedDevicesList.saveCustomDevices();
71 this._emulatedDevicesList.saveCustomDevices(); 73 else
72 else 74 this._emulatedDevicesList.saveStandardDevices();
73 this._emulatedDevicesList.saveStandardDevices(); 75 this._muteUpdate = false;
74 this._muteUpdate = false; 76 }
75 }, 77
76 78 _addCustomDevice() {
77 _addCustomDevice: function() 79 var device = new WebInspector.EmulatedDevice();
78 { 80 device.deviceScaleFactor = 0;
79 var device = new WebInspector.EmulatedDevice(); 81 device.horizontal.width = 700;
80 device.deviceScaleFactor = 0; 82 device.horizontal.height = 400;
81 device.horizontal.width = 700; 83 device.vertical.width = 400;
82 device.horizontal.height = 400; 84 device.vertical.height = 700;
83 device.vertical.width = 400; 85 this._list.addNewItem(this._emulatedDevicesList.custom().length, device);
84 device.vertical.height = 700; 86 }
85 this._list.addNewItem(this._emulatedDevicesList.custom().length, device) ; 87
86 }, 88 /**
87 89 * @param {number} value
88 /** 90 * @return {string}
89 * @param {number} value 91 */
90 * @return {string} 92 _toNumericInputValue(value) {
91 */ 93 return value ? String(value) : '';
92 _toNumericInputValue: function(value) 94 }
93 { 95
94 return value ? String(value) : ""; 96 /**
95 }, 97 * @override
96 98 * @param {*} item
97 /** 99 * @param {boolean} editable
98 * @override 100 * @return {!Element}
99 * @param {*} item 101 */
100 * @param {boolean} editable 102 renderItem(item, editable) {
101 * @return {!Element} 103 var device = /** @type {!WebInspector.EmulatedDevice} */ (item);
102 */ 104 var element = createElementWithClass('div', 'devices-list-item');
103 renderItem: function(item, editable) 105 var checkbox = element.createChild('input', 'devices-list-checkbox');
104 { 106 checkbox.type = 'checkbox';
105 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); 107 checkbox.checked = device.show();
106 var element = createElementWithClass("div", "devices-list-item"); 108 element.createChild('div', 'devices-list-title').textContent = device.title;
107 var checkbox = element.createChild("input", "devices-list-checkbox"); 109 element.addEventListener('click', onItemClicked.bind(this), false);
108 checkbox.type = "checkbox"; 110 return element;
109 checkbox.checked = device.show(); 111
110 element.createChild("div", "devices-list-title").textContent = device.ti tle; 112 /**
111 element.addEventListener("click", onItemClicked.bind(this), false); 113 * @param {!Event} event
112 return element; 114 * @this {WebInspector.DevicesSettingsTab}
113 115 */
114 /** 116 function onItemClicked(event) {
115 * @param {!Event} event 117 var show = !checkbox.checked;
116 * @this {WebInspector.DevicesSettingsTab} 118 device.setShow(show);
117 */ 119 this._muteAndSaveDeviceList(editable);
118 function onItemClicked(event) 120 checkbox.checked = show;
119 { 121 event.consume();
120 var show = !checkbox.checked; 122 }
121 device.setShow(show); 123 }
122 this._muteAndSaveDeviceList(editable); 124
123 checkbox.checked = show; 125 /**
124 event.consume(); 126 * @override
125 } 127 * @param {*} item
126 }, 128 * @param {number} index
127 129 */
128 /** 130 removeItemRequested(item, index) {
129 * @override 131 this._emulatedDevicesList.removeCustomDevice(/** @type {!WebInspector.Emulat edDevice} */ (item));
132 }
133
134 /**
135 * @override
136 * @param {*} item
137 * @param {!WebInspector.ListWidget.Editor} editor
138 * @param {boolean} isNew
139 */
140 commitEdit(item, editor, isNew) {
141 var device = /** @type {!WebInspector.EmulatedDevice} */ (item);
142 device.title = editor.control('title').value.trim();
143 device.vertical.width = editor.control('width').value ? parseInt(editor.cont rol('width').value, 10) : 0;
144 device.vertical.height = editor.control('height').value ? parseInt(editor.co ntrol('height').value, 10) : 0;
145 device.horizontal.width = device.vertical.height;
146 device.horizontal.height = device.vertical.width;
147 device.deviceScaleFactor = editor.control('scale').value ? parseFloat(editor .control('scale').value) : 0;
148 device.userAgent = editor.control('user-agent').value;
149 device.modes = [];
150 device.modes.push(
151 {title: '', orientation: WebInspector.EmulatedDevice.Vertical, insets: n ew Insets(0, 0, 0, 0), image: null});
152 device.modes.push(
153 {title: '', orientation: WebInspector.EmulatedDevice.Horizontal, insets: new Insets(0, 0, 0, 0), image: null});
154 device.capabilities = [];
155 var uaType = editor.control('ua-type').value;
156 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebInspe ctor.DeviceModeModel.UA.MobileNoTouch)
157 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobile);
158 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebInspe ctor.DeviceModeModel.UA.DesktopTouch)
159 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Touch);
160 if (isNew)
161 this._emulatedDevicesList.addCustomDevice(device);
162 else
163 this._emulatedDevicesList.saveCustomDevices();
164 this._addCustomButton.scrollIntoViewIfNeeded();
165 this._addCustomButton.focus();
166 }
167
168 /**
169 * @override
170 * @param {*} item
171 * @return {!WebInspector.ListWidget.Editor}
172 */
173 beginEdit(item) {
174 var device = /** @type {!WebInspector.EmulatedDevice} */ (item);
175 var editor = this._createEditor();
176 editor.control('title').value = device.title;
177 editor.control('width').value = this._toNumericInputValue(device.vertical.wi dth);
178 editor.control('height').value = this._toNumericInputValue(device.vertical.h eight);
179 editor.control('scale').value = this._toNumericInputValue(device.deviceScale Factor);
180 editor.control('user-agent').value = device.userAgent;
181 var uaType;
182 if (device.mobile())
183 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : WebInsp ector.DeviceModeModel.UA.MobileNoTouch;
184 else
185 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTouch : W ebInspector.DeviceModeModel.UA.Desktop;
186 editor.control('ua-type').value = uaType;
187 return editor;
188 }
189
190 /**
191 * @return {!WebInspector.ListWidget.Editor}
192 */
193 _createEditor() {
194 if (this._editor)
195 return this._editor;
196
197 var editor = new WebInspector.ListWidget.Editor();
198 this._editor = editor;
199 var content = editor.contentElement();
200
201 var fields = content.createChild('div', 'devices-edit-fields');
202 fields.createChild('div', 'hbox')
203 .appendChild(editor.createInput('title', 'text', WebInspector.UIString(' Device name'), titleValidator));
204 var screen = fields.createChild('div', 'hbox');
205 screen.appendChild(editor.createInput('width', 'text', WebInspector.UIString ('Width'), sizeValidator));
206 screen.appendChild(editor.createInput('height', 'text', WebInspector.UIStrin g('height'), sizeValidator));
207 var dpr = editor.createInput('scale', 'text', WebInspector.UIString('Device pixel ratio'), scaleValidator);
208 dpr.classList.add('device-edit-fixed');
209 screen.appendChild(dpr);
210 var ua = fields.createChild('div', 'hbox');
211 ua.appendChild(editor.createInput('user-agent', 'text', WebInspector.UIStrin g('User agent string'), () => true));
212 var uaType = editor.createSelect(
213 'ua-type',
214 [
215 WebInspector.DeviceModeModel.UA.Mobile, WebInspector.DeviceModeModel.U A.MobileNoTouch,
216 WebInspector.DeviceModeModel.UA.Desktop, WebInspector.DeviceModeModel. UA.DesktopTouch
217 ],
218 () => true);
219 uaType.classList.add('device-edit-fixed');
220 ua.appendChild(uaType);
221
222 return editor;
223
224 /**
130 * @param {*} item 225 * @param {*} item
131 * @param {number} index 226 * @param {number} index
132 */ 227 * @param {!HTMLInputElement|!HTMLSelectElement} input
133 removeItemRequested: function(item, index) 228 * @return {boolean}
134 { 229 */
135 this._emulatedDevicesList.removeCustomDevice(/** @type {!WebInspector.Em ulatedDevice} */ (item)); 230 function titleValidator(item, index, input) {
136 }, 231 var value = input.value.trim();
137 232 return value.length > 0 && value.length < 50;
138 /** 233 }
139 * @override 234
235 /**
140 * @param {*} item 236 * @param {*} item
141 * @param {!WebInspector.ListWidget.Editor} editor 237 * @param {number} index
142 * @param {boolean} isNew 238 * @param {!HTMLInputElement|!HTMLSelectElement} input
143 */ 239 * @return {boolean}
144 commitEdit: function(item, editor, isNew) 240 */
145 { 241 function sizeValidator(item, index, input) {
146 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); 242 return WebInspector.DeviceModeModel.deviceSizeValidator(input.value);
147 device.title = editor.control("title").value.trim(); 243 }
148 device.vertical.width = editor.control("width").value ? parseInt(editor. control("width").value, 10) : 0; 244
149 device.vertical.height = editor.control("height").value ? parseInt(edito r.control("height").value, 10) : 0; 245 /**
150 device.horizontal.width = device.vertical.height;
151 device.horizontal.height = device.vertical.width;
152 device.deviceScaleFactor = editor.control("scale").value ? parseFloat(ed itor.control("scale").value) : 0;
153 device.userAgent = editor.control("user-agent").value;
154 device.modes = [];
155 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.V ertical, insets: new Insets(0, 0, 0, 0), image: null});
156 device.modes.push({title: "", orientation: WebInspector.EmulatedDevice.H orizontal, insets: new Insets(0, 0, 0, 0), image: null});
157 device.capabilities = [];
158 var uaType = editor.control("ua-type").value;
159 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.MobileNoTouch)
160 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Mobi le);
161 if (uaType === WebInspector.DeviceModeModel.UA.Mobile || uaType === WebI nspector.DeviceModeModel.UA.DesktopTouch)
162 device.capabilities.push(WebInspector.EmulatedDevice.Capability.Touc h);
163 if (isNew)
164 this._emulatedDevicesList.addCustomDevice(device);
165 else
166 this._emulatedDevicesList.saveCustomDevices();
167 this._addCustomButton.scrollIntoViewIfNeeded();
168 this._addCustomButton.focus();
169 },
170
171 /**
172 * @override
173 * @param {*} item 246 * @param {*} item
174 * @return {!WebInspector.ListWidget.Editor} 247 * @param {number} index
175 */ 248 * @param {!HTMLInputElement|!HTMLSelectElement} input
176 beginEdit: function(item) 249 * @return {boolean}
177 { 250 */
178 var device = /** @type {!WebInspector.EmulatedDevice} */ (item); 251 function scaleValidator(item, index, input) {
179 var editor = this._createEditor(); 252 return WebInspector.DeviceModeModel.deviceScaleFactorValidator(input.value );
180 editor.control("title").value = device.title; 253 }
181 editor.control("width").value = this._toNumericInputValue(device.vertica l.width); 254 }
182 editor.control("height").value = this._toNumericInputValue(device.vertic al.height);
183 editor.control("scale").value = this._toNumericInputValue(device.deviceS caleFactor);
184 editor.control("user-agent").value = device.userAgent;
185 var uaType;
186 if (device.mobile())
187 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.Mobile : W ebInspector.DeviceModeModel.UA.MobileNoTouch;
188 else
189 uaType = device.touch() ? WebInspector.DeviceModeModel.UA.DesktopTou ch : WebInspector.DeviceModeModel.UA.Desktop;
190 editor.control("ua-type").value = uaType;
191 return editor;
192 },
193
194 /**
195 * @return {!WebInspector.ListWidget.Editor}
196 */
197 _createEditor: function()
198 {
199 if (this._editor)
200 return this._editor;
201
202 var editor = new WebInspector.ListWidget.Editor();
203 this._editor = editor;
204 var content = editor.contentElement();
205
206 var fields = content.createChild("div", "devices-edit-fields");
207 fields.createChild("div", "hbox").appendChild(editor.createInput("title" , "text", WebInspector.UIString("Device name"), titleValidator));
208 var screen = fields.createChild("div", "hbox");
209 screen.appendChild(editor.createInput("width", "text", WebInspector.UISt ring("Width"), sizeValidator));
210 screen.appendChild(editor.createInput("height", "text", WebInspector.UIS tring("height"), sizeValidator));
211 var dpr = editor.createInput("scale", "text", WebInspector.UIString("Dev ice pixel ratio"), scaleValidator);
212 dpr.classList.add("device-edit-fixed");
213 screen.appendChild(dpr);
214 var ua = fields.createChild("div", "hbox");
215 ua.appendChild(editor.createInput("user-agent", "text", WebInspector.UIS tring("User agent string"), () => true));
216 var uaType = editor.createSelect("ua-type", [WebInspector.DeviceModeMode l.UA.Mobile, WebInspector.DeviceModeModel.UA.MobileNoTouch, WebInspector.DeviceM odeModel.UA.Desktop, WebInspector.DeviceModeModel.UA.DesktopTouch], () => true);
217 uaType.classList.add("device-edit-fixed");
218 ua.appendChild(uaType);
219
220 return editor;
221
222 /**
223 * @param {*} item
224 * @param {number} index
225 * @param {!HTMLInputElement|!HTMLSelectElement} input
226 * @return {boolean}
227 */
228 function titleValidator(item, index, input)
229 {
230 var value = input.value.trim();
231 return value.length > 0 && value.length < 50;
232 }
233
234 /**
235 * @param {*} item
236 * @param {number} index
237 * @param {!HTMLInputElement|!HTMLSelectElement} input
238 * @return {boolean}
239 */
240 function sizeValidator(item, index, input)
241 {
242 return WebInspector.DeviceModeModel.deviceSizeValidator(input.value) ;
243 }
244
245 /**
246 * @param {*} item
247 * @param {number} index
248 * @param {!HTMLInputElement|!HTMLSelectElement} input
249 * @return {boolean}
250 */
251 function scaleValidator(item, index, input)
252 {
253 return WebInspector.DeviceModeModel.deviceScaleFactorValidator(input .value);
254 }
255 },
256
257 __proto__: WebInspector.VBox.prototype
258 }; 255 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698