Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / main / RenderingOptions.js
blob126e0805dc0d8f69a3b694324bd3522a2864ff79
1 /*
2 * Copyright (C) 2013 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 * @implements {WebInspector.TargetManager.Observer}
35 WebInspector.RenderingOptions = function()
37 /**
38 * @type {!Map.<!WebInspector.Setting, string>}
40 this._setterNames = new Map();
41 this._mapSettingToSetter(WebInspector.moduleSetting("showPaintRects"), "setShowPaintRects");
42 this._mapSettingToSetter(WebInspector.moduleSetting("showDebugBorders"), "setShowDebugBorders");
43 this._mapSettingToSetter(WebInspector.moduleSetting("showFPSCounter"), "setShowFPSCounter");
44 this._mapSettingToSetter(WebInspector.moduleSetting("showScrollBottleneckRects"), "setShowScrollBottleneckRects");
46 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Type.Page);
49 WebInspector.RenderingOptions.prototype = {
50 /**
51 * @override
52 * @param {!WebInspector.Target} target
54 targetAdded: function(target)
56 var settings = this._setterNames.keysArray();
57 for (var i = 0; i < settings.length; ++i) {
58 var setting = settings[i];
59 if (setting.get()) {
60 var setterName = this._setterNames.get(setting);
61 target.renderingAgent()[setterName](true);
66 /**
67 * @override
68 * @param {!WebInspector.Target} target
70 targetRemoved: function(target)
74 /**
75 * @param {!WebInspector.Setting} setting
76 * @param {string} setterName
78 _mapSettingToSetter: function(setting, setterName)
80 this._setterNames.set(setting, setterName);
81 setting.addChangeListener(changeListener);
83 function changeListener()
85 var targets = WebInspector.targetManager.targets(WebInspector.Target.Type.Page);
86 for (var i = 0; i < targets.length; ++i)
87 targets[i].renderingAgent()[setterName](setting.get());
92 /**
93 * @constructor
94 * @extends {WebInspector.VBox}
96 WebInspector.RenderingOptions.View = function()
98 WebInspector.VBox.call(this);
99 this.registerRequiredCSS("ui/helpScreen.css");
100 this.element.classList.add("help-indent-labels");
102 var div = this.element.createChild("div", "settings-tab help-content help-container help-no-columns");
103 div.appendChild(WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Enable paint flashing"), WebInspector.moduleSetting("showPaintRects")));
104 div.appendChild(WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Show layer borders"), WebInspector.moduleSetting("showDebugBorders")));
105 div.appendChild(WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Show FPS meter"), WebInspector.moduleSetting("showFPSCounter")));
106 var child = WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Show scrolling perf issues"), WebInspector.moduleSetting("showScrollBottleneckRects"));
107 child.title = WebInspector.UIString("Shows areas of the page that slow down scrolling:\nTouch and mousewheel event listeners can delay scrolling.\nSome areas need to repaint their content when scrolled.");
108 div.appendChild(child);
111 WebInspector.RenderingOptions.View.prototype = {
112 __proto__: WebInspector.VBox.prototype
116 * @constructor
117 * @implements {WebInspector.ToolbarItem.Provider}
119 WebInspector.RenderingOptions.ButtonProvider = function()
121 this._button = new WebInspector.ToolbarMenuButton(WebInspector.UIString("Rendering performance options"), "timer-toolbar-item", this._appendItems.bind(this));
122 this._renderingOptions = [{ label: WebInspector.UIString("Enable paint flashing"), setting: WebInspector.moduleSetting("showPaintRects") },
123 { label: WebInspector.UIString("Show layer borders"), setting: WebInspector.moduleSetting("showDebugBorders") },
124 { label: WebInspector.UIString("Show scrolling perf issues"), setting: WebInspector.moduleSetting("showScrollBottleneckRects") },
125 { label: WebInspector.UIString("Show FPS meter"), setting: WebInspector.moduleSetting("showFPSCounter") }];
128 WebInspector.RenderingOptions.ButtonProvider.prototype = {
130 * @override
131 * @return {?WebInspector.ToolbarItem}
133 item: function()
135 return this._button;
139 * @param {!WebInspector.ContextMenu} contextMenu
141 _appendItems: function(contextMenu)
143 for (var option of this._renderingOptions)
144 contextMenu.appendCheckboxItem(option.label, this._toggleSetting.bind(this, option.setting), option.setting.get());
148 * @param {!WebInspector.Setting} setting
150 _toggleSetting: function(setting)
152 setting.set(!setting.get());