1/*
2 * Copyright (C) 2014 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.TimelineRecordTreeElement = function(timelineRecord, subtitleNameStyle, includeTimerIdentifierInMainTitle, sourceCodeLocation, representedObject)
27{
28    console.assert(timelineRecord);
29
30    this._record = timelineRecord;
31    this._sourceCodeLocation = sourceCodeLocation || timelineRecord.sourceCodeLocation || null;
32
33    var title = "";
34    var subtitle = "";
35
36    if (this._sourceCodeLocation) {
37        subtitle = document.createElement("span");
38
39        if (subtitleNameStyle !== WebInspector.SourceCodeLocation.NameStyle.None)
40            this._sourceCodeLocation.populateLiveDisplayLocationString(subtitle, "textContent", null, subtitleNameStyle);
41        else
42            this._sourceCodeLocation.populateLiveDisplayLocationString(subtitle, "textContent", null, WebInspector.SourceCodeLocation.NameStyle.None, WebInspector.UIString("line "));
43    }
44
45    var iconStyleClass = null;
46
47    switch (timelineRecord.type) {
48    case WebInspector.TimelineRecord.Type.Layout:
49        title = WebInspector.LayoutTimelineRecord.EventType.displayName(timelineRecord.eventType);
50
51        switch (timelineRecord.eventType) {
52        case WebInspector.LayoutTimelineRecord.EventType.InvalidateStyles:
53        case WebInspector.LayoutTimelineRecord.EventType.RecalculateStyles:
54            iconStyleClass = WebInspector.TimelineRecordTreeElement.StyleRecordIconStyleClass;
55            break;
56        case WebInspector.LayoutTimelineRecord.EventType.InvalidateLayout:
57        case WebInspector.LayoutTimelineRecord.EventType.ForcedLayout:
58        case WebInspector.LayoutTimelineRecord.EventType.Layout:
59            iconStyleClass = WebInspector.TimelineRecordTreeElement.LayoutRecordIconStyleClass;
60            break;
61        case WebInspector.LayoutTimelineRecord.EventType.Paint:
62            iconStyleClass = WebInspector.TimelineRecordTreeElement.PaintRecordIconStyleClass;
63            break;
64        default:
65            console.error("Unknown LayoutTimelineRecord eventType: " + timelineRecord.eventType, timelineRecord);
66        }
67
68        break;
69
70    case WebInspector.TimelineRecord.Type.Script:
71        title = WebInspector.ScriptTimelineRecord.EventType.displayName(timelineRecord.eventType, timelineRecord.details, includeTimerIdentifierInMainTitle);
72
73        switch (timelineRecord.eventType) {
74        case WebInspector.ScriptTimelineRecord.EventType.ScriptEvaluated:
75            iconStyleClass = WebInspector.TimelineRecordTreeElement.EvaluatedRecordIconStyleClass;
76            break;
77        case WebInspector.ScriptTimelineRecord.EventType.EventDispatched:
78            iconStyleClass = WebInspector.TimelineRecordTreeElement.EventRecordIconStyleClass;
79            break;
80        case WebInspector.ScriptTimelineRecord.EventType.ProbeSampleRecorded:
81            iconStyleClass = WebInspector.TimelineRecordTreeElement.ProbeRecordIconStyleClass;
82            break;
83        case WebInspector.ScriptTimelineRecord.EventType.ConsoleProfileRecorded:
84            iconStyleClass = WebInspector.TimelineRecordTreeElement.ConsoleProfileIconStyleClass;
85            break;
86        case WebInspector.ScriptTimelineRecord.EventType.TimerFired:
87        case WebInspector.ScriptTimelineRecord.EventType.TimerInstalled:
88        case WebInspector.ScriptTimelineRecord.EventType.TimerRemoved:
89            iconStyleClass = WebInspector.TimelineRecordTreeElement.TimerRecordIconStyleClass;
90            break;
91        case WebInspector.ScriptTimelineRecord.EventType.AnimationFrameFired:
92        case WebInspector.ScriptTimelineRecord.EventType.AnimationFrameRequested:
93        case WebInspector.ScriptTimelineRecord.EventType.AnimationFrameCanceled:
94            iconStyleClass = WebInspector.TimelineRecordTreeElement.AnimationRecordIconStyleClass;
95            break;
96        default:
97            console.error("Unknown ScriptTimelineRecord eventType: " + timelineRecord.eventType, timelineRecord);
98        }
99
100        break;
101
102    default:
103        console.error("Unknown TimelineRecord type: " + timelineRecord.type, timelineRecord);
104    }
105
106    WebInspector.GeneralTreeElement.call(this, [iconStyleClass], title, subtitle, representedObject || timelineRecord, false);
107
108    this.small = true;
109
110    if (this._sourceCodeLocation)
111        this.tooltipHandledSeparately = true;
112};
113
114WebInspector.TimelineRecordTreeElement.StyleRecordIconStyleClass = "style-record";
115WebInspector.TimelineRecordTreeElement.LayoutRecordIconStyleClass = "layout-record";
116WebInspector.TimelineRecordTreeElement.PaintRecordIconStyleClass = "paint-record";
117WebInspector.TimelineRecordTreeElement.EvaluatedRecordIconStyleClass = "evaluated-record";
118WebInspector.TimelineRecordTreeElement.EventRecordIconStyleClass = "event-record";
119WebInspector.TimelineRecordTreeElement.TimerRecordIconStyleClass = "timer-record";
120WebInspector.TimelineRecordTreeElement.AnimationRecordIconStyleClass = "animation-record";
121WebInspector.TimelineRecordTreeElement.ProbeRecordIconStyleClass = "probe-record";
122WebInspector.TimelineRecordTreeElement.ConsoleProfileIconStyleClass = "console-profile-record";
123
124WebInspector.TimelineRecordTreeElement.prototype = {
125    constructor: WebInspector.TimelineRecordTreeElement,
126    __proto__: WebInspector.GeneralTreeElement.prototype,
127
128    // Public
129
130    get record()
131    {
132        return this._record;
133    },
134
135    get filterableData()
136    {
137        var url = this._sourceCodeLocation ? this._sourceCodeLocation.sourceCode.url : "";
138        return {text: [this.mainTitle, url || "", this._record.details || ""]};
139    },
140
141    // Protected
142
143    onattach: function()
144    {
145        WebInspector.GeneralTreeElement.prototype.onattach.call(this);
146
147        console.assert(this.element);
148
149        if (!this.tooltipHandledSeparately)
150            return;
151
152        var tooltipPrefix = this.mainTitle + "\n";
153        this._sourceCodeLocation.populateLiveDisplayLocationTooltip(this.element, tooltipPrefix);
154    }
155};
156