123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- /**
- * @constructor
- * @extends {WebInspector.View}
- */
- WebInspector.InspectorView = function()
- {
- WebInspector.View.call(this);
- this.markAsRoot();
- this.element.id = "main-panels";
- this.element.setAttribute("spellcheck", false);
- this._history = [];
- this._historyIterator = -1;
- document.addEventListener("keydown", this._keyDown.bind(this), false);
- document.addEventListener("keypress", this._keyPress.bind(this), false);
- this._panelOrder = [];
- this._panelDescriptors = {};
- // Windows and Mac have two different definitions of '[' and ']', so accept both of each.
- this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
- this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
- this._footerElementContainer = this.element.createChild("div", "inspector-footer status-bar hidden");
- this._panelsElement = this.element.createChild("div", "fill");
- }
- WebInspector.InspectorView.Events = {
- PanelSelected: "PanelSelected"
- }
- WebInspector.InspectorView.prototype = {
- /**
- * @param {WebInspector.PanelDescriptor} panelDescriptor
- */
- addPanel: function(panelDescriptor)
- {
- this._panelOrder.push(panelDescriptor.name());
- this._panelDescriptors[panelDescriptor.name()] = panelDescriptor;
- WebInspector.toolbar.addPanel(panelDescriptor);
- },
- /**
- * @param {string} panelName
- * @return {?WebInspector.Panel}
- */
- panel: function(panelName)
- {
- var panelDescriptor = this._panelDescriptors[panelName];
- if (!panelDescriptor && this._panelOrder.length)
- panelDescriptor = this._panelDescriptors[this._panelOrder[0]];
- return panelDescriptor ? panelDescriptor.panel() : null;
- },
- /**
- * @param {string} panelName
- * @return {?WebInspector.Panel}
- */
- showPanel: function(panelName)
- {
- var panel = this.panel(panelName);
- if (panel)
- this.setCurrentPanel(panel);
- return panel;
- },
- /**
- * @return {WebInspector.Panel}
- */
- currentPanel: function()
- {
- return this._currentPanel;
- },
-
- /**
- * @param {WebInspector.Panel} x
- */
- setCurrentPanel: function(x)
- {
- if (this._currentPanel === x)
- return;
- if (this._currentPanel)
- this._currentPanel.detach();
- this._currentPanel = x;
- if (x) {
- x.show();
- this.dispatchEventToListeners(WebInspector.InspectorView.Events.PanelSelected);
- // FIXME: remove search controller.
- WebInspector.searchController.cancelSearch();
- }
- for (var panelName in WebInspector.panels) {
- if (WebInspector.panels[panelName] === x) {
- WebInspector.settings.lastActivePanel.set(panelName);
- this._pushToHistory(panelName);
- WebInspector.userMetrics.panelShown(panelName);
- }
- }
- },
- /**
- * @return {Element}
- */
- defaultFocusedElement: function()
- {
- return this._currentPanel ? this._currentPanel.defaultFocusedElement() : null;
- },
- _keyPress: function(event)
- {
- // BUG 104250: Windows 7 posts a WM_CHAR message upon the Ctrl+']' keypress.
- // Any charCode < 32 is not going to be a valid keypress.
- if (event.charCode < 32 && WebInspector.isWin())
- return;
- clearTimeout(this._keyDownTimer);
- delete this._keyDownTimer;
- },
- _keyDown: function(event)
- {
- if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
- return;
- // Ctrl/Cmd + 1-9 should show corresponding panel.
- if (!event.shiftKey && !event.altKey && event.keyCode > 0x30 && event.keyCode < 0x3A) {
- var panelName = this._panelOrder[event.keyCode - 0x31];
- if (panelName) {
- this.showPanel(panelName);
- event.consume(true);
- }
- return;
- }
- // BUG85312: On French AZERTY keyboards, AltGr-]/[ combinations (synonymous to Ctrl-Alt-]/[ on Windows) are used to enter ]/[,
- // so for a ]/[-related keydown we delay the panel switch using a timer, to see if there is a keypress event following this one.
- // If there is, we cancel the timer and do not consider this a panel switch.
- if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
- this._keyDownInternal(event);
- return;
- }
- this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
- },
- _keyDownInternal: function(event)
- {
- if (this._openBracketIdentifiers[event.keyIdentifier]) {
- var isRotateLeft = !event.shiftKey && !event.altKey;
- if (isRotateLeft) {
- var index = this._panelOrder.indexOf(this.currentPanel().name);
- index = (index === 0) ? this._panelOrder.length - 1 : index - 1;
- this.showPanel(this._panelOrder[index]);
- event.consume(true);
- return;
- }
- var isGoBack = event.altKey;
- if (isGoBack && this._canGoBackInHistory()) {
- this._goBackInHistory();
- event.consume(true);
- }
- return;
- }
- if (this._closeBracketIdentifiers[event.keyIdentifier]) {
- var isRotateRight = !event.shiftKey && !event.altKey;
- if (isRotateRight) {
- var index = this._panelOrder.indexOf(this.currentPanel().name);
- index = (index + 1) % this._panelOrder.length;
- this.showPanel(this._panelOrder[index]);
- event.consume(true);
- return;
- }
- var isGoForward = event.altKey;
- if (isGoForward && this._canGoForwardInHistory()) {
- this._goForwardInHistory();
- event.consume(true);
- }
- return;
- }
- },
- _canGoBackInHistory: function()
- {
- return this._historyIterator > 0;
- },
- _goBackInHistory: function()
- {
- this._inHistory = true;
- this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIterator]]);
- delete this._inHistory;
- },
- _canGoForwardInHistory: function()
- {
- return this._historyIterator < this._history.length - 1;
- },
- _goForwardInHistory: function()
- {
- this._inHistory = true;
- this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIterator]]);
- delete this._inHistory;
- },
- _pushToHistory: function(panelName)
- {
- if (this._inHistory)
- return;
- this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
- if (!this._history.length || this._history[this._history.length - 1] !== panelName)
- this._history.push(panelName);
- this._historyIterator = this._history.length - 1;
- },
- panelsElement: function()
- {
- return this._panelsElement;
- },
- /**
- * @param {Element?} element
- */
- setFooterElement: function(element)
- {
- if (element) {
- this._footerElementContainer.removeStyleClass("hidden");
- this._footerElementContainer.appendChild(element);
- this._panelsElement.style.bottom = this._footerElementContainer.offsetHeight + "px";
- } else {
- this._footerElementContainer.addStyleClass("hidden");
- this._footerElementContainer.removeChildren();
- this._panelsElement.style.bottom = 0;
- }
- this.doResize();
- },
- /**
- * @param {WebInspector.Panel} panel
- */
- showPanelForAnchorNavigation: function(panel)
- {
- WebInspector.searchController.disableSearchUntilExplicitAction();
- this.setCurrentPanel(panel);
- },
- __proto__: WebInspector.View.prototype
- }
- /**
- * @type {WebInspector.InspectorView}
- */
- WebInspector.inspectorView = null;
|