OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @constructor | |
33 * @extends {WebInspector.VBox} | |
34 * @implements {WebInspector.TargetManager.Observer} | 31 * @implements {WebInspector.TargetManager.Observer} |
| 32 * @unrestricted |
35 */ | 33 */ |
36 WebInspector.RenderingOptionsView = function() | 34 WebInspector.RenderingOptionsView = class extends WebInspector.VBox { |
37 { | 35 constructor() { |
38 WebInspector.VBox.call(this, true); | 36 super(true); |
39 this.registerRequiredCSS("main/renderingOptions.css"); | 37 this.registerRequiredCSS('main/renderingOptions.css'); |
40 | 38 |
41 /** @type {!Map.<string, !Element>} */ | 39 /** @type {!Map.<string, !Element>} */ |
42 this._settings = new Map(); | 40 this._settings = new Map(); |
43 | 41 |
44 var options = [ | 42 var options = [ |
45 { | 43 { |
46 label: WebInspector.UIString("Paint Flashing"), | 44 label: WebInspector.UIString('Paint Flashing'), |
47 subtitle: WebInspector.UIString("Highlights areas of the page that n
eed to be repainted"), | 45 subtitle: WebInspector.UIString('Highlights areas of the page that need
to be repainted'), |
48 setterName: "setShowPaintRects" | 46 setterName: 'setShowPaintRects' |
49 }, | 47 }, |
50 { | 48 { |
51 label: WebInspector.UIString("Layer Borders"), | 49 label: WebInspector.UIString('Layer Borders'), |
52 subtitle: WebInspector.UIString("Shows layer borders (orange/olive)
and tiles (cyan)"), | 50 subtitle: WebInspector.UIString('Shows layer borders (orange/olive) and
tiles (cyan)'), |
53 setterName: "setShowDebugBorders" | 51 setterName: 'setShowDebugBorders' |
54 }, | 52 }, |
55 { | 53 { |
56 label: WebInspector.UIString("FPS Meter"), | 54 label: WebInspector.UIString('FPS Meter'), |
57 subtitle: WebInspector.UIString("Plots frames per second, frame rate
distribution, and GPU memory"), | 55 subtitle: WebInspector.UIString('Plots frames per second, frame rate dis
tribution, and GPU memory'), |
58 setterName: "setShowFPSCounter" | 56 setterName: 'setShowFPSCounter' |
59 }, | 57 }, |
60 { | 58 { |
61 label: WebInspector.UIString("Scrolling Performance Issues"), | 59 label: WebInspector.UIString('Scrolling Performance Issues'), |
62 subtitle: WebInspector.UIString("Shows areas of the page that slow d
own scrolling"), | 60 subtitle: WebInspector.UIString('Shows areas of the page that slow down
scrolling'), |
63 setterName: "setShowScrollBottleneckRects", | 61 setterName: 'setShowScrollBottleneckRects', |
64 tooltip: "Touch and mousewheel event listeners can delay scrolling.\
nSome areas need to repaint their content when scrolled." | 62 tooltip: |
65 } | 63 'Touch and mousewheel event listeners can delay scrolling.\nSome are
as need to repaint their content when scrolled.' |
| 64 } |
66 ]; | 65 ]; |
67 for (var i = 0; i < options.length; i++) | 66 for (var i = 0; i < options.length; i++) |
68 this._appendCheckbox(options[i].label, options[i].setterName, options[i]
.subtitle, options[i].tooltip); | 67 this._appendCheckbox(options[i].label, options[i].setterName, options[i].s
ubtitle, options[i].tooltip); |
69 | 68 |
70 this.contentElement.createChild("div").classList.add("panel-section-separato
r"); | 69 this.contentElement.createChild('div').classList.add('panel-section-separato
r'); |
71 | 70 |
72 var cssMediaSubtitle = WebInspector.UIString("Forces media type for testing
print and screen styles"); | 71 var cssMediaSubtitle = WebInspector.UIString('Forces media type for testing
print and screen styles'); |
73 var checkboxLabel = createCheckboxLabel(WebInspector.UIString("Emulate CSS M
edia"), false, cssMediaSubtitle); | 72 var checkboxLabel = createCheckboxLabel(WebInspector.UIString('Emulate CSS M
edia'), false, cssMediaSubtitle); |
74 this._mediaCheckbox = checkboxLabel.checkboxElement; | 73 this._mediaCheckbox = checkboxLabel.checkboxElement; |
75 this._mediaCheckbox.addEventListener("click", this._mediaToggled.bind(this),
false); | 74 this._mediaCheckbox.addEventListener('click', this._mediaToggled.bind(this),
false); |
76 this.contentElement.appendChild(checkboxLabel); | 75 this.contentElement.appendChild(checkboxLabel); |
77 | 76 |
78 var mediaRow = this.contentElement.createChild("div", "media-row"); | 77 var mediaRow = this.contentElement.createChild('div', 'media-row'); |
79 this._mediaSelect = mediaRow.createChild("select", "chrome-select"); | 78 this._mediaSelect = mediaRow.createChild('select', 'chrome-select'); |
80 this._mediaSelect.appendChild(new Option(WebInspector.UIString("print"), "pr
int")); | 79 this._mediaSelect.appendChild(new Option(WebInspector.UIString('print'), 'pr
int')); |
81 this._mediaSelect.appendChild(new Option(WebInspector.UIString("screen"), "s
creen")); | 80 this._mediaSelect.appendChild(new Option(WebInspector.UIString('screen'), 's
creen')); |
82 this._mediaSelect.addEventListener("change", this._mediaToggled.bind(this),
false); | 81 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this),
false); |
83 this._mediaSelect.disabled = true; | 82 this._mediaSelect.disabled = true; |
84 | 83 |
85 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.Browser); | 84 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili
ty.Browser); |
| 85 } |
| 86 |
| 87 /** |
| 88 * @return {!WebInspector.RenderingOptionsView} |
| 89 */ |
| 90 static instance() { |
| 91 if (!WebInspector.RenderingOptionsView._instanceObject) |
| 92 WebInspector.RenderingOptionsView._instanceObject = new WebInspector.Rende
ringOptionsView(); |
| 93 return WebInspector.RenderingOptionsView._instanceObject; |
| 94 } |
| 95 |
| 96 /** |
| 97 * @param {string} label |
| 98 * @param {string} setterName |
| 99 * @param {string=} subtitle |
| 100 * @param {string=} tooltip |
| 101 */ |
| 102 _appendCheckbox(label, setterName, subtitle, tooltip) { |
| 103 var checkboxLabel = createCheckboxLabel(label, false, subtitle); |
| 104 this._settings.set(setterName, checkboxLabel.checkboxElement); |
| 105 checkboxLabel.checkboxElement.addEventListener('click', this._settingToggled
.bind(this, setterName)); |
| 106 if (tooltip) |
| 107 checkboxLabel.title = tooltip; |
| 108 this.contentElement.appendChild(checkboxLabel); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @param {string} setterName |
| 113 */ |
| 114 _settingToggled(setterName) { |
| 115 var enabled = this._settings.get(setterName).checked; |
| 116 for (var target of WebInspector.targetManager.targets(WebInspector.Target.Ca
pability.Browser)) |
| 117 target.renderingAgent()[setterName](enabled); |
| 118 } |
| 119 |
| 120 /** |
| 121 * @override |
| 122 * @param {!WebInspector.Target} target |
| 123 */ |
| 124 targetAdded(target) { |
| 125 for (var setterName of this._settings.keysArray()) { |
| 126 if (this._settings.get(setterName).checked) |
| 127 target.renderingAgent()[setterName](true); |
| 128 } |
| 129 if (this._mediaCheckbox.checked) |
| 130 this._applyPrintMediaOverride(target); |
| 131 } |
| 132 |
| 133 _mediaToggled() { |
| 134 this._mediaSelect.disabled = !this._mediaCheckbox.checked; |
| 135 var targets = WebInspector.targetManager.targets(WebInspector.Target.Capabil
ity.Browser); |
| 136 for (var target of targets) |
| 137 this._applyPrintMediaOverride(target); |
| 138 } |
| 139 |
| 140 /** |
| 141 * @param {!WebInspector.Target} target |
| 142 */ |
| 143 _applyPrintMediaOverride(target) { |
| 144 target.emulationAgent().setEmulatedMedia(this._mediaCheckbox.checked ? this.
_mediaSelect.value : ''); |
| 145 var cssModel = WebInspector.CSSModel.fromTarget(target); |
| 146 if (cssModel) |
| 147 cssModel.mediaQueryResultChanged(); |
| 148 } |
| 149 |
| 150 /** |
| 151 * @override |
| 152 * @param {!WebInspector.Target} target |
| 153 */ |
| 154 targetRemoved(target) { |
| 155 } |
86 }; | 156 }; |
87 | 157 |
88 WebInspector.RenderingOptionsView.prototype = { | |
89 /** | |
90 * @param {string} label | |
91 * @param {string} setterName | |
92 * @param {string=} subtitle | |
93 * @param {string=} tooltip | |
94 */ | |
95 _appendCheckbox: function(label, setterName, subtitle, tooltip) | |
96 { | |
97 var checkboxLabel = createCheckboxLabel(label, false, subtitle); | |
98 this._settings.set(setterName, checkboxLabel.checkboxElement); | |
99 checkboxLabel.checkboxElement.addEventListener("click", this._settingTog
gled.bind(this, setterName)); | |
100 if (tooltip) | |
101 checkboxLabel.title = tooltip; | |
102 this.contentElement.appendChild(checkboxLabel); | |
103 }, | |
104 | 158 |
105 /** | |
106 * @param {string} setterName | |
107 */ | |
108 _settingToggled: function(setterName) | |
109 { | |
110 var enabled = this._settings.get(setterName).checked; | |
111 for (var target of WebInspector.targetManager.targets(WebInspector.Targe
t.Capability.Browser)) | |
112 target.renderingAgent()[setterName](enabled); | |
113 }, | |
114 | |
115 /** | |
116 * @override | |
117 * @param {!WebInspector.Target} target | |
118 */ | |
119 targetAdded: function(target) | |
120 { | |
121 for (var setterName of this._settings.keysArray()) { | |
122 if (this._settings.get(setterName).checked) | |
123 target.renderingAgent()[setterName](true); | |
124 } | |
125 if (this._mediaCheckbox.checked) | |
126 this._applyPrintMediaOverride(target); | |
127 }, | |
128 | |
129 _mediaToggled: function() | |
130 { | |
131 this._mediaSelect.disabled = !this._mediaCheckbox.checked; | |
132 var targets = WebInspector.targetManager.targets(WebInspector.Target.Cap
ability.Browser); | |
133 for (var target of targets) | |
134 this._applyPrintMediaOverride(target); | |
135 }, | |
136 | |
137 /** | |
138 * @param {!WebInspector.Target} target | |
139 */ | |
140 _applyPrintMediaOverride: function(target) | |
141 { | |
142 target.emulationAgent().setEmulatedMedia(this._mediaCheckbox.checked ? t
his._mediaSelect.value : ""); | |
143 var cssModel = WebInspector.CSSModel.fromTarget(target); | |
144 if (cssModel) | |
145 cssModel.mediaQueryResultChanged(); | |
146 }, | |
147 | |
148 /** | |
149 * @override | |
150 * @param {!WebInspector.Target} target | |
151 */ | |
152 targetRemoved: function(target) | |
153 { | |
154 }, | |
155 | |
156 __proto__: WebInspector.VBox.prototype | |
157 }; | |
158 | |
159 /** | |
160 * @return {!WebInspector.RenderingOptionsView} | |
161 */ | |
162 WebInspector.RenderingOptionsView.instance = function() | |
163 { | |
164 if (!WebInspector.RenderingOptionsView._instanceObject) | |
165 WebInspector.RenderingOptionsView._instanceObject = new WebInspector.Ren
deringOptionsView(); | |
166 return WebInspector.RenderingOptionsView._instanceObject; | |
167 }; | |
OLD | NEW |