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

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

Issue 2938503002: DevTools: unify Network & CPU throttling (Closed)
Patch Set: fmt Created 3 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 Emulation.DeviceModeToolbar = class { 7 Emulation.DeviceModeToolbar = class {
8 /** 8 /**
9 * @param {!Emulation.DeviceModeModel} model 9 * @param {!Emulation.DeviceModeModel} model
10 * @param {!Common.Setting} showMediaInspectorSetting 10 * @param {!Common.Setting} showMediaInspectorSetting
11 * @param {!Common.Setting} showRulersSetting 11 * @param {!Common.Setting} showRulersSetting
12 */ 12 */
13 constructor(model, showMediaInspectorSetting, showRulersSetting) { 13 constructor(model, showMediaInspectorSetting, showRulersSetting) {
14 this._model = model; 14 this._model = model;
15 this._showMediaInspectorSetting = showMediaInspectorSetting; 15 this._showMediaInspectorSetting = showMediaInspectorSetting;
16 this._showRulersSetting = showRulersSetting; 16 this._showRulersSetting = showRulersSetting;
17 17
18 this._deviceOutlineSetting = this._model.deviceOutlineSetting(); 18 this._deviceOutlineSetting = this._model.deviceOutlineSetting();
19 this._showDeviceScaleFactorSetting = Common.settings.createSetting('emulatio n.showDeviceScaleFactor', false); 19 this._showDeviceScaleFactorSetting = Common.settings.createSetting('emulatio n.showDeviceScaleFactor', false);
20 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this); 20 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this);
21 21
22 this._showUserAgentTypeSetting = Common.settings.createSetting('emulation.sh owUserAgentType', false); 22 this._showUserAgentTypeSetting = Common.settings.createSetting('emulation.sh owUserAgentType', false);
23 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this); 23 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this);
24 24
25 this._showNetworkConditionsSetting = Common.settings.createSetting('emulatio n.showNetworkConditions', false); 25 this._showThrottlingConditionsSetting = Common.settings.createSetting('emula tion.showNetworkConditions', false);
26 this._showNetworkConditionsSetting.addChangeListener(this._updateNetworkCond itionsVisibility, this); 26 this._showThrottlingConditionsSetting.addChangeListener(this._updateThrottli ngVisibility, this);
27 27
28 /** @type {!Map<!Emulation.EmulatedDevice, !Emulation.EmulatedDevice.Mode>} */ 28 /** @type {!Map<!Emulation.EmulatedDevice, !Emulation.EmulatedDevice.Mode>} */
29 this._lastMode = new Map(); 29 this._lastMode = new Map();
30 30
31 /** @type {!Map<!Emulation.EmulatedDevice, number>} */ 31 /** @type {!Map<!Emulation.EmulatedDevice, number>} */
32 this._lastScale = new Map(); 32 this._lastScale = new Map();
33 33
34 this._element = createElementWithClass('div', 'device-mode-toolbar'); 34 this._element = createElementWithClass('div', 'device-mode-toolbar');
35 35
36 var leftContainer = this._element.createChild('div', 'device-mode-toolbar-sp acer'); 36 var leftContainer = this._element.createChild('div', 'device-mode-toolbar-sp acer');
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element'))); 179 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element')));
180 this._modeButton = new UI.ToolbarButton('', 'largeicon-rotate-screen'); 180 this._modeButton = new UI.ToolbarButton('', 'largeicon-rotate-screen');
181 this._modeButton.addEventListener(UI.ToolbarButton.Events.Click, this._modeM enuClicked, this); 181 this._modeButton.addEventListener(UI.ToolbarButton.Events.Click, this._modeM enuClicked, this);
182 toolbar.appendToolbarItem(this._modeButton); 182 toolbar.appendToolbarItem(this._modeButton);
183 } 183 }
184 184
185 /** 185 /**
186 * @param {!UI.Toolbar} toolbar 186 * @param {!UI.Toolbar} toolbar
187 */ 187 */
188 _fillOptionsToolbar(toolbar) { 188 _fillOptionsToolbar(toolbar) {
189 this._networkConditionsItem = MobileThrottling.NetworkConditionsSelector.cre ateToolbarMenuButton(); 189 this._throttlingConditionsItem = MobileThrottling.ThrottlingSelector.createT oolbarMenuButton();
190 this._networkConditionsItem.setVisible(this._showNetworkConditionsSetting.ge t()); 190 this._throttlingConditionsItem.setVisible(this._showThrottlingConditionsSett ing.get());
191 this._networkConditionsItem.setTitle(Common.UIString('Network throttling')); 191 this._throttlingConditionsItem.setTitle(Common.UIString('Mobile throttling') );
192 this._networkConditionsItem.element.style.maxWidth = '140px'; 192 this._throttlingConditionsItem.element.style.maxWidth = '160px';
193 toolbar.appendToolbarItem(this._networkConditionsItem); 193 toolbar.appendToolbarItem(this._throttlingConditionsItem);
194 194
195 var moreOptionsButton = new UI.ToolbarMenuButton(this._appendOptionsMenuItem s.bind(this)); 195 var moreOptionsButton = new UI.ToolbarMenuButton(this._appendOptionsMenuItem s.bind(this));
196 moreOptionsButton.setTitle(Common.UIString('More options')); 196 moreOptionsButton.setTitle(Common.UIString('More options'));
197 toolbar.appendToolbarItem(moreOptionsButton); 197 toolbar.appendToolbarItem(moreOptionsButton);
198 198
199 toolbar.appendToolbarItem( 199 toolbar.appendToolbarItem(
200 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element'))); 200 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element')));
201 } 201 }
202 202
203 /** 203 /**
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 appendToggleItem( 294 appendToggleItem(
295 this._showMediaInspectorSetting, Common.UIString('Hide media queries'), Common.UIString('Show media queries')); 295 this._showMediaInspectorSetting, Common.UIString('Hide media queries'), Common.UIString('Show media queries'));
296 appendToggleItem(this._showRulersSetting, Common.UIString('Hide rulers'), Co mmon.UIString('Show rulers')); 296 appendToggleItem(this._showRulersSetting, Common.UIString('Hide rulers'), Co mmon.UIString('Show rulers'));
297 contextMenu.appendSeparator(); 297 contextMenu.appendSeparator();
298 appendToggleItem( 298 appendToggleItem(
299 this._showDeviceScaleFactorSetting, Common.UIString('Remove device pixel ratio'), 299 this._showDeviceScaleFactorSetting, Common.UIString('Remove device pixel ratio'),
300 Common.UIString('Add device pixel ratio')); 300 Common.UIString('Add device pixel ratio'));
301 appendToggleItem( 301 appendToggleItem(
302 this._showUserAgentTypeSetting, Common.UIString('Remove device type'), C ommon.UIString('Add device type')); 302 this._showUserAgentTypeSetting, Common.UIString('Remove device type'), C ommon.UIString('Add device type'));
303 appendToggleItem( 303 appendToggleItem(
304 this._showNetworkConditionsSetting, Common.UIString('Remove network thro ttling'), 304 this._showThrottlingConditionsSetting, Common.UIString('Remove mobile th rottling'),
dgozman 2017/06/13 01:47:08 Drop 'mobile'. It's a mobile mode anyway.
chenwilliam 2017/06/13 21:54:51 Done.
305 Common.UIString('Add network throttling')); 305 Common.UIString('Add mobile throttling'));
306 contextMenu.appendSeparator(); 306 contextMenu.appendSeparator();
307 contextMenu.appendItemsAtLocation('deviceModeMenu'); 307 contextMenu.appendItemsAtLocation('deviceModeMenu');
308 contextMenu.appendSeparator(); 308 contextMenu.appendSeparator();
309 contextMenu.appendItem(Common.UIString('Reset to defaults'), this._reset.bin d(this)); 309 contextMenu.appendItem(Common.UIString('Reset to defaults'), this._reset.bin d(this));
310 310
311 /** 311 /**
312 * @param {!Common.Setting} setting 312 * @param {!Common.Setting} setting
313 * @param {string} title1 313 * @param {string} title1
314 * @param {string} title2 314 * @param {string} title2
315 * @param {boolean=} disabled 315 * @param {boolean=} disabled
316 */ 316 */
317 function appendToggleItem(setting, title1, title2, disabled) { 317 function appendToggleItem(setting, title1, title2, disabled) {
318 if (typeof disabled === 'undefined') 318 if (typeof disabled === 'undefined')
319 disabled = model.type() === Emulation.DeviceModeModel.Type.None; 319 disabled = model.type() === Emulation.DeviceModeModel.Type.None;
320 contextMenu.appendItem(setting.get() ? title1 : title2, setting.set.bind(s etting, !setting.get()), disabled); 320 contextMenu.appendItem(setting.get() ? title1 : title2, setting.set.bind(s etting, !setting.get()), disabled);
321 } 321 }
322 } 322 }
323 323
324 _reset() { 324 _reset() {
325 this._deviceOutlineSetting.set(false); 325 this._deviceOutlineSetting.set(false);
326 this._showDeviceScaleFactorSetting.set(false); 326 this._showDeviceScaleFactorSetting.set(false);
327 this._showUserAgentTypeSetting.set(false); 327 this._showUserAgentTypeSetting.set(false);
328 this._showMediaInspectorSetting.set(false); 328 this._showMediaInspectorSetting.set(false);
329 this._showRulersSetting.set(false); 329 this._showRulersSetting.set(false);
330 this._showNetworkConditionsSetting.set(false); 330 this._showThrottlingConditionsSetting.set(false);
331 this._model.reset(); 331 this._model.reset();
332 } 332 }
333 333
334 /** 334 /**
335 * @param {!Element} element 335 * @param {!Element} element
336 * @return {!UI.ToolbarItem} 336 * @return {!UI.ToolbarItem}
337 */ 337 */
338 _wrapToolbarItem(element) { 338 _wrapToolbarItem(element) {
339 var container = createElement('div'); 339 var container = createElement('div');
340 var shadowRoot = UI.createShadowRootWithCoreStyles(container, 'emulation/dev iceModeToolbar.css'); 340 var shadowRoot = UI.createShadowRootWithCoreStyles(container, 'emulation/dev iceModeToolbar.css');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 435 }
436 436
437 _updateDeviceScaleFactorVisibility() { 437 _updateDeviceScaleFactorVisibility() {
438 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get()); 438 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get());
439 } 439 }
440 440
441 _updateUserAgentTypeVisibility() { 441 _updateUserAgentTypeVisibility() {
442 this._uaItem.setVisible(this._showUserAgentTypeSetting.get()); 442 this._uaItem.setVisible(this._showUserAgentTypeSetting.get());
443 } 443 }
444 444
445 _updateNetworkConditionsVisibility() { 445 _updateThrottlingVisibility() {
446 this._networkConditionsItem.setVisible(this._showNetworkConditionsSetting.ge t()); 446 this._throttlingConditionsItem.setVisible(this._showThrottlingConditionsSett ing.get());
447 } 447 }
448 448
449 /** 449 /**
450 * @param {!Common.Event} event 450 * @param {!Common.Event} event
451 */ 451 */
452 _modeMenuClicked(event) { 452 _modeMenuClicked(event) {
453 var device = this._model.device(); 453 var device = this._model.device();
454 var model = this._model; 454 var model = this._model;
455 455
456 if (device.modes.length === 2 && device.modes[0].orientation !== device.mode s[1].orientation) { 456 if (device.modes.length === 2 && device.modes[0].orientation !== device.mode s[1].orientation) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 this._emulateDevice(device); 588 this._emulateDevice(device);
589 return; 589 return;
590 } 590 }
591 } 591 }
592 } 592 }
593 } 593 }
594 594
595 this._model.emulate(Emulation.DeviceModeModel.Type.Responsive, null, null); 595 this._model.emulate(Emulation.DeviceModeModel.Type.Responsive, null, null);
596 } 596 }
597 }; 597 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698