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

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: Code review input implemented/fixed 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/treeoutline.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28 matching lines...) Expand all
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 45
46 this.setFocusable(!nonFocusable); 46 this.setFocusable(!nonFocusable);
47 47
48 this.element = this._contentElement; 48 this.element = this._contentElement;
49
50 this._contentElement.addEventListener("keypress", this._handleKeyPressForHig hlighting.bind(this), true);
51 this.element.addEventListener("blur", this._clearFilter.bind(this), true);
52 this.element.addEventListener("click", this._clearFilter.bind(this), true);
53
54 this._currentSelectionFilterString = "";
55 this._interactiveFilterEnabled = false;
56 /** @type {!Array.<!TreeElement>} */
57 this._highlightChangedNodes = []
49 } 58 }
50 59
51 TreeOutline.Events = { 60 TreeOutline.Events = {
52 ElementAttached: "ElementAttached", 61 ElementAttached: "ElementAttached",
53 ElementExpanded: "ElementExpanded", 62 ElementExpanded: "ElementExpanded",
54 ElementCollapsed: "ElementCollapsed", 63 ElementCollapsed: "ElementCollapsed",
55 ElementSelected: "ElementSelected" 64 ElementSelected: "ElementSelected"
56 } 65 }
57 66
58 TreeOutline.prototype = { 67 TreeOutline.prototype = {
59 _createRootElement: function() 68 _createRootElement: function()
60 { 69 {
61 this._rootElement = new TreeElement(); 70 this._rootElement = new TreeElement();
62 this._rootElement.treeOutline = this; 71 this._rootElement.treeOutline = this;
63 this._rootElement.root = true; 72 this._rootElement.root = true;
64 this._rootElement.selectable = false; 73 this._rootElement.selectable = false;
65 this._rootElement.expanded = true; 74 this._rootElement.expanded = true;
66 this._rootElement._childrenListNode.classList.remove("children"); 75 this._rootElement._childrenListNode.classList.remove("children");
67 }, 76 },
68 77
69 /** 78 /**
70 * @return {!TreeElement} 79 * @return {!TreeElement}
71 */ 80 */
72 rootElement: function() 81 rootElement: function()
73 { 82 {
74 return this._rootElement; 83 return this._rootElement;
75 }, 84 },
76 85
77 /** 86 /**
87 * @param {boolean} enable
88 */
89 setInteractiveFilterable: function (enable)
90 {
91 this._interactiveFilterEnabled = enable;
pfeldman 2016/03/22 00:00:33 Should disabling perform the cleanup?
92 },
93
94 /**
95 * @param {string} filterString
96 */
97 _setCurrentSelectionFilterString: function (filterString)
98 {
99 this._currentSelectionFilterString = filterString;
100 this._refreshHighlighting();
101 },
102
103 /**
104 * @param {string} filterString
105 * @return {!RegExp}
106 */
107 _makeFilterRegExpFromString: function (filterString)
108 {
109 return new RegExp(["(", filterString.escapeForRegExp(), ")"].join(""), " gi")
pfeldman 2016/03/22 00:00:34 Do you need the () group?
110 },
111
112 _refreshHighlighting: function ()
113 {
114 if (!this._rootElement)
115 return;
116
117 var filterRegExp = this._makeFilterRegExpFromString(this._currentSelecti onFilterString);
118
119 for (var changedNode of this._highlightChangedNodes)
120 changedNode._revertHighlightChanges();
121
122 this._highlightChanges = [];
123
124 if (this._currentSelectionFilterString === "")
pfeldman 2016/03/22 00:00:33 if (!this._currentSelectionFilterString)
125 return;
126
127 if (this.selectedTreeElement && !this.selectedTreeElement.selectable)
128 this.selectNext() || this.selectPrevious();
pfeldman 2016/03/22 00:00:34 statement per line please. if (!selectNext) se
129
130 var node = this._rootElement.firstChild();
131 do {
132 var textContent = node._listItemNode.textContent;
133 var match = filterRegExp.exec(textContent);
134 var ranges = [];
135 var changes = [];
136 while (true) {
137 if (match === null)
138 break;
139 ranges.push(new WebInspector.SourceRange(match.index, match[0].l ength));
140 match = filterRegExp.exec(textContent);
141 }
142 if (ranges.length > 0)
pfeldman 2016/03/22 00:00:34 if (ranges.length)
143 WebInspector.highlightRangesWithStyleClass(node._listItemNode, r anges, "tree-text-interactive-highlight", changes);
144
145 if (changes.length) {
146 node._setHighlightChanges(changes);
147 this._highlightChangedNodes.push(node);
pfeldman 2016/03/22 00:00:33 Can't there only be one highlighted node?
148 }
149
150 node = node.traverseNextTreeElement(true, null, true);
151 } while(node);
152 },
153
154 /**
155 * @param {!TreeElement} treeElement
156 * @return {boolean}
157 */
158 _checkFilter: function (treeElement)
159 {
160 return this._currentSelectionFilterString !== "" ? this._makeFilterRegEx pFromString(this._currentSelectionFilterString).test(treeElement._titleElement.t extContent) : true;
pfeldman 2016/03/22 00:00:33 this._currentSelectionFilterString ? ...
161 },
162
163 _clearFilter: function ()
164 {
165 if (this._interactiveFilterEnabled)
166 this._setCurrentSelectionFilterString("");
167 },
168
169 /**
170 * @param {!Event} event
171 */
172 _handleKeyPressForHighlighting: function (event)
173 {
174 if (!this._interactiveFilterEnabled)
175 return;
176
177 if (event.target !== this._contentElement)
178 return;
179
180 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
181 return;
182
183 var currentFilterString = this._currentSelectionFilterString;
184
185 switch (event.data) {
186 case "\r":
187 case "\n":
188 break;
189 case " ":
190 if (currentFilterString.length === 0) {
pfeldman 2016/03/22 00:00:34 !length
191 break;
192 }
193 default:
194 this._setCurrentSelectionFilterString(currentFilterString + event.da ta);
195 }
196 },
197
198 /**
78 * @return {?TreeElement} 199 * @return {?TreeElement}
79 */ 200 */
80 firstChild: function() 201 firstChild: function()
81 { 202 {
82 return this._rootElement.firstChild(); 203 return this._rootElement.firstChild();
83 }, 204 },
84 205
85 /** 206 /**
86 * @param {!TreeElement} child 207 * @param {!TreeElement} child
87 */ 208 */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 * @param {!Event} event 343 * @param {!Event} event
223 */ 344 */
224 _treeKeyDown: function(event) 345 _treeKeyDown: function(event)
225 { 346 {
226 if (event.target !== this._contentElement) 347 if (event.target !== this._contentElement)
227 return; 348 return;
228 349
229 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) 350 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
230 return; 351 return;
231 352
353 var currentFilterString = this._currentSelectionFilterString;
232 var handled = false; 354 var handled = false;
355 var key = event.keyCode;
233 var nextSelectedElement; 356 var nextSelectedElement;
234 if (event.keyIdentifier === "Up" && !event.altKey) { 357
235 handled = this.selectPrevious(); 358 switch (key) {
236 } else if (event.keyIdentifier === "Down" && !event.altKey) { 359 case WebInspector.KeyboardShortcut.Keys.Esc.code:
237 handled = this.selectNext(); 360 if (this._interactiveFilterEnabled) {
238 } else if (event.keyIdentifier === "Left") { 361 if (currentFilterString.length)
239 if (this.selectedTreeElement.expanded) { 362 // Consider the item handled if the filter string is already set (this will keep the console from triggering)
240 if (event.altKey) 363 handled = true;
241 this.selectedTreeElement.collapseRecursively(); 364 this._clearFilter();
242 else 365 }
243 this.selectedTreeElement.collapse(); 366 break;
367 case WebInspector.KeyboardShortcut.Keys.Delete.code:
368 if (this._interactiveFilterEnabled && currentFilterString.length) {
244 handled = true; 369 handled = true;
245 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { 370 this._clearFilter();
371 } else
372 handled = this.selectedTreeElement.ondelete();
373 break;
374 case WebInspector.KeyboardShortcut.Keys.Backspace.code:
375 if (this._interactiveFilterEnabled && currentFilterString.length) {
246 handled = true; 376 handled = true;
247 if (this.selectedTreeElement.parent.selectable) { 377 this._setCurrentSelectionFilterString(currentFilterString.substr (0, currentFilterString.length - 1));
248 nextSelectedElement = this.selectedTreeElement.parent; 378 } else
249 while (nextSelectedElement && !nextSelectedElement.selectabl e) 379 handled = this.selectedTreeElement.ondelete();
250 nextSelectedElement = nextSelectedElement.parent; 380 break;
251 handled = nextSelectedElement ? true : false; 381 case WebInspector.KeyboardShortcut.Keys.Right.code:
252 } else if (this.selectedTreeElement.parent) 382 if (this._interactiveFilterEnabled)
253 this.selectedTreeElement.parent.collapse(); 383 this._clearFilter();
254 } 384
255 } else if (event.keyIdentifier === "Right") {
256 if (!this.selectedTreeElement.revealed()) { 385 if (!this.selectedTreeElement.revealed()) {
257 this.selectedTreeElement.reveal(); 386 this.selectedTreeElement.reveal();
258 handled = true; 387 handled = true;
259 } else if (this.selectedTreeElement._expandable) { 388 } else if (this.selectedTreeElement._expandable) {
260 handled = true; 389 handled = true;
261 if (this.selectedTreeElement.expanded) { 390 if (this.selectedTreeElement.expanded) {
262 nextSelectedElement = this.selectedTreeElement.firstChild(); 391 nextSelectedElement = this.selectedTreeElement.firstChild();
263 while (nextSelectedElement && !nextSelectedElement.selectabl e) 392 while (nextSelectedElement && !nextSelectedElement.selectabl e)
264 nextSelectedElement = nextSelectedElement.nextSibling; 393 nextSelectedElement = nextSelectedElement.nextSibling;
265 handled = nextSelectedElement ? true : false; 394 handled = nextSelectedElement ? true : false;
266 } else { 395 } else {
267 if (event.altKey) 396 if (event.altKey)
268 this.selectedTreeElement.expandRecursively(); 397 this.selectedTreeElement.expandRecursively();
269 else 398 else
270 this.selectedTreeElement.expand(); 399 this.selectedTreeElement.expand();
271 } 400 }
272 } 401 }
273 } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 / * Delete */) 402 break;
274 handled = this.selectedTreeElement.ondelete(); 403 case WebInspector.KeyboardShortcut.Keys.Left.code:
275 else if (isEnterKey(event)) 404 if (this._interactiveFilterEnabled)
276 handled = this.selectedTreeElement.onenter(); 405 this._clearFilter();
277 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code ) 406
278 handled = this.selectedTreeElement.onspace(); 407 if (this.selectedTreeElement.expanded) {
408 if (event.altKey)
409 this.selectedTreeElement.collapseRecursively();
410 else
411 this.selectedTreeElement.collapse();
412 handled = true;
413 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) {
414 handled = true;
415 if (this.selectedTreeElement.parent.selectable) {
416 nextSelectedElement = this.selectedTreeElement.parent;
417 while (nextSelectedElement && !nextSelectedElement.selectabl e)
418 nextSelectedElement = nextSelectedElement.parent;
419 handled = nextSelectedElement ? true : false;
420 } else if (this.selectedTreeElement.parent)
421 this.selectedTreeElement.parent.collapse();
422 }
423 break;
424 case WebInspector.KeyboardShortcut.Keys.Down.code:
425 if (!event.altKey)
426 handled = this.selectNext();
427 break;
428 case WebInspector.KeyboardShortcut.Keys.Up.code:
429 if (!event.altKey)
430 handled = this.selectPrevious();
431 break;
432 case WebInspector.KeyboardShortcut.Keys.Space.code:
433 // Do not send space key event if the search filter has stuff in buf fer
434 if (!currentFilterString.length)
435 handled = this.selectedTreeElement.onspace();
436 break;
437 default:
438 if (isEnterKey(event)) {
439 if (this._interactiveFilterEnabled)
440 this._clearFilter();
441
442 handled = this.selectedTreeElement.onenter();
443 }
444 }
279 445
280 if (nextSelectedElement) { 446 if (nextSelectedElement) {
281 nextSelectedElement.reveal(); 447 nextSelectedElement.reveal();
282 nextSelectedElement.select(false, true); 448 nextSelectedElement.select(false, true);
283 } 449 }
284 450
285 if (handled) 451 if (handled)
286 event.consume(true); 452 event.consume(true);
287 }, 453 },
288 454
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 function TreeElement(title, expandable) 519 function TreeElement(title, expandable)
354 { 520 {
355 /** @type {?TreeOutline} */ 521 /** @type {?TreeOutline} */
356 this.treeOutline = null; 522 this.treeOutline = null;
357 this.parent = null; 523 this.parent = null;
358 this.previousSibling = null; 524 this.previousSibling = null;
359 this.nextSibling = null; 525 this.nextSibling = null;
360 526
361 this._listItemNode = createElement("li"); 527 this._listItemNode = createElement("li");
362 this._listItemNode.treeElement = this; 528 this._listItemNode.treeElement = this;
529
363 if (title) 530 if (title)
364 this.title = title; 531 this.title = title;
365 this._listItemNode.addEventListener("mousedown", this._handleMouseDown.bind( this), false); 532 this._listItemNode.addEventListener("mousedown", this._handleMouseDown.bind( this), false);
366 this._listItemNode.addEventListener("selectstart", this._treeElementSelectSt art.bind(this), false); 533 this._listItemNode.addEventListener("selectstart", this._treeElementSelectSt art.bind(this), false);
367 this._listItemNode.addEventListener("click", this._treeElementToggled.bind(t his), false); 534 this._listItemNode.addEventListener("click", this._treeElementToggled.bind(t his), false);
368 this._listItemNode.addEventListener("dblclick", this._handleDoubleClick.bind (this), false); 535 this._listItemNode.addEventListener("dblclick", this._handleDoubleClick.bind (this), false);
369 536
370 this._childrenListNode = createElement("ol"); 537 this._childrenListNode = createElement("ol");
371 this._childrenListNode.parentTreeElement = this; 538 this._childrenListNode.parentTreeElement = this;
372 this._childrenListNode.classList.add("children"); 539 this._childrenListNode.classList.add("children");
373 540
374 this._hidden = false; 541 this._hidden = false;
375 this._selectable = true; 542 this._selectable = true;
376 this.expanded = false; 543 this.expanded = false;
377 this.selected = false; 544 this.selected = false;
378 this.setExpandable(expandable || false); 545 this.setExpandable(expandable || false);
379 this._collapsible = true; 546 this._collapsible = true;
547
548 /** @type {!Array.<!Object>} */
549 this._highlightChanges = [];
380 } 550 }
381 551
382 /** @const */ 552 /** @const */
383 TreeElement._ArrowToggleWidth = 10; 553 TreeElement._ArrowToggleWidth = 10;
384 554
385 TreeElement.prototype = { 555 TreeElement.prototype = {
386 /** 556 /**
557 * @param {!Array.<!Object>} changes
558 */
559 _setHighlightChanges: function (changes)
560 {
561 this._highlightChanges = changes;
562 },
563
564 _revertHighlightChanges: function ()
565 {
566 WebInspector.revertDomChanges(this._highlightChanges);
567 this._highlightChanges = [];
568 },
569
570 /**
387 * @param {?TreeElement} ancestor 571 * @param {?TreeElement} ancestor
388 * @return {boolean} 572 * @return {boolean}
389 */ 573 */
390 hasAncestor: function(ancestor) 574 hasAncestor: function(ancestor)
391 { 575 {
392 if (!ancestor) 576 if (!ancestor)
393 return false; 577 return false;
394 578
395 var currentNode = this.parent; 579 var currentNode = this.parent;
396 while (currentNode) { 580 while (currentNode) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 this.treeOutline._unbindTreeElement(child); 780 this.treeOutline._unbindTreeElement(child);
597 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) 781 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true))
598 this.treeOutline._unbindTreeElement(current); 782 this.treeOutline._unbindTreeElement(current);
599 child._detach(); 783 child._detach();
600 } 784 }
601 this._children = []; 785 this._children = [];
602 }, 786 },
603 787
604 get selectable() 788 get selectable()
605 { 789 {
606 if (this._hidden) 790 if (this._hidden || !this.treeOutline._checkFilter(this))
607 return false; 791 return false;
608 return this._selectable; 792 return this._selectable;
609 }, 793 },
610 794
611 set selectable(x) 795 set selectable(x)
612 { 796 {
613 this._selectable = x; 797 this._selectable = x;
614 }, 798 },
615 799
616 get listItemElement() 800 get listItemElement()
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 isEventWithinDisclosureTriangle: function(event) 1336 isEventWithinDisclosureTriangle: function(event)
1153 { 1337 {
1154 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446) 1338 // 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; 1339 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft;
1156 console.assert(paddingLeftValue.endsWith("px")); 1340 console.assert(paddingLeftValue.endsWith("px"));
1157 var computedLeftPadding = parseFloat(paddingLeftValue); 1341 var computedLeftPadding = parseFloat(paddingLeftValue);
1158 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; 1342 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding;
1159 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; 1343 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable;
1160 } 1344 }
1161 } 1345 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/treeoutline.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698