| 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; |
| 220 this._cachedCssVisiblePageRect = cssVisiblePageRect; | 230 this._cachedCssVisiblePageRect = cssVisiblePageRect; |
| 221 } | 231 } |
| 222 | 232 |
| 233 var outlineRect = this._model.outlineRect().scale(1 / zoomFactor); |
| 234 if (!outlineRect.isEqual(this._cachedOutlineRect)) { |
| 235 applyRect(this._outlineImage, this._model.outlineRect().scale(1 / zo
omFactor)); |
| 236 callDoResize = true; |
| 237 this._cachedOutlineRect = outlineRect; |
| 238 } |
| 239 |
| 223 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type
.Responsive; | 240 var resizable = this._model.type() === WebInspector.DeviceModeModel.Type
.Responsive; |
| 224 if (resizable !== this._cachedResizable) { | 241 if (resizable !== this._cachedResizable) { |
| 225 this._rightResizerElement.classList.toggle("hidden", !resizable); | 242 this._rightResizerElement.classList.toggle("hidden", !resizable); |
| 226 this._leftResizerElement.classList.toggle("hidden", !resizable); | 243 this._leftResizerElement.classList.toggle("hidden", !resizable); |
| 227 this._bottomResizerElement.classList.toggle("hidden", !resizable); | 244 this._bottomResizerElement.classList.toggle("hidden", !resizable); |
| 228 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl
e); | 245 this._bottomRightResizerElement.classList.toggle("hidden", !resizabl
e); |
| 229 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable
); | 246 this._bottomLeftResizerElement.classList.toggle("hidden", !resizable
); |
| 230 this._cachedResizable = resizable; | 247 this._cachedResizable = resizable; |
| 231 } | 248 } |
| 232 | 249 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 257 | 274 |
| 258 if (this._model.scale() !== this._cachedScale) { | 275 if (this._model.scale() !== this._cachedScale) { |
| 259 updateRulers = true; | 276 updateRulers = true; |
| 260 callDoResize = true; | 277 callDoResize = true; |
| 261 for (var block of this._presetBlocks) | 278 for (var block of this._presetBlocks) |
| 262 block.style.width = block.__width * this._model.scale() + "px"; | 279 block.style.width = block.__width * this._model.scale() + "px"; |
| 263 this._cachedScale = this._model.scale(); | 280 this._cachedScale = this._model.scale(); |
| 264 } | 281 } |
| 265 | 282 |
| 266 this._toolbar.update(); | 283 this._toolbar.update(); |
| 267 this._loadScreenImage(this._model.screenImage()); | 284 this._loadImage(this._screenImage, this._model.screenImage()); |
| 285 this._loadImage(this._outlineImage, this._model.outlineImage()); |
| 286 |
| 268 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); | 287 this._mediaInspector.setAxisTransform(-cssScreenRect.left * zoomFactor /
this._model.scale(), this._model.scale()); |
| 269 if (callDoResize) | 288 if (callDoResize) |
| 270 this.doResize(); | 289 this.doResize(); |
| 271 if (updateRulers) { | 290 if (updateRulers) { |
| 272 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale()); | 291 var showingDevice = this._model.type() === WebInspector.DeviceModeMo
del.Type.Device; |
| 273 this._leftRuler.render(0, this._model.scale()); | 292 this._topRuler.render(this._cachedCssScreenRect ? this._cachedCssScr
eenRect.left : 0, this._model.scale(), showingDevice && this._cachedCssScreenRec
t ? this._cachedCssScreenRect.width : 0); |
| 293 this._leftRuler.render(0, this._model.scale(), showingDevice && this
._cachedCssScreenRect ? this._cachedCssScreenRect.height : 0); |
| 294 this._topRuler.element.style.top = this._cachedCssScreenRect ? this.
_cachedCssScreenRect.top + "px" : 0; |
| 295 this._leftRuler.element.style.top = this._cachedCssScreenRect ? this
._cachedCssScreenRect.top + "px" : 0; |
| 274 } | 296 } |
| 275 if (contentAreaResized) | 297 if (contentAreaResized) |
| 276 this._contentAreaResized(); | 298 this._contentAreaResized(); |
| 277 }, | 299 }, |
| 278 | 300 |
| 279 /** | 301 /** |
| 302 * @param {!Element} element |
| 280 * @param {string} srcset | 303 * @param {string} srcset |
| 281 */ | 304 */ |
| 282 _loadScreenImage: function(srcset) | 305 _loadImage: function(element, srcset) |
| 283 { | 306 { |
| 284 if (this._screenImage.getAttribute("srcset") === srcset) | 307 if (element.getAttribute("srcset") === srcset) |
| 285 return; | 308 return; |
| 286 this._screenImage.setAttribute("srcset", srcset); | 309 element.setAttribute("srcset", srcset); |
| 287 if (!srcset) | 310 if (!srcset) |
| 288 this._screenImage.classList.toggle("hidden", true); | 311 element.classList.toggle("hidden", true); |
| 289 }, | 312 }, |
| 290 | 313 |
| 291 /** | 314 /** |
| 315 * @param {!Element} element |
| 292 * @param {boolean} success | 316 * @param {boolean} success |
| 293 */ | 317 */ |
| 294 _onScreenImageLoaded: function(success) | 318 _onScreenImageLoaded: function(element, success) |
| 295 { | 319 { |
| 296 this._screenImage.classList.toggle("hidden", !success); | 320 element.classList.toggle("hidden", !success); |
| 297 }, | 321 }, |
| 298 | 322 |
| 299 _contentAreaResized: function() | 323 _contentAreaResized: function() |
| 300 { | 324 { |
| 301 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 325 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 302 var rect = this._contentArea.getBoundingClientRect(); | 326 var rect = this._contentArea.getBoundingClientRect(); |
| 303 var availableSize = new Size(Math.max(rect.width * zoomFactor, 1), Math.
max(rect.height * zoomFactor, 1)); | 327 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
)); | 328 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); | 329 this._model.setAvailableSize(availableSize, preferredSize); |
| 306 }, | 330 }, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 this._offset = 0; | 394 this._offset = 0; |
| 371 this._count = 0; | 395 this._count = 0; |
| 372 this._throttler = new WebInspector.Throttler(0); | 396 this._throttler = new WebInspector.Throttler(0); |
| 373 this._applyCallback = applyCallback; | 397 this._applyCallback = applyCallback; |
| 374 } | 398 } |
| 375 | 399 |
| 376 WebInspector.DeviceModeView.Ruler.prototype = { | 400 WebInspector.DeviceModeView.Ruler.prototype = { |
| 377 /** | 401 /** |
| 378 * @param {number} offset | 402 * @param {number} offset |
| 379 * @param {number} scale | 403 * @param {number} scale |
| 404 * @param {number} maxLength |
| 380 */ | 405 */ |
| 381 render: function(offset, scale) | 406 render: function(offset, scale, maxLength) |
| 382 { | 407 { |
| 383 this._scale = scale; | 408 this._scale = scale; |
| 384 this._offset = offset; | 409 this._offset = offset; |
| 385 if (this._horizontal) | 410 if (this._horizontal) |
| 386 this.element.style.paddingLeft = this._offset + "px"; | 411 this.element.style.paddingLeft = this._offset + "px"; |
| 387 else | 412 else |
| 388 this.element.style.paddingTop = this._offset + "px"; | 413 this.element.style.paddingTop = this._offset + "px"; |
| 389 this._throttler.schedule(this._update.bind(this)); | 414 this._throttler.schedule(this._update.bind(this)); |
| 415 this._maxLength = maxLength; |
| 390 }, | 416 }, |
| 391 | 417 |
| 392 /** | 418 /** |
| 393 * @override | 419 * @override |
| 394 */ | 420 */ |
| 395 onResize: function() | 421 onResize: function() |
| 396 { | 422 { |
| 397 this._throttler.schedule(this._update.bind(this)); | 423 this._throttler.schedule(this._update.bind(this)); |
| 398 }, | 424 }, |
| 399 | 425 |
| 400 /** | 426 /** |
| 401 * @return {!Promise.<?>} | 427 * @return {!Promise.<?>} |
| 402 */ | 428 */ |
| 403 _update: function() | 429 _update: function() |
| 404 { | 430 { |
| 405 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 431 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 406 var size = this._horizontal ? this._contentElement.offsetWidth : this._c
ontentElement.offsetHeight; | 432 var size = this._horizontal ? this._contentElement.offsetWidth : this._c
ontentElement.offsetHeight; |
| 433 if (this._maxLength) |
| 434 size = Math.min(size, this._maxLength); |
| 407 | 435 |
| 408 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered
ZoomFactor) { | 436 if (this._scale !== this._renderedScale || zoomFactor !== this._rendered
ZoomFactor) { |
| 409 this._contentElement.removeChildren(); | 437 this._contentElement.removeChildren(); |
| 410 this._count = 0; | 438 this._count = 0; |
| 411 this._renderedScale = this._scale; | 439 this._renderedScale = this._scale; |
| 412 this._renderedZoomFactor = zoomFactor; | 440 this._renderedZoomFactor = zoomFactor; |
| 413 } | 441 } |
| 414 | 442 |
| 415 var dipSize = size * zoomFactor / this._scale; | 443 var dipSize = size * zoomFactor / this._scale; |
| 416 var count = Math.ceil(dipSize / 5); | 444 var count = Math.ceil(dipSize / 5); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 /** | 483 /** |
| 456 * @param {number} size | 484 * @param {number} size |
| 457 */ | 485 */ |
| 458 _onMarkerClick: function(size) | 486 _onMarkerClick: function(size) |
| 459 { | 487 { |
| 460 this._applyCallback.call(null, size); | 488 this._applyCallback.call(null, size); |
| 461 }, | 489 }, |
| 462 | 490 |
| 463 __proto__: WebInspector.VBox.prototype | 491 __proto__: WebInspector.VBox.prototype |
| 464 } | 492 } |
| OLD | NEW |