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
26WebInspector.LayoutTimelineRecord = function(eventType, startTime, endTime, callFrames, sourceCodeLocation, x, y, width, height, quad)
27{
28    WebInspector.TimelineRecord.call(this, WebInspector.TimelineRecord.Type.Layout, startTime, endTime, callFrames, sourceCodeLocation);
29
30    console.assert(eventType);
31
32    if (eventType in WebInspector.LayoutTimelineRecord.EventType)
33        eventType = WebInspector.LayoutTimelineRecord.EventType[eventType];
34
35    this._eventType = eventType;
36    this._x = typeof x === "number" ? x : NaN;
37    this._y = typeof y === "number" ? y : NaN;
38    this._width = typeof width === "number" ? width : NaN;
39    this._height = typeof height === "number" ? height : NaN;
40    this._quad = quad instanceof WebInspector.Quad ? quad : null;
41};
42
43WebInspector.LayoutTimelineRecord.EventType = {
44    InvalidateStyles: "layout-timeline-record-invalidate-styles",
45    RecalculateStyles: "layout-timeline-record-recalculate-styles",
46    InvalidateLayout: "layout-timeline-record-invalidate-layout",
47    ForcedLayout: "layout-timeline-record-forced-layout",
48    Layout: "layout-timeline-record-layout",
49    Paint: "layout-timeline-record-paint"
50};
51
52WebInspector.LayoutTimelineRecord.EventType.displayName = function(eventType)
53{
54    switch(eventType) {
55    case WebInspector.LayoutTimelineRecord.EventType.InvalidateStyles:
56        return WebInspector.UIString("Styles Invalidated");
57    case WebInspector.LayoutTimelineRecord.EventType.RecalculateStyles:
58        return WebInspector.UIString("Styles Recalculated");
59    case WebInspector.LayoutTimelineRecord.EventType.InvalidateLayout:
60        return WebInspector.UIString("Layout Invalidated");
61    case WebInspector.LayoutTimelineRecord.EventType.ForcedLayout:
62        return WebInspector.UIString("Forced Layout");
63    case WebInspector.LayoutTimelineRecord.EventType.Layout:
64        return WebInspector.UIString("Layout");
65    case WebInspector.LayoutTimelineRecord.EventType.Paint:
66        return WebInspector.UIString("Paint");
67    }
68};
69
70WebInspector.LayoutTimelineRecord.TypeIdentifier = "layout-timeline-record";
71WebInspector.LayoutTimelineRecord.EventTypeCookieKey = "layout-timeline-record-event-type";
72
73WebInspector.LayoutTimelineRecord.prototype = {
74    constructor: WebInspector.LayoutTimelineRecord,
75
76    // Public
77
78    get eventType()
79    {
80        return this._eventType;
81    },
82
83    get x()
84    {
85        return this._x;
86    },
87
88    get y()
89    {
90        return this._y;
91    },
92
93    get width()
94    {
95        return this._width;
96    },
97
98    get height()
99    {
100        return this._height;
101    },
102
103    get area()
104    {
105        return this._width * this._height;
106    },
107
108    get rect()
109    {
110        if (!isNaN(this._x) && !isNaN(this._y))
111            return new WebInspector.Rect(this._x, this._y, this._width, this._height);
112        return null;
113    },
114
115    get quad()
116    {
117        return this._quad;
118    },
119
120    saveIdentityToCookie: function(cookie)
121    {
122        WebInspector.TimelineRecord.prototype.saveIdentityToCookie.call(this, cookie);
123
124        cookie[WebInspector.LayoutTimelineRecord.EventTypeCookieKey] = this._eventType;
125    }
126};
127
128WebInspector.LayoutTimelineRecord.prototype.__proto__ = WebInspector.TimelineRecord.prototype;
129