| OLD | NEW |
| 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 {function()} pageResizeCallback | 8 * @param {function()} pageResizeCallback |
| 9 */ | 9 */ |
| 10 WebInspector.DeviceModeView = function(pageResizeCallback) | 10 WebInspector.DeviceModeView = function(pageResizeCallback) |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 * @constructor | 278 * @constructor |
| 279 */ | 279 */ |
| 280 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting) | 280 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting) |
| 281 { | 281 { |
| 282 this._model = model; | 282 this._model = model; |
| 283 this._showMediaInspectorSetting = showMediaInspectorSetting; | 283 this._showMediaInspectorSetting = showMediaInspectorSetting; |
| 284 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ | 284 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ |
| 285 this._lastMode = new Map(); | 285 this._lastMode = new Map(); |
| 286 /** @type {?WebInspector.EmulatedDevice} */ | 286 /** @type {?WebInspector.EmulatedDevice} */ |
| 287 this._lastDevice = null; | 287 this._lastDevice = null; |
| 288 /** @type {!Array<!Element>} */ | 288 /** @type {!Array<!WebInspector.ToolbarTextGlyphItem>} */ |
| 289 this._appliedWidthInputs = []; | 289 this._appliedSizeItems = []; |
| 290 /** @type {!Array<!Element>} */ | |
| 291 this._appliedHeightInputs = []; | |
| 292 /** @type {?Element} */ | 290 /** @type {?Element} */ |
| 293 this._visibleToolbar = null; | 291 this._visibleToolbar = null; |
| 294 | 292 |
| 295 this._element = createElementWithClass("div", "device-mode-toolbar"); | 293 this._element = createElementWithClass("div", "device-mode-toolbar"); |
| 296 | 294 |
| 297 var leftToolbar = new WebInspector.Toolbar("", this._element); | 295 var leftContainer = this._element.createChild("div", "device-mode-toolbar-le
ft"); |
| 298 this._noneItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Full"
), "desktop-toolbar-item"); | 296 var leftToolbar = new WebInspector.Toolbar("", leftContainer); |
| 297 this._noneItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Full"
), "enter-fullscreen-toolbar-item"); |
| 299 leftToolbar.appendToolbarItem(this._noneItem); | 298 leftToolbar.appendToolbarItem(this._noneItem); |
| 300 this._noneItem.addEventListener("click", this._noneButtonClick, this); | 299 this._noneItem.addEventListener("click", this._noneButtonClick, this); |
| 301 this._responsiveItem = new WebInspector.ToolbarToggle(WebInspector.UIString(
"Responsive"), "enter-fullscreen-toolbar-item"); | 300 this._responsiveItem = new WebInspector.ToolbarToggle(WebInspector.UIString(
"Responsive"), "responsive-toolbar-item"); |
| 302 leftToolbar.appendToolbarItem(this._responsiveItem); | 301 leftToolbar.appendToolbarItem(this._responsiveItem); |
| 303 this._responsiveItem.addEventListener("click", this._responsiveButtonClick,
this); | 302 this._responsiveItem.addEventListener("click", this._responsiveButtonClick,
this); |
| 304 this._deviceItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Dev
ice"), "emulation-toolbar-item"); | 303 this._deviceItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Dev
ice"), "phone-toolbar-item"); |
| 305 leftToolbar.appendToolbarItem(this._deviceItem); | 304 leftToolbar.appendToolbarItem(this._deviceItem); |
| 306 this._deviceItem.addEventListener("click", this._deviceButtonClick, this); | 305 this._deviceItem.addEventListener("click", this._deviceButtonClick, this); |
| 307 leftToolbar.appendSeparator(); | 306 leftToolbar.appendSeparator(); |
| 308 | 307 |
| 309 var middle = this._element.createChild("div", "device-mode-toolbar-middle-co
ntainer"); | 308 var middle = this._element.createChild("div", "device-mode-toolbar-middle-co
ntainer"); |
| 310 this._noneToolbar = this._wrapMiddleToolbar(middle, this._createNoneToolbar(
)); | 309 this._noneToolbar = this._wrapMiddleToolbar(middle, this._createNoneToolbar(
)); |
| 311 this._responsiveToolbar = this._wrapMiddleToolbar(middle, this._createRespon
siveToolbar()); | 310 this._responsiveToolbar = this._wrapMiddleToolbar(middle, this._createRespon
siveToolbar()); |
| 312 this._deviceToolbar = this._wrapMiddleToolbar(middle, this._createDeviceTool
bar()); | 311 this._deviceToolbar = this._wrapMiddleToolbar(middle, this._createDeviceTool
bar()); |
| 313 | 312 |
| 314 var rightToolbar = new WebInspector.Toolbar("", this._element); | 313 var rightContainer = this._element.createChild("div", "device-mode-toolbar-r
ight"); |
| 314 rightContainer.createChild("div", "device-mode-toolbar-spacer"); |
| 315 var rightToolbar = new WebInspector.Toolbar("", rightContainer); |
| 316 rightToolbar.makeWrappable(true); |
| 317 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMenuIt
ems.bind(this)); |
| 318 this._scaleItem.setTitle(WebInspector.UIString("Click to change zoom")); |
| 319 this._scaleItem.setGlyph(""); |
| 320 this._scaleItem.setBold(false); |
| 321 rightToolbar.appendToolbarItem(this._scaleItem); |
| 315 rightToolbar.appendSeparator(); | 322 rightToolbar.appendSeparator(); |
| 316 this._scaleItem = new WebInspector.ToolbarTextGlyphItem(); | |
| 317 rightToolbar.appendToolbarItem(this._scaleItem); | |
| 318 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendMenuI
tems.bind(this)); | 323 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendMenuI
tems.bind(this)); |
| 319 moreOptionsButton.setTitle(WebInspector.UIString("More options")); | 324 moreOptionsButton.setTitle(WebInspector.UIString("More options")); |
| 320 rightToolbar.appendToolbarItem(moreOptionsButton); | 325 rightToolbar.appendToolbarItem(moreOptionsButton); |
| 321 | 326 |
| 322 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.None, device:
"", orientation: "", mode: ""}); | 327 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.None, device:
"", orientation: "", mode: ""}); |
| 323 this._restored = false; | 328 this._restored = false; |
| 324 } | 329 } |
| 325 | 330 |
| 326 WebInspector.DeviceModeView.Toolbar.prototype = { | 331 WebInspector.DeviceModeView.Toolbar.prototype = { |
| 327 /** | 332 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 390 |
| 386 this._deviceSelect = this._createDeviceSelect(); | 391 this._deviceSelect = this._createDeviceSelect(); |
| 387 toolbar.appendToolbarItem(this._wrapToolbarItem(this._deviceSelect)); | 392 toolbar.appendToolbarItem(this._wrapToolbarItem(this._deviceSelect)); |
| 388 | 393 |
| 389 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); | 394 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); |
| 390 this._modeButton.addEventListener("click", this._modeMenuClicked, this); | 395 this._modeButton.addEventListener("click", this._modeMenuClicked, this); |
| 391 toolbar.appendToolbarItem(this._modeButton); | 396 toolbar.appendToolbarItem(this._modeButton); |
| 392 | 397 |
| 393 toolbar.appendSeparator(); | 398 toolbar.appendSeparator(); |
| 394 this._appendAppliedSizeItems(toolbar); | 399 this._appendAppliedSizeItems(toolbar); |
| 395 toolbar.appendSeparator(); | |
| 396 | 400 |
| 397 return toolbar; | 401 return toolbar; |
| 398 }, | 402 }, |
| 399 | 403 |
| 400 /** | 404 /** |
| 401 * @param {!WebInspector.Toolbar} toolbar | 405 * @param {!WebInspector.Toolbar} toolbar |
| 402 */ | 406 */ |
| 403 _appendAppliedSizeItems: function(toolbar) | 407 _appendAppliedSizeItems: function(toolbar) |
| 404 { | 408 { |
| 405 var widthInput = createElementWithClass("input", "device-mode-size-input
"); | 409 var item = new WebInspector.ToolbarTextGlyphItem(); |
| 406 widthInput.title = WebInspector.UIString("Width"); | 410 this._appliedSizeItems.push(item); |
| 407 widthInput.disabled = true; | 411 toolbar.appendToolbarItem(item); |
| 408 this._appliedWidthInputs.push(widthInput); | |
| 409 toolbar.appendToolbarItem(this._wrapToolbarItem(widthInput)); | |
| 410 | |
| 411 var xElement = createElementWithClass("div", "device-mode-x"); | |
| 412 xElement.textContent = "\u00D7"; | |
| 413 toolbar.appendToolbarItem(this._wrapToolbarItem(xElement)); | |
| 414 | |
| 415 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); | |
| 416 heightInput.title = WebInspector.UIString("Height"); | |
| 417 heightInput.disabled = true; | |
| 418 this._appliedHeightInputs.push(heightInput); | |
| 419 toolbar.appendToolbarItem(this._wrapToolbarItem(heightInput)); | |
| 420 }, | 412 }, |
| 421 | 413 |
| 422 | |
| 423 /** | 414 /** |
| 424 * @param {!WebInspector.ContextMenu} contextMenu | 415 * @param {!WebInspector.ContextMenu} contextMenu |
| 425 */ | 416 */ |
| 426 _appendMenuItems: function(contextMenu) | 417 _appendScaleMenuItems: function(contextMenu) |
| 427 { | 418 { |
| 428 var zoomDisabled = this._model.type() === WebInspector.DeviceModeModel.T
ype.None; | |
| 429 var zoomSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Z
oom"), false); | |
| 430 var scaleSetting = this._model.scaleSetting(); | 419 var scaleSetting = this._model.scaleSetting(); |
| 431 appendScaleItem(WebInspector.UIString("Fit"), 0); | 420 appendScaleItem(WebInspector.UIString("Fit"), 0); |
| 432 zoomSubmenu.appendSeparator(); | 421 contextMenu.appendSeparator(); |
| 433 appendScaleItem(WebInspector.UIString("25%"), 0.25); | 422 appendScaleItem(WebInspector.UIString("25%"), 0.25); |
| 434 appendScaleItem(WebInspector.UIString("50%"), 0.5); | 423 appendScaleItem(WebInspector.UIString("50%"), 0.5); |
| 435 appendScaleItem(WebInspector.UIString("100%"), 1); | 424 appendScaleItem(WebInspector.UIString("100%"), 1); |
| 436 appendScaleItem(WebInspector.UIString("150%"), 1.5); | 425 appendScaleItem(WebInspector.UIString("150%"), 1.5); |
| 437 appendScaleItem(WebInspector.UIString("200%"), 2); | 426 appendScaleItem(WebInspector.UIString("200%"), 2); |
| 438 | 427 |
| 439 /** | 428 /** |
| 440 * @param {string} title | 429 * @param {string} title |
| 441 * @param {number} value | 430 * @param {number} value |
| 442 */ | 431 */ |
| 443 function appendScaleItem(title, value) | 432 function appendScaleItem(title, value) |
| 444 { | 433 { |
| 445 zoomSubmenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, zoomDisabled); | 434 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); |
| 446 } | 435 } |
| 436 }, |
| 447 | 437 |
| 438 /** |
| 439 * @param {!WebInspector.ContextMenu} contextMenu |
| 440 */ |
| 441 _appendMenuItems: function(contextMenu) |
| 442 { |
| 448 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; | 443 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; |
| 449 var uaSetting = this._model.uaSetting(); | 444 var uaSetting = this._model.uaSetting(); |
| 450 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); | 445 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); |
| 451 appendUAItem(WebInspector.UIString("Mobile"), WebInspector.DeviceModeMod
el.UA.Mobile); | 446 appendUAItem(WebInspector.UIString("Mobile"), WebInspector.DeviceModeMod
el.UA.Mobile); |
| 452 appendUAItem(WebInspector.UIString("Desktop"), WebInspector.DeviceModeMo
del.UA.Desktop); | 447 appendUAItem(WebInspector.UIString("Desktop"), WebInspector.DeviceModeMo
del.UA.Desktop); |
| 453 appendUAItem(WebInspector.UIString("Desktop with touch"), WebInspector.D
eviceModeModel.UA.DesktopTouch); | 448 appendUAItem(WebInspector.UIString("Desktop with touch"), WebInspector.D
eviceModeModel.UA.DesktopTouch); |
| 454 | 449 |
| 455 /** | 450 /** |
| 456 * @param {string} title | 451 * @param {string} title |
| 457 * @param {!WebInspector.DeviceModeModel.UA} value | 452 * @param {!WebInspector.DeviceModeModel.UA} value |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 }, | 675 }, |
| 681 | 676 |
| 682 update: function() | 677 update: function() |
| 683 { | 678 { |
| 684 var updatePersistence = false; | 679 var updatePersistence = false; |
| 685 | 680 |
| 686 if (this._model.type() !== this._cachedModelType) { | 681 if (this._model.type() !== this._cachedModelType) { |
| 687 this._noneItem.setToggled(this._model.type() === WebInspector.Device
ModeModel.Type.None); | 682 this._noneItem.setToggled(this._model.type() === WebInspector.Device
ModeModel.Type.None); |
| 688 this._responsiveItem.setToggled(this._model.type() === WebInspector.
DeviceModeModel.Type.Responsive); | 683 this._responsiveItem.setToggled(this._model.type() === WebInspector.
DeviceModeModel.Type.Responsive); |
| 689 this._deviceItem.setToggled(this._model.type() === WebInspector.Devi
ceModeModel.Type.Device); | 684 this._deviceItem.setToggled(this._model.type() === WebInspector.Devi
ceModeModel.Type.Device); |
| 685 this._scaleItem.setVisible(this._model.type() !== WebInspector.Devic
eModeModel.Type.None); |
| 690 | 686 |
| 691 var toolbar = null; | 687 var toolbar = null; |
| 692 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) | 688 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) |
| 693 toolbar = this._noneToolbar; | 689 toolbar = this._noneToolbar; |
| 694 else if (this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive) | 690 else if (this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive) |
| 695 toolbar = this._responsiveToolbar; | 691 toolbar = this._responsiveToolbar; |
| 696 else if (this._model.type() === WebInspector.DeviceModeModel.Type.De
vice) | 692 else if (this._model.type() === WebInspector.DeviceModeModel.Type.De
vice) |
| 697 toolbar = this._deviceToolbar; | 693 toolbar = this._deviceToolbar; |
| 698 | 694 |
| 699 if (this._visibleToolbar !== toolbar) { | 695 if (this._visibleToolbar !== toolbar) { |
| 700 if (this._visibleToolbar) | 696 if (this._visibleToolbar) |
| 701 this._visibleToolbar.classList.add("hidden"); | 697 this._visibleToolbar.classList.add("hidden"); |
| 702 if (toolbar) { | 698 if (toolbar) { |
| 703 toolbar.classList.remove("hidden"); | 699 toolbar.classList.remove("hidden"); |
| 704 toolbar.animate([{opacity: "0"}, {opacity: "1"}], {duration:
100}); | 700 toolbar.animate([{opacity: "0"}, {opacity: "1"}], {duration:
100}); |
| 705 } | 701 } |
| 706 this._visibleToolbar = toolbar; | 702 this._visibleToolbar = toolbar; |
| 707 } | 703 } |
| 708 | 704 |
| 709 this._previousModelType = this._cachedModelType; | 705 this._previousModelType = this._cachedModelType; |
| 710 this._cachedModelType = this._model.type(); | 706 this._cachedModelType = this._model.type(); |
| 711 updatePersistence = true; | 707 updatePersistence = true; |
| 712 } | 708 } |
| 713 | 709 |
| 714 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive)
{ | 710 if (this._model.type() !== WebInspector.DeviceModeModel.Type.Responsive)
{ |
| 715 var size = this._model.appliedDeviceSize(); | 711 var size = this._model.appliedDeviceSize(); |
| 716 if (!size.isEqual(this._cachedSize)) { | 712 if (!size.isEqual(this._cachedSize)) { |
| 717 for (var widthInput of this._appliedWidthInputs) | 713 for (var item of this._appliedSizeItems) |
| 718 widthInput.value = size.width; | 714 item.setText(WebInspector.UIString("%d \u00D7 %d", size.widt
h, size.height)); |
| 719 for (var heightInput of this._appliedHeightInputs) | |
| 720 heightInput.value = size.height; | |
| 721 this._cachedSize = size; | 715 this._cachedSize = size; |
| 722 } | 716 } |
| 723 } | 717 } |
| 724 | 718 |
| 725 var showScale = this._model.scale() !== 1; | 719 if (this._model.scale() !== this._cachedScale) { |
| 726 if (showScale !== this._cachedShowScale) { | 720 this._scaleItem.setText(WebInspector.UIString("Zoom: %.0f%%", this._
model.scale() * 100)); |
| 727 this._scaleItem.setVisible(showScale); | 721 this._scaleItem.setDimmed(this._model.scale() === 1); |
| 728 this._cachedShowScale = showScale; | 722 this._cachedScale = this._model.scale(); |
| 729 } | |
| 730 | |
| 731 if (showScale) { | |
| 732 var scale = this._model.scale(); | |
| 733 if (scale !== this._cachedScale) { | |
| 734 this._scaleItem.setText(WebInspector.UIString("Zoom: %.2f", scal
e)); | |
| 735 this._cachedScale = scale; | |
| 736 } | |
| 737 } | 723 } |
| 738 | 724 |
| 739 if (this._model.device() !== this._cachedModelDevice) { | 725 if (this._model.device() !== this._cachedModelDevice) { |
| 740 var device = this._model.device(); | 726 var device = this._model.device(); |
| 741 | 727 |
| 742 if (device) { | 728 if (device) { |
| 743 var modeCount = device ? device.modes.length : 0; | 729 var modeCount = device ? device.modes.length : 0; |
| 744 this._modeButton.setEnabled(modeCount >= 2); | 730 this._modeButton.setEnabled(modeCount >= 2); |
| 745 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); | 731 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); |
| 746 } | 732 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 }, | 876 }, |
| 891 | 877 |
| 892 _resizePlaceholder: function() | 878 _resizePlaceholder: function() |
| 893 { | 879 { |
| 894 if (this._showDeviceToolbarSetting.get()) | 880 if (this._showDeviceToolbarSetting.get()) |
| 895 this._inspectedPagePlaceholder.onResize(); | 881 this._inspectedPagePlaceholder.onResize(); |
| 896 }, | 882 }, |
| 897 | 883 |
| 898 __proto__: WebInspector.VBox.prototype | 884 __proto__: WebInspector.VBox.prototype |
| 899 } | 885 } |
| OLD | NEW |