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