LayerDetailsView.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2013 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * @constructor
  32. * @extends {WebInspector.View}
  33. */
  34. WebInspector.LayerDetailsView = function()
  35. {
  36. WebInspector.View.call(this);
  37. this.element.classList.add("fill");
  38. this.element.classList.add("layer-details-view");
  39. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("Select a layer to see its details"));
  40. this._createTable();
  41. this.showLayer(null);
  42. }
  43. /**
  44. * @type {Object.<string, string>}
  45. */
  46. WebInspector.LayerDetailsView.CompositingReasonDetail = {
  47. "transform3D": WebInspector.UIString("Composition due to association with an element with a CSS 3D transform."),
  48. "video": WebInspector.UIString("Composition due to association with a <video> element."),
  49. "canvas": WebInspector.UIString("Composition due to the element being a <canvas> element."),
  50. "plugin": WebInspector.UIString("Composition due to association with a plugin."),
  51. "iFrame": WebInspector.UIString("Composition due to association with an <iframe> element."),
  52. "backfaceVisibilityHidden": WebInspector.UIString("Composition due to association with an element with a \"backface-visibility: hidden\" style."),
  53. "animation": WebInspector.UIString("Composition due to association with an animated element."),
  54. "filters": WebInspector.UIString("Composition due to association with an element with CSS filters applied."),
  55. "positionFixed": WebInspector.UIString("Composition due to association with an element with a \"position: fixed\" style."),
  56. "positionSticky": WebInspector.UIString("Composition due to association with an element with a \"position: sticky\" style."),
  57. "overflowScrollingTouch": WebInspector.UIString("Composition due to association with an element with a \"overflow-scrolling: touch\" style."),
  58. "blending": WebInspector.UIString("Composition due to association with an element that has blend mode other than \"normal\"."),
  59. "assumedOverlap": WebInspector.UIString("Composition due to association with an element that may overlap other composited elements."),
  60. "overlap": WebInspector.UIString("Composition due to association with an element overlapping other composited elements."),
  61. "negativeZIndexChildren": WebInspector.UIString("Composition due to association with an element with descendants that have a negative z-index."),
  62. "transformWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with composited descendants."),
  63. "opacityWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with opacity applied and composited descendants."),
  64. "maskWithCompositedDescendants": WebInspector.UIString("Composition due to association with a masked element and composited descendants."),
  65. "reflectionWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with a reflection and composited descendants."),
  66. "filterWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with CSS filters applied and composited descendants."),
  67. "blendingWithCompositedDescendants": WebInspector.UIString("Composition due to association with an element with CSS blending applied and composited descendants."),
  68. "clipsCompositingDescendants": WebInspector.UIString("Composition due to association with an element clipping compositing descendants."),
  69. "perspective": WebInspector.UIString("Composition due to association with an element with perspective applied."),
  70. "preserve3D": WebInspector.UIString("Composition due to association with an element with a \"transform-style: preserve-3d\" style."),
  71. "root": WebInspector.UIString("Root layer."),
  72. "layerForClip": WebInspector.UIString("Layer for clip."),
  73. "layerForScrollbar": WebInspector.UIString("Layer for scrollbar."),
  74. "layerForScrollingContainer": WebInspector.UIString("Layer for scrolling container."),
  75. "layerForForeground": WebInspector.UIString("Layer for foreground."),
  76. "layerForBackground": WebInspector.UIString("Layer for background."),
  77. "layerForMask": WebInspector.UIString("Layer for mask."),
  78. "layerForVideoOverlay": WebInspector.UIString("Layer for video overlay.")
  79. };
  80. WebInspector.LayerDetailsView.prototype = {
  81. /**
  82. * @param {WebInspector.Layer} layer
  83. */
  84. showLayer: function(layer)
  85. {
  86. if (!layer) {
  87. this._tableElement.remove();
  88. this._emptyView.show(this.element);
  89. return;
  90. }
  91. this._emptyView.detach();
  92. this.element.appendChild(this._tableElement);
  93. this._positionCell.textContent = WebInspector.UIString("%d,%d", layer.offsetX(), layer.offsetY());
  94. this._sizeCell.textContent = WebInspector.UIString("%d × %d", layer.width(), layer.height());
  95. this._paintCountCell.textContent = layer.paintCount();
  96. const bytesPerPixel = 4;
  97. this._memoryEstimateCell.textContent = Number.bytesToString(layer.invisible() ? 0 : layer.width() * layer.height() * bytesPerPixel);
  98. layer.requestCompositingReasons(this._updateCompositingReasons.bind(this));
  99. },
  100. _createTable: function()
  101. {
  102. this._tableElement = this.element.createChild("table");
  103. this._tbodyElement = this._tableElement.createChild("tbody");
  104. this._positionCell = this._createRow(WebInspector.UIString("Position in parent:"));
  105. this._sizeCell = this._createRow(WebInspector.UIString("Size:"));
  106. this._compositingReasonsCell = this._createRow(WebInspector.UIString("Compositing Reasons:"));
  107. this._memoryEstimateCell = this._createRow(WebInspector.UIString("Memory estimate:"));
  108. this._paintCountCell = this._createRow(WebInspector.UIString("Paint count:"));
  109. },
  110. /**
  111. * @param {string} title
  112. */
  113. _createRow: function(title)
  114. {
  115. var tr = this._tbodyElement.createChild("tr");
  116. var titleCell = tr.createChild("td");
  117. titleCell.textContent = title;
  118. return tr.createChild("td");
  119. },
  120. /**
  121. * @param {Array.<string>} compositingReasons
  122. */
  123. _updateCompositingReasons: function(compositingReasons)
  124. {
  125. if (!compositingReasons || !compositingReasons.length) {
  126. this._compositingReasonsCell.textContent = "n/a";
  127. return;
  128. }
  129. var fragment = document.createDocumentFragment();
  130. for (var i = 0; i < compositingReasons.length; ++i) {
  131. if (i)
  132. fragment.appendChild(document.createTextNode(","));
  133. var span = document.createElement("span");
  134. span.title = WebInspector.LayerDetailsView.CompositingReasonDetail[compositingReasons[i]] || "";
  135. span.textContent = compositingReasons[i];
  136. fragment.appendChild(span);
  137. }
  138. this._compositingReasonsCell.removeChildren();
  139. this._compositingReasonsCell.appendChild(fragment);
  140. },
  141. __proto__: WebInspector.View.prototype
  142. }