2
* Copyright (C) 2011 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above
11
* copyright notice, this list of conditions and the following disclaimer
12
* in the documentation and/or other materials provided with the
14
* * Neither the name of Google Inc. nor the names of its
15
* contributors may be used to endorse or promote products derived from
16
* this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
* @extends {WebInspector.View}
35
WebInspector.InspectorView = function()
37
WebInspector.View.call(this);
39
this.element.id = "main-panels";
40
this.element.setAttribute("spellcheck", false);
42
this._historyIterator = -1;
43
document.addEventListener("keydown", this._keyDown.bind(this), false);
44
document.addEventListener("keypress", this._keyPress.bind(this), false);
45
this._panelOrder = [];
46
this._panelDescriptors = {};
48
// Windows and Mac have two different definitions of '[' and ']', so accept both of each.
49
this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
50
this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
51
this._footerElementContainer = this.element.createChild("div", "inspector-footer status-bar hidden");
52
this._panelsElement = this.element.createChild("div", "fill");
55
WebInspector.InspectorView.Events = {
56
PanelSelected: "PanelSelected"
59
WebInspector.InspectorView.prototype = {
61
* @param {WebInspector.PanelDescriptor} panelDescriptor
63
addPanel: function(panelDescriptor)
65
this._panelOrder.push(panelDescriptor.name());
66
this._panelDescriptors[panelDescriptor.name()] = panelDescriptor;
67
WebInspector.toolbar.addPanel(panelDescriptor);
71
* @param {string} panelName
72
* @return {?WebInspector.Panel}
74
panel: function(panelName)
76
var panelDescriptor = this._panelDescriptors[panelName];
77
if (!panelDescriptor && this._panelOrder.length)
78
panelDescriptor = this._panelDescriptors[this._panelOrder[0]];
79
return panelDescriptor ? panelDescriptor.panel() : null;
83
* @param {string} panelName
84
* @return {?WebInspector.Panel}
86
showPanel: function(panelName)
88
var panel = this.panel(panelName);
90
this.setCurrentPanel(panel);
94
currentPanel: function()
96
return this._currentPanel;
100
* @param {WebInspector.Panel} x
102
setCurrentPanel: function(x)
104
if (this._currentPanel === x)
107
if (this._currentPanel)
108
this._currentPanel.detach();
110
this._currentPanel = x;
114
this.dispatchEventToListeners(WebInspector.InspectorView.Events.PanelSelected);
115
// FIXME: remove search controller.
116
WebInspector.searchController.cancelSearch();
118
for (var panelName in WebInspector.panels) {
119
if (WebInspector.panels[panelName] === x) {
120
WebInspector.settings.lastActivePanel.set(panelName);
121
this._pushToHistory(panelName);
122
WebInspector.userMetrics.panelShown(panelName);
127
_keyPress: function(event)
129
clearTimeout(this._keyDownTimer);
130
delete this._keyDownTimer;
133
_keyDown: function(event)
135
if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
138
// Ctrl/Cmd + 1-9 should show corresponding panel.
139
if (!event.shiftKey && !event.altKey && event.keyCode > 0x30 && event.keyCode < 0x3A) {
140
var panelName = this._panelOrder[event.keyCode - 0x31];
142
this.showPanel(panelName);
148
// BUG85312: On French AZERTY keyboards, AltGr-]/[ combinations (synonymous to Ctrl-Alt-]/[ on Windows) are used to enter ]/[,
149
// so for a ]/[-related keydown we delay the panel switch using a timer, to see if there is a keypress event following this one.
150
// If there is, we cancel the timer and do not consider this a panel switch.
151
if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
152
this._keyDownInternal(event);
156
this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
159
_keyDownInternal: function(event)
161
if (this._openBracketIdentifiers[event.keyIdentifier]) {
162
var isRotateLeft = !event.shiftKey && !event.altKey;
164
var index = this._panelOrder.indexOf(this.currentPanel().name);
165
index = (index === 0) ? this._panelOrder.length - 1 : index - 1;
166
this.showPanel(this._panelOrder[index]);
171
var isGoBack = event.altKey;
172
if (isGoBack && this._canGoBackInHistory()) {
173
this._goBackInHistory();
179
if (this._closeBracketIdentifiers[event.keyIdentifier]) {
180
var isRotateRight = !event.shiftKey && !event.altKey;
182
var index = this._panelOrder.indexOf(this.currentPanel().name);
183
index = (index + 1) % this._panelOrder.length;
184
this.showPanel(this._panelOrder[index]);
189
var isGoForward = event.altKey;
190
if (isGoForward && this._canGoForwardInHistory()) {
191
this._goForwardInHistory();
198
_canGoBackInHistory: function()
200
return this._historyIterator > 0;
203
_goBackInHistory: function()
205
this._inHistory = true;
206
this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIterator]]);
207
delete this._inHistory;
210
_canGoForwardInHistory: function()
212
return this._historyIterator < this._history.length - 1;
215
_goForwardInHistory: function()
217
this._inHistory = true;
218
this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIterator]]);
219
delete this._inHistory;
222
_pushToHistory: function(panelName)
227
this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
228
if (!this._history.length || this._history[this._history.length - 1] !== panelName)
229
this._history.push(panelName);
230
this._historyIterator = this._history.length - 1;
233
panelsElement: function()
235
return this._panelsElement;
239
* @param {Element?} element
241
setFooterElement: function(element)
244
this._footerElementContainer.removeStyleClass("hidden");
245
this._footerElementContainer.appendChild(element);
246
this._panelsElement.style.bottom = this._footerElementContainer.offsetHeight + "px";
248
this._footerElementContainer.addStyleClass("hidden");
249
this._footerElementContainer.removeChildren();
250
this._panelsElement.style.bottom = 0;
256
* @param {WebInspector.Panel} panel
258
showPanelForAnchorNavigation: function(panel)
260
WebInspector.searchController.disableSearchUntilExplicitAction();
261
this.setCurrentPanel(panel);
264
__proto__: WebInspector.View.prototype
268
* @type {WebInspector.InspectorView}
270
WebInspector.inspectorView = null;