LayoutTimelineRecord.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2013 Apple 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
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. WebInspector.LayoutTimelineRecord = function(eventType, startTime, endTime, callFrames, x, y, width, height, quad)
  26. {
  27. WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Layout, startTime, endTime);
  28. console.assert(eventType);
  29. if (eventType in WebInspector.LayoutTimelineRecord.EventType)
  30. eventType = WebInspector.LayoutTimelineRecord.EventType[eventType];
  31. this._eventType = eventType;
  32. this._callFrames = callFrames || [];
  33. this._x = typeof x === "number" ? x : NaN;
  34. this._y = typeof y === "number" ? y : NaN;
  35. this._width = typeof width === "number" ? width : NaN;
  36. this._height = typeof height === "number" ? height : NaN;
  37. this._quad = quad instanceof WebInspector.Quad ? quad : null;
  38. };
  39. WebInspector.LayoutTimelineRecord.EventType = {
  40. InvalidateStyles: "layout-timeline-record-invalidate-styles",
  41. RecalculateStyles: "layout-timeline-record-recalculate-styles",
  42. InvalidateLayout: "layout-timeline-record-invalidate-layout",
  43. Layout: "layout-timeline-record-layout",
  44. Paint: "layout-timeline-record-paint"
  45. };
  46. WebInspector.LayoutTimelineRecord.EventType.displayName = function(eventType)
  47. {
  48. switch(eventType) {
  49. case WebInspector.LayoutTimelineRecord.EventType.InvalidateStyles:
  50. return WebInspector.UIString("Invalidate Styles");
  51. case WebInspector.LayoutTimelineRecord.EventType.RecalculateStyles:
  52. return WebInspector.UIString("Recalculate Styles");
  53. case WebInspector.LayoutTimelineRecord.EventType.InvalidateLayout:
  54. return WebInspector.UIString("Invalidate Layout");
  55. case WebInspector.LayoutTimelineRecord.EventType.Layout:
  56. return WebInspector.UIString("Layout");
  57. case WebInspector.LayoutTimelineRecord.EventType.Paint:
  58. return WebInspector.UIString("Paint");
  59. }
  60. };
  61. WebInspector.LayoutTimelineRecord.prototype = {
  62. constructor: WebInspector.LayoutTimelineRecord,
  63. // Public
  64. get eventType()
  65. {
  66. return this._eventType;
  67. },
  68. get callFrames()
  69. {
  70. return this._callFrames;
  71. },
  72. get initiatorCallFrame()
  73. {
  74. if (!this._callFrames || !this._callFrames.length)
  75. return null;
  76. // Return the first non-native code call frame as the initiator.
  77. for (var i = 0; i < this._callFrames.length; ++i) {
  78. if (this._callFrames[i].nativeCode)
  79. continue;
  80. return this._callFrames[i];
  81. }
  82. return null;
  83. },
  84. get x()
  85. {
  86. return this._x;
  87. },
  88. get y()
  89. {
  90. return this._y;
  91. },
  92. get width()
  93. {
  94. return this._width;
  95. },
  96. get height()
  97. {
  98. return this._height;
  99. },
  100. get area()
  101. {
  102. return this._width * this._height;
  103. },
  104. get rect()
  105. {
  106. if (!isNaN(this._x) && !isNaN(this._y))
  107. return new WebInspector.Rect(this._x, this._y, this._width, this._height);
  108. return null;
  109. },
  110. get quad()
  111. {
  112. return this._quad;
  113. }
  114. };
  115. WebInspector.LayoutTimelineRecord.prototype.__proto__ = WebInspector.TimelineRecord.prototype;