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
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.
31 WebInspector.ShortcutsScreen = function()
36 WebInspector.ShortcutsScreen.prototype = {
37 section: function(name)
39 var section = this._sections[name];
41 this._sections[name] = section = new WebInspector.ShortcutsSection(name);
47 if (!this._helpScreen) {
48 this._helpScreen = new WebInspector.HelpScreen(WebInspector.UIString("Keyboard Shortcuts"));
49 this._buildTable(this._helpScreen.contentElement, 2);
51 this._helpScreen.show();
57 this._helpScreen.hide();
60 _buildTable: function(parent, nColumns)
63 var orderedSections = [];
64 for (var section in this._sections) {
65 height += this._sections[section]._height;
66 orderedSections.push(this._sections[section])
68 function compareSections(a, b)
70 return a.order - b.order;
72 orderedSections = orderedSections.sort(compareSections);
74 const wrapAfter = height / nColumns;
75 var table = document.createElement("table");
76 table.className = "help-table";
77 var row = table.createChild("tr");
79 // This manual layout ugliness should be gone once WebKit implements
80 // pagination hints for CSS columns (break-inside etc).
81 for (var section = 0; section < orderedSections.length;) {
82 var td = row.createChild("td");
83 td.style.width = (100 / nColumns) + "%";
84 var column = td.createChild("table");
85 for (var columnHeight = 0;
86 columnHeight < wrapAfter && section < orderedSections.length;
87 columnHeight += orderedSections[section]._height, section++) {
88 orderedSections[section].renderSection(column);
91 parent.appendChild(table);
95 WebInspector.shortcutsScreen = new WebInspector.ShortcutsScreen();
97 WebInspector.ShortcutsSection = function(name)
101 this.order = ++WebInspector.ShortcutsSection._sequenceNumber;
104 WebInspector.ShortcutsSection._sequenceNumber = 0;
106 WebInspector.ShortcutsSection.prototype = {
107 addKey: function(key, description)
109 this.addLine(this._renderKey(key), description);
112 addRelatedKeys: function(keys, description)
114 this.addLine(this._renderSequence(keys,"/"), description);
117 addAlternateKeys: function(keys, description)
119 this.addLine(this._renderSequence(keys,WebInspector.UIString("or")), description);
122 addLine: function(htmlKey, description)
124 this._lines.push({ key: htmlKey, text: description })
127 renderSection: function(parent)
129 this._renderHeader(parent);
131 for (var line = 0; line < this._lines.length; ++line) {
132 var tr = parent.createChild("tr");
133 tr.createChild("td", "help-key-cell").innerHTML = this._lines[line].key + " : ";
134 tr.createChild("td").textContent = this._lines[line].text;
138 _renderHeader: function(parent)
140 var trHead = parent.createChild("tr");
142 trHead.createChild("th");
143 trHead.createChild("th").textContent = this.name;
146 _renderSequence: function(sequence, delimiter)
148 var delimiterHtml = '<span class="help-key-delimiter">' + delimiter.escapeHTML() + '</span>'
149 return sequence.map(this._renderKey).join(delimiterHtml);
152 _renderKey: function(key)
154 function renderLabel(label)
156 return '<span class="help-key monospace">' + label.escapeHTML() + '</span>';
158 return key.split(" + ").map(renderLabel).join('<span class="help-combine-keys">+</span>');
163 return this._lines.length + 2; // add some space for header