OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 LayerSelected: "LayerSelected", | 75 LayerSelected: "LayerSelected", |
76 LayerSnapshotRequested: "LayerSnapshotRequested" | 76 LayerSnapshotRequested: "LayerSnapshotRequested" |
77 } | 77 } |
78 | 78 |
79 WebInspector.Layers3DView.PaintRectColors = [ | 79 WebInspector.Layers3DView.PaintRectColors = [ |
80 WebInspector.Color.fromRGBA([0, 0x5F, 0, 0x3F]), | 80 WebInspector.Color.fromRGBA([0, 0x5F, 0, 0x3F]), |
81 WebInspector.Color.fromRGBA([0, 0xAF, 0, 0x3F]), | 81 WebInspector.Color.fromRGBA([0, 0xAF, 0, 0x3F]), |
82 WebInspector.Color.fromRGBA([0, 0xFF, 0, 0x3F]) | 82 WebInspector.Color.fromRGBA([0, 0xFF, 0, 0x3F]) |
83 ] | 83 ] |
84 | 84 |
85 /** | |
86 * @enum {string} | |
87 */ | |
88 WebInspector.Layers3DView.ScrollRectTitles = { | |
89 RepaintsOnScroll: WebInspector.UIString("repaints on scroll"), | |
90 TouchEventHandler: WebInspector.UIString("touch event listener"), | |
91 WheelEventHandler: WebInspector.UIString("mousewheel event listener") | |
92 } | |
93 | |
85 WebInspector.Layers3DView.prototype = { | 94 WebInspector.Layers3DView.prototype = { |
86 onResize: function() | 95 onResize: function() |
87 { | 96 { |
88 this._update(); | 97 this._update(); |
89 }, | 98 }, |
90 | 99 |
91 willHide: function() | 100 willHide: function() |
92 { | 101 { |
93 this._scaleAdjustmentStylesheet.disabled = true; | 102 this._scaleAdjustmentStylesheet.disabled = true; |
94 }, | 103 }, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 var style = this._rotatingContainerElement.style; | 217 var style = this._rotatingContainerElement.style; |
209 // Translate well to front so that no matter how we turn the plane, no p arts of it goes below parent. | 218 // Translate well to front so that no matter how we turn the plane, no p arts of it goes below parent. |
210 // This makes sure mouse events go to proper layers, not straight to the parent. | 219 // This makes sure mouse events go to proper layers, not straight to the parent. |
211 style.webkitTransform = "translateZ(10000px)" + | 220 style.webkitTransform = "translateZ(10000px)" + |
212 " rotateX(" + this._transformController.rotateX() + "deg) rotateY(" + this._transformController.rotateY() + "deg)" + | 221 " rotateX(" + this._transformController.rotateX() + "deg) rotateY(" + this._transformController.rotateY() + "deg)" + |
213 " translateX(" + offsetX + "px) translateY(" + offsetY + "px)"; | 222 " translateX(" + offsetX + "px) translateY(" + offsetY + "px)"; |
214 // Compute where the center of shitfted and scaled root layer would be a nd use is as origin for rotation. | 223 // Compute where the center of shitfted and scaled root layer would be a nd use is as origin for rotation. |
215 style.webkitTransformOrigin = Math.round(this._paddingX + offsetX + root .width() * this._scale / 2) + "px " + Math.round(this._paddingY + offsetY + root .height() * this._scale / 2) + "px"; | 224 style.webkitTransformOrigin = Math.round(this._paddingX + offsetX + root .width() * this._scale / 2) + "px " + Math.round(this._paddingY + offsetY + root .height() * this._scale / 2) + "px"; |
216 }, | 225 }, |
217 | 226 |
227 /** | |
228 * @param {!WebInspector.Layer} layer | |
229 * @return {!Element} | |
230 */ | |
231 _createScrollRectElement: function(layer) | |
232 { | |
233 var element = document.createElement("div"); | |
234 var parentLayerElement = this._elementsByLayerId[layer.id()]; | |
235 element.className = "scroll-rect"; | |
236 parentLayerElement.appendChild(element); | |
237 return element; | |
238 }, | |
239 | |
240 /** | |
241 * @param {!LayerTreeAgent.ScrollRect} rect | |
242 * @param {!Element} element | |
243 */ | |
244 _updateScrollRectElement: function(rect, element) | |
245 { | |
246 var style = element.style; | |
247 style.width = Math.round(rect.rect.width * this._scale) + "px"; | |
248 style.height = Math.round(rect.rect.height * this._scale) + "px"; | |
249 style.left = Math.round(rect.rect.x * this._scale) + "px"; | |
250 style.top = Math.round(rect.rect.y * this._scale) + "px"; | |
251 element.title = WebInspector.Layers3DView.ScrollRectTitles[rect.type]; | |
252 }, | |
253 | |
254 /** | |
255 * @param {!WebInspector.Layer} layer | |
256 */ | |
257 _updateScrollRectsForLayer: function(layer) | |
258 { | |
259 var newScrollRects = layer.scrollRects(), | |
260 layerDetails = this._elementsByLayerId[layer.id()].__layerDetails; | |
caseq
2014/03/11 13:57:03
var layerDetails = ...
malch
2014/03/11 14:51:24
Done.
| |
261 | |
262 /** | |
263 * @param {!Element} element | |
264 */ | |
265 function removeElement(element) | |
266 { | |
267 element.remove() | |
268 } | |
269 | |
270 if (newScrollRects.length !== layerDetails.scrollRects.length) { | |
271 layerDetails.scrollRectElements.forEach(removeElement); | |
272 layerDetails.scrollRects = newScrollRects; | |
caseq
2014/03/11 13:57:03
Do we have to keep them now?
malch
2014/03/11 14:51:24
Done.
| |
273 layerDetails.scrollRectElements = layerDetails.scrollRects.map(this. _createScrollRectElement.bind(this, layer)); | |
274 } | |
275 for (var i = 0; i < layerDetails.scrollRects.length; ++i) | |
276 this._updateScrollRectElement(layerDetails.scrollRects[i], layerDeta ils.scrollRectElements[i]); | |
caseq
2014/03/11 13:57:03
newScrollRects?
malch
2014/03/11 14:51:24
Done.
| |
277 }, | |
278 | |
218 _update: function() | 279 _update: function() |
219 { | 280 { |
220 if (!this.isShowing()) { | 281 if (!this.isShowing()) { |
221 this._needsUpdate = true; | 282 this._needsUpdate = true; |
222 return; | 283 return; |
223 } | 284 } |
224 if (!this._model.contentRoot()) { | 285 if (!this._model.contentRoot()) { |
225 this._emptyView.show(this.element); | 286 this._emptyView.show(this.element); |
226 this._rotatingContainerElement.removeChildren(); | 287 this._rotatingContainerElement.removeChildren(); |
227 return; | 288 return; |
228 } | 289 } |
229 this._emptyView.detach(); | 290 this._emptyView.detach(); |
230 | 291 |
231 /** | 292 /** |
232 * @this {WebInspector.Layers3DView} | 293 * @this {WebInspector.Layers3DView} |
233 */ | 294 */ |
234 function updateLayer(layer) | 295 function updateLayer(layer) |
235 { | 296 { |
236 this._updateLayerElement(this._elementForLayer(layer)); | 297 this._updateLayerElement(this._elementForLayer(layer)); |
298 this._updateScrollRectsForLayer(layer); | |
237 } | 299 } |
238 this._clientWidth = this.element.clientWidth; | 300 this._clientWidth = this.element.clientWidth; |
239 this._clientHeight = this.element.clientHeight; | 301 this._clientHeight = this.element.clientHeight; |
240 for (var layerId in this._elementsByLayerId) { | 302 for (var layerId in this._elementsByLayerId) { |
241 if (this._model.layerById(layerId)) | 303 if (this._model.layerById(layerId)) |
242 continue; | 304 continue; |
243 this._elementsByLayerId[layerId].remove(); | 305 this._elementsByLayerId[layerId].remove(); |
244 delete this._elementsByLayerId[layerId]; | 306 delete this._elementsByLayerId[layerId]; |
245 } | 307 } |
246 this._scaleToFit(); | 308 this._scaleToFit(); |
247 this._updateTransform(); | 309 this._updateTransform(); |
248 this._model.forEachLayer(updateLayer.bind(this), this._model.contentRoot ()); | 310 this._model.forEachLayer(updateLayer.bind(this)); |
249 this._needsUpdate = false; | 311 this._needsUpdate = false; |
250 }, | 312 }, |
251 | 313 |
252 /** | 314 /** |
253 * @param {!WebInspector.Event} event | 315 * @param {!WebInspector.Event} event |
254 */ | 316 */ |
255 _onLayerPainted: function(event) | 317 _onLayerPainted: function(event) |
256 { | 318 { |
257 var layer = /** @type {!WebInspector.Layer} */ (event.data); | 319 var layer = /** @type {!WebInspector.Layer} */ (event.data); |
258 this._updatePaintRect(this._elementForLayer(layer)); | 320 if (layer.nodeId()) |
caseq
2014/03/11 13:57:03
Can we either avoid this check or at least move it
malch
2014/03/11 14:51:24
Done.
| |
321 this._updatePaintRect(this._elementForLayer(layer)); | |
259 }, | 322 }, |
260 | 323 |
261 /** | 324 /** |
262 * @param {!WebInspector.Layer} layer | 325 * @param {!WebInspector.Layer} layer |
263 * @return {!Element} | 326 * @return {!Element} |
264 */ | 327 */ |
265 _elementForLayer: function(layer) | 328 _elementForLayer: function(layer) |
266 { | 329 { |
267 var element = this._elementsByLayerId[layer.id()]; | 330 var element = this._elementsByLayerId[layer.id()]; |
268 if (element) { | 331 if (element) { |
269 // We might have missed an update were a layer with given id was gon e and re-created, | 332 // We might have missed an update were a layer with given id was gon e and re-created, |
270 // so update reference to point to proper layer object. | 333 // so update reference to point to proper layer object. |
271 element.__layerDetails.layer = layer; | 334 element.__layerDetails.layer = layer; |
272 return element; | 335 return element; |
273 } | 336 } |
274 element = document.createElement("div"); | 337 element = document.createElement("div"); |
275 element.className = "layer-container"; | 338 if (layer.nodeId()) { |
276 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bottom ", "side-wall left"].forEach(element.createChild.bind(element, "div")); | 339 element.className = "layer-container"; |
277 element.__layerDetails = new WebInspector.LayerDetails(layer, element.cr eateChild("div", "paint-rect")); | 340 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bo ttom", "side-wall left"].forEach(element.createChild.bind(element, "div")); |
341 element.__layerDetails = new WebInspector.LayerDetails(layer, elemen t.createChild("div", "paint-rect")); | |
342 } else { | |
343 element.className = "layer-transparent"; | |
344 element.__layerDetails = new WebInspector.LayerDetails(layer); | |
345 } | |
278 this._elementsByLayerId[layer.id()] = element; | 346 this._elementsByLayerId[layer.id()] = element; |
279 return element; | 347 return element; |
280 }, | 348 }, |
281 | 349 |
282 /** | 350 /** |
283 * @param {!Element} element | 351 * @param {!Element} element |
284 */ | 352 */ |
285 _updateLayerElement: function(element) | 353 _updateLayerElement: function(element) |
286 { | 354 { |
287 var layer = element.__layerDetails.layer; | 355 var layer = element.__layerDetails.layer; |
288 var style = element.style; | 356 var style = element.style; |
289 var isContentRoot = layer === this._model.contentRoot(); | 357 |
290 var parentElement = isContentRoot ? this._rotatingContainerElement : thi s._elementForLayer(layer.parent()); | 358 var contentRoot = /** @type {!WebInspector.Layer} */ (this._model.conten tRoot()); |
359 var isContentRoot = layer === contentRoot; | |
360 var isRoot = layer === this._model.root(); | |
361 var parentElement; | |
362 if (isContentRoot) { | |
363 parentElement = this._rotatingContainerElement; | |
364 } else if (isRoot) { | |
365 parentElement = this._elementForLayer(contentRoot); | |
366 } else { | |
367 parentElement = this._elementForLayer(layer.parent()); | |
368 } | |
291 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0; | 369 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0; |
292 element.classList.toggle("invisible", layer.invisible()); | 370 element.classList.toggle("invisible", layer.invisible()); |
293 this._updateElementColor(element); | 371 if (layer.nodeId()) |
372 this._updateElementColor(element); | |
294 if (parentElement !== element.parentElement) | 373 if (parentElement !== element.parentElement) |
295 parentElement.appendChild(element); | 374 parentElement.appendChild(element); |
296 | 375 |
297 style.width = Math.round(layer.width() * this._scale) + "px"; | 376 style.width = Math.round(layer.width() * this._scale) + "px"; |
298 style.height = Math.round(layer.height() * this._scale) + "px"; | 377 style.height = Math.round(layer.height() * this._scale) + "px"; |
299 this._updatePaintRect(element); | 378 if (layer.nodeId()) |
300 if (isContentRoot) | 379 this._updatePaintRect(element); |
380 if (isContentRoot || isRoot) | |
301 return; | 381 return; |
302 style.left = Math.round(layer.offsetX() * this._scale) + "px"; | 382 style.left = Math.round(layer.offsetX() * this._scale) + "px"; |
303 style.top = Math.round(layer.offsetY() * this._scale) + "px"; | 383 style.top = Math.round(layer.offsetY() * this._scale) + "px"; |
304 var transform = layer.transform(); | 384 var transform = layer.transform(); |
305 if (transform) { | 385 if (transform) { |
306 transform = transform.slice(); | 386 transform = transform.slice(); |
307 // Adjust offset in the transform matrix according to scale. | 387 // Adjust offset in the transform matrix according to scale. |
308 for (var i = 12; i < 15; ++i) | 388 for (var i = 12; i < 15; ++i) |
309 transform[i] *= this._scale; | 389 transform[i] *= this._scale; |
310 // Avoid exponential notation in CSS. | 390 // Avoid exponential notation in CSS. |
311 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join(" ,") + ") translateZ(" + this._layerSpacing + ")"; | 391 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join(" ,") + ") translateZ(" + this._layerSpacing + ")"; |
312 var anchor = layer.anchorPoint(); | 392 var anchor = layer.anchorPoint(); |
313 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M ath.round(anchor[1] * 100) + "% " + anchor[2]; | 393 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M ath.round(anchor[1] * 100) + "% " + anchor[2]; |
314 } else { | 394 } else { |
315 style.webkitTransform = ""; | 395 style.webkitTransform = ""; |
316 style.webkitTransformOrigin = ""; | 396 style.webkitTransformOrigin = ""; |
317 } | 397 } |
318 | 398 |
319 function toFixed5(x) | 399 function toFixed5(x) |
320 { | 400 { |
321 return x.toFixed(5); | 401 return x.toFixed(5); |
322 } | 402 } |
323 }, | 403 }, |
324 | 404 |
405 /** | |
406 * @param {!Element} element | |
407 */ | |
325 _updatePaintRect: function(element) | 408 _updatePaintRect: function(element) |
326 { | 409 { |
327 var details = element.__layerDetails; | 410 var details = element.__layerDetails; |
328 var paintRect = details.layer.lastPaintRect(); | 411 var paintRect = details.layer.lastPaintRect(); |
329 var paintRectElement = details.paintRectElement; | 412 var paintRectElement = details.paintRectElement; |
330 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { | 413 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { |
331 paintRectElement.classList.add("hidden"); | 414 paintRectElement.classList.add("hidden"); |
332 return; | 415 return; |
333 } | 416 } |
334 paintRectElement.classList.remove("hidden"); | 417 paintRectElement.classList.remove("hidden"); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, layer); | 502 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, layer); |
420 event.stopPropagation(); | 503 event.stopPropagation(); |
421 }, | 504 }, |
422 | 505 |
423 __proto__: WebInspector.View.prototype | 506 __proto__: WebInspector.View.prototype |
424 } | 507 } |
425 | 508 |
426 /** | 509 /** |
427 * @constructor | 510 * @constructor |
428 * @param {!WebInspector.Layer} layer | 511 * @param {!WebInspector.Layer} layer |
429 * @param {!Element} paintRectElement | 512 * @param {!Element=} paintRectElement |
430 */ | 513 */ |
431 WebInspector.LayerDetails = function(layer, paintRectElement) | 514 WebInspector.LayerDetails = function(layer, paintRectElement) |
432 { | 515 { |
433 this.layer = layer; | 516 this.layer = layer; |
434 this.depth = 0; | 517 this.depth = 0; |
435 this.paintRectElement = paintRectElement; | 518 this.paintRectElement = paintRectElement; |
436 this.paintCount = 0; | 519 this.paintCount = 0; |
520 this.scrollRects = []; | |
521 this.scrollRectElements = []; | |
437 } | 522 } |
OLD | NEW |