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.VBox}
35 WebInspector.InspectorView = function()
37 WebInspector.VBox.call(this);
38 WebInspector.Dialog.setModalHostView(this);
39 this.setMinimumSize(180, 72);
41 // DevTools sidebar is a vertical split of panels tabbed pane and a drawer.
42 this._drawerSplitView = new WebInspector.SplitView(false, true, "Inspector.drawerSplitViewState", 200, 200);
43 this._drawerSplitView.hideSidebar();
44 this._drawerSplitView.enableShowModeSaving();
45 this._drawerSplitView.show(this.element);
47 this._tabbedPane = new WebInspector.TabbedPane();
48 this._tabbedPane.setRetainTabOrder(true, WebInspector.moduleManager.orderComparator(WebInspector.Panel, "name", "order"));
49 this._tabbedPane.show(this._drawerSplitView.mainElement());
50 this._drawer = new WebInspector.Drawer(this._drawerSplitView);
52 // Patch tabbed pane header with toolbar actions.
53 this._toolbarElement = document.createElement("div");
54 this._toolbarElement.className = "toolbar toolbar-background";
55 var headerElement = this._tabbedPane.headerElement();
56 headerElement.parentElement.insertBefore(this._toolbarElement, headerElement);
58 this._leftToolbarElement = this._toolbarElement.createChild("div", "toolbar-controls-left");
59 this._toolbarElement.appendChild(headerElement);
60 this._rightToolbarElement = this._toolbarElement.createChild("div", "toolbar-controls-right");
62 this._errorWarningCountElement = this._rightToolbarElement.createChild("div", "hidden");
63 this._errorWarningCountElement.id = "error-warning-count";
65 this._closeButtonToolbarItem = document.createElementWithClass("div", "toolbar-close-button-item");
66 var closeButtonElement = this._closeButtonToolbarItem.createChild("div", "close-button");
67 closeButtonElement.addEventListener("click", InspectorFrontendHost.closeWindow.bind(InspectorFrontendHost), true);
68 this._rightToolbarElement.appendChild(this._closeButtonToolbarItem);
70 this.appendToRightToolbar(this._drawer.toggleButtonElement());
73 this._historyIterator = -1;
74 document.addEventListener("keydown", this._keyDown.bind(this), false);
75 document.addEventListener("keypress", this._keyPress.bind(this), false);
76 this._panelDescriptors = {};
78 // Windows and Mac have two different definitions of '[' and ']', so accept both of each.
79 this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
80 this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
81 this._lastActivePanelSetting = WebInspector.settings.createSetting("lastActivePanel", "elements");
83 this._loadPanelDesciptors();
86 WebInspector.InspectorView.prototype = {
87 _loadPanelDesciptors: function()
89 WebInspector.startBatchUpdate();
90 WebInspector.moduleManager.extensions(WebInspector.Panel).forEach(processPanelExtensions.bind(this));
92 * @param {!WebInspector.ModuleManager.Extension} extension
93 * @this {!WebInspector.InspectorView}
95 function processPanelExtensions(extension)
97 this.addPanel(new WebInspector.ModuleManagerExtensionPanelDescriptor(extension));
99 WebInspector.endBatchUpdate();
103 * @param {!Element} element
105 appendToLeftToolbar: function(element)
107 this._leftToolbarElement.appendChild(element);
111 * @param {!Element} element
113 appendToRightToolbar: function(element)
115 this._rightToolbarElement.insertBefore(element, this._closeButtonToolbarItem);
119 * @param {!WebInspector.PanelDescriptor} panelDescriptor
121 addPanel: function(panelDescriptor)
123 var panelName = panelDescriptor.name();
124 this._panelDescriptors[panelName] = panelDescriptor;
125 this._tabbedPane.appendTab(panelName, panelDescriptor.title(), new WebInspector.View());
126 if (this._lastActivePanelSetting.get() === panelName)
127 this._tabbedPane.selectTab(panelName);
131 * @param {string} panelName
132 * @return {?WebInspector.Panel}
134 panel: function(panelName)
136 var panelDescriptor = this._panelDescriptors[panelName];
137 var panelOrder = this._tabbedPane.allTabs();
138 if (!panelDescriptor && panelOrder.length)
139 panelDescriptor = this._panelDescriptors[panelOrder[0]];
140 return panelDescriptor ? panelDescriptor.panel() : null;
144 * @param {string} panelName
145 * @return {?WebInspector.Panel}
147 showPanel: function(panelName)
149 var panel = this.panel(panelName);
151 this.setCurrentPanel(panel);
156 * @return {!WebInspector.Panel}
158 currentPanel: function()
160 return this._currentPanel;
163 showInitialPanel: function()
165 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
167 this._drawer.initialPanelShown();
170 showDrawerEditor: function()
172 this._drawer.showDrawerEditor();
178 isDrawerEditorShown: function()
180 return this._drawer.isDrawerEditorShown();
183 hideDrawerEditor: function()
185 this._drawer.hideDrawerEditor();
189 * @param {boolean} available
191 setDrawerEditorAvailable: function(available)
193 this._drawer.setDrawerEditorAvailable(available);
196 _tabSelected: function()
198 var panelName = this._tabbedPane.selectedTabId;
199 var panel = this._panelDescriptors[this._tabbedPane.selectedTabId].panel();
200 this._tabbedPane.changeTabView(panelName, panel);
202 this._currentPanel = panel;
203 this._lastActivePanelSetting.set(panel.name);
204 this._pushToHistory(panel.name);
205 WebInspector.userMetrics.panelShown(panel.name);
210 * @param {!WebInspector.Panel} x
212 setCurrentPanel: function(x)
214 if (this._currentPanel === x)
217 this._tabbedPane.changeTabView(x.name, x);
218 this._tabbedPane.selectTab(x.name);
224 closeViewInDrawer: function(id)
226 this._drawer.closeView(id);
231 * @param {string} title
232 * @param {!WebInspector.View} view
234 showCloseableViewInDrawer: function(id, title, view)
236 this._drawer.showCloseableView(id, title, view);
239 showDrawer: function()
241 this._drawer.showDrawer();
247 drawerVisible: function()
249 return this._drawer.isShowing();
254 * @param {boolean=} immediate
256 showViewInDrawer: function(id, immediate)
258 this._drawer.showView(id, immediate);
264 selectedViewInDrawer: function()
266 return this._drawer.selectedViewId();
269 closeDrawer: function()
271 this._drawer.closeDrawer();
277 defaultFocusedElement: function()
279 return this._currentPanel ? this._currentPanel.defaultFocusedElement() : null;
282 _keyPress: function(event)
284 // BUG 104250: Windows 7 posts a WM_CHAR message upon the Ctrl+']' keypress.
285 // Any charCode < 32 is not going to be a valid keypress.
286 if (event.charCode < 32 && WebInspector.isWin())
288 clearTimeout(this._keyDownTimer);
289 delete this._keyDownTimer;
292 _keyDown: function(event)
294 if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
297 var keyboardEvent = /** @type {!KeyboardEvent} */ (event);
298 // Ctrl/Cmd + 1-9 should show corresponding panel.
299 var panelShortcutEnabled = WebInspector.settings.shortcutPanelSwitch.get();
300 if (panelShortcutEnabled && !event.shiftKey && !event.altKey) {
302 if (event.keyCode > 0x30 && event.keyCode < 0x3A)
303 panelIndex = event.keyCode - 0x31;
304 else if (event.keyCode > 0x60 && event.keyCode < 0x6A && keyboardEvent.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD)
305 panelIndex = event.keyCode - 0x61;
306 if (panelIndex !== -1) {
307 var panelName = this._tabbedPane.allTabs()[panelIndex];
309 if (!WebInspector.Dialog.currentInstance())
310 this.showPanel(panelName);
317 // BUG85312: On French AZERTY keyboards, AltGr-]/[ combinations (synonymous to Ctrl-Alt-]/[ on Windows) are used to enter ]/[,
318 // so for a ]/[-related keydown we delay the panel switch using a timer, to see if there is a keypress event following this one.
319 // If there is, we cancel the timer and do not consider this a panel switch.
320 if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
321 this._keyDownInternal(event);
325 this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
328 _keyDownInternal: function(event)
332 if (this._openBracketIdentifiers[event.keyIdentifier])
335 if (this._closeBracketIdentifiers[event.keyIdentifier])
341 if (!event.shiftKey && !event.altKey) {
342 if (!WebInspector.Dialog.currentInstance())
343 this._changePanelInDirection(direction);
348 if (event.altKey && this._moveInHistory(direction))
352 _changePanelInDirection: function(direction)
354 var panelOrder = this._tabbedPane.allTabs();
355 var index = panelOrder.indexOf(this.currentPanel().name);
356 index = (index + panelOrder.length + direction) % panelOrder.length;
357 this.showPanel(panelOrder[index]);
360 _moveInHistory: function(move)
362 var newIndex = this._historyIterator + move;
363 if (newIndex >= this._history.length || newIndex < 0)
366 this._inHistory = true;
367 this._historyIterator = newIndex;
368 if (!WebInspector.Dialog.currentInstance())
369 this.setCurrentPanel(WebInspector.panels[this._history[this._historyIterator]]);
370 delete this._inHistory;
375 _pushToHistory: function(panelName)
380 this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
381 if (!this._history.length || this._history[this._history.length - 1] !== panelName)
382 this._history.push(panelName);
383 this._historyIterator = this._history.length - 1;
388 WebInspector.Dialog.modalHostRepositioned();
394 topResizerElement: function()
396 return this._tabbedPane.headerElement();
399 _createImagedCounterElementIfNeeded: function(count, id, styleName)
404 var imageElement = this._errorWarningCountElement.createChild("div", styleName);
405 var counterElement = this._errorWarningCountElement.createChild("span");
406 counterElement.id = id;
407 counterElement.textContent = count;
411 * @param {number} errors
412 * @param {number} warnings
414 setErrorAndWarningCounts: function(errors, warnings)
416 if (this._errors === errors && this._warnings === warnings)
418 this._errors = errors;
419 this._warnings = warnings;
420 this._errorWarningCountElement.classList.toggle("hidden", !errors && !warnings);
421 this._errorWarningCountElement.removeChildren();
423 this._createImagedCounterElementIfNeeded(errors, "error-count", "error-icon-small");
424 this._createImagedCounterElementIfNeeded(warnings, "warning-count", "warning-icon-small");
426 var errorString = errors ? WebInspector.UIString("%d error%s", errors, errors > 1 ? "s" : "") : "";
427 var warningString = warnings ? WebInspector.UIString("%d warning%s", warnings, warnings > 1 ? "s" : "") : "";
428 var commaString = errors && warnings ? ", " : "";
429 this._errorWarningCountElement.title = errorString + commaString + warningString;
430 this._tabbedPane.headerResized();
433 __proto__: WebInspector.VBox.prototype
437 * @type {!WebInspector.InspectorView}
439 WebInspector.inspectorView;
443 * @implements {WebInspector.ActionDelegate}
445 WebInspector.InspectorView.DrawerToggleActionDelegate = function()
449 WebInspector.InspectorView.DrawerToggleActionDelegate.prototype = {
453 handleAction: function()
455 if (WebInspector.inspectorView.drawerVisible()) {
456 WebInspector.inspectorView.closeDrawer();
459 if (!WebInspector.experimentsSettings.doNotOpenDrawerOnEsc.isEnabled()) {
460 WebInspector.inspectorView.showDrawer();
469 * @extends {WebInspector.VBox}
471 WebInspector.RootView = function()
473 WebInspector.VBox.call(this);
475 this.element.classList.add("root-view");
476 this.element.setAttribute("spellcheck", false);
477 window.addEventListener("resize", this.doResize.bind(this), true);
478 this._onScrollBound = this._onScroll.bind(this);
481 WebInspector.RootView.prototype = {
482 attachToBody: function()
485 this.show(document.body);
488 _onScroll: function()
490 // If we didn't have enough space at the start, we may have wrong scroll offsets.
491 if (document.body.scrollTop !== 0)
492 document.body.scrollTop = 0;
493 if (document.body.scrollLeft !== 0)
494 document.body.scrollLeft = 0;
499 var size = this.minimumSize();
500 var right = Math.min(0, window.innerWidth - size.width);
501 this.element.style.right = right + "px";
502 var bottom = Math.min(0, window.innerHeight - size.height);
503 this.element.style.bottom = bottom + "px";
505 if (window.innerWidth < size.width || window.innerHeight < size.height)
506 window.addEventListener("scroll", this._onScrollBound, false);
508 window.removeEventListener("scroll", this._onScrollBound, false);
510 WebInspector.VBox.prototype.doResize.call(this);
514 __proto__: WebInspector.VBox.prototype