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

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

Issue 1718213003: [DevTools] Add "show throttling" to device mode instead of "configure network". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 /** 5 /**
6 * @param {!WebInspector.DeviceModeModel} model 6 * @param {!WebInspector.DeviceModeModel} model
7 * @param {!WebInspector.Setting} showMediaInspectorSetting 7 * @param {!WebInspector.Setting} showMediaInspectorSetting
8 * @param {!WebInspector.Setting} showRulersSetting 8 * @param {!WebInspector.Setting} showRulersSetting
9 * @constructor 9 * @constructor
10 */ 10 */
11 WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show RulersSetting) 11 WebInspector.DeviceModeToolbar = function(model, showMediaInspectorSetting, show RulersSetting)
12 { 12 {
13 this._model = model; 13 this._model = model;
14 this._showMediaInspectorSetting = showMediaInspectorSetting; 14 this._showMediaInspectorSetting = showMediaInspectorSetting;
15 this._showRulersSetting = showRulersSetting; 15 this._showRulersSetting = showRulersSetting;
16 16
17 this._showDeviceScaleFactorSetting = WebInspector.settings.createSetting("em ulation.showDeviceScaleFactor", false); 17 this._showDeviceScaleFactorSetting = WebInspector.settings.createSetting("em ulation.showDeviceScaleFactor", false);
18 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this); 18 this._showDeviceScaleFactorSetting.addChangeListener(this._updateDeviceScale FactorVisibility, this);
19 19
20 this._showUserAgentTypeSetting = WebInspector.settings.createSetting("emulat ion.showUserAgentType", false); 20 this._showUserAgentTypeSetting = WebInspector.settings.createSetting("emulat ion.showUserAgentType", false);
21 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this); 21 this._showUserAgentTypeSetting.addChangeListener(this._updateUserAgentTypeVi sibility, this);
22 22
23 this._showNetworkConditionsSetting = WebInspector.settings.createSetting("em ulation.showNetworkConditions", false);
24 this._showNetworkConditionsSetting.addChangeListener(this._updateNetworkCond itionsVisibility, this);
25
23 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */ 26 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M ode>} */
24 this._lastMode = new Map(); 27 this._lastMode = new Map();
25 28
26 this._element = createElementWithClass("div", "device-mode-toolbar"); 29 this._element = createElementWithClass("div", "device-mode-toolbar");
27 30
28 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp acer"); 31 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp acer");
29 leftContainer.createChild("div", "device-mode-toolbar-spacer"); 32 leftContainer.createChild("div", "device-mode-toolbar-spacer");
30 var leftToolbar = new WebInspector.Toolbar("", leftContainer); 33 var leftToolbar = new WebInspector.Toolbar("", leftContainer);
31 leftToolbar.makeWrappable(); 34 leftToolbar.makeWrappable();
32 this._fillLeftToolbar(leftToolbar); 35 this._fillLeftToolbar(leftToolbar);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 * @param {!WebInspector.Toolbar} toolbar 132 * @param {!WebInspector.Toolbar} toolbar
130 */ 133 */
131 _fillRightToolbar: function(toolbar) 134 _fillRightToolbar: function(toolbar)
132 { 135 {
133 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); 136 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element")));
134 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe nuItems.bind(this)); 137 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe nuItems.bind(this));
135 this._scaleItem.setTitle(WebInspector.UIString("Zoom")); 138 this._scaleItem.setTitle(WebInspector.UIString("Zoom"));
136 this._scaleItem.setGlyph(""); 139 this._scaleItem.setGlyph("");
137 this._scaleItem.turnIntoSelect(); 140 this._scaleItem.turnIntoSelect();
138 toolbar.appendToolbarItem(this._scaleItem); 141 toolbar.appendToolbarItem(this._scaleItem);
139 },
140 142
141 /**
142 * @param {!WebInspector.Toolbar} toolbar
143 */
144 _fillModeToolbar: function(toolbar)
145 {
146 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); 143 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element")));
147 this._deviceScaleItem = new WebInspector.ToolbarMenuButton(this._appendD eviceScaleMenuItems.bind(this)); 144 this._deviceScaleItem = new WebInspector.ToolbarMenuButton(this._appendD eviceScaleMenuItems.bind(this));
148 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get( )); 145 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get( ));
149 this._deviceScaleItem.setTitle(WebInspector.UIString("Device pixel ratio ")); 146 this._deviceScaleItem.setTitle(WebInspector.UIString("Device pixel ratio "));
150 this._deviceScaleItem.setGlyph(""); 147 this._deviceScaleItem.setGlyph("");
151 this._deviceScaleItem.turnIntoSelect(); 148 this._deviceScaleItem.turnIntoSelect();
152 this._deviceScaleItem.element.style.padding = "0 5px"; 149 this._deviceScaleItem.element.style.padding = "0 5px";
153 toolbar.appendToolbarItem(this._deviceScaleItem); 150 toolbar.appendToolbarItem(this._deviceScaleItem);
154 151
155 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); 152 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element")));
156 this._uaItem = new WebInspector.ToolbarMenuButton(this._appendUserAgentM enuItems.bind(this)); 153 this._uaItem = new WebInspector.ToolbarMenuButton(this._appendUserAgentM enuItems.bind(this));
157 this._uaItem.setVisible(this._showUserAgentTypeSetting.get()); 154 this._uaItem.setVisible(this._showUserAgentTypeSetting.get());
158 this._uaItem.setTitle(WebInspector.UIString("Device type")); 155 this._uaItem.setTitle(WebInspector.UIString("Device type"));
159 this._uaItem.setGlyph(""); 156 this._uaItem.setGlyph("");
160 this._uaItem.turnIntoSelect(); 157 this._uaItem.turnIntoSelect();
161 this._uaItem.element.style.padding = "0 5px"; 158 this._uaItem.element.style.padding = "0 5px";
162 toolbar.appendToolbarItem(this._uaItem); 159 toolbar.appendToolbarItem(this._uaItem);
160 },
163 161
162 /**
163 * @param {!WebInspector.Toolbar} toolbar
164 */
165 _fillModeToolbar: function(toolbar)
166 {
164 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); 167 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element")));
165 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too lbar-item"); 168 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too lbar-item");
166 this._modeButton.addEventListener("click", this._modeMenuClicked, this); 169 this._modeButton.addEventListener("click", this._modeMenuClicked, this);
167 toolbar.appendToolbarItem(this._modeButton); 170 toolbar.appendToolbarItem(this._modeButton);
168 }, 171 },
169 172
170 /** 173 /**
171 * @param {!WebInspector.Toolbar} toolbar 174 * @param {!WebInspector.Toolbar} toolbar
172 */ 175 */
173 _fillOptionsToolbar: function(toolbar) 176 _fillOptionsToolbar: function(toolbar)
174 { 177 {
178 this._networkConditionsItem = WebInspector.NetworkConditionsSelector.cre ateToolbarMenuButton();
179 this._networkConditionsItem.setVisible(this._showNetworkConditionsSettin g.get());
180 this._networkConditionsItem.setTitle(WebInspector.UIString("Network thro ttling"));
181 this._networkConditionsItem.element.style.padding = "0 5px";
182 this._networkConditionsItem.element.style.maxWidth = "140px";
183 toolbar.appendToolbarItem(this._networkConditionsItem);
184
175 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO ptionsMenuItems.bind(this)); 185 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO ptionsMenuItems.bind(this));
176 moreOptionsButton.setTitle(WebInspector.UIString("More options")); 186 moreOptionsButton.setTitle(WebInspector.UIString("More options"));
177 toolbar.appendToolbarItem(moreOptionsButton); 187 toolbar.appendToolbarItem(moreOptionsButton);
178 188
179 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element"))); 189 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass(" div", "device-mode-empty-toolbar-element")));
180 }, 190 },
181 191
182 192
183 /** 193 /**
184 * @param {!WebInspector.ContextMenu} contextMenu 194 * @param {!WebInspector.ContextMenu} contextMenu
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 260 }
251 }, 261 },
252 262
253 /** 263 /**
254 * @param {!WebInspector.ContextMenu} contextMenu 264 * @param {!WebInspector.ContextMenu} contextMenu
255 */ 265 */
256 _appendOptionsMenuItems: function(contextMenu) 266 _appendOptionsMenuItems: function(contextMenu)
257 { 267 {
258 contextMenu.appendCheckboxItem(WebInspector.UIString("Show device pixel ratio"), this._toggleDeviceScaleFactor.bind(this), this._showDeviceScaleFactorSe tting.get(), this._model.type() === WebInspector.DeviceModeModel.Type.None); 268 contextMenu.appendCheckboxItem(WebInspector.UIString("Show device pixel ratio"), this._toggleDeviceScaleFactor.bind(this), this._showDeviceScaleFactorSe tting.get(), this._model.type() === WebInspector.DeviceModeModel.Type.None);
259 contextMenu.appendCheckboxItem(WebInspector.UIString("Show device type") , this._toggleUserAgentType.bind(this), this._showUserAgentTypeSetting.get(), th is._model.type() === WebInspector.DeviceModeModel.Type.None); 269 contextMenu.appendCheckboxItem(WebInspector.UIString("Show device type") , this._toggleUserAgentType.bind(this), this._showUserAgentTypeSetting.get(), th is._model.type() === WebInspector.DeviceModeModel.Type.None);
270 contextMenu.appendCheckboxItem(WebInspector.UIString("Show throttling"), this._toggleNetworkConditions.bind(this), this._showNetworkConditionsSetting.ge t(), this._model.type() === WebInspector.DeviceModeModel.Type.None);
260 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries "), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get() , this._model.type() === WebInspector.DeviceModeModel.Type.None); 271 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries "), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get() , this._model.type() === WebInspector.DeviceModeModel.Type.None);
261 contextMenu.appendCheckboxItem(WebInspector.UIString("Show rulers"), thi s._toggleRulers.bind(this), this._showRulersSetting.get(), this._model.type() == = WebInspector.DeviceModeModel.Type.None); 272 contextMenu.appendCheckboxItem(WebInspector.UIString("Show rulers"), thi s._toggleRulers.bind(this), this._showRulersSetting.get(), this._model.type() == = WebInspector.DeviceModeModel.Type.None);
262 contextMenu.appendSeparator(); 273 contextMenu.appendSeparator();
263 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"), this._openNetworkConfig.bind(this), false);
264 contextMenu.appendItemsAtLocation("deviceModeMenu"); 274 contextMenu.appendItemsAtLocation("deviceModeMenu");
265 contextMenu.appendSeparator(); 275 contextMenu.appendSeparator();
266 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this. _reset.bind(this)); 276 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this. _reset.bind(this));
267 }, 277 },
268 278
269 _toggleDeviceScaleFactor: function() 279 _toggleDeviceScaleFactor: function()
270 { 280 {
271 this._showDeviceScaleFactorSetting.set(!this._showDeviceScaleFactorSetti ng.get()); 281 this._showDeviceScaleFactorSetting.set(!this._showDeviceScaleFactorSetti ng.get());
272 }, 282 },
273 283
274 _toggleUserAgentType: function() 284 _toggleUserAgentType: function()
275 { 285 {
276 this._showUserAgentTypeSetting.set(!this._showUserAgentTypeSetting.get() ); 286 this._showUserAgentTypeSetting.set(!this._showUserAgentTypeSetting.get() );
277 }, 287 },
278 288
279 _toggleMediaInspector: function() 289 _toggleMediaInspector: function()
280 { 290 {
281 this._showMediaInspectorSetting.set(!this._showMediaInspectorSetting.get ()); 291 this._showMediaInspectorSetting.set(!this._showMediaInspectorSetting.get ());
282 }, 292 },
283 293
284 _toggleRulers: function() 294 _toggleRulers: function()
285 { 295 {
286 this._showRulersSetting.set(!this._showRulersSetting.get()); 296 this._showRulersSetting.set(!this._showRulersSetting.get());
287 }, 297 },
288 298
289 _openNetworkConfig: function() 299 _toggleNetworkConditions: function()
290 { 300 {
291 InspectorFrontendHost.bringToFront(); 301 this._showNetworkConditionsSetting.set(!this._showNetworkConditionsSetti ng.get());
292 // TODO(dgozman): make it explicit.
293 WebInspector.actionRegistry.action("network.show-config").execute();
294 }, 302 },
295 303
296 _reset: function() 304 _reset: function()
297 { 305 {
298 this._showDeviceScaleFactorSetting.set(false); 306 this._showDeviceScaleFactorSetting.set(false);
299 this._showUserAgentTypeSetting.set(false); 307 this._showUserAgentTypeSetting.set(false);
300 this._showMediaInspectorSetting.set(false); 308 this._showMediaInspectorSetting.set(false);
301 this._showRulersSetting.set(false); 309 this._showRulersSetting.set(false);
310 this._showNetworkConditionsSetting.set(false);
302 this._model.reset(); 311 this._model.reset();
303 }, 312 },
304 313
305 /** 314 /**
306 * @param {!Element} element 315 * @param {!Element} element
307 * @return {!WebInspector.ToolbarItem} 316 * @return {!WebInspector.ToolbarItem}
308 */ 317 */
309 _wrapToolbarItem: function(element) 318 _wrapToolbarItem: function(element)
310 { 319 {
311 var container = createElement("div"); 320 var container = createElement("div");
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 _updateDeviceScaleFactorVisibility: function() 416 _updateDeviceScaleFactorVisibility: function()
408 { 417 {
409 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get( )); 418 this._deviceScaleItem.setVisible(this._showDeviceScaleFactorSetting.get( ));
410 }, 419 },
411 420
412 _updateUserAgentTypeVisibility: function() 421 _updateUserAgentTypeVisibility: function()
413 { 422 {
414 this._uaItem.setVisible(this._showUserAgentTypeSetting.get()); 423 this._uaItem.setVisible(this._showUserAgentTypeSetting.get());
415 }, 424 },
416 425
426 _updateNetworkConditionsVisibility: function()
427 {
428 this._networkConditionsItem.setVisible(this._showNetworkConditionsSettin g.get());
429 },
430
417 /** 431 /**
418 * @param {!WebInspector.Event} event 432 * @param {!WebInspector.Event} event
419 */ 433 */
420 _modeMenuClicked: function(event) 434 _modeMenuClicked: function(event)
421 { 435 {
422 var device = this._model.device(); 436 var device = this._model.device();
423 var model = this._model; 437 var model = this._model;
424 438
425 if (device.modes.length === 2 && device.modes[0].orientation !== device. modes[1].orientation) { 439 if (device.modes.length === 2 && device.modes[0].orientation !== device. modes[1].orientation) {
426 model.emulate(model.type(), model.device(), model.mode() === device. modes[0] ? device.modes[1] : device.modes[0]); 440 model.emulate(model.type(), model.device(), model.mode() === device. modes[0] ? device.modes[1] : device.modes[0]);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 this._emulateDevice(device); 578 this._emulateDevice(device);
565 return; 579 return;
566 } 580 }
567 } 581 }
568 } 582 }
569 } 583 }
570 584
571 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null); 585 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null, null);
572 } 586 }
573 } 587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698