| 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 24 matching lines...) Expand all Loading... |
| 35 { | 35 { |
| 36 this._toolbar = new WebInspector.DeviceModeToolbar(this._model, this._sh
owMediaInspectorSetting, 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._outlineImage = this._contentArea.createChild("img", "device-mode-o
utline-image fill hidden"); |
| 46 this._outlineImage.addEventListener("load", this._onScreenImageLoaded.bi
nd(this, this._outlineImage, true), false); |
| 47 this._outlineImage.addEventListener("error", this._onScreenImageLoaded.b
ind(this, this._outlineImage, false), false); |
| 48 |
| 45 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); | 49 this._screenArea = this._contentArea.createChild("div", "device-mode-scr
een-area"); |
| 46 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); | 50 this._screenImage = this._screenArea.createChild("img", "device-mode-scr
een-image hidden"); |
| 47 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin
d(this, true), false); | 51 this._screenImage.addEventListener("load", this._onScreenImageLoaded.bin
d(this, this._screenImage, true), false); |
| 48 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi
nd(this, false), false); | 52 this._screenImage.addEventListener("error", this._onScreenImageLoaded.bi
nd(this, this._screenImage, false), false); |
| 49 | 53 |
| 50 this._bottomRightResizerElement = this._screenArea.createChild("div", "d
evice-mode-resizer device-mode-bottom-right-resizer"); | 54 this._bottomRightResizerElement = this._screenArea.createChild("div", "d
evice-mode-resizer device-mode-bottom-right-resizer"); |
| 51 this._bottomRightResizerElement.createChild("div", ""); | 55 this._bottomRightResizerElement.createChild("div", ""); |
| 52 this._createResizer(this._bottomRightResizerElement, 2, 1); | 56 this._createResizer(this._bottomRightResizerElement, 2, 1); |
| 53 | 57 |
| 54 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de
vice-mode-resizer device-mode-bottom-left-resizer"); | 58 this._bottomLeftResizerElement = this._screenArea.createChild("div", "de
vice-mode-resizer device-mode-bottom-left-resizer"); |
| 55 this._bottomLeftResizerElement.createChild("div", ""); | 59 this._bottomLeftResizerElement.createChild("div", ""); |
| 56 this._createResizer(this._bottomLeftResizerElement, -2, 1); | 60 this._createResizer(this._bottomLeftResizerElement, -2, 1); |
| 57 | 61 |
| 58 this._rightResizerElement = this._screenArea.createChild("div", "device-
mode-resizer device-mode-right-resizer"); | 62 this._rightResizerElement = this._screenArea.createChild("div", "device-
mode-resizer device-mode-right-resizer"); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 * @param {!WebInspector.Event} event | 186 * @param {!WebInspector.Event} event |
| 183 */ | 187 */ |
| 184 _onResizeEnd: function(event) | 188 _onResizeEnd: function(event) |
| 185 { | 189 { |
| 186 delete this._resizeStart; | 190 delete this._resizeStart; |
| 187 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res
izedViewInResponsiveMode); | 191 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Res
izedViewInResponsiveMode); |
| 188 }, | 192 }, |
| 189 | 193 |
| 190 _updateUI: function() | 194 _updateUI: function() |
| 191 { | 195 { |
| 196 /** |
| 197 * @param {!Element} element |
| 198 * @param {!WebInspector.Rect} rect |
| 199 */ |
| 200 function applyRect(element, rect) |
| 201 { |
| 202 element.style.left = rect.left + "px"; |
| 203 element.style.top = rect.top + "px"; |
| 204 element.style.width = rect.width + "px"; |
| 205 element.style.height = rect.height + "px"; |
| 206 } |
| 207 |
| 192 if (!this.isShowing()) | 208 if (!this.isShowing()) |
| 193 return; | 209 return; |
| 194 | 210 |
| 195 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 211 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 196 var callDoResize = false; | 212 var callDoResize = false; |
| 197 var showRulers = this._showRulersSetting.get() && this._model.type() !==
WebInspector.DeviceModeModel.Type.None; | 213 var showRulers = this._showRulersSetting.get() && this._model.type() !==
WebInspector.DeviceModeModel.Type.None; |
| 198 var contentAreaResized = false; | 214 var contentAreaResized = false; |
| 199 var updateRulers = false; | 215 var updateRulers = false; |
| 200 | 216 |
| 201 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); | 217 var cssScreenRect = this._model.screenRect().scale(1 / zoomFactor); |
| 202 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { | 218 if (!cssScreenRect.isEqual(this._cachedCssScreenRect)) { |
| 203 this._screenArea.style.left = cssScreenRect.left + "px"; | 219 applyRect(this._screenArea, cssScreenRect); |
| 204 this._screenArea.style.top = cssScreenRect.top + "px"; | |
| 205 this._screenArea.style.width = cssScreenRect.width + "px"; | |
| 206 this._screenArea.style.height = cssScreenRect.height + "px"; | |
| 207 this._leftRuler.element.style.left = cssScreenRect.left + "px"; | 220 this._leftRuler.element.style.left = cssScreenRect.left + "px"; |
| 208 updateRulers = true; | 221 updateRulers = true; |
| 209 callDoResize = true; | 222 callDoResize = true; |
| 210 this._cachedCssScreenRect = cssScreenRect; | 223 this._cachedCssScreenRect = cssScreenRect; |
| 211 } | 224 } |
| 212 | 225 |
| 213 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac
tor); | 226 var cssVisiblePageRect = this._model.visiblePageRect().scale(1 / zoomFac
tor); |
| 214 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { | 227 if (!cssVisiblePageRect.isEqual(this._cachedCssVisiblePageRect)) { |
| 215 this._pageArea.style.left = cssVisiblePageRect.left + "px"; | 228 applyRect(this._pageArea, cssVisiblePageRect); |
| 216 this._pageArea.style.top = cssVisiblePageRect.top + "px"; | |
| 217 this._pageArea.style.width = cssVisiblePageRect.width + "px"; | |
| 218 this._pageArea.style.height = cssVisiblePageRect.height + "px"; | |
| 219 callDoResize = true; | 229 callDoResize = true; |
| 230 updateRulers = true; |
| 220 this._cachedCssVisiblePageRect = cssVisiblePageRect; | 231 this._cachedCssVisiblePageRect = cssVisiblePageRect; |
| 221 } | 232 } |
| 222 | 233 |
| 234 var outlineRect = this._model.outlineRect().scale(1 / zoomFactor); |
| 235 if (!outlineRect.isEqual(this._cachedOutlineRect)) { |
| 236 applyRect(this._outlineImage, this._model.outlineRect().scale(1 / zo
omFactor)); |
| 237 callDoResize = true; |
| 238 this._cachedOutlineRect = outlineRect; |
| 239 } |
| 240 |
| 223 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type
.Responsive; | 241 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type
.Responsive; |
| 224 if (resizable !== this._cachedResizable) { | 242 if (resizable !== this._cachedResizable) { |
| 225 this._rightResizerElement.classList.toggle("hidden", !resizable); | 243 this._rightResizerElement.classList.toggle("hidden", !resizable); |
| 226 this._leftResizerElement.classList.toggle("hidden", !resizable); | 244 this._leftResizerElement.classList.toggle("hidden", !resizable); |
| 227 this._bottomResizerElement.classList.toggle("hidden", !resizable); | 245 this._bottomResizerElement.classList.toggle("hidden", !resizable); |
| 228 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl
e); | 246 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl
e); |
| 229 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable
); | 247 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable
); |
| 230 this._cachedResizable = resizable; | 248 this._cachedResizable = resizable; |
| 231 } | 249 } |
| 232 | 250 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 257 | 275 |
| 258 if (this._model.scale() !== this._cachedScale) { | 276 if (this._model.scale() !== this._cachedScale) { |
| 259 updateRulers = true; | 277 updateRulers = true; |
| 260 callDoResize = true; | 278 callDoResize = true; |
| 261 for (var block of this._presetBlocks) | 279 for (var block of this._presetBlocks) |
| 262 block.style.width = block.__width * this._model.scale() + "px"; | 280 block.style.width = block.__width * this._model.scale() + "px"; |
| 263 this._cachedScale = this._model.scale(); | 281 this._cachedScale = this._model.scale(); |
| 264 } | 282 } |
| 265 | 283 |
| 266 this._toolbar.update(); | 284 this._toolbar.update(); |
| 267 this._loadScreenImage(this._model.screenImage()); | 285 this._loadImage(this._screenImage, this._model.screenImage()); |
| 286 this._loadImage(this._outlineImage, this._model.outlineImage()); |
| 287 |
| 268 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); | 288 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); |
| 269 if (callDoResize) | 289 if (callDoResize) |
| 270 this.doResize(); | 290 this.doResize(); |
| 271 if (updateRulers) { | 291 if (updateRulers) { |
| 272 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); | 292 var showingDevice = this._model.type() === WebInspector.DeviceModeMo
del.Type.Device; |
| 273 this._leftRuler.render(0, this._model.scale()); | 293 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale(), showingDevice && this._cachedCssScreenRec
t ? this._cachedCssScreenRect.width : 0); |
| 294 this._leftRuler.render(0, this._model.scale(), showingDevice && this
._cachedCssScreenRect ? this._cachedCssScreenRect.height : 0); |
| 295 this._topRuler.element.style.top = this._cachedCssScreenRect ? this.
_cachedCssScreenRect.top + "px" : 0; |
| 296 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this
._cachedCssScreenRect.top + "px" : 0; |
| 274 } | 297 } |
| 275 if (contentAreaResized) | 298 if (contentAreaResized) |
| 276 this._contentAreaResized(); | 299 this._contentAreaResized(); |
| 277 }, | 300 }, |
| 278 | 301 |
| 279 /** | 302 /** |
| 303 * @param {!Element} element |
| 280 * @param {string} srcset | 304 * @param {string} srcset |
| 281 */ | 305 */ |
| 282 _loadScreenImage: function(srcset) | 306 _loadImage: function(element, srcset) |
| 283 { | 307 { |
| 284 if (this._screenImage.getAttribute("srcset") === srcset) | 308 if (element.getAttribute("srcset") === srcset) |
| 285 return; | 309 return; |
| 286 this._screenImage.setAttribute("srcset", srcset); | 310 element.setAttribute("srcset", srcset); |
| 287 if (!srcset) | 311 if (!srcset) |
| 288 this._screenImage.classList.toggle("hidden", true); | 312 element.classList.toggle("hidden", true); |
| 289 }, | 313 }, |
| 290 | 314 |
| 291 /** | 315 /** |
| 316 * @param {!Element} element |
| 292 * @param {boolean} success | 317 * @param {boolean} success |
| 293 */ | 318 */ |
| 294 _onScreenImageLoaded: function(success) | 319 _onScreenImageLoaded: function(element, success) |
| 295 { | 320 { |
| 296 this._screenImage.classList.toggle("hidden", !success); | 321 element.classList.toggle("hidden", !success); |
| 297 }, | 322 }, |
| 298 | 323 |
| 299 _contentAreaResized: function() | 324 _contentAreaResized: function() |
| 300 { | 325 { |
| 301 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 326 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 302 var rect = this._contentArea.getBoundingClientRect(); | 327 var rect = this._contentArea.getBoundingClientRect(); |
| 303 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); | 328 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); |
| 304 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt
h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1
)); | 329 var preferredSize = new Size(Math.max((rect.width - 2 * this._handleWidt
h) * zoomFactor, 1), Math.max((rect.height - this._handleHeight) * zoomFactor, 1
)); |
| 305 this._model.setAvailableSize(availableSize, preferredSize); | 330 this._model.setAvailableSize(availableSize, preferredSize); |
| 306 }, | 331 }, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 this._offset = 0; | 395 this._offset = 0; |
| 371 this._count = 0; | 396 this._count = 0; |
| 372 this._throttler = new WebInspector.Throttler(0); | 397 this._throttler = new WebInspector.Throttler(0); |
| 373 this._applyCallback = applyCallback; | 398 this._applyCallback = applyCallback; |
| 374 } | 399 } |
| 375 | 400 |
| 376 WebInspector.DeviceModeView.Ruler.prototype = { | 401 WebInspector.DeviceModeView.Ruler.prototype = { |
| 377 /** | 402 /** |
| 378 * @param {number} offset | 403 * @param {number} offset |
| 379 * @param {number} scale | 404 * @param {number} scale |
| 405 * @param {number} maxLength |
| 380 */ | 406 */ |
| 381 render: function(offset, scale) | 407 render: function(offset, scale, maxLength) |
| 382 { | 408 { |
| 383 this._scale = scale; | 409 this._scale = scale; |
| 384 this._offset = offset; | 410 this._offset = offset; |
| 385 if (this._horizontal) | 411 if (this._horizontal) |
| 386 this.element.style.paddingLeft = this._offset + "px"; | 412 this.element.style.paddingLeft = this._offset + "px"; |
| 387 else | 413 else |
| 388 this.element.style.paddingTop = this._offset + "px"; | 414 this.element.style.paddingTop = this._offset + "px"; |
| 389 this._throttler.schedule(this._update.bind(this)); | 415 this._throttler.schedule(this._update.bind(this)); |
| 416 this._maxLength = maxLength; |
| 390 }, | 417 }, |
| 391 | 418 |
| 392 /** | 419 /** |
| 393 * @override | 420 * @override |
| 394 */ | 421 */ |
| 395 onResize: function() | 422 onResize: function() |
| 396 { | 423 { |
| 397 this._throttler.schedule(this._update.bind(this)); | 424 this._throttler.schedule(this._update.bind(this)); |
| 398 }, | 425 }, |
| 399 | 426 |
| 400 /** | 427 /** |
| 401 * @return {!Promise.<?>} | 428 * @return {!Promise.<?>} |
| 402 */ | 429 */ |
| 403 _update: function() | 430 _update: function() |
| 404 { | 431 { |
| 405 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 432 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 406 var size = this._horizontal ? this._contentElement.offsetWidth : this._c
ontentElement.offsetHeight; | 433 var size = this._horizontal ? this._contentElement.offsetWidth : this._c
ontentElement.offsetHeight; |
| 434 if (this._maxLength) |
| 435 size = Math.min(size, this._maxLength); |
| 407 | 436 |
| 408 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered
ZoomFactor) { | 437 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered
ZoomFactor) { |
| 409 this._contentElement.removeChildren(); | 438 this._contentElement.removeChildren(); |
| 410 this._count = 0; | 439 this._count = 0; |
| 411 this._renderedScale = this._scale; | 440 this._renderedScale = this._scale; |
| 412 this._renderedZoomFactor = zoomFactor; | 441 this._renderedZoomFactor = zoomFactor; |
| 413 } | 442 } |
| 414 | 443 |
| 415 var dipSize = size * zoomFactor / this._scale; | 444 var dipSize = size * zoomFactor / this._scale; |
| 416 var count = Math.ceil(dipSize / 5); | 445 var count = Math.ceil(dipSize / 5); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 /** | 484 /** |
| 456 * @param {number} size | 485 * @param {number} size |
| 457 */ | 486 */ |
| 458 _onMarkerClick: function(size) | 487 _onMarkerClick: function(size) |
| 459 { | 488 { |
| 460 this._applyCallback.call(null, size); | 489 this._applyCallback.call(null, size); |
| 461 }, | 490 }, |
| 462 | 491 |
| 463 __proto__: WebInspector.VBox.prototype | 492 __proto__: WebInspector.VBox.prototype |
| 464 } | 493 } |
| OLD | NEW |