| OLD | NEW |
| 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 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * @param {!WebInspector.Toolbar} toolbar | 63 * @param {!WebInspector.Toolbar} toolbar |
| 64 */ | 64 */ |
| 65 _fillMainToolbar: function(toolbar) | 65 _fillMainToolbar: function(toolbar) |
| 66 { | 66 { |
| 67 var widthInput = createElementWithClass("input", "device-mode-size-input
"); | 67 var widthInput = createElementWithClass("input", "device-mode-size-input
"); |
| 68 widthInput.maxLength = 4; | 68 widthInput.maxLength = 4; |
| 69 widthInput.type = "text"; | 69 widthInput.type = "text"; |
| 70 widthInput.title = WebInspector.UIString("Width"); | 70 widthInput.title = WebInspector.UIString("Width"); |
| 71 this._updateWidthInput = this._bindInput(widthInput, this._model.setWidt
hAndScaleToFit.bind(this._model), WebInspector.DeviceModeModel.deviceSizeValidat
or); | 71 this._updateWidthInput = WebInspector.bindInput(widthInput, applyWidth.b
ind(this), WebInspector.DeviceModeModel.deviceSizeValidator, true); |
| 72 this._widthInput = widthInput; | 72 this._widthInput = widthInput; |
| 73 this._widthItem = this._wrapToolbarItem(widthInput); | 73 this._widthItem = this._wrapToolbarItem(widthInput); |
| 74 toolbar.appendToolbarItem(this._widthItem); | 74 toolbar.appendToolbarItem(this._widthItem); |
| 75 | 75 |
| 76 var xElement = createElementWithClass("div", "device-mode-x"); | 76 var xElement = createElementWithClass("div", "device-mode-x"); |
| 77 xElement.textContent = "\u00D7"; | 77 xElement.textContent = "\u00D7"; |
| 78 this._xItem = this._wrapToolbarItem(xElement); | 78 this._xItem = this._wrapToolbarItem(xElement); |
| 79 toolbar.appendToolbarItem(this._xItem); | 79 toolbar.appendToolbarItem(this._xItem); |
| 80 | 80 |
| 81 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); | 81 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); |
| 82 heightInput.maxLength = 4; | 82 heightInput.maxLength = 4; |
| 83 heightInput.type = "text"; | 83 heightInput.type = "text"; |
| 84 heightInput.title = WebInspector.UIString("Height (leave empty for full)
"); | 84 heightInput.title = WebInspector.UIString("Height (leave empty for full)
"); |
| 85 this._updateHeightInput = this._bindInput(heightInput, this._model.setHe
ightAndScaleToFit.bind(this._model), validateHeight); | 85 this._updateHeightInput = WebInspector.bindInput(heightInput, applyHeigh
t.bind(this), validateHeight, true); |
| 86 this._heightInput = heightInput; | 86 this._heightInput = heightInput; |
| 87 this._heightItem = this._wrapToolbarItem(heightInput); | 87 this._heightItem = this._wrapToolbarItem(heightInput); |
| 88 toolbar.appendToolbarItem(this._heightItem); | 88 toolbar.appendToolbarItem(this._heightItem); |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * @param {string} value | 91 * @param {string} value |
| 92 * @return {string} | 92 * @return {boolean} |
| 93 */ | 93 */ |
| 94 function validateHeight(value) | 94 function validateHeight(value) |
| 95 { | 95 { |
| 96 return !value ? "" : WebInspector.DeviceModeModel.deviceSizeValidato
r(value); | 96 return !value || WebInspector.DeviceModeModel.deviceSizeValidator(va
lue); |
| 97 } |
| 98 |
| 99 /** |
| 100 * @param {string} value |
| 101 * @this {WebInspector.DeviceModeToolbar} |
| 102 */ |
| 103 function applyWidth(value) |
| 104 { |
| 105 var width = value ? Number(value) : 0; |
| 106 this._model.setWidthAndScaleToFit(width); |
| 107 } |
| 108 |
| 109 /** |
| 110 * @param {string} value |
| 111 * @this {WebInspector.DeviceModeToolbar} |
| 112 */ |
| 113 function applyHeight(value) |
| 114 { |
| 115 var height = value ? Number(value) : 0; |
| 116 this._model.setHeightAndScaleToFit(height); |
| 97 } | 117 } |
| 98 }, | 118 }, |
| 99 | 119 |
| 100 /** | 120 /** |
| 101 * @param {!WebInspector.Toolbar} toolbar | 121 * @param {!WebInspector.Toolbar} toolbar |
| 102 */ | 122 */ |
| 103 _fillRightToolbar: function(toolbar) | 123 _fillRightToolbar: function(toolbar) |
| 104 { | 124 { |
| 105 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | 125 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); |
| 106 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe
nuItems.bind(this)); | 126 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe
nuItems.bind(this)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 158 |
| 139 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO
ptionsMenuItems.bind(this)); | 159 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO
ptionsMenuItems.bind(this)); |
| 140 moreOptionsButton.setTitle(WebInspector.UIString("More options")); | 160 moreOptionsButton.setTitle(WebInspector.UIString("More options")); |
| 141 toolbar.appendToolbarItem(moreOptionsButton); | 161 toolbar.appendToolbarItem(moreOptionsButton); |
| 142 | 162 |
| 143 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); | 163 toolbar.appendToolbarItem(this._wrapToolbarItem(createElementWithClass("
div", "device-mode-empty-toolbar-element"))); |
| 144 }, | 164 }, |
| 145 | 165 |
| 146 | 166 |
| 147 /** | 167 /** |
| 148 * @param {!Element} input | |
| 149 * @param {function(number)} apply | |
| 150 * @param {function(string):?string} validate | |
| 151 * @return {function(number)} | |
| 152 */ | |
| 153 _bindInput: function(input, apply, validate) | |
| 154 { | |
| 155 input.addEventListener("change", onChange, false); | |
| 156 input.addEventListener("input", onInput, false); | |
| 157 input.addEventListener("keydown", onKeyDown, false); | |
| 158 input.addEventListener("focus", input.select.bind(input), false); | |
| 159 | |
| 160 function onInput() | |
| 161 { | |
| 162 input.classList.toggle("error-input", !!validate(input.value)); | |
| 163 } | |
| 164 | |
| 165 function onChange() | |
| 166 { | |
| 167 var valid = !validate(input.value); | |
| 168 input.classList.toggle("error-input", !valid); | |
| 169 if (valid) | |
| 170 apply(input.value ? Number(input.value) : 0); | |
| 171 } | |
| 172 | |
| 173 /** | |
| 174 * @param {!Event} event | |
| 175 */ | |
| 176 function onKeyDown(event) | |
| 177 { | |
| 178 if (isEnterKey(event)) { | |
| 179 if (!validate(input.value)) | |
| 180 apply(input.value ? Number(input.value) : 0); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 184 var increment = event.keyIdentifier === "Up" ? 1 : event.keyIdentifi
er === "Down" ? -1 : 0; | |
| 185 if (!increment) | |
| 186 return; | |
| 187 if (event.shiftKey) | |
| 188 increment *= 10; | |
| 189 | |
| 190 var value = input.value; | |
| 191 if (validate(value) || !value) | |
| 192 return; | |
| 193 | |
| 194 value = (value ? Number(value) : 0) + increment; | |
| 195 var stringValue = value ? String(value) : ""; | |
| 196 if (validate(stringValue) || !value) | |
| 197 return; | |
| 198 | |
| 199 input.value = stringValue; | |
| 200 apply(input.value ? Number(input.value) : 0); | |
| 201 event.preventDefault(); | |
| 202 } | |
| 203 | |
| 204 /** | |
| 205 * @param {number} value | |
| 206 */ | |
| 207 function setValue(value) | |
| 208 { | |
| 209 var stringValue = value ? String(value) : ""; | |
| 210 if (stringValue === input.value) | |
| 211 return; | |
| 212 var valid = !validate(stringValue); | |
| 213 input.classList.toggle("error-input", !valid); | |
| 214 input.value = stringValue; | |
| 215 input.setSelectionRange(stringValue.length, stringValue.length); | |
| 216 } | |
| 217 | |
| 218 return setValue; | |
| 219 }, | |
| 220 | |
| 221 /** | |
| 222 * @param {!WebInspector.ContextMenu} contextMenu | 168 * @param {!WebInspector.ContextMenu} contextMenu |
| 223 */ | 169 */ |
| 224 _appendScaleMenuItems: function(contextMenu) | 170 _appendScaleMenuItems: function(contextMenu) |
| 225 { | 171 { |
| 226 var scaleSetting = this._model.scaleSetting(); | 172 var scaleSetting = this._model.scaleSetting(); |
| 227 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { | 173 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { |
| 228 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)
", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode
l.fitScale()), false); | 174 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)
", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode
l.fitScale()), false); |
| 229 contextMenu.appendSeparator(); | 175 contextMenu.appendSeparator(); |
| 230 } | 176 } |
| 231 appendScaleItem(WebInspector.UIString("50%"), 0.5); | 177 appendScaleItem(WebInspector.UIString("50%"), 0.5); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 425 |
| 480 update: function() | 426 update: function() |
| 481 { | 427 { |
| 482 if (this._model.type() !== this._cachedModelType) { | 428 if (this._model.type() !== this._cachedModelType) { |
| 483 this._cachedModelType = this._model.type(); | 429 this._cachedModelType = this._model.type(); |
| 484 this._widthInput.disabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; | 430 this._widthInput.disabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; |
| 485 this._heightInput.disabled = this._model.type() !== WebInspector.Dev
iceModeModel.Type.Responsive; | 431 this._heightInput.disabled = this._model.type() !== WebInspector.Dev
iceModeModel.Type.Responsive; |
| 486 } | 432 } |
| 487 | 433 |
| 488 var size = this._model.appliedDeviceSize(); | 434 var size = this._model.appliedDeviceSize(); |
| 489 this._updateHeightInput(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && this._model.isFullHeight() ? 0 : size.height); | 435 this._updateHeightInput(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && this._model.isFullHeight() ? "" : String(size.height)); |
| 490 this._updateWidthInput(size.width); | 436 this._updateWidthInput(String(size.width)); |
| 491 this._heightInput.placeholder = size.height; | 437 this._heightInput.placeholder = size.height; |
| 492 | 438 |
| 493 if (this._model.scale() !== this._cachedScale) { | 439 if (this._model.scale() !== this._cachedScale) { |
| 494 this._scaleItem.setText(WebInspector.UIString("%.0f%%", this._model.
scale() * 100)); | 440 this._scaleItem.setText(WebInspector.UIString("%.0f%%", this._model.
scale() * 100)); |
| 495 this._scaleItem.setState(this._model.scale() === 1 ? "off" : "on"); | 441 this._scaleItem.setState(this._model.scale() === 1 ? "off" : "on"); |
| 496 this._cachedScale = this._model.scale(); | 442 this._cachedScale = this._model.scale(); |
| 497 } | 443 } |
| 498 | 444 |
| 499 var deviceScale = this._model.deviceScaleFactorSetting().get(); | 445 var deviceScale = this._model.deviceScaleFactorSetting().get(); |
| 500 this._deviceScaleItem.setVisible(this._model.type() === WebInspector.Dev
iceModeModel.Type.Responsive && !!deviceScale); | 446 this._deviceScaleItem.setVisible(this._model.type() === WebInspector.Dev
iceModeModel.Type.Responsive && !!deviceScale); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 this._emulateDevice(device); | 503 this._emulateDevice(device); |
| 558 return; | 504 return; |
| 559 } | 505 } |
| 560 } | 506 } |
| 561 } | 507 } |
| 562 } | 508 } |
| 563 | 509 |
| 564 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); | 510 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); |
| 565 } | 511 } |
| 566 } | 512 } |
| OLD | NEW |