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

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

Issue 1831903002: [DevTools] Added keyboard search while in sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed codereview issues Created 4 years, 8 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 25 matching lines...) Expand all
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 45
46 this.element = this._contentElement;
47
46 this.setFocusable(!nonFocusable); 48 this.setFocusable(!nonFocusable);
47 49
48 this.element = this._contentElement; 50 this.element.addEventListener("keypress", this._handleKeyPressForHighlightin g.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._highlightedNodes = []
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 if (enable === this._interactiveFilterEnabled)
92 return;
93 if (!enable)
lushnikov 2016/04/13 17:57:41 nit: do we need this if statement?
allada 2016/04/13 19:33:06 Yes, if setInteractiveFilter is called to turn it
94 this._setCurrentSelectionFilterString("");
95 this._interactiveFilterEnabled = enable;
96 },
97
98 /**
99 * @param {string} filterString
100 */
101 _setCurrentSelectionFilterString: function(filterString)
102 {
103 this._currentSelectionFilterString = filterString;
104 this._refreshHighlighting();
105 },
106
107 /**
108 * @param {string} filterString
109 * @return {!RegExp}
110 */
111 _makeFilterRegExFromString: function(filterString)
lushnikov 2016/04/13 17:57:41 nit: _makeFilterRegexFromString
allada 2016/04/13 19:33:06 Done.
112 {
113 return new RegExp(filterString.escapeForRegExp(), "gi")
114 },
115
116 _refreshHighlighting: function()
117 {
118 if (!this._rootElement)
119 return;
120
121 for (var changedNode of this._highlightedNodes)
122 changedNode._revertHighlightChanges();
123
124 this._highlightedNodes = [];
125
126 if (!this._currentSelectionFilterString)
127 return;
128
129 if (this.selectedTreeElement && !this.selectedTreeElement.selectable) {
130 if (!this.selectNext())
131 this.selectPrevious();
132 }
133
134 var filterRegEx = this._makeFilterRegExFromString(this._currentSelection FilterString);
lushnikov 2016/04/13 17:57:41 nit: filterRegex
allada 2016/04/13 19:33:06 Done.
135 var node = this._rootElement.firstChild();
136 while (node) {
137 if (node._applyHighlightFilter(filterRegEx))
138 this._highlightedNodes.push(node);
139 node = node.traverseNextTreeElement(true, null, true);
140 }
141 },
142
143 /**
144 * @param {!TreeElement} treeElement
145 * @return {boolean}
146 */
147 _checkFilter: function(treeElement)
lushnikov 2016/04/13 17:57:41 let's move this inside TreeElement.
allada 2016/04/13 19:33:06 Done.
148 {
149 return this._currentSelectionFilterString ? this._makeFilterRegExFromStr ing(this._currentSelectionFilterString).test(treeElement._titleElement.textConte nt) : true;
150 },
151
152 _clearFilter: function()
153 {
154 if (this._interactiveFilterEnabled)
155 this._setCurrentSelectionFilterString("");
156 },
157
158 /**
159 * @param {!Event} event
160 */
161 _handleKeyPressForHighlighting: function(event)
162 {
163 if (!this._interactiveFilterEnabled)
164 return;
165
166 if (event.target !== this._contentElement)
167 return;
168
169 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
170 return;
171
172 var currentFilterString = this._currentSelectionFilterString;
173 var key = event.data;
174 if (key !== "\r" && key !== "\n" && (key !== " " || currentFilterString) )
175 this._setCurrentSelectionFilterString(currentFilterString + event.da ta);
176 },
177
178 /**
78 * @return {?TreeElement} 179 * @return {?TreeElement}
79 */ 180 */
80 firstChild: function() 181 firstChild: function()
81 { 182 {
82 return this._rootElement.firstChild(); 183 return this._rootElement.firstChild();
83 }, 184 },
84 185
85 /** 186 /**
86 * @param {!TreeElement} child 187 * @param {!TreeElement} child
87 */ 188 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 { 246 {
146 this._comparator = comparator; 247 this._comparator = comparator;
147 }, 248 },
148 249
149 /** 250 /**
150 * @param {boolean} focusable 251 * @param {boolean} focusable
151 */ 252 */
152 setFocusable: function(focusable) 253 setFocusable: function(focusable)
153 { 254 {
154 if (focusable) 255 if (focusable)
155 this._contentElement.setAttribute("tabIndex", 0); 256 this.element.setAttribute("tabIndex", 0);
156 else 257 else
157 this._contentElement.removeAttribute("tabIndex"); 258 this.element.removeAttribute("tabIndex");
158 }, 259 },
159 260
160 focus: function() 261 focus: function()
161 { 262 {
162 this._contentElement.focus(); 263 this._contentElement.focus();
163 }, 264 },
164 265
165 /** 266 /**
166 * @param {!TreeElement} element 267 * @param {!TreeElement} element
167 */ 268 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 * @param {!Event} event 323 * @param {!Event} event
223 */ 324 */
224 _treeKeyDown: function(event) 325 _treeKeyDown: function(event)
225 { 326 {
226 if (event.target !== this._contentElement) 327 if (event.target !== this._contentElement)
227 return; 328 return;
228 329
229 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) 330 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
230 return; 331 return;
231 332
333 var currentFilterString = this._currentSelectionFilterString;
232 var handled = false; 334 var handled = false;
335 var key = event.keyCode;
233 var nextSelectedElement; 336 var nextSelectedElement;
234 if (event.keyIdentifier === "Up" && !event.altKey) { 337
235 handled = this.selectPrevious(); 338 switch (key) {
236 } else if (event.keyIdentifier === "Down" && !event.altKey) { 339 case WebInspector.KeyboardShortcut.Keys.Up.code:
237 handled = this.selectNext(); 340 if (!event.altKey)
238 } else if (event.keyIdentifier === "Left") { 341 handled = this.selectPrevious();
342 break;
343 case WebInspector.KeyboardShortcut.Keys.Down.code:
344 if (!event.altKey)
345 handled = this.selectNext();
346 break;
347 case WebInspector.KeyboardShortcut.Keys.Left.code:
348 if (this._interactiveFilterEnabled)
349 this._clearFilter();
350
239 if (this.selectedTreeElement.expanded) { 351 if (this.selectedTreeElement.expanded) {
240 if (event.altKey) 352 if (event.altKey)
241 this.selectedTreeElement.collapseRecursively(); 353 this.selectedTreeElement.collapseRecursively();
242 else 354 else
243 this.selectedTreeElement.collapse(); 355 this.selectedTreeElement.collapse();
356
lushnikov 2016/04/13 17:57:41 nit: stray line
allada 2016/04/13 19:33:06 Done.
244 handled = true; 357 handled = true;
245 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { 358 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) {
246 handled = true; 359 handled = true;
247 if (this.selectedTreeElement.parent.selectable) { 360 if (this.selectedTreeElement.parent.selectable) {
248 nextSelectedElement = this.selectedTreeElement.parent; 361 nextSelectedElement = this.selectedTreeElement.parent;
249 while (nextSelectedElement && !nextSelectedElement.selectabl e) 362 while (nextSelectedElement && !nextSelectedElement.selectabl e)
250 nextSelectedElement = nextSelectedElement.parent; 363 nextSelectedElement = nextSelectedElement.parent;
364
lushnikov 2016/04/13 17:57:41 nit: stray line
allada 2016/04/13 19:33:06 Done.
251 handled = nextSelectedElement ? true : false; 365 handled = nextSelectedElement ? true : false;
252 } else if (this.selectedTreeElement.parent) 366 } else if (this.selectedTreeElement.parent) {
253 this.selectedTreeElement.parent.collapse(); 367 this.selectedTreeElement.parent.collapse();
368 }
254 } 369 }
255 } else if (event.keyIdentifier === "Right") { 370 break;
371 case WebInspector.KeyboardShortcut.Keys.Right.code:
372 if (this._interactiveFilterEnabled)
373 this._clearFilter();
374
256 if (!this.selectedTreeElement.revealed()) { 375 if (!this.selectedTreeElement.revealed()) {
257 this.selectedTreeElement.reveal(); 376 this.selectedTreeElement.reveal();
258 handled = true; 377 handled = true;
259 } else if (this.selectedTreeElement._expandable) { 378 } else if (this.selectedTreeElement._expandable) {
260 handled = true; 379 handled = true;
261 if (this.selectedTreeElement.expanded) { 380 if (this.selectedTreeElement.expanded) {
262 nextSelectedElement = this.selectedTreeElement.firstChild(); 381 nextSelectedElement = this.selectedTreeElement.firstChild();
263 while (nextSelectedElement && !nextSelectedElement.selectabl e) 382 while (nextSelectedElement && !nextSelectedElement.selectabl e)
264 nextSelectedElement = nextSelectedElement.nextSibling; 383 nextSelectedElement = nextSelectedElement.nextSibling;
384
lushnikov 2016/04/13 17:57:41 nit: stray line
allada 2016/04/13 19:33:06 Done.
265 handled = nextSelectedElement ? true : false; 385 handled = nextSelectedElement ? true : false;
266 } else { 386 } else {
267 if (event.altKey) 387 if (event.altKey)
268 this.selectedTreeElement.expandRecursively(); 388 this.selectedTreeElement.expandRecursively();
269 else 389 else
270 this.selectedTreeElement.expand(); 390 this.selectedTreeElement.expand();
271 } 391 }
272 } 392 }
273 } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 / * Delete */) 393 break;
274 handled = this.selectedTreeElement.ondelete(); 394 case WebInspector.KeyboardShortcut.Keys.Backspace.code:
275 else if (isEnterKey(event)) 395 if (this._interactiveFilterEnabled && currentFilterString) {
276 handled = this.selectedTreeElement.onenter(); 396 handled = true;
277 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code ) 397 this._setCurrentSelectionFilterString(currentFilterString.substr (0, currentFilterString.length - 1));
278 handled = this.selectedTreeElement.onspace(); 398 } else {
399 handled = this.selectedTreeElement.ondelete();
400 }
401 break;
402 case WebInspector.KeyboardShortcut.Keys.Delete.code:
403 if (this._interactiveFilterEnabled && currentFilterString) {
404 handled = true;
405 this._clearFilter();
406 } else
407 handled = this.selectedTreeElement.ondelete();
408 break;
409 case WebInspector.KeyboardShortcut.Keys.Esc.code:
410 if (this._interactiveFilterEnabled) {
411 if (currentFilterString)
412 handled = true;
413 this._clearFilter();
414 }
415 break;
416 case WebInspector.KeyboardShortcut.Keys.Space.code:
417 if (!currentFilterString)
418 handled = this.selectedTreeElement.onspace();
419 break;
420 default:
421 if (isEnterKey(event)) {
422 if (this._interactiveFilterEnabled)
423 this._clearFilter();
424
425 handled = this.selectedTreeElement.onenter();
426 }
427 }
279 428
280 if (nextSelectedElement) { 429 if (nextSelectedElement) {
281 nextSelectedElement.reveal(); 430 nextSelectedElement.reveal();
282 nextSelectedElement.select(false, true); 431 nextSelectedElement.select(false, true);
283 } 432 }
284 433
285 if (handled) 434 if (handled)
286 event.consume(true); 435 event.consume(true);
287 }, 436 },
288 437
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 this._childrenListNode = createElement("ol"); 519 this._childrenListNode = createElement("ol");
371 this._childrenListNode.parentTreeElement = this; 520 this._childrenListNode.parentTreeElement = this;
372 this._childrenListNode.classList.add("children"); 521 this._childrenListNode.classList.add("children");
373 522
374 this._hidden = false; 523 this._hidden = false;
375 this._selectable = true; 524 this._selectable = true;
376 this.expanded = false; 525 this.expanded = false;
377 this.selected = false; 526 this.selected = false;
378 this.setExpandable(expandable || false); 527 this.setExpandable(expandable || false);
379 this._collapsible = true; 528 this._collapsible = true;
529
530 /** @type {!Array.<!Object>} */
531 this._highlightChanges = [];
380 } 532 }
381 533
382 /** @const */ 534 /** @const */
383 TreeElement._ArrowToggleWidth = 10; 535 TreeElement._ArrowToggleWidth = 10;
384 536
385 TreeElement.prototype = { 537 TreeElement.prototype = {
386 /** 538 /**
539 * @param {!RegExp} regex
540 * @return {boolean}
541 */
542 _applyHighlightFilter: function(regex) {
543 var textContent = this._listItemNode.textContent;
544 var ranges = [];
545
546 this._revertHighlightChanges();
547
548 var match = regex.exec(textContent);
549 while (match) {
550 ranges.push(new WebInspector.SourceRange(match.index, match[0].lengt h));
551 match = regex.exec(textContent);
552 }
553 if (ranges.length)
554 WebInspector.highlightRangesWithStyleClass(this._listItemNode, range s, "tree-text-interactive-highlight", this._highlightChanges);
555
556 return !!this._highlightChanges.length
557 },
558
559 _revertHighlightChanges: function()
560 {
561 WebInspector.revertDomChanges(this._highlightChanges);
562 this._highlightChanges = [];
563 },
564
565 /**
387 * @param {?TreeElement} ancestor 566 * @param {?TreeElement} ancestor
388 * @return {boolean} 567 * @return {boolean}
389 */ 568 */
390 hasAncestor: function(ancestor) 569 hasAncestor: function(ancestor)
391 { 570 {
392 if (!ancestor) 571 if (!ancestor)
393 return false; 572 return false;
394 573
395 var currentNode = this.parent; 574 var currentNode = this.parent;
396 while (currentNode) { 575 while (currentNode) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 this.treeOutline._unbindTreeElement(child); 775 this.treeOutline._unbindTreeElement(child);
597 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) 776 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true))
598 this.treeOutline._unbindTreeElement(current); 777 this.treeOutline._unbindTreeElement(current);
599 child._detach(); 778 child._detach();
600 } 779 }
601 this._children = []; 780 this._children = [];
602 }, 781 },
603 782
604 get selectable() 783 get selectable()
605 { 784 {
606 if (this._hidden) 785 if (this._hidden || !this.treeOutline._checkFilter(this))
607 return false; 786 return false;
608 return this._selectable; 787 return this._selectable;
609 }, 788 },
610 789
611 set selectable(x) 790 set selectable(x)
612 { 791 {
613 this._selectable = x; 792 this._selectable = x;
614 }, 793 },
615 794
616 get listItemElement() 795 get listItemElement()
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 isEventWithinDisclosureTriangle: function(event) 1331 isEventWithinDisclosureTriangle: function(event)
1153 { 1332 {
1154 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446) 1333 // 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; 1334 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft;
1156 console.assert(paddingLeftValue.endsWith("px")); 1335 console.assert(paddingLeftValue.endsWith("px"));
1157 var computedLeftPadding = parseFloat(paddingLeftValue); 1336 var computedLeftPadding = parseFloat(paddingLeftValue);
1158 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; 1337 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding;
1159 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; 1338 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable;
1160 } 1339 }
1161 } 1340 }
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