2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
9 * @extends {WebInspector.DialogDelegate}
11 WebInspector
.FrameworkBlackboxDialog = function()
13 WebInspector
.DialogDelegate
.call(this);
14 this.element
.classList
.add("blackbox-dialog", "dialog-contents");
16 var header
= this.element
.createChild("div", "header");
17 header
.createChild("span").textContent
= WebInspector
.UIString("Framework blackbox patterns");
19 var closeButton
= header
.createChild("div", "done-button", "dt-close-button");
20 closeButton
.gray
= true;
21 closeButton
.addEventListener("click", this._onDoneClick
.bind(this), false);
23 var contents
= this.element
.createChild("div", "contents");
25 var contentScriptsSection
= contents
.createChild("div", "blackbox-content-scripts");
26 contentScriptsSection
.appendChild(WebInspector
.SettingsUI
.createSettingCheckbox(WebInspector
.UIString("Blackbox content scripts"), WebInspector
.moduleSetting("skipContentScripts"), true));
28 var blockHeader
= contents
.createChild("div", "columns-header");
29 blockHeader
.createChild("span").textContent
= WebInspector
.UIString("URI pattern");
30 blockHeader
.createChild("span").textContent
= WebInspector
.UIString("Behavior");
32 var section
= contents
.createChild("div", "section");
33 var container
= section
.createChild("div", "settings-list-container");
35 this._blackboxLabel
= WebInspector
.UIString("Blackbox");
36 this._disabledLabel
= WebInspector
.UIString("Disabled");
38 var column1
= { id
: "pattern", placeholder
: "/framework\\.js$" };
39 var column2
= { id
: "value", options
: [this._blackboxLabel
, this._disabledLabel
] };
41 this._patternsList
= new WebInspector
.EditableSettingsList([column1
, column2
], this._patternValuesProvider
.bind(this), this._patternValidate
.bind(this), this._patternEdit
.bind(this));
42 this._patternsList
.element
.classList
.add("blackbox-patterns-list");
43 this._patternsList
.addEventListener(WebInspector
.SettingsList
.Events
.Removed
, this._patternRemovedFromList
.bind(this));
44 container
.appendChild(this._patternsList
.element
);
46 /** @type {!Map.<string, string>} */
47 this._entries
= new Map();
48 var patterns
= WebInspector
.moduleSetting("skipStackFramesPattern").getAsArray();
49 for (var i
= 0; i
< patterns
.length
; ++i
)
50 this._addPattern(patterns
[i
].pattern
, patterns
[i
].disabled
);
52 this.element
.tabIndex
= 0;
55 WebInspector
.FrameworkBlackboxDialog
.show = function(element
)
57 var dialog
= new WebInspector
.FrameworkBlackboxDialog();
58 WebInspector
.Dialog
.show(element
, dialog
);
59 var glassPane
= dialog
.element
.ownerDocument
.getElementById("glass-pane");
60 glassPane
.classList
.add("settings-glass-pane");
63 WebInspector
.FrameworkBlackboxDialog
.prototype = {
66 * @param {!Element} element
68 show: function(element
)
70 this._dialogElement
= element
;
71 element
.appendChild(this.element
);
72 element
.classList
.add("settings-dialog", "settings-tab");
77 if (!this._dialogElement
|| !this._relativeToElement
)
81 const minHeight
= 150;
82 var maxHeight
= this._relativeToElement
.offsetHeight
- 10;
83 maxHeight
= Math
.max(minHeight
, maxHeight
);
84 var maxWidth
= Math
.min(540, this._relativeToElement
.offsetWidth
- 10);
85 maxWidth
= Math
.max(minWidth
, maxWidth
);
86 this._dialogElement
.style
.maxHeight
= maxHeight
+ "px";
87 this._dialogElement
.style
.width
= maxWidth
+ "px";
89 WebInspector
.DialogDelegate
.prototype.position(this._dialogElement
, this._relativeToElement
);
94 * @param {!Element} element
95 * @param {!Element} relativeToElement
97 position: function(element
, relativeToElement
)
99 this._relativeToElement
= relativeToElement
;
103 willHide: function(event
)
108 * @param {string} itemId
109 * @param {string} columnId
112 _patternValuesProvider: function(itemId
, columnId
)
120 return /** @type {string} */ (this._entries
.get(itemId
));
122 console
.assert("Should not be reached.");
128 * @param {?string} itemId
129 * @param {!Object} data
130 * @return {!Array.<string>}
132 _patternValidate: function(itemId
, data
)
135 var oldPattern
= itemId
;
136 var newPattern
= data
["pattern"];
138 if (newPattern
&& (oldPattern
=== newPattern
|| !this._entries
.has(newPattern
)))
139 regex
= new RegExp(newPattern
);
142 return regex
? [] : ["pattern"];
146 * @param {?string} itemId
147 * @param {!Object} data
149 _patternEdit: function(itemId
, data
)
151 var oldPattern
= itemId
;
152 var newPattern
= data
["pattern"];
155 var disabled
= (data
["value"] === this._disabledLabel
);
157 var patterns
= WebInspector
.moduleSetting("skipStackFramesPattern").getAsArray();
158 for (var i
= 0; i
<= patterns
.length
; ++i
) {
159 if (i
=== patterns
.length
) {
160 patterns
.push({ pattern
: newPattern
, disabled
: disabled
});
163 if (patterns
[i
].pattern
=== oldPattern
) {
164 patterns
[i
] = { pattern
: newPattern
, disabled
: disabled
};
168 WebInspector
.moduleSetting("skipStackFramesPattern").setAsArray(patterns
);
170 if (oldPattern
&& oldPattern
=== newPattern
) {
171 this._entries
.set(newPattern
, disabled
? this._disabledLabel
: this._blackboxLabel
);
172 this._patternsList
.itemForId(oldPattern
).classList
.toggle("disabled", disabled
);
173 this._patternsList
.refreshItem(newPattern
);
178 this._patternsList
.removeItem(oldPattern
);
179 this._entries
.remove(oldPattern
);
181 this._addPattern(newPattern
, disabled
);
185 * @param {!WebInspector.Event} event
187 _patternRemovedFromList: function(event
)
189 var pattern
= /** @type{?string} */ (event
.data
);
192 this._entries
.remove(pattern
);
194 var patterns
= WebInspector
.moduleSetting("skipStackFramesPattern").getAsArray();
195 for (var i
= 0; i
< patterns
.length
; ++i
) {
196 if (patterns
[i
].pattern
=== pattern
) {
197 patterns
.splice(i
, 1);
201 WebInspector
.moduleSetting("skipStackFramesPattern").setAsArray(patterns
);
205 * @param {string} pattern
206 * @param {boolean=} disabled
208 _addPattern: function(pattern
, disabled
)
210 if (!pattern
|| this._entries
.has(pattern
))
212 this._entries
.set(pattern
, disabled
? this._disabledLabel
: this._blackboxLabel
);
213 var listItem
= this._patternsList
.addItem(pattern
, null);
214 listItem
.classList
.toggle("disabled", disabled
);
220 WebInspector
.setCurrentFocusElement(this.element
);
223 _onDoneClick: function()
225 WebInspector
.Dialog
.hide();
228 onEnter: function(event
)
230 var focusElement
= WebInspector
.currentFocusElement();
231 var nodeName
= focusElement
&& focusElement
.nodeName
.toLowerCase();
232 if (nodeName
=== "input" || nodeName
=== "select") {
239 __proto__
: WebInspector
.DialogDelegate
.prototype