Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / HelpScreen.js
blob5fb4326dc1d62aa01947051a06107557f90a5755
1 /*
2 * Copyright (C) 2010 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
6 * met:
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.
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.
31 /**
32 * @constructor
33 * @param {string=} title
34 * @extends {WebInspector.VBox}
36 WebInspector.HelpScreen = function(title)
38 WebInspector.VBox.call(this);
39 this.markAsRoot();
40 this.registerRequiredCSS("ui/helpScreen.css");
42 this.element.classList.add("help-window-outer");
43 this.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
44 this.element.tabIndex = 0;
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.helpContentElement = mainWindow.createChild("div", "help-content");
51 captionWindow.createChild("h1", "help-window-title").textContent = title;
55 /**
56 * @type {?WebInspector.HelpScreen}
58 WebInspector.HelpScreen._visibleScreen = null;
60 WebInspector.HelpScreen.prototype = {
61 /**
62 * @return {!Element}
64 createCloseButton: function()
66 var closeButton = createElementWithClass("div", "help-close-button", "dt-close-button");
67 closeButton.gray = true;
68 closeButton.addEventListener("click", this.hide.bind(this), false);
69 return closeButton;
72 showModal: function()
74 var visibleHelpScreen = WebInspector.HelpScreen._visibleScreen;
75 if (visibleHelpScreen === this)
76 return;
78 if (visibleHelpScreen)
79 visibleHelpScreen.hide();
80 WebInspector.HelpScreen._visibleScreen = this;
81 WebInspector.GlassPane.DefaultFocusedViewStack.push(this);
82 this.show(WebInspector.Dialog.modalHostView().element);
83 this.focus();
86 hide: function()
88 if (!this.isShowing())
89 return;
91 WebInspector.HelpScreen._visibleScreen = null;
92 WebInspector.GlassPane.DefaultFocusedViewStack.pop();
94 WebInspector.restoreFocusFromElement(this.element);
95 this.detach();
98 /**
99 * @param {number} keyCode
100 * @return {boolean}
102 isClosingKey: function(keyCode)
104 return [
105 WebInspector.KeyboardShortcut.Keys.Enter.code,
106 WebInspector.KeyboardShortcut.Keys.Esc.code,
107 WebInspector.KeyboardShortcut.Keys.Space.code,
108 ].indexOf(keyCode) >= 0;
111 _onKeyDown: function(event)
113 if (this.isShowing() && this.isClosingKey(event.keyCode)) {
114 this.hide();
115 event.consume();
119 __proto__: WebInspector.VBox.prototype