OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
14 * its contributors may be used to endorse or promote products derived | 14 * its contributors may be used to endorse or promote products derived |
15 * from this software without specific prior written permission. | 15 * from this software without specific prior written permission. |
16 * | 16 * |
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | |
29 // For testing. | 28 // For testing. |
30 WebInspector.panels = []; | 29 WebInspector.panels = []; |
31 | 30 |
32 /** | 31 /** |
33 * @extends {WebInspector.VBox} | 32 * @unrestricted |
34 * @constructor | |
35 */ | 33 */ |
36 WebInspector.Panel = function(name) | 34 WebInspector.Panel = class extends WebInspector.VBox { |
37 { | 35 constructor(name) { |
38 WebInspector.VBox.call(this); | 36 super(); |
39 | 37 |
40 this.element.classList.add("panel"); | 38 this.element.classList.add('panel'); |
41 this.element.setAttribute("aria-label", name); | 39 this.element.setAttribute('aria-label', name); |
42 this.element.classList.add(name); | 40 this.element.classList.add(name); |
43 this._panelName = name; | 41 this._panelName = name; |
44 | 42 |
45 // For testing. | 43 // For testing. |
46 WebInspector.panels[name] = this; | 44 WebInspector.panels[name] = this; |
47 | 45 |
48 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); | 46 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); |
| 47 } |
| 48 |
| 49 get name() { |
| 50 return this._panelName; |
| 51 } |
| 52 |
| 53 /** |
| 54 * @return {?WebInspector.SearchableView} |
| 55 */ |
| 56 searchableView() { |
| 57 return null; |
| 58 } |
| 59 |
| 60 /** |
| 61 * @override |
| 62 * @return {!Array.<!Element>} |
| 63 */ |
| 64 elementsToRestoreScrollPositionsFor() { |
| 65 return []; |
| 66 } |
| 67 |
| 68 /** |
| 69 * @param {!KeyboardEvent} event |
| 70 */ |
| 71 handleShortcut(event) { |
| 72 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); |
| 73 var handler = this._shortcuts[shortcutKey]; |
| 74 if (handler && handler(event)) |
| 75 event.handled = true; |
| 76 } |
| 77 |
| 78 /** |
| 79 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys |
| 80 * @param {function(!Event=):boolean} handler |
| 81 */ |
| 82 registerShortcuts(keys, handler) { |
| 83 for (var i = 0; i < keys.length; ++i) |
| 84 this._shortcuts[keys[i].key] = handler; |
| 85 } |
| 86 |
| 87 /** |
| 88 * @param {!WebInspector.Infobar} infobar |
| 89 */ |
| 90 showInfobar(infobar) { |
| 91 infobar.setCloseCallback(this._onInfobarClosed.bind(this, infobar)); |
| 92 if (this.element.firstChild) |
| 93 this.element.insertBefore(infobar.element, this.element.firstChild); |
| 94 else |
| 95 this.element.appendChild(infobar.element); |
| 96 infobar.setParentView(this); |
| 97 this.doResize(); |
| 98 } |
| 99 |
| 100 /** |
| 101 * @param {!WebInspector.Infobar} infobar |
| 102 */ |
| 103 _onInfobarClosed(infobar) { |
| 104 infobar.element.remove(); |
| 105 this.doResize(); |
| 106 } |
49 }; | 107 }; |
50 | 108 |
51 // Should by in sync with style declarations. | 109 // Should by in sync with style declarations. |
52 WebInspector.Panel.counterRightMargin = 25; | 110 WebInspector.Panel.counterRightMargin = 25; |
53 | 111 |
54 WebInspector.Panel.prototype = { | 112 /** |
55 get name() | 113 * @unrestricted |
56 { | 114 */ |
57 return this._panelName; | 115 WebInspector.PanelWithSidebar = class extends WebInspector.Panel { |
58 }, | 116 /** |
| 117 * @param {string} name |
| 118 * @param {number=} defaultWidth |
| 119 */ |
| 120 constructor(name, defaultWidth) { |
| 121 super(name); |
59 | 122 |
60 /** | 123 this._panelSplitWidget = |
61 * @return {?WebInspector.SearchableView} | 124 new WebInspector.SplitWidget(true, false, this._panelName + 'PanelSplitV
iewState', defaultWidth || 200); |
62 */ | |
63 searchableView: function() | |
64 { | |
65 return null; | |
66 }, | |
67 | |
68 /** | |
69 * @override | |
70 * @return {!Array.<!Element>} | |
71 */ | |
72 elementsToRestoreScrollPositionsFor: function() | |
73 { | |
74 return []; | |
75 }, | |
76 | |
77 /** | |
78 * @param {!KeyboardEvent} event | |
79 */ | |
80 handleShortcut: function(event) | |
81 { | |
82 var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); | |
83 var handler = this._shortcuts[shortcutKey]; | |
84 if (handler && handler(event)) | |
85 event.handled = true; | |
86 }, | |
87 | |
88 /** | |
89 * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys | |
90 * @param {function(!Event=):boolean} handler | |
91 */ | |
92 registerShortcuts: function(keys, handler) | |
93 { | |
94 for (var i = 0; i < keys.length; ++i) | |
95 this._shortcuts[keys[i].key] = handler; | |
96 }, | |
97 | |
98 /** | |
99 * @param {!WebInspector.Infobar} infobar | |
100 */ | |
101 showInfobar: function(infobar) | |
102 { | |
103 infobar.setCloseCallback(this._onInfobarClosed.bind(this, infobar)); | |
104 if (this.element.firstChild) | |
105 this.element.insertBefore(infobar.element, this.element.firstChild); | |
106 else | |
107 this.element.appendChild(infobar.element); | |
108 infobar.setParentView(this); | |
109 this.doResize(); | |
110 }, | |
111 | |
112 /** | |
113 * @param {!WebInspector.Infobar} infobar | |
114 */ | |
115 _onInfobarClosed: function(infobar) | |
116 { | |
117 infobar.element.remove(); | |
118 this.doResize(); | |
119 }, | |
120 | |
121 __proto__: WebInspector.VBox.prototype | |
122 }; | |
123 | |
124 /** | |
125 * @extends {WebInspector.Panel} | |
126 * @param {string} name | |
127 * @param {number=} defaultWidth | |
128 * @constructor | |
129 */ | |
130 WebInspector.PanelWithSidebar = function(name, defaultWidth) | |
131 { | |
132 WebInspector.Panel.call(this, name); | |
133 | |
134 this._panelSplitWidget = new WebInspector.SplitWidget(true, false, this._pan
elName + "PanelSplitViewState", defaultWidth || 200); | |
135 this._panelSplitWidget.show(this.element); | 125 this._panelSplitWidget.show(this.element); |
136 | 126 |
137 this._mainWidget = new WebInspector.VBox(); | 127 this._mainWidget = new WebInspector.VBox(); |
138 this._panelSplitWidget.setMainWidget(this._mainWidget); | 128 this._panelSplitWidget.setMainWidget(this._mainWidget); |
139 | 129 |
140 this._sidebarWidget = new WebInspector.VBox(); | 130 this._sidebarWidget = new WebInspector.VBox(); |
141 this._sidebarWidget.setMinimumSize(100, 25); | 131 this._sidebarWidget.setMinimumSize(100, 25); |
142 this._panelSplitWidget.setSidebarWidget(this._sidebarWidget); | 132 this._panelSplitWidget.setSidebarWidget(this._sidebarWidget); |
143 | 133 |
144 this._sidebarWidget.element.classList.add("panel-sidebar"); | 134 this._sidebarWidget.element.classList.add('panel-sidebar'); |
| 135 } |
| 136 |
| 137 /** |
| 138 * @return {!Element} |
| 139 */ |
| 140 panelSidebarElement() { |
| 141 return this._sidebarWidget.element; |
| 142 } |
| 143 |
| 144 /** |
| 145 * @return {!Element} |
| 146 */ |
| 147 mainElement() { |
| 148 return this._mainWidget.element; |
| 149 } |
| 150 |
| 151 /** |
| 152 * @return {!WebInspector.SplitWidget} |
| 153 */ |
| 154 splitWidget() { |
| 155 return this._panelSplitWidget; |
| 156 } |
145 }; | 157 }; |
146 | |
147 WebInspector.PanelWithSidebar.prototype = { | |
148 /** | |
149 * @return {!Element} | |
150 */ | |
151 panelSidebarElement: function() | |
152 { | |
153 return this._sidebarWidget.element; | |
154 }, | |
155 | |
156 /** | |
157 * @return {!Element} | |
158 */ | |
159 mainElement: function() | |
160 { | |
161 return this._mainWidget.element; | |
162 }, | |
163 | |
164 /** | |
165 * @return {!WebInspector.SplitWidget} | |
166 */ | |
167 splitWidget: function() | |
168 { | |
169 return this._panelSplitWidget; | |
170 }, | |
171 | |
172 __proto__: WebInspector.Panel.prototype | |
173 }; | |
OLD | NEW |