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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js

Issue 1803813002: [DevTools] Added keyboard search while in sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 this._createRootElement(); 36 this._createRootElement();
37 37
38 this.selectedTreeElement = null; 38 this.selectedTreeElement = null;
39 this.expandTreeElementsWhenArrowing = false; 39 this.expandTreeElementsWhenArrowing = false;
40 /** @type {?function(!TreeElement, !TreeElement):number} */ 40 /** @type {?function(!TreeElement, !TreeElement):number} */
41 this._comparator = null; 41 this._comparator = null;
42 42
43 this._contentElement = this._rootElement._childrenListNode; 43 this._contentElement = this._rootElement._childrenListNode;
44 this._contentElement.addEventListener("keydown", this._treeKeyDown.bind(this ), true); 44 this._contentElement.addEventListener("keydown", this._treeKeyDown.bind(this ), true);
45 this._contentElement.addEventListener("keypress", this._treeKeyPress.bind(th is), true);
45 46
46 this.setFocusable(!nonFocusable); 47 this.setFocusable(!nonFocusable);
47 48
48 this.element = this._contentElement; 49 this.element = this._contentElement;
49 } 50 }
50 51
51 TreeOutline.Events = { 52 TreeOutline.Events = {
52 ElementAttached: "ElementAttached", 53 ElementAttached: "ElementAttached",
53 ElementExpanded: "ElementExpanded", 54 ElementExpanded: "ElementExpanded",
54 ElementCollapsed: "ElementCollapsed", 55 ElementCollapsed: "ElementCollapsed",
55 ElementSelected: "ElementSelected" 56 ElementSelected: "ElementSelected",
57 FilterChanged: "FilterChanged"
56 } 58 }
57 59
58 TreeOutline.prototype = { 60 TreeOutline.prototype = {
59 _createRootElement: function() 61 _createRootElement: function()
60 { 62 {
61 this._rootElement = new TreeElement(); 63 this._rootElement = new TreeElement();
62 this._rootElement.treeOutline = this; 64 this._rootElement.treeOutline = this;
63 this._rootElement.root = true; 65 this._rootElement.root = true;
64 this._rootElement.selectable = false; 66 this._rootElement.selectable = false;
65 this._rootElement.expanded = true; 67 this._rootElement.expanded = true;
66 this._rootElement._childrenListNode.classList.remove("children"); 68 this._rootElement._childrenListNode.classList.remove("children");
69
70 this._currentSelectionFilterString = '';
lushnikov 2016/03/14 20:56:38 style: double quotes for strings
71 this._currentSelectionFilter = null;
67 }, 72 },
68 73
69 /** 74 /**
70 * @return {!TreeElement} 75 * @return {!TreeElement}
71 */ 76 */
72 rootElement: function() 77 rootElement: function()
73 { 78 {
74 return this._rootElement; 79 return this._rootElement;
75 }, 80 },
76 81
77 /** 82 /**
83 * This will also set/override the RegExp to filter on (ie: setCurrentSelect ionFilter())
84 * @param {string} filterString String to filter text on.
85 */
86 setCurrentSelectionFilterString: function (filterString)
87 {
88 this._currentSelectionFilterString = filterString;
89 if(this._currentSelectionFilterString === '')
90 this.setCurrentSelectionFilter(null);
91 else
92 this.setCurrentSelectionFilter(new RegExp(['(', this._currentSelecti onFilterString, ')'].join(''), 'i'));
93 },
94
95 /**
96 * @return {string}
97 */
98 currentSelectionFilterString: function ()
99 {
100
lushnikov 2016/03/14 20:56:38 style: stray line
101 return this._currentSelectionFilterString;
102 },
103
104 /**
105 * @param {?RegExp} filterRegExp Regular Expression to use to filter selecta ble items
106 */
107 setCurrentSelectionFilter: function (filterRegExp)
108 {
109 var currentFilter = this._currentSelectionFilter;
110 this._currentSelectionFilter = filterRegExp;
111
112 if (filterRegExp !== currentFilter) {
113 this.dispatchEventToListeners(TreeOutline.Events.FilterChanged, {
114 treeOutline: this,
115 changeTo: filterRegExp,
116 changeFrom: currentFilter
117 });
118 }
119 },
120
121 /**
122 * @return {?RegExp}
123 */
124 currentSelectionFilter: function ()
125 {
126 return this._currentSelectionFilter;
127 },
128
129 /**
78 * @return {?TreeElement} 130 * @return {?TreeElement}
79 */ 131 */
80 firstChild: function() 132 firstChild: function()
81 { 133 {
82 return this._rootElement.firstChild(); 134 return this._rootElement.firstChild();
83 }, 135 },
84 136
85 /** 137 /**
86 * @param {!TreeElement} child 138 * @param {!TreeElement} child
87 */ 139 */
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 { 232 {
181 if (!element.treeOutline) 233 if (!element.treeOutline)
182 console.error("Unbinding element that was not bound: " + new Error() .stack); 234 console.error("Unbinding element that was not bound: " + new Error() .stack);
183 235
184 element.deselect(); 236 element.deselect();
185 element.onunbind(); 237 element.onunbind();
186 element.treeOutline = null; 238 element.treeOutline = null;
187 }, 239 },
188 240
189 /** 241 /**
242 * @param {!TreeElement} treeElement
190 * @return {boolean} 243 * @return {boolean}
191 */ 244 */
192 selectPrevious: function() 245 checkFilter: function (treeElement)
246 {
247 return this.currentSelectionFilter() ? this.currentSelectionFilter().tes t(treeElement.titleText) : true;
248 },
249
250 /**
251 * @param {!RegExp=} filter
252 * @return {boolean}
253 */
254 selectPrevious: function(filter)
193 { 255 {
194 var nextSelectedElement = this.selectedTreeElement.traversePreviousTreeE lement(true); 256 var nextSelectedElement = this.selectedTreeElement.traversePreviousTreeE lement(true);
195 while (nextSelectedElement && !nextSelectedElement.selectable) 257 while (nextSelectedElement && (!nextSelectedElement.selectable || (filte r ? !filter.test(nextSelectedElement.titleText) : false)))
196 nextSelectedElement = nextSelectedElement.traversePreviousTreeElemen t(!this.expandTreeElementsWhenArrowing); 258 nextSelectedElement = nextSelectedElement.traversePreviousTreeElemen t(!this.expandTreeElementsWhenArrowing);
197 if (nextSelectedElement) { 259 if (nextSelectedElement) {
198 nextSelectedElement.reveal(); 260 nextSelectedElement.reveal();
199 nextSelectedElement.select(false, true); 261 nextSelectedElement.select(false, true);
200 return true; 262 return true;
201 } 263 }
202 return false; 264 return false;
203 }, 265 },
204 266
205 /** 267 /**
(...skipping 16 matching lines...) Expand all
222 * @param {!Event} event 284 * @param {!Event} event
223 */ 285 */
224 _treeKeyDown: function(event) 286 _treeKeyDown: function(event)
225 { 287 {
226 if (event.target !== this._contentElement) 288 if (event.target !== this._contentElement)
227 return; 289 return;
228 290
229 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) 291 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
230 return; 292 return;
231 293
232 var handled = false; 294 var currentFilterString = this.currentSelectionFilterString(),
233 var nextSelectedElement; 295 nextSelectedElement,
lushnikov 2016/03/14 20:56:38 style: we don't wrap variable declaration. If ther
234 if (event.keyIdentifier === "Up" && !event.altKey) { 296 handled = false,
235 handled = this.selectPrevious(); 297 key = event.keyCode;
236 } else if (event.keyIdentifier === "Down" && !event.altKey) { 298
237 handled = this.selectNext(); 299 // is a key to ignore (non printable key)
238 } else if (event.keyIdentifier === "Left") { 300 switch (key) {
239 if (this.selectedTreeElement.expanded) { 301 case WebInspector.KeyboardShortcut.Keys.Esc.code:
240 if (event.altKey) 302 if (currentFilterString.length !== 0) {
241 this.selectedTreeElement.collapseRecursively(); 303 // Consider the item handled if the filter string is already set. (this will keep the console from triggering)
242 else 304 handled = true;
243 this.selectedTreeElement.collapse(); 305 }
244 handled = true; 306 this.setCurrentSelectionFilterString('');
245 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { 307 break;
246 handled = true; 308 case WebInspector.KeyboardShortcut.Keys.Delete.code:
247 if (this.selectedTreeElement.parent.selectable) { 309 // Clear out the filter
248 nextSelectedElement = this.selectedTreeElement.parent; 310 this.setCurrentSelectionFilterString('');
249 while (nextSelectedElement && !nextSelectedElement.selectabl e) 311 case WebInspector.KeyboardShortcut.Keys.Backspace.code:
250 nextSelectedElement = nextSelectedElement.parent; 312 // Only perform this action if no filter is set.
251 handled = nextSelectedElement ? true : false; 313 if (currentFilterString.length === 0) {
252 } else if (this.selectedTreeElement.parent) 314 handled = this.selectedTreeElement.ondelete();
253 this.selectedTreeElement.parent.collapse(); 315 } else {
254 } 316 this.setCurrentSelectionFilterString(currentFilterString.sub str(0, currentFilterString.length - 1));
255 } else if (event.keyIdentifier === "Right") { 317 }
256 if (!this.selectedTreeElement.revealed()) { 318 break;
257 this.selectedTreeElement.reveal(); 319 case WebInspector.KeyboardShortcut.Keys.Right.code:
258 handled = true; 320 this.setCurrentSelectionFilterString('');
259 } else if (this.selectedTreeElement._expandable) { 321 if (!this.selectedTreeElement.revealed()) {
260 handled = true; 322 this.selectedTreeElement.reveal();
323 handled = true;
324 } else if (this.selectedTreeElement._expandable) {
325 handled = true;
326 if (this.selectedTreeElement.expanded) {
327 nextSelectedElement = this.selectedTreeElement.firstChil d();
328 while (nextSelectedElement && !nextSelectedElement.selec table)
329 nextSelectedElement = nextSelectedElement.nextSiblin g;
330 handled = nextSelectedElement ? true : false;
331 } else {
332 if (event.altKey)
333 this.selectedTreeElement.expandRecursively();
334 else
335 this.selectedTreeElement.expand();
336 }
337 }
338 break;
339 case WebInspector.KeyboardShortcut.Keys.Left.code:
340 this.setCurrentSelectionFilterString('');
261 if (this.selectedTreeElement.expanded) { 341 if (this.selectedTreeElement.expanded) {
262 nextSelectedElement = this.selectedTreeElement.firstChild();
263 while (nextSelectedElement && !nextSelectedElement.selectabl e)
264 nextSelectedElement = nextSelectedElement.nextSibling;
265 handled = nextSelectedElement ? true : false;
266 } else {
267 if (event.altKey) 342 if (event.altKey)
268 this.selectedTreeElement.expandRecursively(); 343 this.selectedTreeElement.collapseRecursively();
269 else 344 else
270 this.selectedTreeElement.expand(); 345 this.selectedTreeElement.collapse();
346 handled = true;
347 } else if (this.selectedTreeElement.parent && !this.selectedTree Element.parent.root) {
348 handled = true;
349 if (this.selectedTreeElement.parent.selectable) {
350 nextSelectedElement = this.selectedTreeElement.parent;
351 while (nextSelectedElement && !nextSelectedElement.selec table)
352 nextSelectedElement = nextSelectedElement.parent;
353 handled = nextSelectedElement ? true : false;
354 } else if (this.selectedTreeElement.parent)
355 this.selectedTreeElement.parent.collapse();
356 }
357 break;
358 case WebInspector.KeyboardShortcut.Keys.Down.code:
359 if(!event.altKey)
360 handled = this.selectNext();
361 break;
362 case WebInspector.KeyboardShortcut.Keys.Up.code:
363 if(!event.altKey)
364 handled = this.selectPrevious();
365 break;
366 case WebInspector.KeyboardShortcut.Keys.Space.code:
367 // Do not send space key event if the search filter has stuff in buffer
368 if (currentFilterString.length === 0)
369 handled = this.selectedTreeElement.onspace();
370 break;
371 default:
372 if (isEnterKey(event)) {
373 this.setCurrentSelectionFilterString('');
374 handled = this.selectedTreeElement.onenter();
271 } 375 }
272 } 376 }
273 } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 / * Delete */)
274 handled = this.selectedTreeElement.ondelete();
275 else if (isEnterKey(event))
276 handled = this.selectedTreeElement.onenter();
277 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code )
278 handled = this.selectedTreeElement.onspace();
279 377
280 if (nextSelectedElement) { 378 if (nextSelectedElement) {
281 nextSelectedElement.reveal(); 379 nextSelectedElement.reveal();
282 nextSelectedElement.select(false, true); 380 nextSelectedElement.select(false, true);
283 } 381 }
284 382
285 if (handled) 383 if (handled)
286 event.consume(true); 384 event.consume(true);
287 }, 385 },
288 386
289 /** 387 /**
388 * @param {!Event} event
389 */
390 _treeKeyPress: function (event)
391 {
392 if (event.target !== this._contentElement)
393 return;
394
395 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
396 return;
397
398 var currentFilterString = this.currentSelectionFilterString();
399
400 switch (event.data) {
401 case "\r":
402 case "\n":
403 // Ignore these (do not append to filter string)
404 break;
405 case " ":
406 if (currentFilterString.length === 0) {
407 // Do not append string if there is no filter data
408 break;
409 }
410 default:
411 // Append the new character to the current filter string and select next element if fails try previous element
412 this.setCurrentSelectionFilterString(currentFilterString + event.dat a);
413 }
414 },
415
416 /**
290 * @param {!TreeElement} treeElement 417 * @param {!TreeElement} treeElement
291 * @param {boolean} center 418 * @param {boolean} center
292 */ 419 */
293 _deferredScrollIntoView: function(treeElement, center) 420 _deferredScrollIntoView: function(treeElement, center)
294 { 421 {
295 if (!this._treeElementToScrollIntoView) 422 if (!this._treeElementToScrollIntoView)
296 this.element.window().requestAnimationFrame(deferredScrollIntoView.b ind(this)); 423 this.element.window().requestAnimationFrame(deferredScrollIntoView.b ind(this));
297 this._treeElementToScrollIntoView = treeElement; 424 this._treeElementToScrollIntoView = treeElement;
298 this._centerUponScrollIntoView = center; 425 this._centerUponScrollIntoView = center;
299 /** 426 /**
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 function TreeElement(title, expandable) 480 function TreeElement(title, expandable)
354 { 481 {
355 /** @type {?TreeOutline} */ 482 /** @type {?TreeOutline} */
356 this.treeOutline = null; 483 this.treeOutline = null;
357 this.parent = null; 484 this.parent = null;
358 this.previousSibling = null; 485 this.previousSibling = null;
359 this.nextSibling = null; 486 this.nextSibling = null;
360 487
361 this._listItemNode = createElement("li"); 488 this._listItemNode = createElement("li");
362 this._listItemNode.treeElement = this; 489 this._listItemNode.treeElement = this;
490 this.titleText = null;
363 if (title) 491 if (title)
364 this.title = title; 492 this.title = title;
365 this._listItemNode.addEventListener("mousedown", this._handleMouseDown.bind( this), false); 493 this._listItemNode.addEventListener("mousedown", this._handleMouseDown.bind( this), false);
366 this._listItemNode.addEventListener("selectstart", this._treeElementSelectSt art.bind(this), false); 494 this._listItemNode.addEventListener("selectstart", this._treeElementSelectSt art.bind(this), false);
367 this._listItemNode.addEventListener("click", this._treeElementToggled.bind(t his), false); 495 this._listItemNode.addEventListener("click", this._treeElementToggled.bind(t his), false);
368 this._listItemNode.addEventListener("dblclick", this._handleDoubleClick.bind (this), false); 496 this._listItemNode.addEventListener("dblclick", this._handleDoubleClick.bind (this), false);
369 497
370 this._childrenListNode = createElement("ol"); 498 this._childrenListNode = createElement("ol");
371 this._childrenListNode.parentTreeElement = this; 499 this._childrenListNode.parentTreeElement = this;
372 this._childrenListNode.classList.add("children"); 500 this._childrenListNode.classList.add("children");
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 this.treeOutline._unbindTreeElement(child); 724 this.treeOutline._unbindTreeElement(child);
597 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) 725 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true))
598 this.treeOutline._unbindTreeElement(current); 726 this.treeOutline._unbindTreeElement(current);
599 child._detach(); 727 child._detach();
600 } 728 }
601 this._children = []; 729 this._children = [];
602 }, 730 },
603 731
604 get selectable() 732 get selectable()
605 { 733 {
606 if (this._hidden) 734 if (this._hidden || !this.treeOutline.checkFilter(this))
607 return false; 735 return false;
608 return this._selectable; 736 return this._selectable;
609 }, 737 },
610 738
611 set selectable(x) 739 set selectable(x)
612 { 740 {
613 this._selectable = x; 741 this._selectable = x;
614 }, 742 },
615 743
616 get listItemElement() 744 get listItemElement()
(...skipping 17 matching lines...) Expand all
634 set title(x) 762 set title(x)
635 { 763 {
636 if (this._title === x) 764 if (this._title === x)
637 return; 765 return;
638 this._title = x; 766 this._title = x;
639 767
640 if (typeof x === "string") { 768 if (typeof x === "string") {
641 this._titleElement = createElementWithClass("span", "tree-element-ti tle"); 769 this._titleElement = createElementWithClass("span", "tree-element-ti tle");
642 this._titleElement.textContent = x; 770 this._titleElement.textContent = x;
643 this.tooltip = x; 771 this.tooltip = x;
772 this.titleText = x;
644 } else { 773 } else {
645 this._titleElement = x; 774 this._titleElement = x;
646 this.tooltip = ""; 775 this.tooltip = "";
647 } 776 }
648 777
649 this._listItemNode.removeChildren(); 778 this._listItemNode.removeChildren();
650 if (this._iconElement) 779 if (this._iconElement)
651 this._listItemNode.appendChild(this._iconElement); 780 this._listItemNode.appendChild(this._iconElement);
652 781
653 this._listItemNode.appendChild(this._titleElement); 782 this._listItemNode.appendChild(this._titleElement);
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 isEventWithinDisclosureTriangle: function(event) 1281 isEventWithinDisclosureTriangle: function(event)
1153 { 1282 {
1154 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446) 1283 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446)
1155 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft; 1284 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft;
1156 console.assert(paddingLeftValue.endsWith("px")); 1285 console.assert(paddingLeftValue.endsWith("px"));
1157 var computedLeftPadding = parseFloat(paddingLeftValue); 1286 var computedLeftPadding = parseFloat(paddingLeftValue);
1158 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; 1287 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding;
1159 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; 1288 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable;
1160 } 1289 }
1161 } 1290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698