Initial patch.
[vuplus_webkit] / Source / WebCore / inspector / front-end / SettingsScreen.js
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 WebInspector.SettingsScreen = function()
32 {
33     WebInspector.HelpScreen.call(this, WebInspector.UIString("Settings"));
34
35     this._leftColumnElement = document.createElement("td");
36     this._rightColumnElement = document.createElement("td");
37
38     var p = this._appendSection(WebInspector.UIString("Elements"));
39     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Word wrap"), WebInspector.settings.domWordWrap));
40
41     p = this._appendSection(WebInspector.UIString("Styles"));
42     p.appendChild(this._createRadioSetting(WebInspector.UIString("Color format"), [
43         [ WebInspector.StylesSidebarPane.ColorFormat.Original, WebInspector.UIString("As authored") ],
44         [ WebInspector.StylesSidebarPane.ColorFormat.HEX, "HEX: #DAC0DE" ],
45         [ WebInspector.StylesSidebarPane.ColorFormat.RGB, "RGB: rgb(128, 255, 255)" ],
46         [ WebInspector.StylesSidebarPane.ColorFormat.HSL, "HSL: hsl(300, 80%, 90%)" ] ], WebInspector.settings.colorFormat));
47     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show user agent styles"), WebInspector.settings.showUserAgentStyles));
48
49     if (Preferences.canDisableCache) {
50         p = this._appendSection(WebInspector.UIString("Network"), true);
51         p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Disable cache"), WebInspector.settings.cacheDisabled));
52     }
53
54     p = this._appendSection(WebInspector.UIString("Scripts"), true);
55     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show script folders"), WebInspector.settings.showScriptFolders));
56
57     p = this._appendSection(WebInspector.UIString("Console"), true);
58     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Log XMLHttpRequests"), WebInspector.settings.monitoringXHREnabled));
59     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Preserve log upon navigation"), WebInspector.settings.preserveConsoleLog));
60
61     var table = document.createElement("table");
62     table.className = "help-table";
63     var tr = document.createElement("tr");
64     tr.appendChild(this._leftColumnElement);
65     tr.appendChild(this._rightColumnElement);
66     table.appendChild(tr);
67     this.contentElement.appendChild(table);
68 }
69
70 WebInspector.SettingsScreen.prototype = {
71     _appendSection: function(name, right)
72     {
73         var p = document.createElement("p");
74         p.className = "help-section";
75         var title = document.createElement("div");
76         title.className = "help-section-title";
77         title.textContent = name;
78         p.appendChild(title);
79         this._columnElement(right).appendChild(p);
80         return p;
81     },
82
83     _columnElement: function(right)
84     {
85         return right ? this._rightColumnElement : this._leftColumnElement;
86     },
87
88     _createCheckboxSetting: function(name, setting)
89     {
90         var input = document.createElement("input");
91         input.type = "checkbox";
92         input.name = name;
93         input.checked = setting.get();
94         function listener()
95         {
96             setting.set(input.checked);
97         }
98         input.addEventListener("click", listener, false);
99
100         var p = document.createElement("p");
101         var label = document.createElement("label");
102         label.appendChild(input);
103         label.appendChild(document.createTextNode(name));
104         p.appendChild(label);
105         return p;
106     },
107
108     _createRadioSetting: function(name, options, setting)
109     {
110         var pp = document.createElement("p");
111         var fieldsetElement = document.createElement("fieldset");
112         var legendElement = document.createElement("legend");
113         legendElement.textContent = name;
114         fieldsetElement.appendChild(legendElement);
115
116         function clickListener(e)
117         {
118             setting.set(e.target.value);
119         }
120
121         var settingValue = setting.get();
122         for (var i = 0; i < options.length; ++i) {
123             var p = document.createElement("p");
124             var label = document.createElement("label");
125             p.appendChild(label);
126
127             var input = document.createElement("input");
128             input.type = "radio";
129             input.name = setting.name;
130             input.value = options[i][0];
131             input.addEventListener("click", clickListener, false);
132             if (settingValue == input.value)
133                 input.checked = true;
134
135             label.appendChild(input);
136             label.appendChild(document.createTextNode(options[i][1]));
137
138             fieldsetElement.appendChild(p);
139         }
140
141         pp.appendChild(fieldsetElement);
142         return pp;
143     }
144 };
145
146 WebInspector.SettingsScreen.prototype.__proto__ = WebInspector.HelpScreen.prototype;