~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/inspector/front-end/InspectorView.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are
 
6
 * met:
 
7
 *
 
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
 
13
 * distribution.
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
/**
 
32
 * @constructor
 
33
 * @extends {WebInspector.View}
 
34
 */
 
35
WebInspector.InspectorView = function()
 
36
{
 
37
    WebInspector.View.call(this);
 
38
    this.markAsRoot();
 
39
    this.element.id = "main-panels";
 
40
    this.element.setAttribute("spellcheck", false);
 
41
    this._history = [];
 
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 = {};
 
47
 
 
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");
 
53
}
 
54
 
 
55
WebInspector.InspectorView.Events = {
 
56
    PanelSelected: "PanelSelected"
 
57
}
 
58
 
 
59
WebInspector.InspectorView.prototype = {
 
60
    /**
 
61
     * @param {WebInspector.PanelDescriptor} panelDescriptor
 
62
     */
 
63
    addPanel: function(panelDescriptor)
 
64
    {
 
65
        this._panelOrder.push(panelDescriptor.name());
 
66
        this._panelDescriptors[panelDescriptor.name()] = panelDescriptor;
 
67
        WebInspector.toolbar.addPanel(panelDescriptor);
 
68
    },
 
69
 
 
70
    /**
 
71
     * @param {string} panelName
 
72
     * @return {?WebInspector.Panel}
 
73
     */
 
74
    panel: function(panelName)
 
75
    {
 
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;
 
80
    },
 
81
 
 
82
    /**
 
83
     * @param {string} panelName
 
84
     * @return {?WebInspector.Panel}
 
85
     */
 
86
    showPanel: function(panelName)
 
87
    {
 
88
        var panel = this.panel(panelName);
 
89
        if (panel)
 
90
            this.setCurrentPanel(panel);
 
91
        return panel;
 
92
    },
 
93
 
 
94
    currentPanel: function()
 
95
    {
 
96
        return this._currentPanel;
 
97
    },
 
98
    
 
99
    /**
 
100
     * @param {WebInspector.Panel} x
 
101
     */
 
102
    setCurrentPanel: function(x)
 
103
    {
 
104
        if (this._currentPanel === x)
 
105
            return;
 
106
 
 
107
        if (this._currentPanel)
 
108
            this._currentPanel.detach();
 
109
 
 
110
        this._currentPanel = x;
 
111
 
 
112
        if (x) {
 
113
            x.show();
 
114
            this.dispatchEventToListeners(WebInspector.InspectorView.Events.PanelSelected);
 
115
            // FIXME: remove search controller.
 
116
            WebInspector.searchController.cancelSearch();
 
117
        }
 
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);
 
123
            }
 
124
        }
 
125
    },
 
126
 
 
127
    _keyPress: function(event)
 
128
    {
 
129
        clearTimeout(this._keyDownTimer);
 
130
        delete this._keyDownTimer;
 
131
    },
 
132
 
 
133
    _keyDown: function(event)
 
134
    {
 
135
        if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
 
136
            return;
 
137
 
 
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];
 
141
            if (panelName) {
 
142
                this.showPanel(panelName);
 
143
                event.consume(true);
 
144
            }
 
145
            return;
 
146
        }
 
147
 
 
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);
 
153
            return;
 
154
        }
 
155
 
 
156
        this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
 
157
    },
 
158
 
 
159
    _keyDownInternal: function(event)
 
160
    {
 
161
        if (this._openBracketIdentifiers[event.keyIdentifier]) {
 
162
            var isRotateLeft = !event.shiftKey && !event.altKey;
 
163
            if (isRotateLeft) {
 
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]);
 
167
                event.consume(true);
 
168
                return;
 
169
            }
 
170
 
 
171
            var isGoBack = event.altKey;
 
172
            if (isGoBack && this._canGoBackInHistory()) {
 
173
                this._goBackInHistory();
 
174
                event.consume(true);
 
175
            }
 
176
            return;
 
177
        }
 
178
 
 
179
        if (this._closeBracketIdentifiers[event.keyIdentifier]) {
 
180
            var isRotateRight = !event.shiftKey && !event.altKey;
 
181
            if (isRotateRight) {
 
182
                var index = this._panelOrder.indexOf(this.currentPanel().name);
 
183
                index = (index + 1) % this._panelOrder.length;
 
184
                this.showPanel(this._panelOrder[index]);
 
185
                event.consume(true);
 
186
                return;
 
187
            }
 
188
 
 
189
            var isGoForward = event.altKey;
 
190
            if (isGoForward && this._canGoForwardInHistory()) {
 
191
                this._goForwardInHistory();
 
192
                event.consume(true);
 
193
            }
 
194
            return;
 
195
        }
 
196
    },
 
197
 
 
198
    _canGoBackInHistory: function()
 
199
    {
 
200
        return this._historyIterator > 0;
 
201
    },
 
202
 
 
203
    _goBackInHistory: function()
 
204
    {
 
205
        this._inHistory = true;
 
206
        this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIterator]]);
 
207
        delete this._inHistory;
 
208
    },
 
209
 
 
210
    _canGoForwardInHistory: function()
 
211
    {
 
212
        return this._historyIterator < this._history.length - 1;
 
213
    },
 
214
 
 
215
    _goForwardInHistory: function()
 
216
    {
 
217
        this._inHistory = true;
 
218
        this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIterator]]);
 
219
        delete this._inHistory;
 
220
    },
 
221
 
 
222
    _pushToHistory: function(panelName)
 
223
    {
 
224
        if (this._inHistory)
 
225
            return;
 
226
 
 
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;
 
231
    },
 
232
 
 
233
    panelsElement: function()
 
234
    {
 
235
        return this._panelsElement;
 
236
    },
 
237
 
 
238
    /**
 
239
     * @param {Element?} element
 
240
     */
 
241
    setFooterElement: function(element)
 
242
    {
 
243
        if (element) {
 
244
            this._footerElementContainer.removeStyleClass("hidden");
 
245
            this._footerElementContainer.appendChild(element);
 
246
            this._panelsElement.style.bottom = this._footerElementContainer.offsetHeight + "px";
 
247
        } else {
 
248
            this._footerElementContainer.addStyleClass("hidden");
 
249
            this._footerElementContainer.removeChildren();
 
250
            this._panelsElement.style.bottom = 0;
 
251
        }
 
252
        this.doResize();
 
253
    },
 
254
 
 
255
    /**
 
256
     * @param {WebInspector.Panel} panel
 
257
     */
 
258
    showPanelForAnchorNavigation: function(panel)
 
259
    {
 
260
        WebInspector.searchController.disableSearchUntilExplicitAction();
 
261
        this.setCurrentPanel(panel);
 
262
    },
 
263
 
 
264
    __proto__: WebInspector.View.prototype
 
265
}
 
266
 
 
267
/**
 
268
 * @type {WebInspector.InspectorView}
 
269
 */
 
270
WebInspector.inspectorView = null;