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); |
| 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 element.__layerDetails = new WebInspector.LayerDetails(layer, element.cr
eateChild("div", "paint-rect")); |
276 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bottom
", "side-wall left"].forEach(element.createChild.bind(element, "div")); | 336 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bottom
", "side-wall left"].forEach(element.createChild.bind(element, "div")); |
277 element.__layerDetails = new WebInspector.LayerDetails(layer, element.cr
eateChild("div", "paint-rect")); | |
278 this._elementsByLayerId[layer.id()] = element; | 337 this._elementsByLayerId[layer.id()] = element; |
279 return element; | 338 return element; |
280 }, | 339 }, |
281 | 340 |
282 /** | 341 /** |
283 * @param {!Element} element | 342 * @param {!Element} element |
284 */ | 343 */ |
285 _updateLayerElement: function(element) | 344 _updateLayerElement: function(element) |
286 { | 345 { |
287 var layer = element.__layerDetails.layer; | 346 var layer = element.__layerDetails.layer; |
288 var style = element.style; | 347 var style = element.style; |
289 var isContentRoot = layer === this._model.contentRoot(); | 348 |
290 var parentElement = isContentRoot ? this._rotatingContainerElement : thi
s._elementForLayer(layer.parent()); | 349 var contentRoot = /** @type {!WebInspector.Layer} */ (this._model.conten
tRoot()); |
291 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem
ent.__layerDetails.depth + 1 : 0; | 350 var isContentRoot = layer === contentRoot; |
| 351 var isRoot = layer === this._model.root(); |
| 352 var parentElement; |
| 353 if (isContentRoot) { |
| 354 parentElement = this._rotatingContainerElement; |
| 355 element.__layerDetails.depth = 0; |
| 356 } else if (isRoot) { |
| 357 parentElement = this._elementForLayer(contentRoot); |
| 358 element.__layerDetails.depth = undefined; |
| 359 } else { |
| 360 parentElement = this._elementForLayer(layer.parent()); |
| 361 element.__layerDetails.depth = parentElement.__layerDetails.isAboveC
ontentRoot() ? undefined : parentElement.__layerDetails.depth + 1; |
| 362 } |
| 363 if (!element.__layerDetails.isAboveContentRoot()) |
| 364 element.className = "layer-container"; |
| 365 else |
| 366 element.className = "layer-transparent"; |
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 this._updatePaintRect(element); |
300 if (isContentRoot) | 375 if (isContentRoot || isRoot) |
301 return; | 376 return; |
302 style.left = Math.round(layer.offsetX() * this._scale) + "px"; | 377 style.left = Math.round(layer.offsetX() * this._scale) + "px"; |
303 style.top = Math.round(layer.offsetY() * this._scale) + "px"; | 378 style.top = Math.round(layer.offsetY() * this._scale) + "px"; |
304 var transform = layer.transform(); | 379 var transform = layer.transform(); |
305 if (transform) { | 380 if (transform) { |
306 transform = transform.slice(); | 381 transform = transform.slice(); |
307 // Adjust offset in the transform matrix according to scale. | 382 // Adjust offset in the transform matrix according to scale. |
308 for (var i = 12; i < 15; ++i) | 383 for (var i = 12; i < 15; ++i) |
309 transform[i] *= this._scale; | 384 transform[i] *= this._scale; |
310 // Avoid exponential notation in CSS. | 385 // Avoid exponential notation in CSS. |
311 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join("
,") + ") translateZ(" + this._layerSpacing + ")"; | 386 style.webkitTransform = "matrix3d(" + transform.map(toFixed5).join("
,") + ") translateZ(" + this._layerSpacing + ")"; |
312 var anchor = layer.anchorPoint(); | 387 var anchor = layer.anchorPoint(); |
313 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M
ath.round(anchor[1] * 100) + "% " + anchor[2]; | 388 style.webkitTransformOrigin = Math.round(anchor[0] * 100) + "% " + M
ath.round(anchor[1] * 100) + "% " + anchor[2]; |
314 } else { | 389 } else { |
315 style.webkitTransform = ""; | 390 style.webkitTransform = ""; |
316 style.webkitTransformOrigin = ""; | 391 style.webkitTransformOrigin = ""; |
317 } | 392 } |
318 | 393 |
319 function toFixed5(x) | 394 function toFixed5(x) |
320 { | 395 { |
321 return x.toFixed(5); | 396 return x.toFixed(5); |
322 } | 397 } |
323 }, | 398 }, |
324 | 399 |
| 400 /** |
| 401 * @param {!Element} element |
| 402 */ |
325 _updatePaintRect: function(element) | 403 _updatePaintRect: function(element) |
326 { | 404 { |
327 var details = element.__layerDetails; | 405 var details = element.__layerDetails; |
328 var paintRect = details.layer.lastPaintRect(); | 406 var paintRect = details.layer.lastPaintRect(); |
329 var paintRectElement = details.paintRectElement; | 407 var paintRectElement = details.paintRectElement; |
330 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { | 408 if (!paintRect || !WebInspector.settings.showPaintRects.get()) { |
331 paintRectElement.classList.add("hidden"); | 409 paintRectElement.classList.add("hidden"); |
332 return; | 410 return; |
333 } | 411 } |
334 paintRectElement.classList.remove("hidden"); | 412 paintRectElement.classList.remove("hidden"); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 * @constructor | 505 * @constructor |
428 * @param {!WebInspector.Layer} layer | 506 * @param {!WebInspector.Layer} layer |
429 * @param {!Element} paintRectElement | 507 * @param {!Element} paintRectElement |
430 */ | 508 */ |
431 WebInspector.LayerDetails = function(layer, paintRectElement) | 509 WebInspector.LayerDetails = function(layer, paintRectElement) |
432 { | 510 { |
433 this.layer = layer; | 511 this.layer = layer; |
434 this.depth = 0; | 512 this.depth = 0; |
435 this.paintRectElement = paintRectElement; | 513 this.paintRectElement = paintRectElement; |
436 this.paintCount = 0; | 514 this.paintCount = 0; |
| 515 this.scrollRectElements = []; |
437 } | 516 } |
| 517 |
| 518 WebInspector.LayerDetails.prototype = { |
| 519 /** |
| 520 * @return {boolean} |
| 521 */ |
| 522 isAboveContentRoot: function() |
| 523 { |
| 524 return this.depth === undefined; |
| 525 } |
| 526 } |
OLD | NEW |