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