Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: Source/devtools/front_end/FilterBar.js

Issue 33143002: DevTools: Unify filtering UI (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comments addressed Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/ConsoleView.js ('k') | Source/devtools/front_end/NetworkPanel.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 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.Object}
34 */
35 WebInspector.FilterBar = function()
36 {
37 this._filtersShown = false;
38 this._element = document.createElement("div");
39 this._element.className = "hbox";
40
41 this._filterButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Filter"), "filters-toggle", 3);
42 this._filterButton.element.addEventListener("mousedown", this._handleFilterB uttonClick.bind(this), false);
43
44 this._filters = [];
45 }
46
47 WebInspector.FilterBar.Events = {
48 FiltersToggled: "FiltersToggled"
49 }
50
51 WebInspector.FilterBar.FilterBarState = {
52 Inactive : "inactive",
53 Active : "active",
54 Shown : "shown"
55 };
56
57 WebInspector.FilterBar.prototype = {
58 /**
59 * @return {Element}
60 */
61 filterButton: function()
62 {
63 return this._filterButton.element;
64 },
65
66 /**
67 * @return {Element}
68 */
69 filtersElement: function()
70 {
71 return this._element;
72 },
73
74 /**
75 * @return {boolean}
76 */
77 filtersToggled: function()
78 {
79 return this._filtersShown;
80 },
81
82 /**
83 * @param {WebInspector.FilterUI} filter
84 */
85 addFilter: function(filter)
86 {
87 this._filters.push(filter);
88 this._element.appendChild(filter.element());
89 filter.addEventListener(WebInspector.FilterUI.Events.FilterChanged, this ._filterChanged, this);
90 this._updateFilterButton();
91 },
92
93 /**
94 * @param {WebInspector.Event} event
95 */
96 _filterChanged: function(event)
97 {
98 this._updateFilterButton();
99 },
100
101 /**
102 * @return {string}
103 */
104 _filterBarState: function()
105 {
106 if (this._filtersShown)
107 return WebInspector.FilterBar.FilterBarState.Shown;
108 var isActive = false;
109 for (var i = 0; i < this._filters.length; ++i) {
110 if (this._filters[i].isActive())
111 return WebInspector.FilterBar.FilterBarState.Active;
112 }
113 return WebInspector.FilterBar.FilterBarState.Inactive;
114 },
115
116 _updateFilterButton: function()
117 {
118 this._filterButton.state = this._filterBarState();
119 },
120
121 /**
122 * @param {Event} event
123 */
124 _handleFilterButtonClick: function(event)
125 {
126 this._filtersShown = !this._filtersShown;
127 this._updateFilterButton();
128 this.dispatchEventToListeners(WebInspector.FilterBar.Events.FiltersToggl ed, this._filtersShown);
129 },
130
131 __proto__: WebInspector.Object.prototype
132 }
133
134 /**
135 * @interface
136 * @extends {WebInspector.EventTarget}
137 */
138 WebInspector.FilterUI = function()
139 {
140 }
141
142 WebInspector.FilterUI.Events = {
143 FilterChanged: "FilterChanged"
144 }
145
146 WebInspector.FilterUI.prototype = {
147 /**
148 * @return {boolean}
149 */
150 isActive: function() { },
151
152 /**
153 * @return {Element}
154 */
155 element: function() { }
156 }
157
158 /**
159 * @constructor
160 * @implements {WebInspector.FilterUI}
161 * @extends {WebInspector.Object}
162 */
163 WebInspector.TextFilterUI = function()
164 {
165 this._filterElement = document.createElement("div");
166 this._filterElement.className = "filter-text-filter";
167
168 this._filterInputElement = this._filterElement.createChild("input", "search- replace toolbar-replace-control");
169 this._filterInputElement.placeholder = WebInspector.UIString("Filter");
170 this._filterInputElement.id = "filter-input-field";
171 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa nualFocus.bind(this), false); // when the search field is manually selected
172 this._filterInputElement.addEventListener("input", this._onInput.bind(this), false);
173 }
174
175 WebInspector.TextFilterUI.prototype = {
176 /**
177 * @return {boolean}
178 */
179 isActive: function()
180 {
181 return !!this._filterInputElement.value;
182 },
183
184 /**
185 * @return {Element}
186 */
187 element: function()
188 {
189 return this._filterElement;
190 },
191
192 /**
193 * @return {string}
194 */
195 value: function()
196 {
197 return this._filterInputElement.value;
198 },
199
200 /**
201 * @param {string} value
202 */
203 setValue: function(value)
204 {
205 this._filterInputElement.value = value;
206 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
207 },
208
209 /**
210 * @return {RegExp}
211 */
212 regex: function()
213 {
214 var filterQuery = this._filterInputElement.value;
215 return filterQuery ? createPlainTextSearchRegex(filterQuery, "i") : null ;
216 },
217
218 /**
219 * @param {Event} event
220 */
221 _onFilterFieldManualFocus: function(event)
222 {
223 WebInspector.setCurrentFocusElement(event.target);
224 },
225
226 /**
227 * @param {WebInspector.Event} event
228 */
229 _onInput: function(event)
230 {
231 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
232 },
233
234 __proto__: WebInspector.Object.prototype
235 }
236
237 /**
238 * @constructor
239 * @implements {WebInspector.FilterUI}
240 * @extends {WebInspector.Object}
241 */
242 WebInspector.NamedBitSetFilterUI = function()
243 {
244 this._filtersElement = document.createElement("div");
245 this._filtersElement.className = "filter-bitset-filter status-bar-item";
246 this._filtersElement.title = WebInspector.UIString("Use %s Click to select m ultiple types.", WebInspector.KeyboardShortcut.shortcutToString("", WebInspector .KeyboardShortcut.Modifiers.CtrlOrMeta));
247
248 this._names = [];
249 this._allowedTypes = {};
250 this._typeFilterElements = {};
251 this._addTypeFilter(WebInspector.NamedBitSetFilterUI.ALL_TYPES, WebInspector .UIString("All"));
252 this._filtersElement.createChild("div", "filter-bitset-filter-divider");
253 this._toggleTypeFilter(WebInspector.NamedBitSetFilterUI.ALL_TYPES, false);
254 }
255
256 WebInspector.NamedBitSetFilterUI.ALL_TYPES = "all";
257
258 WebInspector.NamedBitSetFilterUI.prototype = {
259 /**
260 * @return {boolean}
261 */
262 isActive: function()
263 {
264 return !this._allowedTypes[WebInspector.NamedBitSetFilterUI.ALL_TYPES];
265 },
266
267 /**
268 * @param {string} name
269 * @param {string} label
270 */
271 addBit: function(name, label)
272 {
273 this._addTypeFilter(name, label);
274 },
275
276 /**
277 * @return {Element}
278 */
279 element: function()
280 {
281 return this._filtersElement;
282 },
283
284 /**
285 * @param {string} typeName
286 * @return {boolean}
287 */
288 accept: function(typeName)
289 {
290 return !!this._allowedTypes[WebInspector.NamedBitSetFilterUI.ALL_TYPES] || !!this._allowedTypes[typeName];
291 },
292
293 /**
294 * @return {Array.<string>}
295 */
296 filteredOutTypes: function()
297 {
298 if (this._allowedTypes[WebInspector.NamedBitSetFilterUI.ALL_TYPES])
299 return [];
300 var result = [];
301 for (var i = 0; i < this._names.length; ++i) {
302 var name = this._names[i];
303 if (!this._allowedTypes[name])
304 result.push(name);
305 }
306 return result;
307 },
308
309 /**
310 * @param {Array.<string>} filteredOutTypes
311 */
312 setFilteredOutTypes: function(filteredOutTypes)
313 {
314 this._allowedTypes = {};
315 if (filteredOutTypes.length === 0) {
316 this._allowedTypes[WebInspector.NamedBitSetFilterUI.ALL_TYPES] = tru e;
317 } else {
318 for (var i = 0; i < this._names.length; ++i) {
319 var name = this._names[i];
320 this._allowedTypes[name] = true;
321 }
322 for (var i = 0; i < filteredOutTypes.length; ++i)
323 delete this._allowedTypes[filteredOutTypes[i]];
324 }
325 for (var typeName in this._typeFilterElements)
326 this._typeFilterElements[typeName].enableStyleClass("selected", this ._allowedTypes[typeName]);
327 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
328 },
329
330 /**
331 * @return {Array.<string>}
332 */
333 acceptedTypes: function()
334 {
335 if (this._allowedTypes[WebInspector.NamedBitSetFilterUI.ALL_TYPES])
336 return [WebInspector.NamedBitSetFilterUI.ALL_TYPES];
337 var result = [];
338 for (var i = 0; i < this._names.length; ++i) {
339 var name = this._names[i];
340 if (this._allowedTypes[name])
341 result.push(name);
342 }
343 return result;
344 },
345
346 /**
347 * @param {Array.<string>} acceptedTypes
348 */
349 setAcceptedTypes: function(acceptedTypes)
350 {
351 this._allowedTypes = {};
352 for (var i = 0; i < acceptedTypes.length; ++i)
353 this._allowedTypes[acceptedTypes[i]] = true;
354 for (var typeName in this._typeFilterElements)
355 this._typeFilterElements[typeName].enableStyleClass("selected", this ._allowedTypes[typeName]);
356 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
357 },
358
359 /**
360 * @param {string} typeName
361 * @param {string} label
362 */
363 _addTypeFilter: function(typeName, label)
364 {
365 var typeFilterElement = this._filtersElement.createChild("li", typeName) ;
366 typeFilterElement.typeName = typeName;
367 typeFilterElement.createTextChild(label);
368 typeFilterElement.addEventListener("click", this._onTypeFilterClicked.bi nd(this), false);
369 this._typeFilterElements[typeName] = typeFilterElement;
370 this._names.push(typeName);
371 },
372
373 /**
374 * @param {!Event} e
375 */
376 _onTypeFilterClicked: function(e)
377 {
378 var toggle;
379 if (WebInspector.isMac())
380 toggle = e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey;
381 else
382 toggle = e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
383 this._toggleTypeFilter(e.target.typeName, toggle);
384 },
385
386 /**
387 * @param {string} typeName
388 * @param {boolean} allowMultiSelect
389 */
390 _toggleTypeFilter: function(typeName, allowMultiSelect)
391 {
392 if (allowMultiSelect && typeName !== WebInspector.NamedBitSetFilterUI.AL L_TYPES)
393 this._typeFilterElements[WebInspector.NamedBitSetFilterUI.ALL_TYPES] .removeStyleClass("selected");
394 else {
395 for (var key in this._typeFilterElements)
396 this._typeFilterElements[key].removeStyleClass("selected");
397 }
398
399 var filterElement = this._typeFilterElements[typeName];
400 filterElement.enableStyleClass("selected", !filterElement.hasStyleClass( "selected"));
401
402 this._allowedTypes = {};
403 for (var key in this._typeFilterElements) {
404 if (this._typeFilterElements[key].hasStyleClass("selected"))
405 this._allowedTypes[key] = true;
406 }
407 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
408 },
409
410 __proto__: WebInspector.Object.prototype
411 }
412
413 /**
414 * @constructor
415 * @implements {WebInspector.FilterUI}
416 * @extends {WebInspector.Object}
417 * @param {Array.<{value: *, label: string, title: string}>} options
418 */
419 WebInspector.ComboBoxFilterUI = function(options)
420 {
421 this._filterElement = document.createElement("div");
422 this._filterElement.className = "filter-combobox-filter";
423
424 this._options = options;
425 this._filterComboBox = new WebInspector.StatusBarComboBox(this._filterChange d.bind(this));
426 for (var i = 0; i < options.length; ++i) {
427 var filterOption = options[i];
428 var option = document.createElement("option");
429 option.text = filterOption.label;
430 option.title = filterOption.title;
431 this._filterComboBox.addOption(option);
432 this._filterComboBox.element.title = this._filterComboBox.selectedOption ().title;
433 }
434 this._filterElement.appendChild(this._filterComboBox.element);
435 }
436
437 WebInspector.ComboBoxFilterUI.prototype = {
438 /**
439 * @return {boolean}
440 */
441 isActive: function()
442 {
443 return this._filterComboBox.selectedIndex() !== 0;
444 },
445
446 /**
447 * @return {Element}
448 */
449 element: function()
450 {
451 return this._filterElement;
452 },
453
454 /**
455 * @param {string} typeName
456 * @return {*}
457 */
458 value: function(typeName)
459 {
460 var option = this._options[this._filterComboBox.selectedIndex()];
461 return option.value;
462 },
463
464 /**
465 * @param {Event} event
466 */
467 _filterChanged: function(event)
468 {
469 var option = this._options[this._filterComboBox.selectedIndex()];
470 this._filterComboBox.element.title = option.title;
471 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
472 },
473
474 __proto__: WebInspector.Object.prototype
475 }
476
477 /**
478 * @constructor
479 * @implements {WebInspector.FilterUI}
480 * @extends {WebInspector.Object}
481 * @param {boolean} activeWhenChecked
482 */
483 WebInspector.CheckboxFilterUI = function(className, title, activeWhenChecked)
484 {
485 this._className = className;
486 this._filterElement = document.createElement("div");
487 this._filterElement.classList.add("filter-checkbox-filter", "filter-checkbox -filter-" + this._className);
488 this._activeWhenChecked = activeWhenChecked;
489 this._createCheckbox(title);
490 }
491
492 WebInspector.CheckboxFilterUI.prototype = {
493 /**
494 * @return {boolean}
495 */
496 isActive: function()
497 {
498 return this._activeWhenChecked === this._checkElement.checked;
499 },
500
501 /**
502 * @return {Element}
503 */
504 element: function()
505 {
506 return this._filterElement;
507 },
508
509 /**
510 * @return {boolean}
511 */
512 checked: function()
513 {
514 return this._checkElement.checked;
515 },
516
517 /**
518 * @param {boolean} checked
519 */
520 setChecked: function(checked)
521 {
522 this._checkElement.checked = checked;
523 this._checkElement.enableStyleClass("checkbox-filter-checkbox-checked", this._checkElement.checked);
524 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
525 },
526
527 _createCheckbox: function(title)
528 {
529 var label = this._filterElement.createChild("label");
530 var checkBorder = label.createChild("div", "checkbox-filter-checkbox");
531 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che ckbox-check checkbox-filter-checkbox-checked");
532 this._checkElement.type = "checkbox";
533 this._checkElement.checked = true;
534 this._filterElement.addEventListener("click", listener.bind(this), false );
535
536 function listener(event)
537 {
538 this.setChecked(!this._checkElement.checked);
539 }
540
541 var typeElement = label.createChild("span", "type");
542 typeElement.textContent = title;
543 },
544
545 __proto__: WebInspector.Object.prototype
546 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ConsoleView.js ('k') | Source/devtools/front_end/NetworkPanel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698