| 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 { |
| 11 WebInspector.VBox.call(this, true); | 11 WebInspector.VBox.call(this, true); |
| 12 this.setMinimumSize(150, 150); | 12 this.setMinimumSize(150, 150); |
| 13 this.element.classList.add("device-mode-view"); | 13 this.element.classList.add("device-mode-view"); |
| 14 this.registerRequiredCSS("emulation/deviceModeView.css"); | 14 this.registerRequiredCSS("emulation/deviceModeView.css"); |
| 15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement); | 15 WebInspector.Tooltip.addNativeOverrideContainer(this.contentElement); |
| 16 | 16 |
| 17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this)); | 17 this._model = new WebInspector.DeviceModeModel(this._updateUI.bind(this)); |
| 18 this._mediaInspector = new WebInspector.MediaQueryInspector(() => this._mode
l.appliedDeviceSize().width, this._model.setWidth.bind(this._model)); | 18 this._mediaInspector = new WebInspector.MediaQueryInspector(() => this._mode
l.appliedDeviceSize().width, this._model.setWidth.bind(this._model)); |
| 19 // TODO(dgozman): remove CountUpdated event. | 19 // TODO(dgozman): remove CountUpdated event. |
| 20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM
ediaQueryInspector", false); | 20 this._showMediaInspectorSetting = WebInspector.settings.createSetting("showM
ediaQueryInspector", false); |
| 21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this); | 21 this._showMediaInspectorSetting.addChangeListener(this._updateUI, this); |
| 22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho
wRulers", false); | 22 this._showRulersSetting = WebInspector.settings.createSetting("emulation.sho
wRulers", false); |
| 23 this._showRulersSetting.addChangeListener(this._updateUI, this); | 23 this._showRulersSetting.addChangeListener(this._updateUI, this); |
| 24 | 24 |
| 25 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.set
Width.bind(this._model)); | 25 this._topRuler = new WebInspector.DeviceModeView.Ruler(true, this._model.set
WidthAndScaleToFit.bind(this._model)); |
| 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
etHeight.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.DeviceModeView.Toolbar(this._model, thi
s._showMediaInspectorSetting, this._showRulersSetting); |
| 37 this.contentElement.appendChild(this._toolbar.element()); | 37 this.contentElement.appendChild(this._toolbar.element()); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 if (mediaInspectorVisible) | 218 if (mediaInspectorVisible) |
| 219 this._mediaInspector.show(this._mediaInspectorContainer); | 219 this._mediaInspector.show(this._mediaInspectorContainer); |
| 220 else | 220 else |
| 221 this._mediaInspector.detach(); | 221 this._mediaInspector.detach(); |
| 222 contentAreaResized = true; | 222 contentAreaResized = true; |
| 223 callDoResize = true; | 223 callDoResize = true; |
| 224 this._cachedMediaInspectorVisible = mediaInspectorVisible; | 224 this._cachedMediaInspectorVisible = mediaInspectorVisible; |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (showRulers !== this._cachedShowRulers) { | 227 if (showRulers !== this._cachedShowRulers) { |
| 228 this._contentArea.classList.toggle("device-mode-rulers-visible", sho
wRulers); | 228 this._contentClip.classList.toggle("device-mode-rulers-visible", sho
wRulers); |
| 229 if (showRulers) { | 229 if (showRulers) { |
| 230 this._topRuler.show(this._contentClip, this._contentArea); | 230 this._topRuler.show(this._contentClip, this._contentArea); |
| 231 this._leftRuler.show(this._contentArea); | 231 this._leftRuler.show(this._contentArea); |
| 232 } else { | 232 } else { |
| 233 this._topRuler.detach(); | 233 this._topRuler.detach(); |
| 234 this._leftRuler.detach(); | 234 this._leftRuler.detach(); |
| 235 } | 235 } |
| 236 contentAreaResized = true; | 236 contentAreaResized = true; |
| 237 callDoResize = true; | 237 callDoResize = true; |
| 238 this._cachedShowRulers = showRulers; | 238 this._cachedShowRulers = showRulers; |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (this._model.scale() !== this._cachedScale) { | 241 if (this._model.scale() !== this._cachedScale) { |
| 242 updateRulers = true; | 242 updateRulers = true; |
| 243 callDoResize = true; |
| 243 for (var block of this._presetBlocks) | 244 for (var block of this._presetBlocks) |
| 244 block.style.width = block.__width * this._model.scale() + "px"; | 245 block.style.width = block.__width * this._model.scale() + "px"; |
| 245 this._cachedScale = this._model.scale(); | 246 this._cachedScale = this._model.scale(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 this._toolbar.update(); | 249 this._toolbar.update(); |
| 249 this._loadScreenImage(this._model.screenImage()); | 250 this._loadScreenImage(this._model.screenImage()); |
| 250 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); | 251 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); |
| 251 if (callDoResize) | 252 if (callDoResize) |
| 252 this.doResize(); | 253 this.doResize(); |
| 253 if (updateRulers) { | 254 if (updateRulers) { |
| 254 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); | 255 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); |
| 255 this._leftRuler.render(0, this._model.scale()); | 256 this._leftRuler.render(0, this._model.scale()); |
| 256 } | 257 } |
| 257 if (contentAreaResized) | 258 if (contentAreaResized) |
| 258 this._contentAreaResized(); | 259 this._contentAreaResized(); |
| 259 | |
| 260 if (this._model.type() !== this._cachedModelType) { | |
| 261 this._cachedModelType = this._model.type(); | |
| 262 this._contentArea.classList.toggle("device-mode-type-none", this._ca
chedModelType === WebInspector.DeviceModeModel.Type.None); | |
| 263 this._contentArea.classList.toggle("device-mode-type-responsive", th
is._cachedModelType === WebInspector.DeviceModeModel.Type.Responsive); | |
| 264 this._contentArea.classList.toggle("device-mode-type-device", this._
cachedModelType === WebInspector.DeviceModeModel.Type.Device); | |
| 265 this._responsivePresetsContainer.classList.toggle("hidden", this._ca
chedModelType === WebInspector.DeviceModeModel.Type.None); | |
| 266 } | |
| 267 }, | 260 }, |
| 268 | 261 |
| 269 /** | 262 /** |
| 270 * @param {string} srcset | 263 * @param {string} srcset |
| 271 */ | 264 */ |
| 272 _loadScreenImage: function(srcset) | 265 _loadScreenImage: function(srcset) |
| 273 { | 266 { |
| 274 if (this._screenImage.getAttribute("srcset") === srcset) | 267 if (this._screenImage.getAttribute("srcset") === srcset) |
| 275 return; | 268 return; |
| 276 this._screenImage.setAttribute("srcset", srcset); | 269 this._screenImage.setAttribute("srcset", srcset); |
| 277 if (!srcset) | 270 if (!srcset) |
| 278 this._screenImage.classList.toggle("hidden", true); | 271 this._screenImage.classList.toggle("hidden", true); |
| 279 }, | 272 }, |
| 280 | 273 |
| 281 /** | 274 /** |
| 282 * @param {boolean} success | 275 * @param {boolean} success |
| 283 */ | 276 */ |
| 284 _onScreenImageLoaded: function(success) | 277 _onScreenImageLoaded: function(success) |
| 285 { | 278 { |
| 286 this._screenImage.classList.toggle("hidden", !success); | 279 this._screenImage.classList.toggle("hidden", !success); |
| 287 }, | 280 }, |
| 288 | 281 |
| 289 _contentAreaResized: function() | 282 _contentAreaResized: function() |
| 290 { | 283 { |
| 291 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 284 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 292 var rect = this._contentArea.getBoundingClientRect(); | 285 var rect = this._contentArea.getBoundingClientRect(); |
| 293 this._handleWidth = this._handleWidth || this._widthResizerElement.offse
tWidth; | |
| 294 this._handleHeight = this._handleHeight || this._heightResizerElement.of
fsetHeight; | |
| 295 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); | 286 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); |
| 296 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt
h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1
)); | 287 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt
h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1
)); |
| 297 this._model.setAvailableSize(availableSize, preferredSize); | 288 this._model.setAvailableSize(availableSize, preferredSize); |
| 298 }, | 289 }, |
| 299 | 290 |
| 291 _measureHandles: function() |
| 292 { |
| 293 var hidden = this._widthResizerElement.classList.contains("hidden"); |
| 294 this._widthResizerElement.classList.toggle("hidden", false); |
| 295 this._heightResizerElement.classList.toggle("hidden", false); |
| 296 this._handleWidth = this._widthResizerElement.offsetWidth; |
| 297 this._handleHeight = this._heightResizerElement.offsetHeight; |
| 298 this._widthResizerElement.classList.toggle("hidden", hidden); |
| 299 this._heightResizerElement.classList.toggle("hidden", hidden); |
| 300 }, |
| 301 |
| 300 _zoomChanged: function() | 302 _zoomChanged: function() |
| 301 { | 303 { |
| 302 delete this._handleWidth; | 304 delete this._handleWidth; |
| 303 delete this._handleHeight; | 305 delete this._handleHeight; |
| 304 if (this.isShowing()) | 306 if (this.isShowing()) { |
| 307 this._measureHandles(); |
| 305 this._contentAreaResized(); | 308 this._contentAreaResized(); |
| 309 } |
| 306 }, | 310 }, |
| 307 | 311 |
| 308 /** | 312 /** |
| 309 * @override | 313 * @override |
| 310 */ | 314 */ |
| 311 onResize: function() | 315 onResize: function() |
| 312 { | 316 { |
| 313 if (this.isShowing()) | 317 if (this.isShowing()) |
| 314 this._contentAreaResized(); | 318 this._contentAreaResized(); |
| 315 }, | 319 }, |
| 316 | 320 |
| 317 /** | 321 /** |
| 318 * @override | 322 * @override |
| 319 */ | 323 */ |
| 320 wasShown: function() | 324 wasShown: function() |
| 321 { | 325 { |
| 326 this._measureHandles(); |
| 322 this._mediaInspector.setEnabled(true); | 327 this._mediaInspector.setEnabled(true); |
| 323 this._toolbar.restore(); | 328 this._toolbar.restore(); |
| 324 }, | 329 }, |
| 325 | 330 |
| 326 /** | 331 /** |
| 327 * @override | 332 * @override |
| 328 */ | 333 */ |
| 329 willHide: function() | 334 willHide: function() |
| 330 { | 335 { |
| 331 this._mediaInspector.setEnabled(false); | 336 this._mediaInspector.setEnabled(false); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 342 */ | 347 */ |
| 343 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting,
showRulersSetting) | 348 WebInspector.DeviceModeView.Toolbar = function(model, showMediaInspectorSetting,
showRulersSetting) |
| 344 { | 349 { |
| 345 this._model = model; | 350 this._model = model; |
| 346 this._showMediaInspectorSetting = showMediaInspectorSetting; | 351 this._showMediaInspectorSetting = showMediaInspectorSetting; |
| 347 this._showRulersSetting = showRulersSetting; | 352 this._showRulersSetting = showRulersSetting; |
| 348 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ | 353 /** @type {!Map<!WebInspector.EmulatedDevice, !WebInspector.EmulatedDevice.M
ode>} */ |
| 349 this._lastMode = new Map(); | 354 this._lastMode = new Map(); |
| 350 /** @type {?WebInspector.EmulatedDevice} */ | 355 /** @type {?WebInspector.EmulatedDevice} */ |
| 351 this._lastDevice = null; | 356 this._lastDevice = null; |
| 352 /** @type {!Array<!WebInspector.ToolbarButton>} */ | |
| 353 this._appliedSizeItems = []; | |
| 354 /** @type {!Array<!WebInspector.ToolbarMenuButton>} */ | |
| 355 this._scaleItems = []; | |
| 356 /** @type {?Element} */ | |
| 357 this._visibleToolbar = null; | |
| 358 | 357 |
| 359 this._element = createElementWithClass("div", "device-mode-toolbar"); | 358 this._element = createElementWithClass("div", "device-mode-toolbar"); |
| 360 | 359 |
| 361 var leftContainer = this._element.createChild("div", "device-mode-toolbar-le
ft"); | 360 var leftContainer = this._element.createChild("div", "device-mode-toolbar-sp
acer"); |
| 361 leftContainer.createChild("div", "device-mode-toolbar-spacer"); |
| 362 var leftToolbar = new WebInspector.Toolbar("", leftContainer); | 362 var leftToolbar = new WebInspector.Toolbar("", leftContainer); |
| 363 this._noneItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Full"
), "enter-fullscreen-toolbar-item"); | 363 leftToolbar.makeWrappable(); |
| 364 leftToolbar.appendToolbarItem(this._noneItem); | 364 this._fillLeftToolbar(leftToolbar); |
| 365 this._noneItem.addEventListener("click", this._noneButtonClick, this); | |
| 366 this._responsiveItem = new WebInspector.ToolbarToggle(WebInspector.UIString(
"Responsive"), "responsive-toolbar-item"); | |
| 367 leftToolbar.appendToolbarItem(this._responsiveItem); | |
| 368 this._responsiveItem.addEventListener("click", this._responsiveButtonClick,
this); | |
| 369 this._deviceItem = new WebInspector.ToolbarToggle(WebInspector.UIString("Dev
ice"), "phone-toolbar-item"); | |
| 370 leftToolbar.appendToolbarItem(this._deviceItem); | |
| 371 this._deviceItem.addEventListener("click", this._deviceButtonClick, this); | |
| 372 leftToolbar.appendSeparator(); | |
| 373 | 365 |
| 374 var middle = this._element.createChild("div", "device-mode-toolbar-middle-co
ntainer"); | 366 var mainToolbar = new WebInspector.Toolbar("", this._element); |
| 375 this._noneToolbar = this._wrapMiddleToolbar(middle, this._createNoneToolbar(
)); | 367 mainToolbar.makeWrappable(); |
| 376 this._responsiveToolbar = this._wrapMiddleToolbar(middle, this._createRespon
siveToolbar()); | 368 this._fillMainToolbar(mainToolbar); |
| 377 this._deviceToolbar = this._wrapMiddleToolbar(middle, this._createDeviceTool
bar()); | |
| 378 | 369 |
| 379 var rightContainer = this._element.createChild("div", "device-mode-toolbar-r
ight"); | 370 var rightContainer = this._element.createChild("div", "device-mode-toolbar-s
pacer"); |
| 371 var rightToolbar = new WebInspector.Toolbar("", rightContainer); |
| 372 this._fillRightToolbar(rightToolbar); |
| 373 var modeToolbar = new WebInspector.Toolbar("", rightContainer); |
| 374 this._fillModeToolbar(modeToolbar); |
| 380 rightContainer.createChild("div", "device-mode-toolbar-spacer"); | 375 rightContainer.createChild("div", "device-mode-toolbar-spacer"); |
| 381 var rightToolbar = new WebInspector.Toolbar("", rightContainer); | 376 var optionsToolbar = new WebInspector.Toolbar("", rightContainer); |
| 382 rightToolbar.makeWrappable(true); | 377 optionsToolbar.makeWrappable(true); |
| 383 this._uaItem = new WebInspector.ToolbarText(); | 378 this._fillOptionsToolbar(optionsToolbar); |
| 384 this._uaItem.setVisible(false); | |
| 385 this._uaItem.setTitle(WebInspector.UIString("User agent type")); | |
| 386 rightToolbar.appendToolbarItem(this._uaItem); | |
| 387 this._deviceScaleItem = new WebInspector.ToolbarText(); | |
| 388 this._deviceScaleItem.setVisible(false); | |
| 389 this._deviceScaleItem.setTitle(WebInspector.UIString("Device pixel ratio")); | |
| 390 rightToolbar.appendToolbarItem(this._deviceScaleItem); | |
| 391 rightToolbar.appendSeparator(); | |
| 392 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendMenuI
tems.bind(this)); | |
| 393 moreOptionsButton.setTitle(WebInspector.UIString("More options")); | |
| 394 rightToolbar.appendToolbarItem(moreOptionsButton); | |
| 395 | 379 |
| 396 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.None, device:
"", orientation: "", mode: ""}); | 380 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.CustomDevicesUpdated, this._deviceListChanged, this); |
| 381 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedDevic
esList.Events.StandardDevicesUpdated, this._deviceListChanged, this); |
| 382 |
| 383 this._persistenceSetting = WebInspector.settings.createSetting("emulation.de
viceModeViewPersistence", {type: WebInspector.DeviceModeModel.Type.Responsive, d
evice: "", orientation: "", mode: ""}); |
| 397 this._restored = false; | 384 this._restored = false; |
| 398 } | 385 } |
| 399 | 386 |
| 400 WebInspector.DeviceModeView.Toolbar.prototype = { | 387 WebInspector.DeviceModeView.Toolbar.prototype = { |
| 401 /** | 388 /** |
| 402 * @param {!Element} parent | |
| 403 * @param {!WebInspector.Toolbar} toolbar | 389 * @param {!WebInspector.Toolbar} toolbar |
| 404 * @return {!Element} | |
| 405 */ | 390 */ |
| 406 _wrapMiddleToolbar: function(parent, toolbar) | 391 _fillLeftToolbar: function(toolbar) |
| 407 { | 392 { |
| 408 toolbar.makeWrappable(); | 393 this._deviceSelectItem = new WebInspector.ToolbarMenuButton(this._append
DeviceMenuItems.bind(this)); |
| 409 var container = parent.createChild("div", "device-mode-toolbar-middle fi
ll"); | 394 this._deviceSelectItem.setGlyph(""); |
| 410 container.createChild("div", "device-mode-toolbar-spacer"); | 395 this._deviceSelectItem.turnIntoSelect(95); |
| 411 container.appendChild(toolbar.element); | 396 toolbar.appendToolbarItem(this._deviceSelectItem); |
| 412 container.createChild("div", "device-mode-toolbar-spacer"); | |
| 413 container.classList.add("hidden"); | |
| 414 return container; | |
| 415 }, | 397 }, |
| 416 | 398 |
| 417 /** | 399 /** |
| 418 * @return {!WebInspector.Toolbar} | 400 * @param {!WebInspector.Toolbar} toolbar |
| 419 */ | 401 */ |
| 420 _createNoneToolbar: function() | 402 _fillMainToolbar: function(toolbar) |
| 421 { | 403 { |
| 422 var toolbar = new WebInspector.Toolbar(""); | |
| 423 this._appendAppliedSizeItems(toolbar); | |
| 424 return toolbar; | |
| 425 }, | |
| 426 | |
| 427 /** | |
| 428 * @return {!WebInspector.Toolbar} | |
| 429 */ | |
| 430 _createResponsiveToolbar: function() | |
| 431 { | |
| 432 var toolbar = new WebInspector.Toolbar(""); | |
| 433 | |
| 434 var widthInput = createElementWithClass("input", "device-mode-size-input
"); | 404 var widthInput = createElementWithClass("input", "device-mode-size-input
"); |
| 435 widthInput.maxLength = 5; | 405 widthInput.maxLength = 4; |
| 406 widthInput.type = "text"; |
| 436 widthInput.title = WebInspector.UIString("Width"); | 407 widthInput.title = WebInspector.UIString("Width"); |
| 437 this._updateWidthInput = this._bindInput(widthInput, this._model.setWidt
h.bind(this._model), WebInspector.DeviceModeModel.deviceSizeValidator); | 408 this._updateWidthInput = this._bindInput(widthInput, this._model.setWidt
hAndScaleToFit.bind(this._model), WebInspector.DeviceModeModel.deviceSizeValidat
or); |
| 438 toolbar.appendToolbarItem(this._wrapToolbarItem(widthInput)); | 409 this._widthInput = widthInput; |
| 410 this._widthItem = this._wrapToolbarItem(widthInput); |
| 411 toolbar.appendToolbarItem(this._widthItem); |
| 439 | 412 |
| 440 var xElement = createElementWithClass("div", "device-mode-x"); | 413 var xElement = createElementWithClass("div", "device-mode-x"); |
| 441 xElement.textContent = "\u00D7"; | 414 xElement.textContent = "\u00D7"; |
| 442 toolbar.appendToolbarItem(this._wrapToolbarItem(xElement)); | 415 this._xItem = this._wrapToolbarItem(xElement); |
| 416 toolbar.appendToolbarItem(this._xItem); |
| 443 | 417 |
| 444 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); | 418 var heightInput = createElementWithClass("input", "device-mode-size-inpu
t"); |
| 445 heightInput.maxLength = 5; | 419 heightInput.maxLength = 4; |
| 420 heightInput.type = "text"; |
| 446 heightInput.title = WebInspector.UIString("Height (leave empty for full)
"); | 421 heightInput.title = WebInspector.UIString("Height (leave empty for full)
"); |
| 447 this._updateHeightInput = this._bindInput(heightInput, this._model.setHe
ight.bind(this._model), validateHeight); | 422 this._updateHeightInput = this._bindInput(heightInput, this._model.setHe
ightAndScaleToFit.bind(this._model), validateHeight); |
| 448 toolbar.appendToolbarItem(this._wrapToolbarItem(heightInput)); | |
| 449 this._heightInput = heightInput; | 423 this._heightInput = heightInput; |
| 450 | 424 this._heightItem = this._wrapToolbarItem(heightInput); |
| 451 toolbar.appendSeparator(); | 425 toolbar.appendToolbarItem(this._heightItem); |
| 452 this._appendScaleItem(toolbar); | |
| 453 return toolbar; | |
| 454 | 426 |
| 455 /** | 427 /** |
| 456 * @param {string} value | 428 * @param {string} value |
| 457 * @return {string} | 429 * @return {string} |
| 458 */ | 430 */ |
| 459 function validateHeight(value) | 431 function validateHeight(value) |
| 460 { | 432 { |
| 461 return !value ? "" : WebInspector.DeviceModeModel.deviceSizeValidato
r(value); | 433 return !value ? "" : WebInspector.DeviceModeModel.deviceSizeValidato
r(value); |
| 462 } | 434 } |
| 463 }, | 435 }, |
| 464 | 436 |
| 465 /** | 437 /** |
| 438 * @param {!WebInspector.Toolbar} toolbar |
| 439 */ |
| 440 _fillRightToolbar: function(toolbar) |
| 441 { |
| 442 this._scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMe
nuItems.bind(this)); |
| 443 this._scaleItem.setTitle(WebInspector.UIString("Zoom")); |
| 444 this._scaleItem.setGlyph(""); |
| 445 this._scaleItem.turnIntoSelect(); |
| 446 toolbar.appendToolbarItem(this._scaleItem); |
| 447 }, |
| 448 |
| 449 /** |
| 450 * @param {!WebInspector.Toolbar} toolbar |
| 451 */ |
| 452 _fillModeToolbar: function(toolbar) |
| 453 { |
| 454 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); |
| 455 this._modeButton.addEventListener("click", this._modeMenuClicked, this); |
| 456 toolbar.appendToolbarItem(this._modeButton); |
| 457 }, |
| 458 |
| 459 /** |
| 460 * @param {!WebInspector.Toolbar} toolbar |
| 461 */ |
| 462 _fillOptionsToolbar: function(toolbar) |
| 463 { |
| 464 this._uaItem = new WebInspector.ToolbarText(); |
| 465 this._uaItem.setVisible(false); |
| 466 this._uaItem.setTitle(WebInspector.UIString("User agent type")); |
| 467 toolbar.appendToolbarItem(this._uaItem); |
| 468 |
| 469 this._deviceScaleItem = new WebInspector.ToolbarText(); |
| 470 this._deviceScaleItem.setVisible(false); |
| 471 this._deviceScaleItem.setTitle(WebInspector.UIString("Device pixel ratio
")); |
| 472 toolbar.appendToolbarItem(this._deviceScaleItem); |
| 473 |
| 474 var moreOptionsButton = new WebInspector.ToolbarMenuButton(this._appendO
ptionsMenuItems.bind(this)); |
| 475 moreOptionsButton.setTitle(WebInspector.UIString("More options")); |
| 476 toolbar.appendToolbarItem(moreOptionsButton); |
| 477 }, |
| 478 |
| 479 |
| 480 /** |
| 466 * @param {!Element} input | 481 * @param {!Element} input |
| 467 * @param {function(number)} apply | 482 * @param {function(number)} apply |
| 468 * @param {function(string):?string} validate | 483 * @param {function(string):?string} validate |
| 469 * @return {function(number)} | 484 * @return {function(number)} |
| 470 */ | 485 */ |
| 471 _bindInput: function(input, apply, validate) | 486 _bindInput: function(input, apply, validate) |
| 472 { | 487 { |
| 473 input.addEventListener("change", onChange, false); | 488 input.addEventListener("change", onChange, false); |
| 474 input.addEventListener("input", onInput, false); | 489 input.addEventListener("input", onInput, false); |
| 475 input.addEventListener("keydown", onKeyDown, false); | 490 input.addEventListener("keydown", onKeyDown, false); |
| 491 input.addEventListener("focus", input.select.bind(input), false); |
| 476 | 492 |
| 477 function onInput() | 493 function onInput() |
| 478 { | 494 { |
| 479 input.classList.toggle("error-input", !!validate(input.value)); | 495 input.classList.toggle("error-input", !!validate(input.value)); |
| 480 } | 496 } |
| 481 | 497 |
| 482 function onChange() | 498 function onChange() |
| 483 { | 499 { |
| 484 var valid = !validate(input.value); | 500 var valid = !validate(input.value); |
| 485 input.classList.toggle("error-input", !valid); | 501 input.classList.toggle("error-input", !valid); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 var valid = !validate(stringValue); | 545 var valid = !validate(stringValue); |
| 530 input.classList.toggle("error-input", !valid); | 546 input.classList.toggle("error-input", !valid); |
| 531 input.value = stringValue; | 547 input.value = stringValue; |
| 532 input.setSelectionRange(stringValue.length, stringValue.length); | 548 input.setSelectionRange(stringValue.length, stringValue.length); |
| 533 } | 549 } |
| 534 | 550 |
| 535 return setValue; | 551 return setValue; |
| 536 }, | 552 }, |
| 537 | 553 |
| 538 /** | 554 /** |
| 539 * @return {!WebInspector.Toolbar} | |
| 540 */ | |
| 541 _createDeviceToolbar: function() | |
| 542 { | |
| 543 var toolbar = new WebInspector.Toolbar(""); | |
| 544 | |
| 545 this._deviceSelect = this._createDeviceSelect(); | |
| 546 toolbar.appendToolbarItem(this._wrapToolbarItem(this._deviceSelect)); | |
| 547 | |
| 548 this._modeButton = new WebInspector.ToolbarButton("", "rotate-screen-too
lbar-item"); | |
| 549 this._modeButton.addEventListener("click", this._modeMenuClicked, this); | |
| 550 toolbar.appendToolbarItem(this._modeButton); | |
| 551 | |
| 552 toolbar.appendSeparator(); | |
| 553 this._appendAppliedSizeItems(toolbar); | |
| 554 toolbar.appendSeparator(); | |
| 555 this._appendScaleItem(toolbar); | |
| 556 | |
| 557 return toolbar; | |
| 558 }, | |
| 559 | |
| 560 /** | |
| 561 * @param {!WebInspector.Toolbar} toolbar | |
| 562 */ | |
| 563 _appendAppliedSizeItems: function(toolbar) | |
| 564 { | |
| 565 var item = new WebInspector.ToolbarText(""); | |
| 566 this._appliedSizeItems.push(item); | |
| 567 toolbar.appendToolbarItem(item); | |
| 568 }, | |
| 569 | |
| 570 /** | |
| 571 * @param {!WebInspector.Toolbar} toolbar | |
| 572 */ | |
| 573 _appendScaleItem: function(toolbar) | |
| 574 { | |
| 575 var scaleItem = new WebInspector.ToolbarMenuButton(this._appendScaleMenu
Items.bind(this)); | |
| 576 scaleItem.setTitle(WebInspector.UIString("Zoom")); | |
| 577 scaleItem.setGlyph(""); | |
| 578 scaleItem.addDropDownArrow(); | |
| 579 toolbar.appendToolbarItem(scaleItem); | |
| 580 this._scaleItems.push(scaleItem); | |
| 581 }, | |
| 582 | |
| 583 /** | |
| 584 * @param {!WebInspector.ContextMenu} contextMenu | 555 * @param {!WebInspector.ContextMenu} contextMenu |
| 585 */ | 556 */ |
| 586 _appendScaleMenuItems: function(contextMenu) | 557 _appendScaleMenuItems: function(contextMenu) |
| 587 { | 558 { |
| 588 var scaleSetting = this._model.scaleSetting(); | 559 var scaleSetting = this._model.scaleSetting(); |
| 589 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { | 560 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { |
| 590 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)
", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode
l.fitScale()), false); | 561 contextMenu.appendItem(WebInspector.UIString("Fit to window (%.0f%%)
", this._model.fitScale() * 100), scaleSetting.set.bind(scaleSetting, this._mode
l.fitScale()), false); |
| 591 contextMenu.appendSeparator(); | 562 contextMenu.appendSeparator(); |
| 592 } | 563 } |
| 593 appendScaleItem(WebInspector.UIString("50%"), 0.5); | 564 appendScaleItem(WebInspector.UIString("50%"), 0.5); |
| 594 appendScaleItem(WebInspector.UIString("75%"), 0.75); | 565 appendScaleItem(WebInspector.UIString("75%"), 0.75); |
| 595 appendScaleItem(WebInspector.UIString("100%"), 1); | 566 appendScaleItem(WebInspector.UIString("100%"), 1); |
| 596 appendScaleItem(WebInspector.UIString("125%"), 1.25); | 567 appendScaleItem(WebInspector.UIString("125%"), 1.25); |
| 597 appendScaleItem(WebInspector.UIString("150%"), 1.5); | 568 appendScaleItem(WebInspector.UIString("150%"), 1.5); |
| 598 | 569 |
| 599 /** | 570 /** |
| 600 * @param {string} title | 571 * @param {string} title |
| 601 * @param {number} value | 572 * @param {number} value |
| 602 */ | 573 */ |
| 603 function appendScaleItem(title, value) | 574 function appendScaleItem(title, value) |
| 604 { | 575 { |
| 605 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); | 576 contextMenu.appendCheckboxItem(title, scaleSetting.set.bind(scaleSet
ting, value), scaleSetting.get() === value, false); |
| 606 } | 577 } |
| 607 }, | 578 }, |
| 608 | 579 |
| 609 /** | 580 /** |
| 610 * @param {!WebInspector.ContextMenu} contextMenu | 581 * @param {!WebInspector.ContextMenu} contextMenu |
| 611 */ | 582 */ |
| 612 _appendMenuItems: function(contextMenu) | 583 _appendOptionsMenuItems: function(contextMenu) |
| 613 { | 584 { |
| 614 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; | 585 var uaDisabled = this._model.type() !== WebInspector.DeviceModeModel.Typ
e.Responsive; |
| 615 var uaSetting = this._model.uaSetting(); | 586 var uaSetting = this._model.uaSetting(); |
| 616 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); | 587 var uaSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Use
r agent type"), false); |
| 617 var uaValue = this._model.uaSetting().get(); | 588 var uaValue = this._model.uaSetting().get(); |
| 618 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) | 589 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) |
| 619 uaValue = WebInspector.DeviceModeModel.UA.Desktop; | 590 uaValue = WebInspector.DeviceModeModel.UA.Desktop; |
| 620 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) | 591 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) |
| 621 uaValue = this._model.device().mobile() ? WebInspector.DeviceModeMod
el.UA.Mobile : this._model.device().touch() ? WebInspector.DeviceModeModel.UA.De
sktopTouch : WebInspector.DeviceModeModel.UA.Desktop; | 592 uaValue = this._model.device().mobile() ? WebInspector.DeviceModeMod
el.UA.Mobile : this._model.device().touch() ? WebInspector.DeviceModeModel.UA.De
sktopTouch : WebInspector.DeviceModeModel.UA.Desktop; |
| 622 appendUAItem(WebInspector.UIString("Mobile (default)"), WebInspector.Dev
iceModeModel.UA.Mobile); | 593 appendUAItem(WebInspector.UIString("Mobile (default)"), WebInspector.Dev
iceModeModel.UA.Mobile); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 * @return {!WebInspector.ToolbarItem} | 652 * @return {!WebInspector.ToolbarItem} |
| 682 */ | 653 */ |
| 683 _wrapToolbarItem: function(element) | 654 _wrapToolbarItem: function(element) |
| 684 { | 655 { |
| 685 var container = createElement("div"); | 656 var container = createElement("div"); |
| 686 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container,
"emulation/deviceModeToolbar.css"); | 657 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(container,
"emulation/deviceModeToolbar.css"); |
| 687 shadowRoot.appendChild(element); | 658 shadowRoot.appendChild(element); |
| 688 return new WebInspector.ToolbarItem(container); | 659 return new WebInspector.ToolbarItem(container); |
| 689 }, | 660 }, |
| 690 | 661 |
| 691 _noneButtonClick: function() | |
| 692 { | |
| 693 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, null); | |
| 694 }, | |
| 695 | |
| 696 _responsiveButtonClick: function() | |
| 697 { | |
| 698 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); | |
| 699 }, | |
| 700 | |
| 701 _deviceButtonClick: function() | |
| 702 { | |
| 703 this._emulateDevice(this._lastDevice || this._deviceSelect.options[0].de
vice || WebInspector.emulatedDevicesList.standard()[0]); | |
| 704 }, | |
| 705 | |
| 706 /** | 662 /** |
| 707 * @param {!WebInspector.EmulatedDevice} device | 663 * @param {!WebInspector.EmulatedDevice} device |
| 708 */ | 664 */ |
| 709 _emulateDevice: function(device) | 665 _emulateDevice: function(device) |
| 710 { | 666 { |
| 711 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, th
is._lastMode.get(device) || device.modes[0]); | 667 this._model.emulate(WebInspector.DeviceModeModel.Type.Device, device, th
is._lastMode.get(device) || device.modes[0]); |
| 712 }, | 668 }, |
| 713 | 669 |
| 670 _switchToResponsive: function() |
| 671 { |
| 672 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, null,
null); |
| 673 }, |
| 674 |
| 714 /** | 675 /** |
| 715 * @return {!Element} | 676 * @param {!Array<!WebInspector.EmulatedDevice>} devices |
| 677 * @return {!Array<!WebInspector.EmulatedDevice>} |
| 716 */ | 678 */ |
| 717 _createDeviceSelect: function() | 679 _filterDevices: function(devices) |
| 718 { | 680 { |
| 719 var select = createElementWithClass("select", "device-mode-device-select
"); | 681 devices = devices.filter(function(d) { return d.show(); }); |
| 720 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedD
evicesList.Events.CustomDevicesUpdated, deviceListChanged, this); | 682 devices.sort(WebInspector.EmulatedDevice.deviceComparator); |
| 721 WebInspector.emulatedDevicesList.addEventListener(WebInspector.EmulatedD
evicesList.Events.StandardDevicesUpdated, deviceListChanged, this); | 683 return devices; |
| 722 populateDeviceList.call(this); | 684 }, |
| 723 select.addEventListener("change", optionSelected.bind(this), false); | 685 |
| 724 return select; | 686 /** |
| 687 * @return {!Array<!WebInspector.EmulatedDevice>} |
| 688 */ |
| 689 _standardDevices: function() |
| 690 { |
| 691 return this._filterDevices(WebInspector.emulatedDevicesList.standard()); |
| 692 }, |
| 693 |
| 694 /** |
| 695 * @return {!Array<!WebInspector.EmulatedDevice>} |
| 696 */ |
| 697 _customDevices: function() |
| 698 { |
| 699 return this._filterDevices(WebInspector.emulatedDevicesList.custom()); |
| 700 }, |
| 701 |
| 702 /** |
| 703 * @return {!Array<!WebInspector.EmulatedDevice>} |
| 704 */ |
| 705 _allDevices: function() |
| 706 { |
| 707 return this._standardDevices().concat(this._customDevices()); |
| 708 }, |
| 709 |
| 710 /** |
| 711 * @param {!WebInspector.ContextMenu} contextMenu |
| 712 */ |
| 713 _appendDeviceMenuItems: function(contextMenu) |
| 714 { |
| 715 contextMenu.appendCheckboxItem(WebInspector.UIString("Responsive"), this
._switchToResponsive.bind(this), this._model.type() === WebInspector.DeviceModeM
odel.Type.Responsive, false); |
| 716 appendGroup.call(this, this._standardDevices()); |
| 717 appendGroup.call(this, this._customDevices()); |
| 718 contextMenu.appendSeparator(); |
| 719 contextMenu.appendItem(WebInspector.UIString("Edit\u2026"), WebInspector
.emulatedDevicesList.revealCustomSetting.bind(WebInspector.emulatedDevicesList),
false); |
| 725 | 720 |
| 726 /** | 721 /** |
| 727 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 728 */ | |
| 729 function populateDeviceList() | |
| 730 { | |
| 731 select.removeChildren(); | |
| 732 | |
| 733 var devicesGroup = select.createChild("optgroup"); | |
| 734 devicesGroup.label = WebInspector.UIString("Devices"); | |
| 735 addGroup.call(this, devicesGroup, WebInspector.emulatedDevicesList.s
tandard()); | |
| 736 | |
| 737 var customGroup = select.createChild("optgroup"); | |
| 738 customGroup.label = WebInspector.UIString("Custom"); | |
| 739 addGroup.call(this, customGroup, WebInspector.emulatedDevicesList.cu
stom()); | |
| 740 var editCustomOption = new Option(WebInspector.UIString("Edit\u2026"
), WebInspector.UIString("Edit\u2026")); | |
| 741 editCustomOption.edit = true; | |
| 742 customGroup.appendChild(editCustomOption); | |
| 743 } | |
| 744 | |
| 745 /** | |
| 746 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 747 */ | |
| 748 function deviceListChanged() | |
| 749 { | |
| 750 populateDeviceList.call(this); | |
| 751 if (!this._updateDeviceSelectedIndex() && this._model.type() === Web
Inspector.DeviceModeModel.Type.Device) { | |
| 752 select.selectedIndex = 0; | |
| 753 if (!select.options[0].edit) | |
| 754 this._emulateDevice(select.options[0].device); | |
| 755 } | |
| 756 } | |
| 757 | |
| 758 /** | |
| 759 * @param {!Element} parent | |
| 760 * @param {!Array<!WebInspector.EmulatedDevice>} devices | 722 * @param {!Array<!WebInspector.EmulatedDevice>} devices |
| 761 * @this {WebInspector.DeviceModeView.Toolbar} | 723 * @this {WebInspector.DeviceModeView.Toolbar} |
| 762 */ | 724 */ |
| 763 function addGroup(parent, devices) | 725 function appendGroup(devices) |
| 764 { | 726 { |
| 765 devices = devices.filter(function(d) { return d.show(); }); | 727 if (!devices.length) |
| 766 devices.sort(WebInspector.EmulatedDevice.deviceComparator); | 728 return; |
| 729 contextMenu.appendSeparator(); |
| 767 for (var device of devices) | 730 for (var device of devices) |
| 768 addOption.call(this, parent, device); | 731 contextMenu.appendCheckboxItem(device.title, this._emulateDevice
.bind(this, device), this._model.device() === device, false); |
| 769 } | |
| 770 | |
| 771 /** | |
| 772 * @param {!Element} parent | |
| 773 * @param {!WebInspector.EmulatedDevice} device | |
| 774 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 775 */ | |
| 776 function addOption(parent, device) | |
| 777 { | |
| 778 var option = new Option(device.title, device.title); | |
| 779 option.device = device; | |
| 780 parent.appendChild(option); | |
| 781 | |
| 782 if (device === this._model.device()) | |
| 783 select.selectedIndex = Array.prototype.slice.call(select.options
).indexOf(option); | |
| 784 } | |
| 785 | |
| 786 /** | |
| 787 * @this {WebInspector.DeviceModeView.Toolbar} | |
| 788 */ | |
| 789 function optionSelected() | |
| 790 { | |
| 791 var option = select.options[select.selectedIndex]; | |
| 792 if (option.edit) { | |
| 793 WebInspector.emulatedDevicesList.revealCustomSetting(); | |
| 794 this._updateDeviceSelectedIndex(); | |
| 795 } else { | |
| 796 this._emulateDevice(option.device); | |
| 797 } | |
| 798 } | 732 } |
| 799 }, | 733 }, |
| 800 | 734 |
| 801 /** | 735 /** |
| 802 * @return {boolean} | 736 * @this {WebInspector.DeviceModeView.Toolbar} |
| 803 */ | 737 */ |
| 804 _updateDeviceSelectedIndex: function() | 738 _deviceListChanged: function() |
| 805 { | 739 { |
| 806 for (var i = 0; i < this._deviceSelect.options.length; ++i) { | 740 if (!this._model.device()) |
| 807 if (this._deviceSelect.options[i].device === this._model.device()) { | 741 return; |
| 808 this._deviceSelect.selectedIndex = i; | 742 |
| 809 return true; | 743 var devices = this._allDevices(); |
| 810 } | 744 if (devices.indexOf(this._model.device()) === -1) |
| 811 } | 745 this._emulateDevice(devices[0] || WebInspector.emulatedDevicesList.s
tandard()[0]); |
| 812 return false; | |
| 813 }, | 746 }, |
| 814 | 747 |
| 815 /** | 748 /** |
| 816 * @param {!WebInspector.Event} event | 749 * @param {!WebInspector.Event} event |
| 817 */ | 750 */ |
| 818 _modeMenuClicked: function(event) | 751 _modeMenuClicked: function(event) |
| 819 { | 752 { |
| 820 var device = this._model.device(); | 753 var device = this._model.device(); |
| 821 var model = this._model; | 754 var model = this._model; |
| 822 | 755 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 element: function() | 807 element: function() |
| 875 { | 808 { |
| 876 return this._element; | 809 return this._element; |
| 877 }, | 810 }, |
| 878 | 811 |
| 879 update: function() | 812 update: function() |
| 880 { | 813 { |
| 881 var updatePersistence = false; | 814 var updatePersistence = false; |
| 882 | 815 |
| 883 if (this._model.type() !== this._cachedModelType) { | 816 if (this._model.type() !== this._cachedModelType) { |
| 884 this._noneItem.setToggled(this._model.type() === WebInspector.Device
ModeModel.Type.None); | |
| 885 this._responsiveItem.setToggled(this._model.type() === WebInspector.
DeviceModeModel.Type.Responsive); | |
| 886 this._deviceItem.setToggled(this._model.type() === WebInspector.Devi
ceModeModel.Type.Device); | |
| 887 | |
| 888 var toolbar = null; | |
| 889 if (this._model.type() === WebInspector.DeviceModeModel.Type.None) | |
| 890 toolbar = this._noneToolbar; | |
| 891 else if (this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive) | |
| 892 toolbar = this._responsiveToolbar; | |
| 893 else if (this._model.type() === WebInspector.DeviceModeModel.Type.De
vice) | |
| 894 toolbar = this._deviceToolbar; | |
| 895 | |
| 896 if (this._visibleToolbar !== toolbar) { | |
| 897 if (this._visibleToolbar) | |
| 898 this._visibleToolbar.classList.add("hidden"); | |
| 899 if (toolbar) { | |
| 900 toolbar.classList.remove("hidden"); | |
| 901 toolbar.animate([{opacity: "0"}, {opacity: "1"}], {duration:
100}); | |
| 902 } | |
| 903 this._visibleToolbar = toolbar; | |
| 904 } | |
| 905 | |
| 906 this._previousModelType = this._cachedModelType; | 817 this._previousModelType = this._cachedModelType; |
| 907 this._cachedModelType = this._model.type(); | 818 this._cachedModelType = this._model.type(); |
| 819 this._widthInput.disabled = this._model.type() !== WebInspector.Devi
ceModeModel.Type.Responsive; |
| 820 this._heightInput.disabled = this._model.type() !== WebInspector.Dev
iceModeModel.Type.Responsive; |
| 908 updatePersistence = true; | 821 updatePersistence = true; |
| 909 } | 822 } |
| 910 | 823 |
| 911 var size = this._model.appliedDeviceSize(); | 824 var size = this._model.appliedDeviceSize(); |
| 912 this._updateHeightInput(this._model.isFullHeight() ? 0 : size.height); | 825 this._updateHeightInput(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && this._model.isFullHeight() ? 0 : size.height); |
| 913 this._updateWidthInput(size.width); | 826 this._updateWidthInput(size.width); |
| 914 if (!size.isEqual(this._cachedSize)) { | 827 this._heightInput.placeholder = size.height; |
| 915 for (var item of this._appliedSizeItems) | |
| 916 item.setText(WebInspector.UIString("%d \u00D7 %d", size.width, s
ize.height)); | |
| 917 this._heightInput.placeholder = size.height; | |
| 918 this._cachedSize = size; | |
| 919 } | |
| 920 | 828 |
| 921 if (this._model.scale() !== this._cachedScale) { | 829 if (this._model.scale() !== this._cachedScale) { |
| 922 for (var item of this._scaleItems) { | 830 this._scaleItem.setText(WebInspector.UIString("%.0f%%", this._model.
scale() * 100)); |
| 923 item.setText(WebInspector.UIString("%.0f%%", this._model.scale()
* 100)); | 831 this._scaleItem.setState(this._model.scale() === 1 ? "off" : "on"); |
| 924 item.setState(this._model.scale() === 1 ? "off" : "on"); | |
| 925 } | |
| 926 this._cachedScale = this._model.scale(); | 832 this._cachedScale = this._model.scale(); |
| 927 } | 833 } |
| 928 | 834 |
| 929 var deviceScale = this._model.deviceScaleFactorSetting().get(); | 835 var deviceScale = this._model.deviceScaleFactorSetting().get(); |
| 930 this._deviceScaleItem.setVisible(this._model.type() === WebInspector.Dev
iceModeModel.Type.Responsive && !!deviceScale); | 836 this._deviceScaleItem.setVisible(this._model.type() === WebInspector.Dev
iceModeModel.Type.Responsive && !!deviceScale); |
| 931 if (deviceScale !== this._cachedDeviceScale) { | 837 if (deviceScale !== this._cachedDeviceScale) { |
| 932 this._deviceScaleItem.setText(WebInspector.UIString("DPR: %.1f", dev
iceScale)); | 838 this._deviceScaleItem.setText(WebInspector.UIString("DPR: %.1f", dev
iceScale)); |
| 933 this._cachedDeviceScale = deviceScale; | 839 this._cachedDeviceScale = deviceScale; |
| 934 } | 840 } |
| 935 | 841 |
| 936 var uaType = this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive ? this._model.uaSetting().get() : WebInspector.DeviceModeModel.UA.Mobil
e; | 842 var uaType = this._model.type() === WebInspector.DeviceModeModel.Type.Re
sponsive ? this._model.uaSetting().get() : WebInspector.DeviceModeModel.UA.Mobil
e; |
| 937 this._uaItem.setVisible(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && uaType !== WebInspector.DeviceModeModel.UA.Mobile); | 843 this._uaItem.setVisible(this._model.type() === WebInspector.DeviceModeMo
del.Type.Responsive && uaType !== WebInspector.DeviceModeModel.UA.Mobile); |
| 938 if (uaType !== this._cachedUaType) { | 844 if (uaType !== this._cachedUaType) { |
| 939 this._uaItem.setText(uaType === WebInspector.DeviceModeModel.UA.Desk
top ? WebInspector.UIString("Desktop") : WebInspector.UIString("Touch")); | 845 this._uaItem.setText(uaType === WebInspector.DeviceModeModel.UA.Desk
top ? WebInspector.UIString("Desktop") : WebInspector.UIString("Touch")); |
| 940 this._cachedUaType = uaType; | 846 this._cachedUaType = uaType; |
| 941 } | 847 } |
| 942 | 848 |
| 849 var deviceItemTitle = WebInspector.UIString("None"); |
| 850 if (this._model.type() === WebInspector.DeviceModeModel.Type.Responsive) |
| 851 deviceItemTitle = WebInspector.UIString("Responsive"); |
| 852 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) |
| 853 deviceItemTitle = this._model.device().title; |
| 854 this._deviceSelectItem.setText(deviceItemTitle); |
| 855 |
| 943 if (this._model.device() !== this._cachedModelDevice) { | 856 if (this._model.device() !== this._cachedModelDevice) { |
| 944 var device = this._model.device(); | 857 var device = this._model.device(); |
| 945 | 858 this._modeButton.setVisible(!!device); |
| 946 if (device) { | 859 if (device) { |
| 947 var modeCount = device ? device.modes.length : 0; | 860 var modeCount = device ? device.modes.length : 0; |
| 948 this._modeButton.setEnabled(modeCount >= 2); | 861 this._modeButton.setEnabled(modeCount >= 2); |
| 949 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); | 862 this._modeButton.setTitle(modeCount === 2 ? WebInspector.UIStrin
g("Rotate") : WebInspector.UIString("Screen options")); |
| 950 } | 863 } |
| 951 this._updateDeviceSelectedIndex(); | |
| 952 | |
| 953 this._cachedModelDevice = device; | 864 this._cachedModelDevice = device; |
| 954 updatePersistence = true; | 865 updatePersistence = true; |
| 955 } | 866 } |
| 956 | 867 |
| 957 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { | 868 if (this._model.type() === WebInspector.DeviceModeModel.Type.Device) { |
| 958 this._lastDevice = this._model.device(); | 869 this._lastDevice = this._model.device(); |
| 959 this._lastMode.set(/** @type {!WebInspector.EmulatedDevice} */ (this
._model.device()), /** @type {!WebInspector.EmulatedDevice.Mode} */ (this._model
.mode())); | 870 this._lastMode.set(/** @type {!WebInspector.EmulatedDevice} */ (this
._model.device()), /** @type {!WebInspector.EmulatedDevice.Mode} */ (this._model
.mode())); |
| 960 } | 871 } |
| 961 | 872 |
| 962 if (this._model.mode() !== this._cachedModelMode) { | 873 if (this._model.mode() !== this._cachedModelMode) { |
| 963 this._cachedModelMode = this._model.mode(); | 874 this._cachedModelMode = this._model.mode(); |
| 964 updatePersistence = true; | 875 updatePersistence = true; |
| 965 } | 876 } |
| 966 | 877 |
| 967 if (updatePersistence) { | 878 if (updatePersistence && this._cachedModelType !== WebInspector.DeviceMo
deModel.Type.None) { |
| 968 var value = this._persistenceSetting.get(); | 879 var value = this._persistenceSetting.get(); |
| 969 value.type = this._cachedModelType; | 880 value.type = this._cachedModelType; |
| 970 if (this._cachedModelDevice) { | 881 if (this._cachedModelDevice) { |
| 971 value.device = this._cachedModelDevice.title; | 882 value.device = this._cachedModelDevice.title; |
| 972 value.orientation = this._cachedModelMode ? this._cachedModelMod
e.orientation : ""; | 883 value.orientation = this._cachedModelMode ? this._cachedModelMod
e.orientation : ""; |
| 973 value.mode = this._cachedModelMode ? this._cachedModelMode.title
: ""; | 884 value.mode = this._cachedModelMode ? this._cachedModelMode.title
: ""; |
| 974 } | 885 } |
| 975 this._persistenceSetting.set(value); | 886 this._persistenceSetting.set(value); |
| 976 } | 887 } |
| 977 }, | 888 }, |
| 978 | 889 |
| 979 restore: function() | 890 restore: function() |
| 980 { | 891 { |
| 981 if (this._restored) | 892 if (this._restored) |
| 982 return; | 893 return; |
| 983 | |
| 984 this._restored = true; | 894 this._restored = true; |
| 985 | 895 |
| 986 for (var i = 0; i < this._deviceSelect.options.length; ++i) { | 896 for (var device of this._allDevices()) { |
| 987 if (this._deviceSelect.options[i].device && this._deviceSelect.optio
ns[i].device.title === this._persistenceSetting.get().device) | 897 if (device.title === this._persistenceSetting.get().device) { |
| 988 this._lastDevice = this._deviceSelect.options[i].device; | 898 this._lastDevice = device; |
| 989 } | 899 for (var mode of device.modes) { |
| 990 if (this._lastDevice) { | 900 if (mode.orientation === this._persistenceSetting.get().orie
ntation && mode.title === this._persistenceSetting.get().mode) |
| 991 for (var i = 0; i < this._lastDevice.modes.length; ++i) { | 901 this._lastMode.set(device, mode); |
| 992 if (this._lastDevice.modes[i].orientation === this._persistenceS
etting.get().orientation && this._lastDevice.modes[i].title === this._persistenc
eSetting.get().mode) | 902 } |
| 993 this._lastMode.set(this._lastDevice, this._lastDevice.modes[
i]); | |
| 994 } | 903 } |
| 995 } else { | |
| 996 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, nu
ll); | |
| 997 } | 904 } |
| 998 | 905 |
| 999 this._applyType(/** @type {!WebInspector.DeviceModeModel.Type} */ (this.
_persistenceSetting.get().type)); | 906 this._applyType(/** @type {!WebInspector.DeviceModeModel.Type} */ (this.
_persistenceSetting.get().type)); |
| 1000 }, | 907 }, |
| 1001 | 908 |
| 1002 toggleDeviceMode: function() | 909 toggleDeviceMode: function() |
| 1003 { | 910 { |
| 1004 this._applyType(this._model.type() === WebInspector.DeviceModeModel.Type
.None ? (this._previousModelType || WebInspector.DeviceModeModel.Type.Responsive
) : WebInspector.DeviceModeModel.Type.None); | 911 this._applyType(this._model.type() === WebInspector.DeviceModeModel.Type
.None ? (this._previousModelType || WebInspector.DeviceModeModel.Type.Responsive
) : WebInspector.DeviceModeModel.Type.None); |
| 1005 }, | 912 }, |
| 1006 | 913 |
| 1007 /** | 914 /** |
| 1008 * @param {!WebInspector.DeviceModeModel.Type} type | 915 * @param {!WebInspector.DeviceModeModel.Type} type |
| 1009 */ | 916 */ |
| 1010 _applyType: function(type) | 917 _applyType: function(type) |
| 1011 { | 918 { |
| 1012 if (type === WebInspector.DeviceModeModel.Type.Responsive) | 919 if (type === WebInspector.DeviceModeModel.Type.Responsive) |
| 1013 this._responsiveButtonClick(); | 920 this._model.emulate(WebInspector.DeviceModeModel.Type.Responsive, nu
ll, null); |
| 1014 else if (type === WebInspector.DeviceModeModel.Type.Device) | 921 else if (type === WebInspector.DeviceModeModel.Type.Device) |
| 1015 this._deviceButtonClick(); | 922 this._emulateDevice(this._lastDevice || this._allDevices()[0] || Web
Inspector.emulatedDevicesList.standard()[0]); |
| 1016 else | 923 else |
| 1017 this._noneButtonClick(); | 924 this._model.emulate(WebInspector.DeviceModeModel.Type.None, null, nu
ll); |
| 1018 } | 925 } |
| 1019 } | 926 } |
| 1020 | 927 |
| 1021 /** | 928 /** |
| 1022 * @constructor | 929 * @constructor |
| 1023 * @extends {WebInspector.VBox} | 930 * @extends {WebInspector.VBox} |
| 1024 * @param {boolean} horizontal | 931 * @param {boolean} horizontal |
| 1025 * @param {function(number)} applyCallback | 932 * @param {function(number)} applyCallback |
| 1026 */ | 933 */ |
| 1027 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) | 934 WebInspector.DeviceModeView.Ruler = function(horizontal, applyCallback) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 * @param {!WebInspector.Context} context | 1048 * @param {!WebInspector.Context} context |
| 1142 * @param {string} actionId | 1049 * @param {string} actionId |
| 1143 * @return {boolean} | 1050 * @return {boolean} |
| 1144 */ | 1051 */ |
| 1145 handleAction: function(context, actionId) | 1052 handleAction: function(context, actionId) |
| 1146 { | 1053 { |
| 1147 if (actionId === "emulation.toggle-device-mode" && WebInspector.DeviceMo
deView._wrapperInstance) { | 1054 if (actionId === "emulation.toggle-device-mode" && WebInspector.DeviceMo
deView._wrapperInstance) { |
| 1148 WebInspector.DeviceModeView._wrapperInstance._toggleDeviceMode(); | 1055 WebInspector.DeviceModeView._wrapperInstance._toggleDeviceMode(); |
| 1149 return true; | 1056 return true; |
| 1150 } | 1057 } |
| 1151 if (actionId === "emulation.toggle-device-toolbar" && WebInspector.Devic
eModeView._wrapperInstance) { | |
| 1152 WebInspector.DeviceModeView._wrapperInstance._toggleDeviceToolbar(); | |
| 1153 return true; | |
| 1154 } | |
| 1155 return false; | 1058 return false; |
| 1156 } | 1059 } |
| 1157 } | 1060 } |
| 1158 | 1061 |
| 1159 | 1062 |
| 1160 /** | 1063 /** |
| 1161 * @extends {WebInspector.VBox} | 1064 * @extends {WebInspector.VBox} |
| 1162 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder | 1065 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder |
| 1163 * @constructor | 1066 * @constructor |
| 1164 */ | 1067 */ |
| 1165 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder) | 1068 WebInspector.DeviceModeView.Wrapper = function(inspectedPagePlaceholder) |
| 1166 { | 1069 { |
| 1167 WebInspector.VBox.call(this); | 1070 WebInspector.VBox.call(this); |
| 1168 WebInspector.DeviceModeView._wrapperInstance = this; | 1071 WebInspector.DeviceModeView._wrapperInstance = this; |
| 1169 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 1072 this._inspectedPagePlaceholder = inspectedPagePlaceholder; |
| 1170 this._deviceModeView = new WebInspector.DeviceModeView(); | 1073 this._deviceModeView = new WebInspector.DeviceModeView(); |
| 1171 this._showDeviceToolbarSetting = WebInspector.settings.createSetting("emulat
ion.showDeviceToolbar", true); | 1074 this._toggleDeviceModeAction = WebInspector.actionRegistry.action("emulation
.toggle-device-mode"); |
| 1172 this._showDeviceToolbarSetting.addChangeListener(this._update, this); | 1075 this._showDeviceModeSetting = WebInspector.settings.createSetting("emulation
.showDeviceMode", false); |
| 1173 this._update(); | 1076 this._showDeviceModeSetting.addChangeListener(this._update.bind(this, false)
); |
| 1077 this._update(true); |
| 1174 } | 1078 } |
| 1175 | 1079 |
| 1176 /** @type {!WebInspector.DeviceModeView.Wrapper} */ | 1080 /** @type {!WebInspector.DeviceModeView.Wrapper} */ |
| 1177 WebInspector.DeviceModeView._wrapperInstance; | 1081 WebInspector.DeviceModeView._wrapperInstance; |
| 1178 | 1082 |
| 1179 WebInspector.DeviceModeView.Wrapper.prototype = { | 1083 WebInspector.DeviceModeView.Wrapper.prototype = { |
| 1180 _toggleDeviceMode: function() | 1084 _toggleDeviceMode: function() |
| 1181 { | 1085 { |
| 1182 if (this._showDeviceToolbarSetting.get()) | 1086 this._showDeviceModeSetting.set(!this._showDeviceModeSetting.get()); |
| 1183 this._deviceModeView.toggleDeviceMode(); | |
| 1184 }, | 1087 }, |
| 1185 | 1088 |
| 1186 _toggleDeviceToolbar: function() | 1089 /** |
| 1090 * @param {boolean} force |
| 1091 */ |
| 1092 _update: function(force) |
| 1187 { | 1093 { |
| 1188 this._showDeviceToolbarSetting.set(!this._showDeviceToolbarSetting.get()
); | 1094 this._toggleDeviceModeAction.setToggled(this._showDeviceModeSetting.get(
)); |
| 1189 }, | 1095 if (!force && this._showDeviceModeSetting.get() === this._deviceModeView
.isShowing()) |
| 1096 return; |
| 1190 | 1097 |
| 1191 _update: function() | 1098 if (this._showDeviceModeSetting.get()) { |
| 1192 { | |
| 1193 if (this._showDeviceToolbarSetting.get()) { | |
| 1194 this._deviceModeView.show(this.element); | 1099 this._deviceModeView.show(this.element); |
| 1195 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); | 1100 this._inspectedPagePlaceholder.clearMinimumSizeAndMargins(); |
| 1196 this._inspectedPagePlaceholder.show(this._deviceModeView.element); | 1101 this._inspectedPagePlaceholder.show(this._deviceModeView.element); |
| 1197 } else { | 1102 } else { |
| 1198 this._deviceModeView.detach(); | 1103 this._deviceModeView.detach(); |
| 1199 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); | 1104 this._inspectedPagePlaceholder.restoreMinimumSizeAndMargins(); |
| 1200 this._inspectedPagePlaceholder.show(this.element); | 1105 this._inspectedPagePlaceholder.show(this.element); |
| 1201 this._deviceModeView._model.emulate(WebInspector.DeviceModeModel.Typ
e.None, null, null); | |
| 1202 } | 1106 } |
| 1107 this._deviceModeView.toggleDeviceMode(); |
| 1203 }, | 1108 }, |
| 1204 | 1109 |
| 1205 __proto__: WebInspector.VBox.prototype | 1110 __proto__: WebInspector.VBox.prototype |
| 1206 } | 1111 } |
| OLD | NEW |