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; | |
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; | |
273 layerDetails.scrollRectElements = layerDetails.scrollRects.map(this. _createScrollRectElement.bind(this, layer)); | |
274 } | |
275 for (var i = 0; i < layerDetails.scrollRects.length; ++i) { | |
caseq
2014/03/11 13:40:32
nit: drop {}
malch
2014/03/11 13:48:56
Done.
| |
276 this._updateScrollRectElement(layerDetails.scrollRects[i], layerDeta ils.scrollRectElements[i]); | |
277 } | |
278 }, | |
279 | |
218 _update: function() | 280 _update: function() |
219 { | 281 { |
220 if (!this.isShowing()) { | 282 if (!this.isShowing()) { |
221 this._needsUpdate = true; | 283 this._needsUpdate = true; |
222 return; | 284 return; |
223 } | 285 } |
224 if (!this._model.contentRoot()) { | 286 if (!this._model.contentRoot()) { |
225 this._emptyView.show(this.element); | 287 this._emptyView.show(this.element); |
226 this._rotatingContainerElement.removeChildren(); | 288 this._rotatingContainerElement.removeChildren(); |
227 return; | 289 return; |
228 } | 290 } |
229 this._emptyView.detach(); | 291 this._emptyView.detach(); |
230 | 292 |
231 /** | 293 /** |
232 * @this {WebInspector.Layers3DView} | 294 * @this {WebInspector.Layers3DView} |
233 */ | 295 */ |
234 function updateLayer(layer) | 296 function updateLayer(layer) |
235 { | 297 { |
236 this._updateLayerElement(this._elementForLayer(layer)); | 298 this._updateLayerElement(this._elementForLayer(layer)); |
299 this._updateScrollRectsForLayer(layer); | |
237 } | 300 } |
238 this._clientWidth = this.element.clientWidth; | 301 this._clientWidth = this.element.clientWidth; |
239 this._clientHeight = this.element.clientHeight; | 302 this._clientHeight = this.element.clientHeight; |
240 for (var layerId in this._elementsByLayerId) { | 303 for (var layerId in this._elementsByLayerId) { |
241 if (this._model.layerById(layerId)) | 304 if (this._model.layerById(layerId)) |
242 continue; | 305 continue; |
243 this._elementsByLayerId[layerId].remove(); | 306 this._elementsByLayerId[layerId].remove(); |
244 delete this._elementsByLayerId[layerId]; | 307 delete this._elementsByLayerId[layerId]; |
245 } | 308 } |
246 this._scaleToFit(); | 309 this._scaleToFit(); |
247 this._updateTransform(); | 310 this._updateTransform(); |
248 this._model.forEachLayer(updateLayer.bind(this), this._model.contentRoot ()); | 311 this._model.forEachLayer(updateLayer.bind(this)); |
249 this._needsUpdate = false; | 312 this._needsUpdate = false; |
250 }, | 313 }, |
251 | 314 |
252 /** | 315 /** |
253 * @param {!WebInspector.Event} event | 316 * @param {!WebInspector.Event} event |
254 */ | 317 */ |
255 _onLayerPainted: function(event) | 318 _onLayerPainted: function(event) |
256 { | 319 { |
257 var layer = /** @type {!WebInspector.Layer} */ (event.data); | 320 var layer = /** @type {!WebInspector.Layer} */ (event.data); |
258 this._updatePaintRect(this._elementForLayer(layer)); | 321 if (layer.nodeId()) |
322 this._updatePaintRect(this._elementForLayer(layer)); | |
259 }, | 323 }, |
260 | 324 |
261 /** | 325 /** |
262 * @param {!WebInspector.Layer} layer | 326 * @param {!WebInspector.Layer} layer |
263 * @return {!Element} | 327 * @return {!Element} |
264 */ | 328 */ |
265 _elementForLayer: function(layer) | 329 _elementForLayer: function(layer) |
266 { | 330 { |
267 var element = this._elementsByLayerId[layer.id()]; | 331 var element = this._elementsByLayerId[layer.id()]; |
268 if (element) { | 332 if (element) { |
269 // We might have missed an update were a layer with given id was gon e and re-created, | 333 // 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. | 334 // so update reference to point to proper layer object. |
271 element.__layerDetails.layer = layer; | 335 element.__layerDetails.layer = layer; |
272 return element; | 336 return element; |
273 } | 337 } |
274 element = document.createElement("div"); | 338 element = document.createElement("div"); |
275 element.className = "layer-container"; | 339 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")); | 340 element.className = "layer-container"; |
277 element.__layerDetails = new WebInspector.LayerDetails(layer, element.cr eateChild("div", "paint-rect")); | 341 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bo ttom", "side-wall left"].forEach(element.createChild.bind(element, "div")); |
342 element.__layerDetails = new WebInspector.LayerDetails(layer, elemen t.createChild("div", "paint-rect")); | |
343 } else { | |
344 element.className = "layer-transparent"; | |
345 element.__layerDetails = new WebInspector.LayerDetails(layer); | |
346 } | |
278 this._elementsByLayerId[layer.id()] = element; | 347 this._elementsByLayerId[layer.id()] = element; |
279 return element; | 348 return element; |
280 }, | 349 }, |
281 | 350 |
282 /** | 351 /** |
283 * @param {!Element} element | 352 * @param {!Element} element |
284 */ | 353 */ |
285 _updateLayerElement: function(element) | 354 _updateLayerElement: function(element) |
286 { | 355 { |
287 var layer = element.__layerDetails.layer; | 356 var layer = element.__layerDetails.layer; |
288 var style = element.style; | 357 var style = element.style; |
289 var isContentRoot = layer === this._model.contentRoot(); | 358 |
290 var parentElement = isContentRoot ? this._rotatingContainerElement : thi s._elementForLayer(layer.parent()); | 359 var contentRoot = /** @type {!WebInspector.Layer} */ (this._model.conten tRoot()); |
360 var isContentRoot = layer === contentRoot; | |
361 var isRoot = layer === this._model.root(); | |
362 var parentElement; | |
363 if (isContentRoot) { | |
364 parentElement = this._rotatingContainerElement | |
caseq
2014/03/11 13:40:32
terminate line with ;
malch
2014/03/11 13:48:56
Done.
| |
365 } else { | |
caseq
2014/03/11 13:40:32
this should be structured as
if (...) {
...
}
malch
2014/03/11 13:48:56
Done.
| |
366 if (isRoot) | |
367 parentElement = this._elementForLayer(contentRoot) | |
caseq
2014/03/11 13:40:32
ditto
malch
2014/03/11 13:48:56
Done.
| |
368 else | |
369 parentElement = this._elementForLayer(layer.parent()); | |
alph
2014/03/11 13:56:31
nit:
parentElement = this._elementForLayer(isRoot
| |
370 } | |
291 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0; | 371 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0; |
292 element.classList.toggle("invisible", layer.invisible()); | 372 element.classList.toggle("invisible", layer.invisible()); |
293 this._updateElementColor(element); | 373 if (layer.nodeId()) |
374 this._updateElementColor(element); | |
294 if (parentElement !== element.parentElement) | 375 if (parentElement !== element.parentElement) |
295 parentElement.appendChild(element); | 376 parentElement.appendChild(element); |
296 | 377 |
297 style.width = Math.round(layer.width() * this._scale) + "px"; | 378 style.width = Math.round(layer.width() * this._scale) + "px"; |
298 style.height = Math.round(layer.height() * this._scale) + "px"; | 379 style.height = Math.round(layer.height() * this._scale) + "px"; |
299 this._updatePaintRect(element); | 380 if (layer.nodeId()) |
300 if (isContentRoot) | 381 this._updatePaintRect(element); |
382 if (isContentRoot || isRoot) | |
301 return; | 383 return; |
302 style.left = Math.round(layer.offsetX() * this._scale) + "px"; | 384 style.left = Math.round(layer.offsetX() * this._scale) + "px"; |
303 style.top = Math.round(layer.offsetY() * this._scale) + "px"; | 385 style.top = Math.round(layer.offsetY() * this._scale) + "px"; |
304 var transform = layer.transform(); | 386 var transform = layer.transform(); |
305 if (transform) { | 387 if (transform) { |
306 transform = transform.slice(); | 388 transform = transform.slice(); |
307 // Adjust offset in the transform matrix according to scale. | 389 // Adjust offset in the transform matrix according to scale. |
308 for (var i = 12; i < 15; ++i) | 390 for (var i = 12; i < 15; ++i) |
309 transform[i] *= this._scale; | 391 transform[i] *= this._scale; |
310 // Avoid exponential notation in CSS. | 392 // Avoid exponential notation in CSS. |
311 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join(" ,") + ") translateZ(" + this._layerSpacing + ")"; | 393 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join(" ,") + ") translateZ(" + this._layerSpacing + ")"; |
312 var anchor = layer.anchorPoint(); | 394 var anchor = layer.anchorPoint(); |
313 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M ath.round(anchor[1] * 100) + "% " + anchor[2]; | 395 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M ath.round(anchor[1] * 100) + "% " + anchor[2]; |
314 } else { | 396 } else { |
315 style.webkitTransform = ""; | 397 style.webkitTransform = ""; |
316 style.webkitTransformOrigin = ""; | 398 style.webkitTransformOrigin = ""; |
317 } | 399 } |
318 | 400 |
319 function toFixed5(x) | 401 function toFixed5(x) |
320 { | 402 { |
321 return x.toFixed(5); | 403 return x.toFixed(5); |
322 } | 404 } |
323 }, | 405 }, |
324 | 406 |
407 /** | |
408 * @param {!Element} element | |
409 */ | |
325 _updatePaintRect: function(element) | 410 _updatePaintRect: function(element) |
326 { | 411 { |
327 var details = element.__layerDetails; | 412 var details = element.__layerDetails; |
328 var paintRect = details.layer.lastPaintRect(); | 413 var paintRect = details.layer.lastPaintRect(); |
329 var paintRectElement = details.paintRectElement; | 414 var paintRectElement = details.paintRectElement; |
330 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { | 415 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { |
331 paintRectElement.classList.add("hidden"); | 416 paintRectElement.classList.add("hidden"); |
332 return; | 417 return; |
333 } | 418 } |
334 paintRectElement.classList.remove("hidden"); | 419 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); | 504 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, layer); |
420 event.stopPropagation(); | 505 event.stopPropagation(); |
421 }, | 506 }, |
422 | 507 |
423 __proto__: WebInspector.View.prototype | 508 __proto__: WebInspector.View.prototype |
424 } | 509 } |
425 | 510 |
426 /** | 511 /** |
427 * @constructor | 512 * @constructor |
428 * @param {!WebInspector.Layer} layer | 513 * @param {!WebInspector.Layer} layer |
429 * @param {!Element} paintRectElement | 514 * @param {!Element=} paintRectElement |
430 */ | 515 */ |
431 WebInspector.LayerDetails = function(layer, paintRectElement) | 516 WebInspector.LayerDetails = function(layer, paintRectElement) |
432 { | 517 { |
433 this.layer = layer; | 518 this.layer = layer; |
434 this.depth = 0; | 519 this.depth = 0; |
435 this.paintRectElement = paintRectElement; | 520 this.paintRectElement = paintRectElement; |
436 this.paintCount = 0; | 521 this.paintCount = 0; |
522 this.scrollRects = []; | |
523 this.scrollRectElements = []; | |
437 } | 524 } |
OLD | NEW |