Web Inspector: new glyphs are visible on OS X 10.9 builds
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / DebuggerDashboardView.js
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
26 WebInspector.DebuggerDashboardView = function(representedObject)
27 {
28     WebInspector.DashboardView.call(this, representedObject, "debugger");
29
30     WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, this._rebuildLocation, this);
31
32     this._navigationBar = new WebInspector.NavigationBar;
33     this.element.appendChild(this._navigationBar.element);
34
35     var resumeImage;
36     if (WebInspector.Platform.isLegacyMacOS)
37         resumeImage = {src: "Images/Legacy/Resume.svg", width: 16, height: 16};
38     else
39         resumeImage = {src: "Images/Resume.svg", width: 15, height: 15};
40
41     var tooltip = WebInspector.UIString("Continue script execution (%s or %s)").format(WebInspector.debuggerSidebarPanel.pauseOrResumeKeyboardShortcut.displayName, WebInspector.debuggerSidebarPanel.pauseOrResumeAlternateKeyboardShortcut.displayName);
42     this._debuggerResumeButtonItem = new WebInspector.ActivateButtonNavigationItem("debugger-dashboard-pause", tooltip, tooltip, resumeImage.src, resumeImage.width, resumeImage.height, true);
43     this._debuggerResumeButtonItem.activated = true;
44     this._debuggerResumeButtonItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._resumeButtonClicked, this);
45     this._navigationBar.addNavigationItem(this._debuggerResumeButtonItem);
46
47     var message = this._messageElement = document.createElement("div");
48     message.classList.add(WebInspector.DebuggerDashboardView.MessageStyleClassName);
49     message.title = message.textContent = WebInspector.UIString("Debugger Paused");
50     this.element.appendChild(message);
51
52     var dividerElement = document.createElement("div");
53     dividerElement.classList.add(WebInspector.DebuggerDashboardView.DividerStyleClassName);
54     this.element.appendChild(dividerElement);
55
56     var locationElement = this._locationElement = document.createElement("div");
57     locationElement.classList.add(WebInspector.DebuggerDashboardView.LocationStyleClassName);
58     this.element.appendChild(locationElement);
59
60     this._rebuildLocation();
61 };
62
63 WebInspector.DebuggerDashboardView.FunctionIconStyleClassName = WebInspector.CallFrameTreeElement.FunctionIconStyleClassName;
64 WebInspector.DebuggerDashboardView.EventListenerIconStyleClassName = WebInspector.CallFrameTreeElement.EventListenerIconStyleClassName;
65
66 WebInspector.DebuggerDashboardView.IconStyleClassName = "icon";
67 WebInspector.DebuggerDashboardView.MessageStyleClassName = "message";
68 WebInspector.DebuggerDashboardView.DividerStyleClassName = "divider";
69 WebInspector.DebuggerDashboardView.LocationStyleClassName = "location";
70 WebInspector.DebuggerDashboardView.FunctionNameStyleClassName = "function-name";
71
72 WebInspector.DebuggerDashboardView.prototype = {
73     constructor: WebInspector.DebuggerDashboardView,
74     __proto__: WebInspector.DashboardView.prototype,
75
76     _rebuildLocation: function()
77     {
78         if (!WebInspector.debuggerManager.activeCallFrame)
79             return;
80
81         this._locationElement.removeChildren();
82
83         var callFrame = WebInspector.debuggerManager.activeCallFrame;
84         var functionName = callFrame.functionName || WebInspector.UIString("(anonymous function)");
85
86         var iconClassName = WebInspector.DebuggerDashboardView.FunctionIconStyleClassName;
87
88         // This is more than likely an event listener function with an "on" prefix and it is
89         // as long or longer than the shortest event listener name -- "oncut".
90         if (callFrame.functionName && callFrame.functionName.startsWith("on") && callFrame.functionName.length >= 5)
91             iconClassName = WebInspector.DebuggerDashboardView.EventListenerIconStyleClassName;
92
93         var iconElement = document.createElement("div");
94         iconElement.classList.add(iconClassName);
95         this._locationElement.appendChild(iconElement);
96
97         var iconImageElement = document.createElement("img");
98         iconImageElement.className = WebInspector.DebuggerDashboardView.IconStyleClassName;
99         iconElement.appendChild(iconImageElement);
100
101         var nameElement = document.createElement("div");
102         nameElement.appendChild(document.createTextNode(functionName));
103         nameElement.classList.add(WebInspector.DebuggerDashboardView.FunctionNameStyleClassName);
104         this._locationElement.appendChild(nameElement);
105
106         var sourceCodeLocation = WebInspector.debuggerManager.activeCallFrame.sourceCodeLocation;
107         var shouldPreventLinkFloat = true;
108         var linkElement = WebInspector.createSourceCodeLocationLink(sourceCodeLocation, shouldPreventLinkFloat);
109         this._locationElement.appendChild(linkElement);
110     },
111
112     _resumeButtonClicked: function()
113     {
114         WebInspector.debuggerManager.resume();
115     }
116 };