Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1199)

Side by Side Diff: Source/devtools/front_end/Layers3DView.js

Issue 166273018: Added showing slow scroll rectangles in Layers panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: New fixes. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 * @param {!LayerTreeAgent.ScrollRect} scrollRect
230 * @return {!Element}
231 */
232 _createScrollRectElement: function(layer, scrollRect)
233 {
234 var element = document.createElement("div");
235 var parentLayerElement = this._elementsByLayerId[layer.id()];
236 element.className = "scroll-rect";
237 element.title = WebInspector.Layers3DView.ScrollRectTitles[scrollRect.ty pe];
238 parentLayerElement.appendChild(element);
239 return element;
240 },
241
242 /**
243 * @param {!Array.<!Element>} elements
244 * @param {!LayerTreeAgent.ScrollRect} scrollRect
245 * @param {!number} index
246 */
247 _updateScrollRectElement: function(elements, scrollRect, index)
caseq 2014/03/11 12:04:09 I don't think using forEach() justifies method sig
malch 2014/03/11 12:48:49 Done.
248 {
249 var element = elements[index];
250 var style = element.style;
251 style.width = Math.round(scrollRect.rect.width * this._scale) + "px";
252 style.height = Math.round(scrollRect.rect.height * this._scale) + "px";
253 style.left = Math.round(scrollRect.rect.x * this._scale) + "px";
254 style.top = Math.round(scrollRect.rect.y * this._scale) + "px";
255 },
256
257 /**
258 * @param {!WebInspector.Layer} layer
259 */
260 _updateScrollRectsForLayer: function(layer)
261 {
262 var newScrollRects = layer.scrollRects(),
263 layerDetails = this._elementsByLayerId[layer.id()].__layerDetails;
264
265 /**
266 * @param {!Element} element
267 */
268 function removeElement(element)
269 {
270 element.remove()
271 }
272
273 if (newScrollRects !== layerDetails.scrollRects) {
274 layerDetails.scrollRectElements.forEach(removeElement);
275 layerDetails.scrollRects = newScrollRects;
276 layerDetails.scrollRectElements = layerDetails.scrollRects.map(this. _createScrollRectElement.bind(this, layer));
277 }
278 layerDetails.scrollRects.forEach(this._updateScrollRectElement.bind(this , layerDetails.scrollRectElements));
caseq 2014/03/11 12:04:09 Why would we update if the rects did not change?
malch 2014/03/11 12:48:49 Done.
279 },
280
218 _update: function() 281 _update: function()
219 { 282 {
220 if (!this.isShowing()) { 283 if (!this.isShowing()) {
221 this._needsUpdate = true; 284 this._needsUpdate = true;
222 return; 285 return;
223 } 286 }
224 if (!this._model.contentRoot()) { 287 if (!this._model.contentRoot()) {
225 this._emptyView.show(this.element); 288 this._emptyView.show(this.element);
226 this._rotatingContainerElement.removeChildren(); 289 this._rotatingContainerElement.removeChildren();
227 return; 290 return;
(...skipping 10 matching lines...) Expand all
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));
312 this._model.forEachLayer(this._updateScrollRectsForLayer.bind(this));
caseq 2014/03/11 12:04:09 Can we rather call updateScrollRectsForLayer from
malch 2014/03/11 12:48:49 Done.
249 this._needsUpdate = false; 313 this._needsUpdate = false;
250 }, 314 },
251 315
252 /** 316 /**
253 * @param {!WebInspector.Event} event 317 * @param {!WebInspector.Event} event
254 */ 318 */
255 _onLayerPainted: function(event) 319 _onLayerPainted: function(event)
256 { 320 {
257 var layer = /** @type {!WebInspector.Layer} */ (event.data); 321 var layer = /** @type {!WebInspector.Layer} */ (event.data);
258 this._updatePaintRect(this._elementForLayer(layer)); 322 if (layer.nodeId())
323 this._updatePaintRect(this._elementForLayer(layer));
259 }, 324 },
260 325
261 /** 326 /**
262 * @param {!WebInspector.Layer} layer 327 * @param {!WebInspector.Layer} layer
263 * @return {!Element} 328 * @return {!Element}
264 */ 329 */
265 _elementForLayer: function(layer) 330 _elementForLayer: function(layer)
266 { 331 {
267 var element = this._elementsByLayerId[layer.id()]; 332 var element = this._elementsByLayerId[layer.id()];
268 if (element) { 333 if (element) {
269 // We might have missed an update were a layer with given id was gon e and re-created, 334 // 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. 335 // so update reference to point to proper layer object.
271 element.__layerDetails.layer = layer; 336 element.__layerDetails.layer = layer;
272 return element; 337 return element;
273 } 338 }
274 element = document.createElement("div"); 339 element = document.createElement("div");
275 element.className = "layer-container"; 340 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")); 341 element.className = "layer-container";
277 element.__layerDetails = new WebInspector.LayerDetails(layer, element.cr eateChild("div", "paint-rect")); 342 ["fill back-wall", "side-wall top", "side-wall right", "side-wall bo ttom", "side-wall left"].forEach(element.createChild.bind(element, "div"));
343 element.__layerDetails = new WebInspector.LayerDetails(layer, elemen t.createChild("div", "paint-rect"));
344 } else {
345 element.className = "layer-transparent";
346 element.__layerDetails = new WebInspector.LayerDetails(layer);
347 }
278 this._elementsByLayerId[layer.id()] = element; 348 this._elementsByLayerId[layer.id()] = element;
279 return element; 349 return element;
280 }, 350 },
281 351
282 /** 352 /**
283 * @param {!Element} element 353 * @param {!Element} element
284 */ 354 */
285 _updateLayerElement: function(element) 355 _updateLayerElement: function(element)
286 { 356 {
287 var layer = element.__layerDetails.layer; 357 var layer = element.__layerDetails.layer;
288 var style = element.style; 358 var style = element.style;
289 var isContentRoot = layer === this._model.contentRoot(); 359
290 var parentElement = isContentRoot ? this._rotatingContainerElement : thi s._elementForLayer(layer.parent()); 360 var contentRoot = /** @type {!WebInspector.Layer} */ (this._model.conten tRoot());
361 var isContentRoot = layer === contentRoot;
362 var isRoot = layer === this._model.root();
363 var parentElement = isContentRoot ? this._rotatingContainerElement : (is Root ? this._elementForLayer(contentRoot) : this._elementForLayer(layer.parent() ));
caseq 2014/03/11 12:04:09 Two ternary operators per statement is a bit of ov
malch 2014/03/11 12:48:49 Done.
291 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0; 364 element.__layerDetails.depth = parentElement.__layerDetails ? parentElem ent.__layerDetails.depth + 1 : 0;
292 element.classList.toggle("invisible", layer.invisible()); 365 element.classList.toggle("invisible", layer.invisible());
293 this._updateElementColor(element); 366 if (layer.nodeId())
367 this._updateElementColor(element);
294 if (parentElement !== element.parentElement) 368 if (parentElement !== element.parentElement)
295 parentElement.appendChild(element); 369 parentElement.appendChild(element);
296 370
297 style.width = Math.round(layer.width() * this._scale) + "px"; 371 style.width = Math.round(layer.width() * this._scale) + "px";
298 style.height = Math.round(layer.height() * this._scale) + "px"; 372 style.height = Math.round(layer.height() * this._scale) + "px";
299 this._updatePaintRect(element); 373 if (layer.nodeId())
300 if (isContentRoot) 374 this._updatePaintRect(element);
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, layer); 497 this.dispatchEventToListeners(WebInspector.Layers3DView.Events.Layer SnapshotRequested, layer);
420 event.stopPropagation(); 498 event.stopPropagation();
421 }, 499 },
422 500
423 __proto__: WebInspector.View.prototype 501 __proto__: WebInspector.View.prototype
424 } 502 }
425 503
426 /** 504 /**
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.scrollRects = [];
516 this.scrollRectElements = [];
437 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698