| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @implements {WebInspector.OverridesSupport.PageResizer} | 8 * @implements {WebInspector.OverridesSupport.PageResizer} |
| 9 * @implements {WebInspector.TargetManager.Observer} | 9 * @implements {WebInspector.TargetManager.Observer} |
| 10 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder | 10 * @param {!WebInspector.InspectedPagePlaceholder} inspectedPagePlaceholder |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 this._decreasePageScaleButton.element.tabIndex = -1; | 67 this._decreasePageScaleButton.element.tabIndex = -1; |
| 68 this._decreasePageScaleButton.addEventListener("click", this._pageScaleButto
nClicked.bind(this, false), this); | 68 this._decreasePageScaleButton.addEventListener("click", this._pageScaleButto
nClicked.bind(this, false), this); |
| 69 this._pageScaleContainer.appendChild(this._decreasePageScaleButton.element); | 69 this._pageScaleContainer.appendChild(this._decreasePageScaleButton.element); |
| 70 | 70 |
| 71 this._inspectedPagePlaceholder = inspectedPagePlaceholder; | 71 this._inspectedPagePlaceholder = inspectedPagePlaceholder; |
| 72 inspectedPagePlaceholder.show(this.element); | 72 inspectedPagePlaceholder.show(this.element); |
| 73 | 73 |
| 74 this._enabled = false; | 74 this._enabled = false; |
| 75 this._viewport = { scrollX: 0, scrollY: 0, contentsWidth: 0, contentsHeight:
0, pageScaleFactor: 1, minimumPageScaleFactor: 1, maximumPageScaleFactor: 1 }; | 75 this._viewport = { scrollX: 0, scrollY: 0, contentsWidth: 0, contentsHeight:
0, pageScaleFactor: 1, minimumPageScaleFactor: 1, maximumPageScaleFactor: 1 }; |
| 76 this._drawContentsSize = true; | 76 this._drawContentsSize = true; |
| 77 this._hideTopRulerText = false; |
| 77 this._viewportChangedThrottler = new WebInspector.Throttler(0); | 78 this._viewportChangedThrottler = new WebInspector.Throttler(0); |
| 78 this._pageScaleFactorThrottler = new WebInspector.Throttler(50); | 79 this._pageScaleFactorThrottler = new WebInspector.Throttler(50); |
| 79 | 80 |
| 80 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); | 81 WebInspector.zoomManager.addEventListener(WebInspector.ZoomManager.Events.Zo
omChanged, this._onZoomChanged, this); |
| 81 WebInspector.overridesSupport.addEventListener(WebInspector.OverridesSupport
.Events.EmulationStateChanged, this._emulationEnabledChanged, this); | 82 WebInspector.overridesSupport.addEventListener(WebInspector.OverridesSupport
.Events.EmulationStateChanged, this._emulationEnabledChanged, this); |
| 82 this._mediaInspector.addEventListener(WebInspector.MediaQueryInspector.Event
s.CountUpdated, this._updateMediaQueryInspectorButton, this); | 83 this._mediaInspector.addEventListener(WebInspector.MediaQueryInspector.Event
s.CountUpdated, this._updateMediaQueryInspectorButton, this); |
| 83 this._mediaInspector.addEventListener(WebInspector.MediaQueryInspector.Event
s.HeightUpdated, this.onResize, this); | 84 this._mediaInspector.addEventListener(WebInspector.MediaQueryInspector.Event
s.HeightUpdated, this.onResize, this); |
| 85 this._mediaInspector.addEventListener(WebInspector.MediaQueryInspector.Event
s.HighlightDecorationUpdated, this._updateUI, this); |
| 84 WebInspector.targetManager.observeTargets(this); | 86 WebInspector.targetManager.observeTargets(this); |
| 85 | 87 |
| 86 this._emulationEnabledChanged(); | 88 this._emulationEnabledChanged(); |
| 87 this._overridesWarningUpdated(); | 89 this._overridesWarningUpdated(); |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 // Measured in DIP. | 92 // Measured in DIP. |
| 91 WebInspector.ResponsiveDesignView.SliderWidth = 19; | 93 WebInspector.ResponsiveDesignView.SliderWidth = 19; |
| 92 WebInspector.ResponsiveDesignView.RulerWidth = 22; | 94 WebInspector.ResponsiveDesignView.RulerWidth = 22; |
| 93 WebInspector.ResponsiveDesignView.PageScaleContainerWidth = 40; | 95 WebInspector.ResponsiveDesignView.PageScaleContainerWidth = 40; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 120 _invalidateCache: function() | 122 _invalidateCache: function() |
| 121 { | 123 { |
| 122 delete this._cachedScale; | 124 delete this._cachedScale; |
| 123 delete this._cachedCssCanvasWidth; | 125 delete this._cachedCssCanvasWidth; |
| 124 delete this._cachedCssCanvasHeight; | 126 delete this._cachedCssCanvasHeight; |
| 125 delete this._cachedCssHeight; | 127 delete this._cachedCssHeight; |
| 126 delete this._cachedCssWidth; | 128 delete this._cachedCssWidth; |
| 127 delete this._cachedZoomFactor; | 129 delete this._cachedZoomFactor; |
| 128 delete this._cachedViewport; | 130 delete this._cachedViewport; |
| 129 delete this._cachedDrawContentsSize; | 131 delete this._cachedDrawContentsSize; |
| 132 delete this._cachedHideTopRulerText; |
| 130 delete this._availableSize; | 133 delete this._availableSize; |
| 131 }, | 134 }, |
| 132 | 135 |
| 133 _emulationEnabledChanged: function() | 136 _emulationEnabledChanged: function() |
| 134 { | 137 { |
| 135 var enabled = WebInspector.overridesSupport.emulationEnabled(); | 138 var enabled = WebInspector.overridesSupport.emulationEnabled(); |
| 136 this._mediaInspector.setEnabled(enabled); | 139 this._mediaInspector.setEnabled(enabled); |
| 137 if (enabled && !this._enabled) { | 140 if (enabled && !this._enabled) { |
| 138 this._invalidateCache(); | 141 this._invalidateCache(); |
| 139 this._ignoreResize = true; | 142 this._ignoreResize = true; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 context.fillRect(-rulerWidth, 0, rulerWidth, dipGridHeight); | 309 context.fillRect(-rulerWidth, 0, rulerWidth, dipGridHeight); |
| 307 | 310 |
| 308 context.fillStyle = backgroundColor; | 311 context.fillStyle = backgroundColor; |
| 309 context.fillRect(0, 0, dipGridWidth, dipGridHeight); | 312 context.fillRect(0, 0, dipGridWidth, dipGridHeight); |
| 310 | 313 |
| 311 context.translate(0.5, 0.5); | 314 context.translate(0.5, 0.5); |
| 312 context.strokeStyle = rulerColor; | 315 context.strokeStyle = rulerColor; |
| 313 context.fillStyle = textColor; | 316 context.fillStyle = textColor; |
| 314 context.lineWidth = 1; | 317 context.lineWidth = 1; |
| 315 | 318 |
| 316 // Draw vertical ruler. | 319 // Draw horizontal ruler. |
| 317 context.save(); | 320 context.save(); |
| 318 var minXIndex = Math.ceil(dipScrollX / rulerSubStep); | 321 var minXIndex = Math.ceil(dipScrollX / rulerSubStep); |
| 319 var maxXIndex = Math.floor((dipScrollX + dipGridWidth) / rulerSubStep); | 322 var maxXIndex = Math.floor((dipScrollX + dipGridWidth) / rulerSubStep); |
| 320 context.translate(-dipScrollX, 0); | 323 context.translate(-dipScrollX, 0); |
| 321 for (var index = minXIndex; index <= maxXIndex; index++) { | 324 for (var index = minXIndex; index <= maxXIndex; index++) { |
| 322 var x = index * rulerSubStep; | 325 var x = index * rulerSubStep; |
| 323 var y = -rulerWidth / 4; | 326 var y = -rulerWidth / 4; |
| 324 if (!(index % (rulerStepCount / 4))) | 327 if (!(index % (rulerStepCount / 4))) |
| 325 y = -rulerWidth / 2; | 328 y = -rulerWidth / 2; |
| 326 if (!(index % (rulerStepCount / 2))) | 329 if (!(index % (rulerStepCount / 2))) |
| 327 y = -rulerWidth + 2; | 330 y = -rulerWidth + 2; |
| 328 | 331 |
| 329 if (!(index % rulerStepCount)) { | 332 if (!(index % rulerStepCount)) { |
| 330 context.save(); | 333 if (!this._hideTopRulerText) { |
| 331 context.translate(x, 0); | 334 context.save(); |
| 332 context.fillText(Math.round(x / scale), 2, -rulerWidth / 2); | 335 context.translate(x, 0); |
| 333 context.restore(); | 336 context.fillText(Math.round(x / scale), 2, -rulerWidth / 2); |
| 337 context.restore(); |
| 338 } |
| 334 y = -rulerWidth; | 339 y = -rulerWidth; |
| 335 } | 340 } |
| 336 | 341 |
| 337 context.beginPath(); | 342 context.beginPath(); |
| 338 context.moveTo(x, y); | 343 context.moveTo(x, y); |
| 339 context.lineTo(x, 0); | 344 context.lineTo(x, 0); |
| 340 context.stroke(); | 345 context.stroke(); |
| 341 } | 346 } |
| 342 context.restore(); | 347 context.restore(); |
| 343 | 348 |
| 344 // Draw horizontal ruler. | 349 // Draw vertical ruler. |
| 345 context.save(); | 350 context.save(); |
| 346 var minYIndex = Math.ceil(dipScrollY / rulerSubStep); | 351 var minYIndex = Math.ceil(dipScrollY / rulerSubStep); |
| 347 var maxYIndex = Math.floor((dipScrollY + dipGridHeight) / rulerSubStep); | 352 var maxYIndex = Math.floor((dipScrollY + dipGridHeight) / rulerSubStep); |
| 348 context.translate(0, -dipScrollY); | 353 context.translate(0, -dipScrollY); |
| 349 for (var index = minYIndex; index <= maxYIndex; index++) { | 354 for (var index = minYIndex; index <= maxYIndex; index++) { |
| 350 var y = index * rulerSubStep; | 355 var y = index * rulerSubStep; |
| 351 var x = -rulerWidth / 4; | 356 var x = -rulerWidth / 4; |
| 352 if (!(index % (rulerStepCount / 4))) | 357 if (!(index % (rulerStepCount / 4))) |
| 353 x = -rulerWidth / 2; | 358 x = -rulerWidth / 2; |
| 354 if (!(index % (rulerStepCount / 2))) | 359 if (!(index % (rulerStepCount / 2))) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 _updateUI: function() | 429 _updateUI: function() |
| 425 { | 430 { |
| 426 if (!this._enabled || !this.isShowing()) | 431 if (!this._enabled || !this.isShowing()) |
| 427 return; | 432 return; |
| 428 | 433 |
| 429 var zoomFactor = WebInspector.zoomManager.zoomFactor(); | 434 var zoomFactor = WebInspector.zoomManager.zoomFactor(); |
| 430 var rect = this._canvas.parentElement.getBoundingClientRect(); | 435 var rect = this._canvas.parentElement.getBoundingClientRect(); |
| 431 var availableDip = this._availableDipSize(); | 436 var availableDip = this._availableDipSize(); |
| 432 var cssCanvasWidth = rect.width; | 437 var cssCanvasWidth = rect.width; |
| 433 var cssCanvasHeight = rect.height; | 438 var cssCanvasHeight = rect.height; |
| 439 this._hideTopRulerText = this._mediaInspector.highlightDecorationVisible
(); |
| 434 | 440 |
| 435 this._mediaInspector.setAxisTransform(WebInspector.ResponsiveDesignView.
RulerWidth / zoomFactor, this._viewport.scrollX, this._scale * this._viewport.pa
geScaleFactor); | 441 this._mediaInspector.setAxisTransform(WebInspector.ResponsiveDesignView.
RulerWidth / zoomFactor, this._viewport.scrollX, this._scale * this._viewport.pa
geScaleFactor); |
| 436 | 442 |
| 437 if (this._cachedZoomFactor !== zoomFactor) { | 443 if (this._cachedZoomFactor !== zoomFactor) { |
| 438 var cssRulerWidth = WebInspector.ResponsiveDesignView.RulerWidth / z
oomFactor + "px"; | 444 var cssRulerWidth = WebInspector.ResponsiveDesignView.RulerWidth / z
oomFactor + "px"; |
| 439 this._rulerGlasspane.style.height = cssRulerWidth; | 445 this._rulerGlasspane.style.height = cssRulerWidth; |
| 440 this._rulerGlasspane.style.left = cssRulerWidth; | 446 this._rulerGlasspane.style.left = cssRulerWidth; |
| 441 this._slidersContainer.style.left = cssRulerWidth; | 447 this._slidersContainer.style.left = cssRulerWidth; |
| 442 this._slidersContainer.style.top = cssRulerWidth; | 448 this._slidersContainer.style.top = cssRulerWidth; |
| 443 this._warningMessage.style.height = cssRulerWidth; | 449 this._warningMessage.style.height = cssRulerWidth; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 460 var pageScaleVisible = cssWidth + WebInspector.ResponsiveDesignView.Page
ScaleContainerWidth + WebInspector.ResponsiveDesignView.RulerWidth <= rect.width
|| | 466 var pageScaleVisible = cssWidth + WebInspector.ResponsiveDesignView.Page
ScaleContainerWidth + WebInspector.ResponsiveDesignView.RulerWidth <= rect.width
|| |
| 461 cssHeight + WebInspector.ResponsiveDesignView.PageScaleContainerHeig
ht + WebInspector.ResponsiveDesignView.RulerWidth <= rect.height; | 467 cssHeight + WebInspector.ResponsiveDesignView.PageScaleContainerHeig
ht + WebInspector.ResponsiveDesignView.RulerWidth <= rect.height; |
| 462 this._pageScaleContainer.classList.toggle("hidden", !pageScaleVisible); | 468 this._pageScaleContainer.classList.toggle("hidden", !pageScaleVisible); |
| 463 | 469 |
| 464 var viewportChanged = !this._cachedViewport | 470 var viewportChanged = !this._cachedViewport |
| 465 || this._cachedViewport.scrollX !== this._viewport.scrollX || this._
cachedViewport.scrollY !== this._viewport.scrollY | 471 || this._cachedViewport.scrollX !== this._viewport.scrollX || this._
cachedViewport.scrollY !== this._viewport.scrollY |
| 466 || this._cachedViewport.contentsWidth !== this._viewport.contentsWid
th || this._cachedViewport.contentsHeight !== this._viewport.contentsHeight | 472 || this._cachedViewport.contentsWidth !== this._viewport.contentsWid
th || this._cachedViewport.contentsHeight !== this._viewport.contentsHeight |
| 467 || this._cachedViewport.pageScaleFactor !== this._viewport.pageScale
Factor | 473 || this._cachedViewport.pageScaleFactor !== this._viewport.pageScale
Factor |
| 468 || this._cachedViewport.minimumPageScaleFactor !== this._viewport.mi
nimumPageScaleFactor | 474 || this._cachedViewport.minimumPageScaleFactor !== this._viewport.mi
nimumPageScaleFactor |
| 469 || this._cachedViewport.maximumPageScaleFactor !== this._viewport.ma
ximumPageScaleFactor; | 475 || this._cachedViewport.maximumPageScaleFactor !== this._viewport.ma
ximumPageScaleFactor; |
| 470 if (viewportChanged || this._drawContentsSize !== this._cachedDrawConten
tsSize || this._cachedScale !== this._scale || this._cachedCssCanvasWidth !== cs
sCanvasWidth || this._cachedCssCanvasHeight !== cssCanvasHeight || this._cachedZ
oomFactor !== zoomFactor) | 476 if (viewportChanged || this._drawContentsSize !== this._cachedDrawConten
tsSize || this._cachedScale !== this._scale || this._cachedCssCanvasWidth !== cs
sCanvasWidth || this._cachedCssCanvasHeight !== cssCanvasHeight || this._cachedZ
oomFactor !== zoomFactor || this._cachedHideTopRulerText !== this._hideTopRulerT
ext) |
| 471 this._drawCanvas(cssCanvasWidth, cssCanvasHeight); | 477 this._drawCanvas(cssCanvasWidth, cssCanvasHeight); |
| 472 | 478 |
| 473 if (viewportChanged) { | 479 if (viewportChanged) { |
| 474 this._pageScaleLabel.textContent = WebInspector.UIString("%.1f", thi
s._viewport.pageScaleFactor); | 480 this._pageScaleLabel.textContent = WebInspector.UIString("%.1f", thi
s._viewport.pageScaleFactor); |
| 475 this._decreasePageScaleButton.title = WebInspector.UIString("Scale d
own (minimum %.1f)", this._viewport.minimumPageScaleFactor); | 481 this._decreasePageScaleButton.title = WebInspector.UIString("Scale d
own (minimum %.1f)", this._viewport.minimumPageScaleFactor); |
| 476 this._decreasePageScaleButton.setEnabled(this._viewport.pageScaleFac
tor > this._viewport.minimumPageScaleFactor); | 482 this._decreasePageScaleButton.setEnabled(this._viewport.pageScaleFac
tor > this._viewport.minimumPageScaleFactor); |
| 477 this._increasePageScaleButton.title = WebInspector.UIString("Scale u
p (maximum %.1f)", this._viewport.maximumPageScaleFactor); | 483 this._increasePageScaleButton.title = WebInspector.UIString("Scale u
p (maximum %.1f)", this._viewport.maximumPageScaleFactor); |
| 478 this._increasePageScaleButton.setEnabled(this._viewport.pageScaleFac
tor < this._viewport.maximumPageScaleFactor); | 484 this._increasePageScaleButton.setEnabled(this._viewport.pageScaleFac
tor < this._viewport.maximumPageScaleFactor); |
| 479 } | 485 } |
| 480 | 486 |
| 481 this._cachedScale = this._scale; | 487 this._cachedScale = this._scale; |
| 482 this._cachedCssCanvasWidth = cssCanvasWidth; | 488 this._cachedCssCanvasWidth = cssCanvasWidth; |
| 483 this._cachedCssCanvasHeight = cssCanvasHeight; | 489 this._cachedCssCanvasHeight = cssCanvasHeight; |
| 484 this._cachedCssHeight = cssHeight; | 490 this._cachedCssHeight = cssHeight; |
| 485 this._cachedCssWidth = cssWidth; | 491 this._cachedCssWidth = cssWidth; |
| 486 this._cachedZoomFactor = zoomFactor; | 492 this._cachedZoomFactor = zoomFactor; |
| 487 this._cachedViewport = this._viewport; | 493 this._cachedViewport = this._viewport; |
| 488 this._cachedDrawContentsSize = this._drawContentsSize; | 494 this._cachedDrawContentsSize = this._drawContentsSize; |
| 495 this._cachedHideTopRulerText = this._hideTopRulerText; |
| 489 }, | 496 }, |
| 490 | 497 |
| 491 onResize: function() | 498 onResize: function() |
| 492 { | 499 { |
| 493 if (!this._enabled || this._ignoreResize) | 500 if (!this._enabled || this._ignoreResize) |
| 494 return; | 501 return; |
| 495 var oldSize = this._availableSize; | 502 var oldSize = this._availableSize; |
| 496 delete this._availableSize; | 503 delete this._availableSize; |
| 497 var newSize = this._availableDipSize(); | 504 var newSize = this._availableDipSize(); |
| 498 if (!newSize.isEqual(oldSize)) | 505 if (!newSize.isEqual(oldSize)) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 value = Math.min(this._viewport.maximumPageScaleFactor, value); | 711 value = Math.min(this._viewport.maximumPageScaleFactor, value); |
| 705 value = Math.max(this._viewport.minimumPageScaleFactor, value) | 712 value = Math.max(this._viewport.minimumPageScaleFactor, value) |
| 706 this._target.pageAgent().setPageScaleFactor(value); | 713 this._target.pageAgent().setPageScaleFactor(value); |
| 707 } | 714 } |
| 708 finishCallback(); | 715 finishCallback(); |
| 709 } | 716 } |
| 710 }, | 717 }, |
| 711 | 718 |
| 712 __proto__: WebInspector.VBox.prototype | 719 __proto__: WebInspector.VBox.prototype |
| 713 }; | 720 }; |
| OLD | NEW |