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

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

Issue 2938503002: DevTools: unify Network & CPU throttling (Closed)
Patch Set: update test Created 3 years, 5 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);
26 this._showNetworkConditionsSetting.addChangeListener(this._updateNetworkCond itionsVisibility, this);
27
28 /** @type {!Map<!Emulation.EmulatedDevice, !Emulation.EmulatedDevice.Mode>} */ 25 /** @type {!Map<!Emulation.EmulatedDevice, !Emulation.EmulatedDevice.Mode>} */
29 this._lastMode = new Map(); 26 this._lastMode = new Map();
30 27
31 /** @type {!Map<!Emulation.EmulatedDevice, number>} */ 28 /** @type {!Map<!Emulation.EmulatedDevice, number>} */
32 this._lastScale = new Map(); 29 this._lastScale = new Map();
33 30
34 this._element = createElementWithClass('div', 'device-mode-toolbar'); 31 this._element = createElementWithClass('div', 'device-mode-toolbar');
35 32
36 var leftContainer = this._element.createChild('div', 'device-mode-toolbar-sp acer'); 33 var leftContainer = this._element.createChild('div', 'device-mode-toolbar-sp acer');
37 leftContainer.createChild('div', 'device-mode-toolbar-spacer'); 34 leftContainer.createChild('div', 'device-mode-toolbar-spacer');
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 toolbar.appendToolbarItem(this._deviceScaleItem); 159 toolbar.appendToolbarItem(this._deviceScaleItem);
163 160
164 toolbar.appendToolbarItem( 161 toolbar.appendToolbarItem(
165 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element'))); 162 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element')));
166 this._uaItem = new UI.ToolbarMenuButton(this._appendUserAgentMenuItems.bind( this)); 163 this._uaItem = new UI.ToolbarMenuButton(this._appendUserAgentMenuItems.bind( this));
167 this._uaItem.setVisible(this._showUserAgentTypeSetting.get()); 164 this._uaItem.setVisible(this._showUserAgentTypeSetting.get());
168 this._uaItem.setTitle(Common.UIString('Device type')); 165 this._uaItem.setTitle(Common.UIString('Device type'));
169 this._uaItem.setGlyph(''); 166 this._uaItem.setGlyph('');
170 this._uaItem.turnIntoSelect(); 167 this._uaItem.turnIntoSelect();
171 toolbar.appendToolbarItem(this._uaItem); 168 toolbar.appendToolbarItem(this._uaItem);
169
170 this._throttlingConditionsItem = MobileThrottling.throttlingManager().create MobileThrottlingButton();
171 toolbar.appendToolbarItem(this._throttlingConditionsItem);
172 } 172 }
173 173
174 /** 174 /**
175 * @param {!UI.Toolbar} toolbar 175 * @param {!UI.Toolbar} toolbar
176 */ 176 */
177 _fillModeToolbar(toolbar) { 177 _fillModeToolbar(toolbar) {
178 toolbar.appendToolbarItem( 178 toolbar.appendToolbarItem(
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();
190 this._networkConditionsItem.setVisible(this._showNetworkConditionsSetting.ge t());
191 this._networkConditionsItem.setTitle(Common.UIString('Network throttling'));
192 this._networkConditionsItem.element.style.maxWidth = '140px';
193 toolbar.appendToolbarItem(this._networkConditionsItem);
194
195 var moreOptionsButton = new UI.ToolbarMenuButton(this._appendOptionsMenuItem s.bind(this)); 189 var moreOptionsButton = new UI.ToolbarMenuButton(this._appendOptionsMenuItem s.bind(this));
196 moreOptionsButton.setTitle(Common.UIString('More options')); 190 moreOptionsButton.setTitle(Common.UIString('More options'));
197 toolbar.appendToolbarItem(moreOptionsButton); 191 toolbar.appendToolbarItem(moreOptionsButton);
198 192
199 toolbar.appendToolbarItem( 193 toolbar.appendToolbarItem(
200 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element'))); 194 this._wrapToolbarItem(createElementWithClass('div', 'device-mode-empty-t oolbar-element')));
201 } 195 }
202 196
203 /** 197 /**
204 * @param {!UI.ContextMenu} contextMenu 198 * @param {!UI.ContextMenu} contextMenu
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 model.type() !== Emulation.DeviceModeModel.Type.Device); 287 model.type() !== Emulation.DeviceModeModel.Type.Device);
294 appendToggleItem( 288 appendToggleItem(
295 this._showMediaInspectorSetting, Common.UIString('Hide media queries'), Common.UIString('Show media queries')); 289 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')); 290 appendToggleItem(this._showRulersSetting, Common.UIString('Hide rulers'), Co mmon.UIString('Show rulers'));
297 contextMenu.appendSeparator(); 291 contextMenu.appendSeparator();
298 appendToggleItem( 292 appendToggleItem(
299 this._showDeviceScaleFactorSetting, Common.UIString('Remove device pixel ratio'), 293 this._showDeviceScaleFactorSetting, Common.UIString('Remove device pixel ratio'),
300 Common.UIString('Add device pixel ratio')); 294 Common.UIString('Add device pixel ratio'));
301 appendToggleItem( 295 appendToggleItem(
302 this._showUserAgentTypeSetting, Common.UIString('Remove device type'), C ommon.UIString('Add device type')); 296 this._showUserAgentTypeSetting, Common.UIString('Remove device type'), C ommon.UIString('Add device type'));
303 appendToggleItem(
304 this._showNetworkConditionsSetting, Common.UIString('Remove network thro ttling'),
305 Common.UIString('Add network throttling'));
306 contextMenu.appendSeparator(); 297 contextMenu.appendSeparator();
307 contextMenu.appendItemsAtLocation('deviceModeMenu'); 298 contextMenu.appendItemsAtLocation('deviceModeMenu');
308 contextMenu.appendSeparator(); 299 contextMenu.appendSeparator();
309 contextMenu.appendItem(Common.UIString('Reset to defaults'), this._reset.bin d(this)); 300 contextMenu.appendItem(Common.UIString('Reset to defaults'), this._reset.bin d(this));
310 301
311 /** 302 /**
312 * @param {!Common.Setting} setting 303 * @param {!Common.Setting} setting
313 * @param {string} title1 304 * @param {string} title1
314 * @param {string} title2 305 * @param {string} title2
315 * @param {boolean=} disabled 306 * @param {boolean=} disabled
316 */ 307 */
317 function appendToggleItem(setting, title1, title2, disabled) { 308 function appendToggleItem(setting, title1, title2, disabled) {
318 if (typeof disabled === 'undefined') 309 if (typeof disabled === 'undefined')
319 disabled = model.type() === Emulation.DeviceModeModel.Type.None; 310 disabled = model.type() === Emulation.DeviceModeModel.Type.None;
320 contextMenu.appendItem(setting.get() ? title1 : title2, setting.set.bind(s etting, !setting.get()), disabled); 311 contextMenu.appendItem(setting.get() ? title1 : title2, setting.set.bind(s etting, !setting.get()), disabled);
321 } 312 }
322 } 313 }
323 314
324 _reset() { 315 _reset() {
325 this._deviceOutlineSetting.set(false); 316 this._deviceOutlineSetting.set(false);
326 this._showDeviceScaleFactorSetting.set(false); 317 this._showDeviceScaleFactorSetting.set(false);
327 this._showUserAgentTypeSetting.set(false); 318 this._showUserAgentTypeSetting.set(false);
328 this._showMediaInspectorSetting.set(false); 319 this._showMediaInspectorSetting.set(false);
329 this._showRulersSetting.set(false); 320 this._showRulersSetting.set(false);
330 this._showNetworkConditionsSetting.set(false);
331 this._model.reset(); 321 this._model.reset();
332 } 322 }
333 323
334 /** 324 /**
335 * @param {!Element} element 325 * @param {!Element} element
336 * @return {!UI.ToolbarItem} 326 * @return {!UI.ToolbarItem}
337 */ 327 */
338 _wrapToolbarItem(element) { 328 _wrapToolbarItem(element) {
339 var container = createElement('div'); 329 var container = createElement('div');
340 var shadowRoot = UI.createShadowRootWithCoreStyles(container, 'emulation/dev iceModeToolbar.css'); 330 var shadowRoot = UI.createShadowRootWithCoreStyles(container, 'emulation/dev iceModeToolbar.css');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 425 }
436 426
437 _updateDeviceScaleFactorVisibility() { 427 _updateDeviceScaleFactorVisibility() {
438 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get()); 428 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get());
439 } 429 }
440 430
441 _updateUserAgentTypeVisibility() { 431 _updateUserAgentTypeVisibility() {
442 this._uaItem.setVisible(this._showUserAgentTypeSetting.get()); 432 this._uaItem.setVisible(this._showUserAgentTypeSetting.get());
443 } 433 }
444 434
445 _updateNetworkConditionsVisibility() {
446 this._networkConditionsItem.setVisible(this._showNetworkConditionsSetting.ge t());
447 }
448
449 /** 435 /**
450 * @param {!Common.Event} event 436 * @param {!Common.Event} event
451 */ 437 */
452 _modeMenuClicked(event) { 438 _modeMenuClicked(event) {
453 var device = this._model.device(); 439 var device = this._model.device();
454 var model = this._model; 440 var model = this._model;
455 441
456 if (device.modes.length === 2 && device.modes[0].orientation !== device.mode s[1].orientation) { 442 if (device.modes.length === 2 && device.modes[0].orientation !== device.mode s[1].orientation) {
457 model.emulate(model.type(), model.device(), model.mode() === device.modes[ 0] ? device.modes[1] : device.modes[0]); 443 model.emulate(model.type(), model.device(), model.mode() === device.modes[ 0] ? device.modes[1] : device.modes[0]);
458 return; 444 return;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 this._emulateDevice(device); 574 this._emulateDevice(device);
589 return; 575 return;
590 } 576 }
591 } 577 }
592 } 578 }
593 } 579 }
594 580
595 this._model.emulate(Emulation.DeviceModeModel.Type.Responsive, null, null); 581 this._model.emulate(Emulation.DeviceModeModel.Type.Responsive, null, null);
596 } 582 }
597 }; 583 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698