Chromium Code Reviews| Index: Source/devtools/front_end/Layers3DView.js |
| diff --git a/Source/devtools/front_end/Layers3DView.js b/Source/devtools/front_end/Layers3DView.js |
| index 411036b855fe2f0b2d4a4711d916642a3a44daa6..37555c55d1a2052a7496d7b39ee0729bc3857bb0 100644 |
| --- a/Source/devtools/front_end/Layers3DView.js |
| +++ b/Source/devtools/front_end/Layers3DView.js |
| @@ -50,6 +50,7 @@ WebInspector.Layers3DView = function(model) |
| this.element.addEventListener("mousemove", this._onMouseMove.bind(this), false); |
| this.element.addEventListener("contextmenu", this._onContextMenu.bind(this), false); |
| this._elementsByLayerId = {}; |
| + this._scrollRectElementsByLayerId = {} |
|
caseq
2014/03/11 11:14:38
unused?
malch
2014/03/11 11:49:08
Done.
|
| this._scaleAdjustmentStylesheet = this.element.ownerDocument.head.createChild("style"); |
| this._scaleAdjustmentStylesheet.disabled = true; |
| this._lastOutlinedElement = {}; |
| @@ -82,6 +83,15 @@ WebInspector.Layers3DView.PaintRectColors = [ |
| WebInspector.Color.fromRGBA([0, 0xFF, 0, 0x3F]) |
| ] |
| +/** |
| + * @enum {string} |
| + */ |
| +WebInspector.Layers3DView.ScrollRectTitles = { |
| + RepaintsOnScroll: WebInspector.UIString("repaints on scroll"), |
| + TouchEventHandler: WebInspector.UIString("touch event listener"), |
| + WheelEventHandler: WebInspector.UIString("mousewheel event listener") |
| +} |
| + |
| WebInspector.Layers3DView.prototype = { |
| onResize: function() |
| { |
| @@ -153,18 +163,20 @@ WebInspector.Layers3DView.prototype = { |
| _scaleToFit: function() |
| { |
| - var root = this._model.contentRoot(); |
| - if (!root) |
| + // var root = this._model.root(); |
| + // TODO: RENAME |
| + var contentRoot = this._model.contentRoot(); |
|
caseq
2014/03/11 11:14:38
Do we really have to rename it here?
malch
2014/03/11 11:49:08
Done.
|
| + if (!contentRoot) |
| return; |
| const padding = 40; |
| - var scaleX = this._clientWidth / (root.width() + 2 * padding); |
| - var scaleY = this._clientHeight / (root.height() + 2 * padding); |
| + var scaleX = this._clientWidth / (contentRoot.width() + 2 * padding); |
| + var scaleY = this._clientHeight / (contentRoot.height() + 2 * padding); |
| var autoScale = Math.min(scaleX, scaleY); |
| this._scale = autoScale * this._transformController.scale(); |
| - this._paddingX = ((this._clientWidth / autoScale - root.width()) >> 1) * this._scale; |
| - this._paddingY = ((this._clientHeight / autoScale - root.height()) >> 1) * this._scale; |
| + this._paddingX = ((this._clientWidth / autoScale - contentRoot.width()) >> 1) * this._scale; |
| + this._paddingY = ((this._clientHeight / autoScale - contentRoot.height()) >> 1) * this._scale; |
| const screenLayerSpacing = 20; |
| this._layerSpacing = screenLayerSpacing + "px"; |
| const screenLayerThickness = 4; |
| @@ -180,7 +192,7 @@ WebInspector.Layers3DView.prototype = { |
| else |
| stylesheetTextNode.nodeValue = stylesheetContent; |
| - var style = this._elementForLayer(root).style; |
| + var style = this._elementForLayer(contentRoot).style; |
| style.left = Math.round(this._paddingX) + "px"; |
| style.top = Math.round(this._paddingY) + "px"; |
| style.webkitTransformOrigin = ""; |
| @@ -215,6 +227,61 @@ WebInspector.Layers3DView.prototype = { |
| style.webkitTransformOrigin = Math.round(this._paddingX + offsetX + root.width() * this._scale / 2) + "px " + Math.round(this._paddingY + offsetY + root.height() * this._scale / 2) + "px"; |
| }, |
| + /** |
| + * @param {!Element} element |
| + */ |
| + _removeElement: function(element) |
|
caseq
2014/03/11 11:14:38
looks like you can define it within the only remai
malch
2014/03/11 11:49:08
Done.
|
| + { |
| + element.remove() |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Layer} layer |
| + * @param {!LayerTreeAgent.ScrollRect} scrollRect |
| + * @return {!Element} |
| + */ |
| + _createScrollRectElement: function(layer, scrollRect) |
| + { |
| + var element = document.createElement("div"); |
| + var style = element.style; |
|
caseq
2014/03/11 11:14:38
unused?
malch
2014/03/11 11:49:08
Done.
|
| + var parentLayerId = layer.id(); |
|
caseq
2014/03/11 11:14:38
inline
malch
2014/03/11 11:49:08
Done.
|
| + var parentLayerElement = this._elementsByLayerId[parentLayerId]; |
| + element.className = "scroll-rect"; |
| + element.title = WebInspector.Layers3DView.ScrollRectTitles[scrollRect.type]; |
| + parentLayerElement.appendChild(element); |
| + return element; |
| + }, |
| + |
| + /** |
| + * @param {!Array.<!Element>} elements |
| + * @param {!LayerTreeAgent.ScrollRect} scrollRect |
| + * @param {!number} index |
| + */ |
| + _updateScrollRectElement: function(elements, scrollRect, index) |
| + { |
| + var element = elements[index]; |
| + var style = element.style; |
| + style.width = Math.round(scrollRect.rect.width * this._scale) + "px"; |
| + style.height = Math.round(scrollRect.rect.height * this._scale) + "px"; |
| + style.left = Math.round(scrollRect.rect.x * this._scale) + "px"; |
| + style.top = Math.round(scrollRect.rect.y * this._scale) + "px"; |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Layer} layer |
| + */ |
| + _updateScrollRectsForLayer: function(layer) |
| + { |
| + var newScrollRects = layer.scrollRects(), |
| + layerDetails = this._elementsByLayerId[layer.id()].__layerDetails; |
| + if (newScrollRects != layerDetails.scrollRects) { |
|
caseq
2014/03/11 11:14:38
We use !==
malch
2014/03/11 11:49:08
Done.
|
| + layerDetails.scrollRectElements.forEach(this._removeElement); |
| + layerDetails.scrollRects = newScrollRects; |
| + layerDetails.scrollRectElements = layerDetails.scrollRects.map(this._createScrollRectElement.bind(this, layer)); |
| + } |
| + layerDetails.scrollRects.forEach(this._updateScrollRectElement.bind(this, layerDetails.scrollRectElements)); |
| + }, |
| + |
| _update: function() |
| { |
| if (!this.isShowing()) { |
| @@ -245,7 +312,8 @@ WebInspector.Layers3DView.prototype = { |
| } |
| this._scaleToFit(); |
| this._updateTransform(); |
| - this._model.forEachLayer(updateLayer.bind(this), this._model.contentRoot()); |
| + this._model.forEachLayer(updateLayer.bind(this)); |
| + this._model.forEachLayer(this._updateScrollRectsForLayer.bind(this)); |
| this._needsUpdate = false; |
| }, |
| @@ -255,7 +323,8 @@ WebInspector.Layers3DView.prototype = { |
| _onLayerPainted: function(event) |
| { |
| var layer = /** @type {!WebInspector.Layer} */ (event.data); |
| - this._updatePaintRect(this._elementForLayer(layer)); |
| + if (layer.nodeId()) |
| + this._updatePaintRect(this._elementForLayer(layer)); |
| }, |
| /** |
| @@ -272,9 +341,14 @@ WebInspector.Layers3DView.prototype = { |
| return element; |
| } |
| element = document.createElement("div"); |
| - element.className = "layer-container"; |
| - ["fill back-wall", "side-wall top", "side-wall right", "side-wall bottom", "side-wall left"].forEach(element.createChild.bind(element, "div")); |
| - element.__layerDetails = new WebInspector.LayerDetails(layer, element.createChild("div", "paint-rect")); |
| + if (layer.nodeId()) { |
| + element.className = "layer-container"; |
| + ["fill back-wall", "side-wall top", "side-wall right", "side-wall bottom", "side-wall left"].forEach(element.createChild.bind(element, "div")); |
| + element.__layerDetails = new WebInspector.LayerDetails(layer, element.createChild("div", "paint-rect")); |
| + } else { |
| + element.className = "layer-transparent"; |
| + element.__layerDetails = new WebInspector.LayerDetails(layer); |
| + } |
| this._elementsByLayerId[layer.id()] = element; |
| return element; |
| }, |
| @@ -286,18 +360,23 @@ WebInspector.Layers3DView.prototype = { |
| { |
| var layer = element.__layerDetails.layer; |
| var style = element.style; |
| - var isContentRoot = layer === this._model.contentRoot(); |
| - var parentElement = isContentRoot ? this._rotatingContainerElement : this._elementForLayer(layer.parent()); |
| + |
| + var contentRoot = /** @type {!WebInspector.Layer} */ (this._model.contentRoot()); |
| + var isContentRoot = layer === contentRoot; |
| + var isRoot = layer === this._model.root(); |
| + var parentElement = isContentRoot ? this._rotatingContainerElement : (isRoot ? this._elementForLayer(contentRoot) : this._elementForLayer(layer.parent())); |
| element.__layerDetails.depth = parentElement.__layerDetails ? parentElement.__layerDetails.depth + 1 : 0; |
| element.classList.toggle("invisible", layer.invisible()); |
| - this._updateElementColor(element); |
| + if (layer.nodeId()) |
| + this._updateElementColor(element); |
| if (parentElement !== element.parentElement) |
| parentElement.appendChild(element); |
| style.width = Math.round(layer.width() * this._scale) + "px"; |
| style.height = Math.round(layer.height() * this._scale) + "px"; |
| - this._updatePaintRect(element); |
| - if (isContentRoot) |
| + if (layer.nodeId()) |
| + this._updatePaintRect(element); |
| + if (isContentRoot || isRoot) |
| return; |
| style.left = Math.round(layer.offsetX() * this._scale) + "px"; |
| style.top = Math.round(layer.offsetY() * this._scale) + "px"; |
| @@ -322,6 +401,9 @@ WebInspector.Layers3DView.prototype = { |
| } |
| }, |
| + /** |
| + * @param {!Element} element |
| + */ |
| _updatePaintRect: function(element) |
| { |
| var details = element.__layerDetails; |
| @@ -426,12 +508,15 @@ WebInspector.Layers3DView.prototype = { |
| /** |
| * @constructor |
| * @param {!WebInspector.Layer} layer |
| - * @param {!Element} paintRectElement |
| + * @param {!Element=} paintRectElement |
| */ |
| WebInspector.LayerDetails = function(layer, paintRectElement) |
| { |
| this.layer = layer; |
| this.depth = 0; |
| - this.paintRectElement = paintRectElement; |
| + if (paintRectElement) |
|
caseq
2014/03/11 11:14:38
I think you can omit this check.
malch
2014/03/11 11:49:08
Done.
|
| + this.paintRectElement = paintRectElement; |
| this.paintCount = 0; |
| + this.scrollRects = []; |
| + this.scrollRectElements = []; |
| } |