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());
74 WebInspector["panels"] = this._panels;
77 this._historyIterator = -1;
78 document.addEventListener("keydown", this._keyDown.bind(this), false);
79 document.addEventListener("keypress", this._keyPress.bind(this), false);
80 this._panelDescriptors = {};
82 // Windows and Mac have two different definitions of '[' and ']', so accept both of each.
83 this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
84 this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
85 this._lastActivePanelSetting = WebInspector.settings.createSetting("lastActivePanel", "elements");
87 this._loadPanelDesciptors();
90 WebInspector.InspectorView.prototype = {
91 _loadPanelDesciptors: function()
93 WebInspector.startBatchUpdate();
94 WebInspector.moduleManager.extensions(WebInspector.Panel).forEach(processPanelExtensions.bind(this));
96 * @param {!WebInspector.ModuleManager.Extension} extension
97 * @this {!WebInspector.InspectorView}
99 function processPanelExtensions(extension)
101 this.addPanel(new WebInspector.ModuleManagerExtensionPanelDescriptor(extension));
103 WebInspector.endBatchUpdate();
107 * @param {!Element} element
109 appendToLeftToolbar: function(element)
111 this._leftToolbarElement.appendChild(element);
115 * @param {!Element} element
117 appendToRightToolbar: function(element)
119 this._rightToolbarElement.insertBefore(element, this._closeButtonToolbarItem);
123 * @param {!WebInspector.PanelDescriptor} panelDescriptor
125 addPanel: function(panelDescriptor)
127 var panelName = panelDescriptor.name();
128 this._panelDescriptors[panelName] = panelDescriptor;
129 this._tabbedPane.appendTab(panelName, panelDescriptor.title(), new WebInspector.View());
130 if (this._lastActivePanelSetting.get() === panelName)
131 this._tabbedPane.selectTab(panelName);
135 * @param {string} panelName
138 hasPanel: function(panelName)
140 return !!this._panelDescriptors[panelName];
144 * @param {string} panelName
145 * @return {?WebInspector.Panel}
147 panel: function(panelName)
149 var panelDescriptor = this._panelDescriptors[panelName];
150 var panelOrder = this._tabbedPane.allTabs();
151 if (!panelDescriptor && panelOrder.length)
152 panelDescriptor = this._panelDescriptors[panelOrder[0]];
153 var panel = panelDescriptor ? panelDescriptor.panel() : null;
155 this._panels[panelName] = panel;
160 * @param {string} panelName
161 * @return {?WebInspector.Panel}
163 showPanel: function(panelName)
165 var panel = this.panel(panelName);
167 this.setCurrentPanel(panel);
172 * @return {!WebInspector.Panel}
174 currentPanel: function()
176 return this._currentPanel;
179 showInitialPanel: function()
181 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
183 this._drawer.initialPanelShown();
186 showDrawerEditor: function()
188 this._drawer.showDrawerEditor();
194 isDrawerEditorShown: function()
196 return this._drawer.isDrawerEditorShown();
199 hideDrawerEditor: function()
201 this._drawer.hideDrawerEditor();
205 * @param {boolean} available
207 setDrawerEditorAvailable: function(available)
209 this._drawer.setDrawerEditorAvailable(available);
212 _tabSelected: function()
214 var panelName = this._tabbedPane.selectedTabId;
217 var panel = this._panelDescriptors[this._tabbedPane.selectedTabId].panel();
218 this._panels[panelName] = panel;
219 this._tabbedPane.changeTabView(panelName, panel);
221 this._currentPanel = panel;
222 this._lastActivePanelSetting.set(panel.name);
223 this._pushToHistory(panel.name);
224 WebInspector.userMetrics.panelShown(panel.name);
229 * @param {!WebInspector.Panel} x
231 setCurrentPanel: function(x)
233 if (this._currentPanel === x)
236 this._tabbedPane.changeTabView(x.name, x);
237 this._tabbedPane.selectTab(x.name);
243 closeViewInDrawer: function(id)
245 this._drawer.closeView(id);
250 * @param {string} title
251 * @param {!WebInspector.View} view
253 showCloseableViewInDrawer: function(id, title, view)
255 this._drawer.showCloseableView(id, title, view);
258 showDrawer: function()
260 this._drawer.showDrawer();
266 drawerVisible: function()
268 return this._drawer.isShowing();
273 * @param {boolean=} immediate
275 showViewInDrawer: function(id, immediate)
277 this._drawer.showView(id, immediate);
283 selectedViewInDrawer: function()
285 return this._drawer.selectedViewId();
288 closeDrawer: function()
290 this._drawer.closeDrawer();
296 defaultFocusedElement: function()
298 return this._currentPanel ? this._currentPanel.defaultFocusedElement() : null;
301 _keyPress: function(event)
303 // BUG 104250: Windows 7 posts a WM_CHAR message upon the Ctrl+']' keypress.
304 // Any charCode < 32 is not going to be a valid keypress.
305 if (event.charCode < 32 && WebInspector.isWin())
307 clearTimeout(this._keyDownTimer);
308 delete this._keyDownTimer;
311 _keyDown: function(event)
313 if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
316 var keyboardEvent = /** @type {!KeyboardEvent} */ (event);
317 // Ctrl/Cmd + 1-9 should show corresponding panel.
318 var panelShortcutEnabled = WebInspector.settings.shortcutPanelSwitch.get();
319 if (panelShortcutEnabled && !event.shiftKey && !event.altKey) {
321 if (event.keyCode > 0x30 && event.keyCode < 0x3A)
322 panelIndex = event.keyCode - 0x31;
323 else if (event.keyCode > 0x60 && event.keyCode < 0x6A && keyboardEvent.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD)
324 panelIndex = event.keyCode - 0x61;
325 if (panelIndex !== -1) {
326 var panelName = this._tabbedPane.allTabs()[panelIndex];
328 if (!WebInspector.Dialog.currentInstance())
329 this.showPanel(panelName);
336 // BUG85312: On French AZERTY keyboards, AltGr-]/[ combinations (synonymous to Ctrl-Alt-]/[ on Windows) are used to enter ]/[,
337 // so for a ]/[-related keydown we delay the panel switch using a timer, to see if there is a keypress event following this one.
338 // If there is, we cancel the timer and do not consider this a panel switch.
339 if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
340 this._keyDownInternal(event);
344 this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
347 _keyDownInternal: function(event)
351 if (this._openBracketIdentifiers[event.keyIdentifier])
354 if (this._closeBracketIdentifiers[event.keyIdentifier])
360 if (!event.shiftKey && !event.altKey) {
361 if (!WebInspector.Dialog.currentInstance())
362 this._changePanelInDirection(direction);
367 if (event.altKey && this._moveInHistory(direction))
371 _changePanelInDirection: function(direction)
373 var panelOrder = this._tabbedPane.allTabs();
374 var index = panelOrder.indexOf(this.currentPanel().name);
375 index = (index + panelOrder.length + direction) % panelOrder.length;
376 this.showPanel(panelOrder[index]);
379 _moveInHistory: function(move)
381 var newIndex = this._historyIterator + move;
382 if (newIndex >= this._history.length || newIndex < 0)
385 this._inHistory = true;
386 this._historyIterator = newIndex;
387 if (!WebInspector.Dialog.currentInstance())
388 this.setCurrentPanel(this._panels[this._history[this._historyIterator]]);
389 delete this._inHistory;
394 _pushToHistory: function(panelName)
399 this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
400 if (!this._history.length || this._history[this._history.length - 1] !== panelName)
401 this._history.push(panelName);
402 this._historyIterator = this._history.length - 1;
407 WebInspector.Dialog.modalHostRepositioned();
413 topResizerElement: function()
415 return this._tabbedPane.headerElement();
418 _createImagedCounterElementIfNeeded: function(count, id, styleName)
423 var imageElement = this._errorWarningCountElement.createChild("div", styleName);
424 var counterElement = this._errorWarningCountElement.createChild("span");
425 counterElement.id = id;
426 counterElement.textContent = count;
430 * @param {number} errors
431 * @param {number} warnings
433 setErrorAndWarningCounts: function(errors, warnings)
435 if (this._errors === errors && this._warnings === warnings)
437 this._errors = errors;
438 this._warnings = warnings;
439 this._errorWarningCountElement.classList.toggle("hidden", !errors && !warnings);
440 this._errorWarningCountElement.removeChildren();
442 this._createImagedCounterElementIfNeeded(errors, "error-count", "error-icon-small");
443 this._createImagedCounterElementIfNeeded(warnings, "warning-count", "warning-icon-small");
445 var errorString = errors ? WebInspector.UIString("%d error%s", errors, errors > 1 ? "s" : "") : "";
446 var warningString = warnings ? WebInspector.UIString("%d warning%s", warnings, warnings > 1 ? "s" : "") : "";
447 var commaString = errors && warnings ? ", " : "";
448 this._errorWarningCountElement.title = errorString + commaString + warningString;
449 this._tabbedPane.headerResized();
452 __proto__: WebInspector.VBox.prototype
456 * @type {!WebInspector.InspectorView}
458 WebInspector.inspectorView;
462 * @implements {WebInspector.ActionDelegate}
464 WebInspector.InspectorView.DrawerToggleActionDelegate = function()
468 WebInspector.InspectorView.DrawerToggleActionDelegate.prototype = {
472 handleAction: function()
474 if (WebInspector.inspectorView.drawerVisible()) {
475 WebInspector.inspectorView.closeDrawer();
478 WebInspector.inspectorView.showDrawer();
485 * @extends {WebInspector.VBox}
487 WebInspector.RootView = function()
489 WebInspector.VBox.call(this);
491 this.element.classList.add("root-view");
492 this.element.setAttribute("spellcheck", false);
493 window.addEventListener("resize", this.doResize.bind(this), true);
494 this._onScrollBound = this._onScroll.bind(this);
497 WebInspector.RootView.prototype = {
498 attachToBody: function()
501 this.show(document.body);
504 _onScroll: function()
506 // If we didn't have enough space at the start, we may have wrong scroll offsets.
507 if (document.body.scrollTop !== 0)
508 document.body.scrollTop = 0;
509 if (document.body.scrollLeft !== 0)
510 document.body.scrollLeft = 0;
515 var size = this.constraints().minimum;
516 var right = Math.min(0, window.innerWidth - size.width);
517 this.element.style.right = right + "px";
518 var bottom = Math.min(0, window.innerHeight - size.height);
519 this.element.style.bottom = bottom + "px";
521 if (window.innerWidth < size.width || window.innerHeight < size.height)
522 window.addEventListener("scroll", this._onScrollBound, false);
524 window.removeEventListener("scroll", this._onScrollBound, false);
526 WebInspector.VBox.prototype.doResize.call(this);
530 __proto__: WebInspector.VBox.prototype