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

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

Issue 1460433002: [DevTools] Persist device mode state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder 8 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder
9 */ 9 */
10 WebInspector.DeviceModeView = function(inspectedPagePlaceholder) 10 WebInspector.DeviceModeView = function(inspectedPagePlaceholder)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 var rect = this._contentArea.getBoundingClientRect(); 197 var rect = this._contentArea.getBoundingClientRect();
198 this._model.availableSizeChanged(new Size(Math.max(rect.width * zoomFact or, 1), Math.max(rect.height * zoomFactor, 1))); 198 this._model.availableSizeChanged(new Size(Math.max(rect.width * zoomFact or, 1), Math.max(rect.height * zoomFactor, 1)));
199 }, 199 },
200 200
201 /** 201 /**
202 * @override 202 * @override
203 */ 203 */
204 wasShown: function() 204 wasShown: function()
205 { 205 {
206 this._mediaInspector.setEnabled(true); 206 this._mediaInspector.setEnabled(true);
207 this._toolbar.restore();
207 }, 208 },
208 209
209 /** 210 /**
210 * @override 211 * @override
211 */ 212 */
212 willHide: function() 213 willHide: function()
213 { 214 {
214 this._mediaInspector.setEnabled(false); 215 this._mediaInspector.setEnabled(false);
215 }, 216 },
216 217
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 this._optionsToolbar.appendToolbarItem(this._appliedHeightItem); 283 this._optionsToolbar.appendToolbarItem(this._appliedHeightItem);
283 284
284 this._deviceScaleFactorItem = new WebInspector.ToolbarText("", "fullscreen-t oolbar-item"); 285 this._deviceScaleFactorItem = new WebInspector.ToolbarText("", "fullscreen-t oolbar-item");
285 this._deviceScaleFactorItem.element.title = WebInspector.UIString("Device pi xel ratio"); 286 this._deviceScaleFactorItem.element.title = WebInspector.UIString("Device pi xel ratio");
286 this._deviceScaleFactorItem.showGlyph(); 287 this._deviceScaleFactorItem.showGlyph();
287 this._optionsToolbar.appendToolbarItem(this._deviceScaleFactorItem); 288 this._optionsToolbar.appendToolbarItem(this._deviceScaleFactorItem);
288 289
289 this._optionsToolbar.appendSeparator(); 290 this._optionsToolbar.appendSeparator();
290 291
291 this._optionsToolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(We bInspector.UIString("More options"), "menu-toolbar-item", this._appendMenuItems. bind(this))); 292 this._optionsToolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(We bInspector.UIString("More options"), "menu-toolbar-item", this._appendMenuItems. bind(this)));
293
294 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.Desktop, devi ce: "", orientation: "", mode: ""});
295 this._restored = false;
292 } 296 }
293 297
294 WebInspector.DeviceModeView.Toolbar.prototype = { 298 WebInspector.DeviceModeView.Toolbar.prototype = {
295 /** 299 /**
296 * @param {!WebInspector.ContextMenu} contextMenu 300 * @param {!WebInspector.ContextMenu} contextMenu
297 */ 301 */
298 _appendMenuItems: function(contextMenu) 302 _appendMenuItems: function(contextMenu)
299 { 303 {
300 var fitSetting = this._model.fitSetting(); 304 var fitSetting = this._model.fitSetting();
301 appendFitItem(WebInspector.UIString("Fit"), 0); 305 appendFitItem(WebInspector.UIString("Fit"), 0);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 /** 553 /**
550 * @return {!Element} 554 * @return {!Element}
551 */ 555 */
552 screenOptionsElement: function() 556 screenOptionsElement: function()
553 { 557 {
554 return this._modeToolbar.element; 558 return this._modeToolbar.element;
555 }, 559 },
556 560
557 update: function() 561 update: function()
558 { 562 {
563 var updatePersistence = false;
564
559 if (this._model.type() !== this._cachedModelType) { 565 if (this._model.type() !== this._cachedModelType) {
560 var isDesktop = this._model.type() === WebInspector.DeviceModeModel. Type.Desktop; 566 var isDesktop = this._model.type() === WebInspector.DeviceModeModel. Type.Desktop;
561 this._desktopItem.setToggled(isDesktop); 567 this._desktopItem.setToggled(isDesktop);
562 this._mobileItem.setToggled(!isDesktop); 568 this._mobileItem.setToggled(!isDesktop);
563 this._deviceSelectItem.setVisible(!isDesktop); 569 this._deviceSelectItem.setVisible(!isDesktop);
564 this._cachedModelType = this._model.type(); 570 this._cachedModelType = this._model.type();
571 updatePersistence = true;
565 } 572 }
566 573
567 var resizable = this._model.isResizable(); 574 var resizable = this._model.isResizable();
568 if (resizable !== this._cachedResizable) { 575 if (resizable !== this._cachedResizable) {
569 this._widthItem.setVisible(resizable); 576 this._widthItem.setVisible(resizable);
570 this._cachedResizable = resizable; 577 this._cachedResizable = resizable;
571 } 578 }
572 579
573 var showWidth = this._model.type() === WebInspector.DeviceModeModel.Type .Device || (this._model.type() === WebInspector.DeviceModeModel.Type.Desktop && !resizable); 580 var showWidth = this._model.type() === WebInspector.DeviceModeModel.Type .Device || (this._model.type() === WebInspector.DeviceModeModel.Type.Desktop && !resizable);
574 if (showWidth !== this._cachedShowWidth) { 581 if (showWidth !== this._cachedShowWidth) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 621 }
615 622
616 if (this._model.device() !== this._cachedModelDevice) { 623 if (this._model.device() !== this._cachedModelDevice) {
617 var device = this._model.device(); 624 var device = this._model.device();
618 625
619 var modeCount = device ? device.modes.length : 0; 626 var modeCount = device ? device.modes.length : 0;
620 this._modeToolbar.element.classList.toggle("hidden", modeCount < 2); 627 this._modeToolbar.element.classList.toggle("hidden", modeCount < 2);
621 this._updateDeviceSelectedIndex(); 628 this._updateDeviceSelectedIndex();
622 629
623 this._cachedModelDevice = device; 630 this._cachedModelDevice = device;
631 updatePersistence = true;
624 } 632 }
625 633
626 if (this._model.device() && this._model.mode()) 634 if (this._model.device() && this._model.mode())
627 this._lastMode.set(/** @type {!WebInspector.EmulatedDevice} */ (this ._model.device()), /** @type {!WebInspector.EmulatedDevice.Mode} */ (this._model .mode())); 635 this._lastMode.set(/** @type {!WebInspector.EmulatedDevice} */ (this ._model.device()), /** @type {!WebInspector.EmulatedDevice.Mode} */ (this._model .mode()));
628 636
629 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Desktop) 637 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Desktop)
630 this._lastDevice = this._model.device(); 638 this._lastDevice = this._model.device();
639
640 if (this._model.mode() !== this._cachedModelMode) {
641 this._cachedModelMode = this._model.mode();
642 updatePersistence = true;
643 }
644
645 if (updatePersistence) {
646 this._persistenceSetting.set({
647 type: this._cachedModelType,
648 device: this._cachedModelDevice ? this._cachedModelDevice.title : "",
649 orientation: this._cachedModelMode ? this._cachedModelMode.orien tation : "",
650 mode: this._cachedModelMode ? this._cachedModelMode.title : ""
651 });
652 }
653 },
654
655 restore: function()
656 {
657 if (this._restored)
658 return;
659
660 this._restored = true;
661 var type = this._persistenceSetting.get().type;
662 if (type === WebInspector.DeviceModeModel.Type.Mobile) {
663 this._model.emulate(WebInspector.DeviceModeModel.Type.Mobile, null, null);
664 } else if (type === WebInspector.DeviceModeModel.Type.Device) {
665 var device = null;
666 for (var i = 0; i < this._deviceSelect.options.length; ++i) {
667 if (this._deviceSelect.options[i].device && this._deviceSelect.o ptions[i].device.title === this._persistenceSetting.get().device)
668 device = this._deviceSelect.options[i].device;
669 }
670 if (device) {
671 var mode = null;
672 for (var i = 0; i < device.modes.length; ++i) {
673 if (device.modes[i].orientation === this._persistenceSetting .get().orientation && device.modes[i].title === this._persistenceSetting.get().m ode)
674 mode = device.modes[i];
675 }
676 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, de vice, mode || device.modes[0]);
677 } else {
678 this._model.emulate(WebInspector.DeviceModeModel.Type.Mobile, nu ll, null);
679 }
680 } else {
681 this._model.emulate(WebInspector.DeviceModeModel.Type.Desktop, null, null);
682 }
631 } 683 }
632 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698