0d9c6dd174a11313e1c562685dcc3498e9bca956
[WebKit-https.git] / WebCore / page / inspector / ScriptsPanel.js
1 /*
2  * Copyright (C) 2008 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. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WebInspector.ScriptsPanel = function()
27 {
28     WebInspector.Panel.call(this);
29
30     this.element.addStyleClass("scripts");
31
32     this.topStatusBar = document.createElement("div");
33     this.topStatusBar.className = "status-bar";
34     this.topStatusBar.id = "scripts-status-bar";
35     this.element.appendChild(this.topStatusBar);
36
37     this.backButton = document.createElement("button");
38     this.backButton.className = "status-bar-item";
39     this.backButton.id = "scripts-back";
40     this.backButton.title = WebInspector.UIString("Show the previous script resource.");
41     this.backButton.disabled = true;
42     this.backButton.appendChild(document.createElement("img"));
43     this.topStatusBar.appendChild(this.backButton);
44
45     this.forwardButton = document.createElement("button");
46     this.forwardButton.className = "status-bar-item";
47     this.forwardButton.id = "scripts-forward";
48     this.forwardButton.title = WebInspector.UIString("Show the next script resource.");
49     this.forwardButton.disabled = true;
50     this.forwardButton.appendChild(document.createElement("img"));
51     this.topStatusBar.appendChild(this.forwardButton);
52
53     this.filesSelectElement = document.createElement("select");
54     this.filesSelectElement.className = "status-bar-item";
55     this.filesSelectElement.id = "scripts-files";
56     this.topStatusBar.appendChild(this.filesSelectElement);
57
58     this.functionsSelectElement = document.createElement("select");
59     this.functionsSelectElement.className = "status-bar-item";
60     this.functionsSelectElement.id = "scripts-functions";
61     this.topStatusBar.appendChild(this.functionsSelectElement);
62
63     this.sidebarButtonsElement = document.createElement("div");
64     this.sidebarButtonsElement.id = "scripts-sidebar-buttons";
65     this.topStatusBar.appendChild(this.sidebarButtonsElement);
66
67     this.pauseButton = document.createElement("button");
68     this.pauseButton.className = "status-bar-item";
69     this.pauseButton.id = "scripts-pause";
70     this.pauseButton.title = WebInspector.UIString("Pause script execution.");
71     this.pauseButton.appendChild(document.createElement("img"));
72     this.sidebarButtonsElement.appendChild(this.pauseButton);
73
74     this.stepOverButton = document.createElement("button");
75     this.stepOverButton.className = "status-bar-item";
76     this.stepOverButton.id = "scripts-step-over";
77     this.stepOverButton.title = WebInspector.UIString("Step over next function call.");
78     this.stepOverButton.disabled = true;
79     this.stepOverButton.appendChild(document.createElement("img"));
80     this.sidebarButtonsElement.appendChild(this.stepOverButton);
81
82     this.stepIntoButton = document.createElement("button");
83     this.stepIntoButton.className = "status-bar-item";
84     this.stepIntoButton.id = "scripts-step-into";
85     this.stepIntoButton.title = WebInspector.UIString("Step into next function call.");
86     this.stepIntoButton.disabled = true;
87     this.stepIntoButton.appendChild(document.createElement("img"));
88     this.sidebarButtonsElement.appendChild(this.stepIntoButton);
89
90     this.stepOutButton = document.createElement("button");
91     this.stepOutButton.className = "status-bar-item";
92     this.stepOutButton.id = "scripts-step-out";
93     this.stepOutButton.title = WebInspector.UIString("Step out of current function.");
94     this.stepOutButton.disabled = true;
95     this.stepOutButton.appendChild(document.createElement("img"));
96     this.sidebarButtonsElement.appendChild(this.stepOutButton);
97
98     this.debuggerStatusElement = document.createElement("div");
99     this.debuggerStatusElement.id = "scripts-debugger-status";
100     this.sidebarButtonsElement.appendChild(this.debuggerStatusElement);
101
102     this.scriptResourceViews = document.createElement("div");
103     this.scriptResourceViews.id = "script-resource-views";
104
105     this.sidebarElement = document.createElement("div");
106     this.sidebarElement.id = "scripts-sidebar";
107
108     this.sidebarResizeElement = document.createElement("div");
109     this.sidebarResizeElement.className = "sidebar-resizer-vertical";
110     this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarResizeDrag.bind(this), false);
111
112     this.sidebarResizeWidgetElement = document.createElement("div");
113     this.sidebarResizeWidgetElement.id = "scripts-sidebar-resizer-widget";
114     this.sidebarResizeWidgetElement.addEventListener("mousedown", this._startSidebarResizeDrag.bind(this), false);
115     this.topStatusBar.appendChild(this.sidebarResizeWidgetElement);
116
117     this.sidebarPanes = {};
118     this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane();
119     this.sidebarPanes.breakpoints = new WebInspector.BreakpointsSidebarPane();
120
121     for (var pane in this.sidebarPanes)
122         this.sidebarElement.appendChild(this.sidebarPanes[pane].element);
123
124     this.element.appendChild(this.scriptResourceViews);
125     this.element.appendChild(this.sidebarElement);
126     this.element.appendChild(this.sidebarResizeElement);
127 }
128
129 WebInspector.ScriptsPanel.prototype = {
130     toolbarItemClass: "scripts",
131
132     get toolbarItemLabel()
133     {
134         return WebInspector.UIString("Scripts");
135     },
136
137     get statusBarItems()
138     {
139         return [];
140     },
141
142     show: function()
143     {
144         WebInspector.Panel.prototype.show.call(this);
145         this.sidebarResizeElement.style.right = (this.sidebarElement.offsetWidth - 3) + "px";
146     },
147
148     _startSidebarResizeDrag: function(event)
149     {
150         WebInspector.elementDragStart(this.sidebarElement, this._sidebarResizeDrag.bind(this), this._endSidebarResizeDrag.bind(this), event, "col-resize");
151
152         if (event.target === this.sidebarResizeWidgetElement)
153             this._dragOffset = (event.target.offsetWidth - (event.pageX - event.target.totalOffsetLeft));
154         else
155             this._dragOffset = 0;
156     },
157
158     _endSidebarResizeDrag: function(event)
159     {
160         WebInspector.elementDragEnd(event);
161
162         delete this._dragOffset;
163     },
164
165     _sidebarResizeDrag: function(event)
166     {
167         var x = event.pageX + this._dragOffset;
168         var newWidth = Number.constrain(window.innerWidth - x, Preferences.minScriptsSidebarWidth, window.innerWidth * 0.66);
169
170         this.sidebarElement.style.width = newWidth + "px";
171         this.sidebarButtonsElement.style.width = newWidth + "px";
172         this.scriptResourceViews.style.right = newWidth + "px";
173         this.sidebarResizeWidgetElement.style.right = newWidth + "px";
174         this.sidebarResizeElement.style.right = (newWidth - 3) + "px";
175
176         event.preventDefault();
177     },
178 }
179
180 WebInspector.ScriptsPanel.prototype.__proto__ = WebInspector.Panel.prototype;