• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2010 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 * @param {string=} title
34 * @extends {WebInspector.View}
35 */
36WebInspector.HelpScreen = function(title)
37{
38    WebInspector.View.call(this);
39    this.markAsRoot();
40    this.registerRequiredCSS("helpScreen.css");
41
42    this.element.className = "help-window-outer";
43    this.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
44    this.element.tabIndex = 0;
45
46    if (title) {
47        var mainWindow = this.element.createChild("div", "help-window-main");
48        var captionWindow = mainWindow.createChild("div", "help-window-caption");
49        captionWindow.appendChild(this._createCloseButton());
50        this.contentElement = mainWindow.createChild("div", "help-content");
51        captionWindow.createChild("h1", "help-window-title").textContent = title;
52    }
53}
54
55/**
56 * @type {?WebInspector.HelpScreen}
57 */
58WebInspector.HelpScreen._visibleScreen = null;
59
60/**
61 * @return {boolean}
62 */
63WebInspector.HelpScreen.isVisible = function()
64{
65    return !!WebInspector.HelpScreen._visibleScreen;
66}
67
68WebInspector.HelpScreen.focus = function()
69{
70    WebInspector.HelpScreen._visibleScreen.element.focus();
71}
72
73WebInspector.HelpScreen.prototype = {
74    _createCloseButton: function()
75    {
76        var closeButton = document.createElement("div");
77        closeButton.className = "help-close-button close-button-gray";
78        closeButton.addEventListener("click", this.hide.bind(this), false);
79        return closeButton;
80    },
81
82    showModal: function()
83    {
84        var visibleHelpScreen = WebInspector.HelpScreen._visibleScreen;
85        if (visibleHelpScreen === this)
86            return;
87
88        if (visibleHelpScreen)
89            visibleHelpScreen.hide();
90        WebInspector.HelpScreen._visibleScreen = this;
91        this.show(WebInspector.inspectorView.devtoolsElement());
92        this.focus();
93    },
94
95    hide: function()
96    {
97        if (!this.isShowing())
98            return;
99
100        WebInspector.HelpScreen._visibleScreen = null;
101
102        WebInspector.restoreFocusFromElement(this.element);
103        this.detach();
104    },
105
106    /**
107     * @param {number} keyCode
108     * @return {boolean}
109     */
110    isClosingKey: function(keyCode)
111    {
112        return [
113            WebInspector.KeyboardShortcut.Keys.Enter.code,
114            WebInspector.KeyboardShortcut.Keys.Esc.code,
115            WebInspector.KeyboardShortcut.Keys.Space.code,
116        ].indexOf(keyCode) >= 0;
117    },
118
119    _onKeyDown: function(event)
120    {
121        if (this.isShowing() && this.isClosingKey(event.keyCode)) {
122            this.hide();
123            event.consume();
124        }
125    },
126
127    __proto__: WebInspector.View.prototype
128}
129
130/**
131 * @constructor
132 * @param {string=} title
133 * @param {string=} message
134 * @extends {WebInspector.HelpScreen}
135 */
136WebInspector.HelpScreenUntilReload = function(title, message)
137{
138    WebInspector.HelpScreen.call(this, title);
139    var p = this.contentElement.createChild("p");
140    p.classList.add("help-section");
141    p.textContent = message;
142    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this.hide, this);
143}
144
145WebInspector.HelpScreenUntilReload.prototype = {
146    /**
147     * @override
148     */
149    willHide: function()
150    {
151        WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this.hide, this);
152        WebInspector.HelpScreen.prototype.willHide.call(this);
153    },
154
155    __proto__: WebInspector.HelpScreen.prototype
156}
157
158