| 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 */ | 8 */ |
| 9 WebInspector.DeviceModeView = function() | 9 WebInspector.DeviceModeView = function() |
| 10 { | 10 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 this._topRuler.element.classList.add("device-mode-ruler-top"); | 26 this._topRuler.element.classList.add("device-mode-ruler-top"); |
| 27 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.s
etHeightAndScaleToFit.bind(this._model)); | 27 this._leftRuler = new WebInspector.DeviceModeView.Ruler(false, this._model.s
etHeightAndScaleToFit.bind(this._model)); |
| 28 this._leftRuler.element.classList.add("device-mode-ruler-left"); | 28 this._leftRuler.element.classList.add("device-mode-ruler-left"); |
| 29 this._createUI(); | 29 this._createUI(); |
| 30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._zoomChanged, this); | 30 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._zoomChanged, this); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 WebInspector.DeviceModeView.prototype = { | 33 WebInspector.DeviceModeView.prototype = { |
| 34 _createUI: function() | 34 _createUI: function() |
| 35 { | 35 { |
| 36 this._toolbar = new WebInspector.DeviceModeView.Toolbar(this._model, thi
s._showMediaInspectorSetting, this._showRulersSetting); | 36 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh
owMediaInspectorSetting, this._showRulersSetting); |
| 37 this.contentElement.appendChild(this._toolbar.element()); | 37 this.contentElement.appendChild(this._toolbar.element()); |
| 38 | 38 |
| 39 this._contentClip = this.contentElement.createChild("div", "device-mode-
content-clip vbox"); | 39 this._contentClip = this.contentElement.createChild("div", "device-mode-
content-clip vbox"); |
| 40 this._responsivePresetsContainer = this._contentClip.createChild("div",
"device-mode-presets-container"); | 40 this._responsivePresetsContainer = this._contentClip.createChild("div",
"device-mode-presets-container"); |
| 41 this._populatePresetsContainer(); | 41 this._populatePresetsContainer(); |
| 42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de
vice-mode-media-container"); | 42 this._mediaInspectorContainer = this._contentClip.createChild("div", "de
vice-mode-media-container"); |
| 43 this._contentArea = this._contentClip.createChild("div", "device-mode-co
ntent-area"); | 43 this._contentArea = this._contentClip.createChild("div", "device-mode-co
ntent-area"); |
| 44 | 44 |
| 45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); | 45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); |
| 46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); | 46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 willHide: function() | 336 willHide: function() |
| 337 { | 337 { |
| 338 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null); | 338 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null); |
| 339 this._mediaInspector.setEnabled(false); | 339 this._mediaInspector.setEnabled(false); |
| 340 }, | 340 }, |
| 341 | 341 |
| 342 __proto__: WebInspector.VBox.prototype | 342 __proto__: WebInspector.VBox.prototype |
| 343 } | 343 } |
| 344 | 344 |
| 345 /** | 345 /** |
| 346 * @param {!WebInspector.DeviceModeModel} model | |
| 347 * @param {!WebInspector.Setting} showMediaInspectorSetting | |
| 348 * @param {!WebInspector.Setting} showRulersSetting | |
| 349 * @constructor | |
| 350 */ | |
| 351 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting,
showRulersSetting) | |
| 352 { | |
| 353 this._model = model; | |
| 354 this._showMediaInspectorSetting = showMediaInspectorSetting; | |
| 355 this._showRulersSetting = showRulersSetting; | |
| 356 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ | |
| 357 this._lastMode = new Map(); | |
| 358 | |
| 359 this._element = createElementWithClass("div", "device-mode-toolbar"); | |
| 360 | |
| 361 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp
acer"); | |
| 362 leftContainer.createChild("div", "device-mode-toolbar-spacer"); | |
| 363 var leftToolbar = new WebInspector.Toolbar("", leftContainer); | |
| 364 leftToolbar.makeWrappable(); | |
| 365 this._fillLeftToolbar(leftToolbar); | |
| 366 | |
| 367 var mainToolbar = new WebInspector.Toolbar("", this._element); | |
| 368 mainToolbar.makeWrappable(); | |
| 369 this._fillMainToolbar(mainToolbar); | |
| 370 | |
| 371 var rightContainer = this._element.createChild("div", "device-mode-toolbar-s
pacer"); | |
| 372 var rightToolbar = new WebInspector.Toolbar("device-mode-toolbar-fixed-size"
, rightContainer); | |
| 373 rightToolbar.makeWrappable(); | |
| 374 this._fillRightToolbar(rightToolbar); | |
| 375 var modeToolbar = new WebInspector.Toolbar("device-mode-toolbar-fixed-size",
rightContainer); | |
| 376 modeToolbar.makeWrappable(); | |
| 377 this._fillModeToolbar(modeToolbar); | |
| 378 rightContainer.createChild("div", "device-mode-toolbar-spacer"); | |
| 379 var optionsToolbar = new WebInspector.Toolbar("", rightContainer); | |
| 380 optionsToolbar.makeWrappable(true); | |
| 381 this._fillOptionsToolbar(optionsToolbar); | |
| 382 | |
| 383 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, this._deviceListChanged, this); | |
| 384 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, this._deviceListChanged, this); | |
| 385 | |
| 386 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeValue", {device: "", orientation: "", mode: ""}); | |
| 387 } | |
| 388 | |
| 389 WebInspector.DeviceModeView.Toolbar.prototype = { | |
| 390 /** | |
| 391 * @param {!WebInspector.Toolbar} toolbar | |
| 392 */ | |
| 393 _fillLeftToolbar: function(toolbar) | |
| 394 { | |
| 395 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | |
| 396 this._deviceSelectItem = new WebInspector.ToolbarMenuButton(this._append
DeviceMenuItems.bind(this)); | |
| 397 this._deviceSelectItem.setGlyph(""); | |
| 398 this._deviceSelectItem.turnIntoSelect(95); | |
| 399 toolbar.appendToolbarItem(this._deviceSelectItem); | |
| 400 }, | |
| 401 | |
| 402 /** | |
| 403 * @param {!WebInspector.Toolbar} toolbar | |
| 404 */ | |
| 405 _fillMainToolbar: function(toolbar) | |
| 406 { | |
| 407 var widthInput = createElementWithClass("input", "device-mode-size-input
"); | |
| 408 widthInput.maxLength = 4; | |
| 409 widthInput.type = "text"; | |
| 410 widthInput.title = WebInspector.UIString("Width"); | |
| 411 this._updateWidthInput = this._bindInput(widthInput, this._model.setWidt
hAndScaleToFit.bind(this._model), WebInspector.DeviceModeModel.deviceSizeValidat
or); | |
| 412 this._widthInput = widthInput; | |
| 413 this._widthItem = this._wrapToolbarItem(widthInput); | |
| 414 toolbar.appendToolbarItem(this._widthItem); | |
| 415 | |
| 416 var xElement = createElementWithClass("div", "device-mode-x"); | |
| 417 xElement.textContent = "\u00D7"; | |
| 418 this._xItem = this._wrapToolbarItem(xElement); | |
| 419 toolbar.appendToolbarItem(this._xItem); | |
| 420 | |
| 421 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); | |
| 422 heightInput.maxLength = 4; | |
| 423 heightInput.type = "text"; | |
| 424 heightInput.title = WebInspector.UIString("Height (leave empty for full)
"); | |
| 425 this._updateHeightInput = this._bindInput(heightInput, this._model.setHe
ightAndScaleToFit.bind(this._model), validateHeight); | |
| 426 this._heightInput = heightInput; | |
| 427 this._heightItem = this._wrapToolbarItem(heightInput); | |
| 428 toolbar.appendToolbarItem(this._heightItem); | |
| 429 | |
| 430 /** | |
| 431 * @param {string} value | |
| 432 * @return {string} | |
| 433 */ | |
| 434 function validateHeight(value) | |
| 435 { | |
| 436 return !value ? "" : WebInspector.DeviceModeModel.deviceSizeValidato
r(value); | |
| 437 } | |
| 438 }, | |
| 439 | |
| 440 /** | |
| 441 * @param {!WebInspector.Toolbar} toolbar | |
| 442 */ | |
| 443 _fillRightToolbar: function(toolbar) | |
| 444 { | |
| 445 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | |
| 446 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe
nuItems.bind(this)); | |
| 447 this._scaleItem.setTitle(WebInspector.UIString("Zoom")); | |
| 448 this._scaleItem.setGlyph(""); | |
| 449 this._scaleItem.turnIntoSelect(); | |
| 450 toolbar.appendToolbarItem(this._scaleItem); | |
| 451 }, | |
| 452 | |
| 453 /** | |
| 454 * @param {!WebInspector.Toolbar} toolbar | |
| 455 */ | |
| 456 _fillModeToolbar: function(toolbar) | |
| 457 { | |
| 458 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | |
| 459 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); | |
| 460 this._modeButton.addEventListener("click", this._modeMenuClicked, this); | |
| 461 toolbar.appendToolbarItem(this._modeButton); | |
| 462 }, | |
| 463 | |
| 464 /** | |
| 465 * @param {!WebInspector.Toolbar} toolbar | |
| 466 */ | |
| 467 _fillOptionsToolbar: function(toolbar) | |
| 468 { | |
| 469 this._uaItem = new WebInspector.ToolbarText(); | |
| 470 this._uaItem.setVisible(false); | |
| 471 this._uaItem.setTitle(WebInspector.UIString("User agent type")); | |
| 472 toolbar.appendToolbarItem(this._uaItem); | |
| 473 | |
| 474 this._deviceScaleItem = new WebInspector.ToolbarText(); | |
| 475 this._deviceScaleItem.setVisible(false); | |
| 476 this._deviceScaleItem.setTitle(WebInspector.UIString("Device pixel ratio
")); | |
| 477 toolbar.appendToolbarItem(this._deviceScaleItem); | |
| 478 | |
| 479 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO
ptionsMenuItems.bind(this)); | |
| 480 moreOptionsButton.setTitle(WebInspector.UIString("More options")); | |
| 481 toolbar.appendToolbarItem(moreOptionsButton); | |
| 482 | |
| 483 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | |
| 484 }, | |
| 485 | |
| 486 | |
| 487 /** | |
| 488 * @param {!Element} input | |
| 489 * @param {function(number)} apply | |
| 490 * @param {function(string):?string} validate | |
| 491 * @return {function(number)} | |
| 492 */ | |
| 493 _bindInput: function(input, apply, validate) | |
| 494 { | |
| 495 input.addEventListener("change", onChange, false); | |
| 496 input.addEventListener("input", onInput, false); | |
| 497 input.addEventListener("keydown", onKeyDown, false); | |
| 498 input.addEventListener("focus", input.select.bind(input), false); | |
| 499 | |
| 500 function onInput() | |
| 501 { | |
| 502 input.classList.toggle("error-input", !!validate(input.value)); | |
| 503 } | |
| 504 | |
| 505 function onChange() | |
| 506 { | |
| 507 var valid = !validate(input.value); | |
| 508 input.classList.toggle("error-input", !valid); | |
| 509 if (valid) | |
| 510 apply(input.value ? Number(input.value) : 0); | |
| 511 } | |
| 512 | |
| 513 /** | |
| 514 * @param {!Event} event | |
| 515 */ | |
| 516 function onKeyDown(event) | |
| 517 { | |
| 518 if (isEnterKey(event)) { | |
| 519 if (!validate(input.value)) | |
| 520 apply(input.value ? Number(input.value) : 0); | |
| 521 return; | |
| 522 } | |
| 523 | |
| 524 var increment = event.keyIdentifier === "Up" ? 1 : event.keyIdentifi
er === "Down" ? -1 : 0; | |
| 525 if (!increment) | |
| 526 return; | |
| 527 if (event.shiftKey) | |
| 528 increment *= 10; | |
| 529 | |
| 530 var value = input.value; | |
| 531 if (validate(value) || !value) | |
| 532 return; | |
| 533 | |
| 534 value = (value ? Number(value) : 0) + increment; | |
| 535 var stringValue = value ? String(value) : ""; | |
| 536 if (validate(stringValue) || !value) | |
| 537 return; | |
| 538 | |
| 539 input.value = stringValue; | |
| 540 apply(input.value ? Number(input.value) : 0); | |
| 541 event.preventDefault(); | |
| 542 } | |
| 543 | |
| 544 /** | |
| 545 * @param {number} value | |
| 546 */ | |
| 547 function setValue(value) | |
| 548 { | |
| 549 var stringValue = value ? String(value) : ""; | |
| 550 if (stringValue === input.value) | |
| 551 return; | |
| 552 var valid = !validate(stringValue); | |
| 553 input.classList.toggle("error-input", !valid); | |
| 554 input.value = stringValue; | |
| 555 input.setSelectionRange(stringValue.length, stringValue.length); | |
| 556 } | |
| 557 | |
| 558 return setValue; | |
| 559 }, | |
| 560 | |
| 561 /** | |
| 562 * @param {!WebInspector.ContextMenu} contextMenu | |
| 563 */ | |
| 564 _appendScaleMenuItems: function(contextMenu) | |
| 565 { | |
| 566 var scaleSetting = this._model.scaleSetting(); | |
| 567 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { | |
| 568 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)
", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode
l.fitScale()), false); | |
| 569 contextMenu.appendSeparator(); | |
| 570 } | |
| 571 appendScaleItem(WebInspector.UIString("50%"), 0.5); | |
| 572 appendScaleItem(WebInspector.UIString("75%"), 0.75); | |
| 573 appendScaleItem(WebInspector.UIString("100%"), 1); | |
| 574 appendScaleItem(WebInspector.UIString("125%"), 1.25); | |
| 575 appendScaleItem(WebInspector.UIString("150%"), 1.5); | |
| 576 | |
| 577 /** | |
| 578 * @param {string} title | |
| 579 * @param {number} value | |
| 580 */ | |
| 581 function appendScaleItem(title, value) | |
| 582 { | |
| 583 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); | |
| 584 } | |
| 585 }, | |
| 586 | |
| 587 /** | |
| 588 * @param {!WebInspector.ContextMenu} contextMenu | |
| 589 */ | |
| 590 _appendOptionsMenuItems: function(contextMenu) | |
| 591 { | |
| 592 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; | |
| 593 var uaSetting = this._model.uaSetting(); | |
| 594 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); | |
| 595 var uaValue = this._model.uaSetting().get(); | |
| 596 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) | |
| 597 uaValue = WebInspector.DeviceModeModel.UA.Desktop; | |
| 598 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) | |
| 599 uaValue = this._model.device().mobile() ? WebInspector.DeviceModeMod
el.UA.Mobile : this._model.device().touch() ? WebInspector.DeviceModeModel.UA.De
sktopTouch : WebInspector.DeviceModeModel.UA.Desktop; | |
| 600 appendUAItem(WebInspector.UIString("Mobile (default)"), WebInspector.Dev
iceModeModel.UA.Mobile); | |
| 601 appendUAItem(WebInspector.UIString("Desktop"), WebInspector.DeviceModeMo
del.UA.Desktop); | |
| 602 appendUAItem(WebInspector.UIString("Desktop with touch"), WebInspector.D
eviceModeModel.UA.DesktopTouch); | |
| 603 | |
| 604 /** | |
| 605 * @param {string} title | |
| 606 * @param {!WebInspector.DeviceModeModel.UA} value | |
| 607 */ | |
| 608 function appendUAItem(title, value) | |
| 609 { | |
| 610 uaSubmenu.appendCheckboxItem(title, uaSetting.set.bind(uaSetting, va
lue), uaValue === value, uaDisabled); | |
| 611 } | |
| 612 | |
| 613 var deviceScaleFactorDisabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; | |
| 614 var deviceScaleFactorSubmenu = contextMenu.appendSubMenuItem(WebInspecto
r.UIString("Device pixel ratio"), false); | |
| 615 var deviceScaleFactorSetting = this._model.deviceScaleFactorSetting(); | |
| 616 var deviceScaleFactorValue = deviceScaleFactorDisabled ? 0 : deviceScale
FactorSetting.get(); | |
| 617 appendDeviceScaleFactorItem(WebInspector.UIString("Default: %f", this._m
odel.defaultDeviceScaleFactor()), 0); | |
| 618 deviceScaleFactorSubmenu.appendSeparator(); | |
| 619 appendDeviceScaleFactorItem(WebInspector.UIString("1"), 1); | |
| 620 appendDeviceScaleFactorItem(WebInspector.UIString("2"), 2); | |
| 621 appendDeviceScaleFactorItem(WebInspector.UIString("3"), 3); | |
| 622 | |
| 623 /** | |
| 624 * @param {string} title | |
| 625 * @param {number} value | |
| 626 */ | |
| 627 function appendDeviceScaleFactorItem(title, value) | |
| 628 { | |
| 629 deviceScaleFactorSubmenu.appendCheckboxItem(title, deviceScaleFactor
Setting.set.bind(deviceScaleFactorSetting, value), deviceScaleFactorValue === va
lue, deviceScaleFactorDisabled); | |
| 630 } | |
| 631 | |
| 632 contextMenu.appendItem(WebInspector.UIString("Reset to defaults"), this.
_model.reset.bind(this._model), this._model.type() !== WebInspector.DeviceModeMo
del.Type.Responsive); | |
| 633 contextMenu.appendSeparator(); | |
| 634 | |
| 635 contextMenu.appendCheckboxItem(WebInspector.UIString("Show media queries
"), this._toggleMediaInspector.bind(this), this._showMediaInspectorSetting.get()
, this._model.type() === WebInspector.DeviceModeModel.Type.None); | |
| 636 contextMenu.appendCheckboxItem(WebInspector.UIString("Show rulers"), thi
s._toggleRulers.bind(this), this._showRulersSetting.get(), this._model.type() ==
= WebInspector.DeviceModeModel.Type.None); | |
| 637 contextMenu.appendItem(WebInspector.UIString("Configure network\u2026"),
this._openNetworkConfig.bind(this), false); | |
| 638 contextMenu.appendItemsAtLocation("deviceModeMenu"); | |
| 639 }, | |
| 640 | |
| 641 _toggleMediaInspector: function() | |
| 642 { | |
| 643 this._showMediaInspectorSetting.set(!this._showMediaInspectorSetting.get
()); | |
| 644 }, | |
| 645 | |
| 646 _toggleRulers: function() | |
| 647 { | |
| 648 this._showRulersSetting.set(!this._showRulersSetting.get()); | |
| 649 }, | |
| 650 | |
| 651 _openNetworkConfig: function() | |
| 652 { | |
| 653 InspectorFrontendHost.bringToFront(); | |
| 654 // TODO(dgozman): make it explicit. | |
| 655 WebInspector.actionRegistry.action("network.show-config").execute(); | |
| 656 }, | |
| 657 | |
| 658 /** | |
| 659 * @param {!Element} element | |
| 660 * @return {!WebInspector.ToolbarItem} | |
| 661 */ | |
| 662 _wrapToolbarItem: function(element) | |
| 663 { | |
| 664 var container = createElement("div"); | |
| 665 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container,
"emulation/deviceModeToolbar.css"); | |
| 666 shadowRoot.appendChild(element); | |
| 667 return new WebInspector.ToolbarItem(container); | |
| 668 }, | |
| 669 | |
| 670 /** | |
| 671 * @param {!WebInspector.EmulatedDevice} device | |
| 672 */ | |
| 673 _emulateDevice: function(device) | |
| 674 { | |
| 675 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, th
is._lastMode.get(device) || device.modes[0]); | |
| 676 }, | |
| 677 | |
| 678 _switchToResponsive: function() | |
| 679 { | |
| 680 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); | |
| 681 }, | |
| 682 | |
| 683 /** | |
| 684 * @param {!Array<!WebInspector.EmulatedDevice>} devices | |
| 685 * @return {!Array<!WebInspector.EmulatedDevice>} | |
| 686 */ | |
| 687 _filterDevices: function(devices) | |
| 688 { | |
| 689 devices = devices.filter(function(d) { return d.show(); }); | |
| 690 devices.sort(WebInspector.EmulatedDevice.deviceComparator); | |
| 691 return devices; | |
| 692 }, | |
| 693 | |
| 694 /** | |
| 695 * @return {!Array<!WebInspector.EmulatedDevice>} | |
| 696 */ | |
| 697 _standardDevices: function() | |
| 698 { | |
| 699 return this._filterDevices(WebInspector.emulatedDevicesList.standard()); | |
| 700 }, | |
| 701 | |
| 702 /** | |
| 703 * @return {!Array<!WebInspector.EmulatedDevice>} | |
| 704 */ | |
| 705 _customDevices: function() | |
| 706 { | |
| 707 return this._filterDevices(WebInspector.emulatedDevicesList.custom()); | |
| 708 }, | |
| 709 | |
| 710 /** | |
| 711 * @return {!Array<!WebInspector.EmulatedDevice>} | |
| 712 */ | |
| 713 _allDevices: function() | |
| 714 { | |
| 715 return this._standardDevices().concat(this._customDevices()); | |
| 716 }, | |
| 717 | |
| 718 /** | |
| 719 * @param {!WebInspector.ContextMenu} contextMenu | |
| 720 */ | |
| 721 _appendDeviceMenuItems: function(contextMenu) | |
| 722 { | |
| 723 contextMenu.appendCheckboxItem(WebInspector.UIString("Responsive"), this
._switchToResponsive.bind(this), this._model.type() === WebInspector.DeviceModeM
odel.Type.Responsive, false); | |
| 724 appendGroup.call(this, this._standardDevices()); | |
| 725 appendGroup.call(this, this._customDevices()); | |
| 726 contextMenu.appendSeparator(); | |
| 727 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), WebInspector
.emulatedDevicesList.revealCustomSetting.bind(WebInspector.emulatedDevicesList),
false); | |
| 728 | |
| 729 /** | |
| 730 * @param {!Array<!WebInspector.EmulatedDevice>} devices | |
| 731 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 732 */ | |
| 733 function appendGroup(devices) | |
| 734 { | |
| 735 if (!devices.length) | |
| 736 return; | |
| 737 contextMenu.appendSeparator(); | |
| 738 for (var device of devices) | |
| 739 contextMenu.appendCheckboxItem(device.title, this._emulateDevice
.bind(this, device), this._model.device() === device, false); | |
| 740 } | |
| 741 }, | |
| 742 | |
| 743 /** | |
| 744 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 745 */ | |
| 746 _deviceListChanged: function() | |
| 747 { | |
| 748 if (!this._model.device()) | |
| 749 return; | |
| 750 | |
| 751 var devices = this._allDevices(); | |
| 752 if (devices.indexOf(this._model.device()) === -1) | |
| 753 this._emulateDevice(devices[0] || WebInspector.emulatedDevicesList.s
tandard()[0]); | |
| 754 }, | |
| 755 | |
| 756 /** | |
| 757 * @param {!WebInspector.Event} event | |
| 758 */ | |
| 759 _modeMenuClicked: function(event) | |
| 760 { | |
| 761 var device = this._model.device(); | |
| 762 var model = this._model; | |
| 763 | |
| 764 if (device.modes.length === 2 && device.modes[0].orientation !== device.
modes[1].orientation) { | |
| 765 model.emulate(model.type(), model.device(), model.mode() === device.
modes[0] ? device.modes[1] : device.modes[0]); | |
| 766 return; | |
| 767 } | |
| 768 | |
| 769 var contextMenu = new WebInspector.ContextMenu(/** @type {!Event} */ (ev
ent.data), | |
| 770 false, | |
| 771 event.target.element.totalOffsetLeft(), | |
| 772 event.target.element.totalOffsetTop() + event.target.element.offsetH
eight); | |
| 773 addOrientation(WebInspector.EmulatedDevice.Vertical, WebInspector.UIStri
ng("Portrait")); | |
| 774 addOrientation(WebInspector.EmulatedDevice.Horizontal, WebInspector.UISt
ring("Landscape")); | |
| 775 contextMenu.show(); | |
| 776 | |
| 777 /** | |
| 778 * @param {string} orientation | |
| 779 * @param {string} title | |
| 780 */ | |
| 781 function addOrientation(orientation, title) | |
| 782 { | |
| 783 var modes = device.modesForOrientation(orientation); | |
| 784 if (!modes.length) | |
| 785 return; | |
| 786 if (modes.length === 1) { | |
| 787 addMode(modes[0], title); | |
| 788 } else { | |
| 789 for (var index = 0; index < modes.length; index++) | |
| 790 addMode(modes[index], title + " \u2013 " + modes[index].titl
e); | |
| 791 } | |
| 792 } | |
| 793 | |
| 794 /** | |
| 795 * @param {!WebInspector.EmulatedDevice.Mode} mode | |
| 796 * @param {string} title | |
| 797 */ | |
| 798 function addMode(mode, title) | |
| 799 { | |
| 800 contextMenu.appendCheckboxItem(title, applyMode.bind(null, mode), mo
del.mode() === mode, false); | |
| 801 } | |
| 802 | |
| 803 /** | |
| 804 * @param {!WebInspector.EmulatedDevice.Mode} mode | |
| 805 */ | |
| 806 function applyMode(mode) | |
| 807 { | |
| 808 model.emulate(model.type(), model.device(), mode); | |
| 809 } | |
| 810 }, | |
| 811 | |
| 812 /** | |
| 813 * @return {!Element} | |
| 814 */ | |
| 815 element: function() | |
| 816 { | |
| 817 return this._element; | |
| 818 }, | |
| 819 | |
| 820 update: function() | |
| 821 { | |
| 822 if (this._model.type() !== this._cachedModelType) { | |
| 823 this._cachedModelType = this._model.type(); | |
| 824 this._widthInput.disabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; | |
| 825 this._heightInput.disabled = this._model.type() !== WebInspector.Dev
iceModeModel.Type.Responsive; | |
| 826 } | |
| 827 | |
| 828 var size = this._model.appliedDeviceSize(); | |
| 829 this._updateHeightInput(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && this._model.isFullHeight() ? 0 : size.height); | |
| 830 this._updateWidthInput(size.width); | |
| 831 this._heightInput.placeholder = size.height; | |
| 832 | |
| 833 if (this._model.scale() !== this._cachedScale) { | |
| 834 this._scaleItem.setText(WebInspector.UIString("%.0f%%", this._model.
scale() * 100)); | |
| 835 this._scaleItem.setState(this._model.scale() === 1 ? "off" : "on"); | |
| 836 this._cachedScale = this._model.scale(); | |
| 837 } | |
| 838 | |
| 839 var deviceScale = this._model.deviceScaleFactorSetting().get(); | |
| 840 this._deviceScaleItem.setVisible(this._model.type() === WebInspector.Dev
iceModeModel.Type.Responsive && !!deviceScale); | |
| 841 if (deviceScale !== this._cachedDeviceScale) { | |
| 842 this._deviceScaleItem.setText(WebInspector.UIString("DPR: %.1f", dev
iceScale)); | |
| 843 this._cachedDeviceScale = deviceScale; | |
| 844 } | |
| 845 | |
| 846 var uaType = this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive ? this._model.uaSetting().get() : WebInspector.DeviceModeModel.UA.Mobil
e; | |
| 847 this._uaItem.setVisible(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && uaType !== WebInspector.DeviceModeModel.UA.Mobile); | |
| 848 if (uaType !== this._cachedUaType) { | |
| 849 this._uaItem.setText(uaType === WebInspector.DeviceModeModel.UA.Desk
top ? WebInspector.UIString("Desktop") : WebInspector.UIString("Touch")); | |
| 850 this._cachedUaType = uaType; | |
| 851 } | |
| 852 | |
| 853 var deviceItemTitle = WebInspector.UIString("None"); | |
| 854 if (this._model.type() === WebInspector.DeviceModeModel.Type.Responsive) | |
| 855 deviceItemTitle = WebInspector.UIString("Responsive"); | |
| 856 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) | |
| 857 deviceItemTitle = this._model.device().title; | |
| 858 this._deviceSelectItem.setText(deviceItemTitle); | |
| 859 | |
| 860 if (this._model.device() !== this._cachedModelDevice) { | |
| 861 var device = this._model.device(); | |
| 862 this._modeButton.setVisible(!!device); | |
| 863 if (device) { | |
| 864 var modeCount = device ? device.modes.length : 0; | |
| 865 this._modeButton.setEnabled(modeCount >= 2); | |
| 866 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); | |
| 867 } | |
| 868 this._cachedModelDevice = device; | |
| 869 } | |
| 870 | |
| 871 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) | |
| 872 this._lastMode.set(/** @type {!WebInspector.EmulatedDevice} */ (this
._model.device()), /** @type {!WebInspector.EmulatedDevice.Mode} */ (this._model
.mode())); | |
| 873 | |
| 874 if (this._model.mode() !== this._cachedModelMode && this._model.type() !
== WebInspector.DeviceModeModel.Type.None) { | |
| 875 this._cachedModelMode = this._model.mode(); | |
| 876 var value = this._persistenceSetting.get(); | |
| 877 if (this._model.device()) { | |
| 878 value.device = this._model.device().title; | |
| 879 value.orientation = this._model.mode() ? this._model.mode().orie
ntation : ""; | |
| 880 value.mode = this._model.mode() ? this._model.mode().title : ""; | |
| 881 } else { | |
| 882 value.device = ""; | |
| 883 value.orientation = ""; | |
| 884 value.mode = ""; | |
| 885 } | |
| 886 this._persistenceSetting.set(value); | |
| 887 } | |
| 888 }, | |
| 889 | |
| 890 restore: function() | |
| 891 { | |
| 892 for (var device of this._allDevices()) { | |
| 893 if (device.title === this._persistenceSetting.get().device) { | |
| 894 for (var mode of device.modes) { | |
| 895 if (mode.orientation === this._persistenceSetting.get().orie
ntation && mode.title === this._persistenceSetting.get().mode) { | |
| 896 this._lastMode.set(device, mode); | |
| 897 this._emulateDevice(device); | |
| 898 return; | |
| 899 } | |
| 900 } | |
| 901 } | |
| 902 } | |
| 903 | |
| 904 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); | |
| 905 } | |
| 906 } | |
| 907 | |
| 908 /** | |
| 909 * @constructor | 346 * @constructor |
| 910 * @extends {WebInspector.VBox} | 347 * @extends {WebInspector.VBox} |
| 911 * @param {boolean} horizontal | 348 * @param {boolean} horizontal |
| 912 * @param {function(number)} applyCallback | 349 * @param {function(number)} applyCallback |
| 913 */ | 350 */ |
| 914 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) | 351 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) |
| 915 { | 352 { |
| 916 WebInspector.VBox.call(this); | 353 WebInspector.VBox.call(this); |
| 917 this._contentElement = this.element.createChild("div", "device-mode-ruler fl
ex-auto"); | 354 this._contentElement = this.element.createChild("div", "device-mode-ruler fl
ex-auto"); |
| 918 this._horizontal = horizontal; | 355 this._horizontal = horizontal; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 /** | 442 /** |
| 1006 * @param {number} size | 443 * @param {number} size |
| 1007 */ | 444 */ |
| 1008 _onMarkerClick: function(size) | 445 _onMarkerClick: function(size) |
| 1009 { | 446 { |
| 1010 this._applyCallback.call(null, size); | 447 this._applyCallback.call(null, size); |
| 1011 }, | 448 }, |
| 1012 | 449 |
| 1013 __proto__: WebInspector.VBox.prototype | 450 __proto__: WebInspector.VBox.prototype |
| 1014 } | 451 } |
| 1015 | |
| 1016 | |
| 1017 /** | |
| 1018 * @constructor | |
| 1019 * @implements {WebInspector.ActionDelegate} | |
| 1020 */ | |
| 1021 WebInspector.DeviceModeView.ActionDelegate = function() | |
| 1022 { | |
| 1023 } | |
| 1024 | |
| 1025 WebInspector.DeviceModeView.ActionDelegate.prototype = { | |
| 1026 /** | |
| 1027 * @override | |
| 1028 * @param {!WebInspector.Context} context | |
| 1029 * @param {string} actionId | |
| 1030 * @return {boolean} | |
| 1031 */ | |
| 1032 handleAction: function(context, actionId) | |
| 1033 { | |
| 1034 if (WebInspector.DeviceModeView._wrapperInstance) { | |
| 1035 if (actionId === "emulation.toggle-device-mode") { | |
| 1036 WebInspector.DeviceModeView._wrapperInstance._toggleDeviceMode()
; | |
| 1037 return true; | |
| 1038 } | |
| 1039 if (actionId === "emulation.request-app-banner") { | |
| 1040 WebInspector.DeviceModeView._wrapperInstance._requestAppBanner()
; | |
| 1041 return true; | |
| 1042 } | |
| 1043 } | |
| 1044 return false; | |
| 1045 } | |
| 1046 } | |
| 1047 | |
| 1048 | |
| 1049 /** | |
| 1050 * @extends {WebInspector.VBox} | |
| 1051 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder | |
| 1052 * @constructor | |
| 1053 */ | |
| 1054 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder) | |
| 1055 { | |
| 1056 WebInspector.VBox.call(this); | |
| 1057 WebInspector.DeviceModeView._wrapperInstance = this; | |
| 1058 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | |
| 1059 /** @type {?WebInspector.DeviceModeView} */ | |
| 1060 this._deviceModeView = null; | |
| 1061 this._toggleDeviceModeAction = WebInspector.actionRegistry.action("emulation
.toggle-device-mode"); | |
| 1062 this._showDeviceModeSetting = WebInspector.settings.createSetting("emulation
.showDeviceMode", false); | |
| 1063 this._showDeviceModeSetting.addChangeListener(this._update.bind(this, false)
); | |
| 1064 this._update(true); | |
| 1065 } | |
| 1066 | |
| 1067 /** @type {!WebInspector.DeviceModeView.Wrapper} */ | |
| 1068 WebInspector.DeviceModeView._wrapperInstance; | |
| 1069 | |
| 1070 WebInspector.DeviceModeView.Wrapper.prototype = { | |
| 1071 _toggleDeviceMode: function() | |
| 1072 { | |
| 1073 this._showDeviceModeSetting.set(!this._showDeviceModeSetting.get()); | |
| 1074 }, | |
| 1075 | |
| 1076 /** | |
| 1077 * @param {boolean} force | |
| 1078 */ | |
| 1079 _update: function(force) | |
| 1080 { | |
| 1081 this._toggleDeviceModeAction.setToggled(this._showDeviceModeSetting.get(
)); | |
| 1082 if (!force) { | |
| 1083 var showing = this._deviceModeView && this._deviceModeView.isShowing
(); | |
| 1084 if (this._showDeviceModeSetting.get() === showing) | |
| 1085 return; | |
| 1086 } | |
| 1087 | |
| 1088 if (this._showDeviceModeSetting.get()) { | |
| 1089 if (!this._deviceModeView) | |
| 1090 this._deviceModeView = new WebInspector.DeviceModeView(); | |
| 1091 this._deviceModeView.show(this.element); | |
| 1092 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | |
| 1093 this._inspectedPagePlaceholder.show(this._deviceModeView.element); | |
| 1094 } else { | |
| 1095 if (this._deviceModeView) | |
| 1096 this._deviceModeView.detach(); | |
| 1097 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | |
| 1098 this._inspectedPagePlaceholder.show(this.element); | |
| 1099 } | |
| 1100 }, | |
| 1101 | |
| 1102 _requestAppBanner: function() | |
| 1103 { | |
| 1104 this._deviceModeView._model.requestAppBanner(); | |
| 1105 }, | |
| 1106 | |
| 1107 __proto__: WebInspector.VBox.prototype | |
| 1108 } | |
| OLD | NEW |