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

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 a few code styling 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._contentElement.addEventListener("keypress", this._handleKeyPressForHig hlighting.bind(this), true);
lushnikov 2016/04/06 00:22:36 this.element.addEventListener...
allada 2016/04/09 00:42:47 Done.
51 this.element.addEventListener("blur", this._clearFilter.bind(this), true);
lushnikov 2016/04/06 00:22:36 is capturing actually needed in these three events
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)
92 this._setCurrentSelectionFilterString("");
93
94 this._interactiveFilterEnabled = enable;
95 },
96
97 /**
98 * @param {string} filterString
99 */
100 _setCurrentSelectionFilterString: function (filterString)
101 {
102 this._currentSelectionFilterString = filterString;
103 this._refreshHighlighting();
104 },
105
106 /**
107 * @param {string} filterString
108 * @return {!RegExp}
109 */
110 _makeFilterRegExpFromString: function (filterString)
111 {
112 return new RegExp(filterString.escapeForRegExp(), "gi")
113 },
114
115 _refreshHighlighting: function ()
lushnikov 2016/04/06 00:22:37 nit: _refreshHighlight:
allada 2016/04/09 00:42:48 Done.
116 {
117 if (!this._rootElement)
118 return;
119
120 var filterRegExp = this._makeFilterRegExpFromString(this._currentSelecti onFilterString);
lushnikov 2016/04/06 00:22:36 nit: filterRegex =
allada 2016/04/09 00:42:48 Done.
121
122 for (var changedNode of this._highlightedNodes)
123 changedNode._revertHighlightChanges();
124
125 this._highlightedNodes = [];
126
127 if (!this._currentSelectionFilterString)
128 return;
129
130 if (this.selectedTreeElement && !this.selectedTreeElement.selectable) {
131 if (!this.selectNext())
132 this.selectPrevious();
133 }
134
135 var node = this._rootElement.firstChild();
136 do {
lushnikov 2016/04/06 00:22:36 nit: no need for do-while; simple while will work
allada 2016/04/09 00:42:48 Done.
137 if (node._applyHighlightFilter(filterRegExp))
138 this._highlightedNodes.push(node);
139 node = node.traverseNextTreeElement(true, null, true);
140 } while(node);
141 },
142
143 /**
144 * @param {!TreeElement} treeElement
145 * @return {boolean}
146 */
147 _checkFilter: function (treeElement)
lushnikov 2016/04/06 00:22:36 Let's move this method into TreeElement; treeEleme
allada 2016/04/09 00:42:48 Done.
148 {
149 return this._currentSelectionFilterString ? this._makeFilterRegExpFromSt ring(this._currentSelectionFilterString).test(treeElement._titleElement.textCont ent) : 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
174 switch (event.data) {
175 case "\r":
176 case "\n":
177 break;
178 case " ":
179 if (!currentFilterString)
180 break;
181 default:
182 this._setCurrentSelectionFilterString(currentFilterString + event.da ta);
183 }
184 },
185
186 /**
78 * @return {?TreeElement} 187 * @return {?TreeElement}
79 */ 188 */
80 firstChild: function() 189 firstChild: function()
81 { 190 {
82 return this._rootElement.firstChild(); 191 return this._rootElement.firstChild();
83 }, 192 },
84 193
85 /** 194 /**
86 * @param {!TreeElement} child 195 * @param {!TreeElement} child
87 */ 196 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 { 254 {
146 this._comparator = comparator; 255 this._comparator = comparator;
147 }, 256 },
148 257
149 /** 258 /**
150 * @param {boolean} focusable 259 * @param {boolean} focusable
151 */ 260 */
152 setFocusable: function(focusable) 261 setFocusable: function(focusable)
153 { 262 {
154 if (focusable) 263 if (focusable)
155 this._contentElement.setAttribute("tabIndex", 0); 264 this.element.setAttribute("tabIndex", 0);
lushnikov 2016/04/06 00:22:36 this and below seems to be unnecessary
allada 2016/04/09 00:42:48 This is needed to be able to capture keyboard even
156 else 265 else
157 this._contentElement.removeAttribute("tabIndex"); 266 this.element.removeAttribute("tabIndex");
158 }, 267 },
159 268
160 focus: function() 269 focus: function()
161 { 270 {
162 this._contentElement.focus(); 271 this._contentElement.focus();
163 }, 272 },
164 273
165 /** 274 /**
166 * @param {!TreeElement} element 275 * @param {!TreeElement} element
167 */ 276 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 * @param {!Event} event 331 * @param {!Event} event
223 */ 332 */
224 _treeKeyDown: function(event) 333 _treeKeyDown: function(event)
225 { 334 {
226 if (event.target !== this._contentElement) 335 if (event.target !== this._contentElement)
227 return; 336 return;
228 337
229 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) 338 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey)
230 return; 339 return;
231 340
341 var currentFilterString = this._currentSelectionFilterString;
232 var handled = false; 342 var handled = false;
343 var key = event.keyCode;
233 var nextSelectedElement; 344 var nextSelectedElement;
234 if (event.keyIdentifier === "Up" && !event.altKey) { 345
235 handled = this.selectPrevious(); 346 switch (key) {
236 } else if (event.keyIdentifier === "Down" && !event.altKey) { 347 case WebInspector.KeyboardShortcut.Keys.Esc.code:
237 handled = this.selectNext(); 348 if (this._interactiveFilterEnabled) {
238 } else if (event.keyIdentifier === "Left") { 349 if (currentFilterString)
239 if (this.selectedTreeElement.expanded) { 350 handled = true;
240 if (event.altKey) 351 this._clearFilter();
241 this.selectedTreeElement.collapseRecursively(); 352 }
242 else 353 break;
243 this.selectedTreeElement.collapse(); 354 case WebInspector.KeyboardShortcut.Keys.Delete.code:
355 if (this._interactiveFilterEnabled && currentFilterString) {
244 handled = true; 356 handled = true;
245 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { 357 this._clearFilter();
358 } else
359 handled = this.selectedTreeElement.ondelete();
360 break;
361 case WebInspector.KeyboardShortcut.Keys.Backspace.code:
362 if (this._interactiveFilterEnabled && currentFilterString) {
246 handled = true; 363 handled = true;
247 if (this.selectedTreeElement.parent.selectable) { 364 this._setCurrentSelectionFilterString(currentFilterString.substr (0, currentFilterString.length - 1));
248 nextSelectedElement = this.selectedTreeElement.parent; 365 } else {
249 while (nextSelectedElement && !nextSelectedElement.selectabl e) 366 handled = this.selectedTreeElement.ondelete();
250 nextSelectedElement = nextSelectedElement.parent;
251 handled = nextSelectedElement ? true : false;
252 } else if (this.selectedTreeElement.parent)
253 this.selectedTreeElement.parent.collapse();
254 } 367 }
255 } else if (event.keyIdentifier === "Right") { 368 break;
369 case WebInspector.KeyboardShortcut.Keys.Right.code:
370 if (this._interactiveFilterEnabled)
371 this._clearFilter();
372
256 if (!this.selectedTreeElement.revealed()) { 373 if (!this.selectedTreeElement.revealed()) {
257 this.selectedTreeElement.reveal(); 374 this.selectedTreeElement.reveal();
258 handled = true; 375 handled = true;
259 } else if (this.selectedTreeElement._expandable) { 376 } else if (this.selectedTreeElement._expandable) {
260 handled = true; 377 handled = true;
261 if (this.selectedTreeElement.expanded) { 378 if (this.selectedTreeElement.expanded) {
262 nextSelectedElement = this.selectedTreeElement.firstChild(); 379 nextSelectedElement = this.selectedTreeElement.firstChild();
263 while (nextSelectedElement && !nextSelectedElement.selectabl e) 380 while (nextSelectedElement && !nextSelectedElement.selectabl e)
264 nextSelectedElement = nextSelectedElement.nextSibling; 381 nextSelectedElement = nextSelectedElement.nextSibling;
382
lushnikov 2016/04/06 00:22:36 nit: stray line
allada 2016/04/09 00:42:47 Done.
265 handled = nextSelectedElement ? true : false; 383 handled = nextSelectedElement ? true : false;
266 } else { 384 } else {
267 if (event.altKey) 385 if (event.altKey)
268 this.selectedTreeElement.expandRecursively(); 386 this.selectedTreeElement.expandRecursively();
269 else 387 else
270 this.selectedTreeElement.expand(); 388 this.selectedTreeElement.expand();
271 } 389 }
272 } 390 }
273 } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 / * Delete */) 391 break;
274 handled = this.selectedTreeElement.ondelete(); 392 case WebInspector.KeyboardShortcut.Keys.Left.code:
275 else if (isEnterKey(event)) 393 if (this._interactiveFilterEnabled)
276 handled = this.selectedTreeElement.onenter(); 394 this._clearFilter();
277 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code ) 395
278 handled = this.selectedTreeElement.onspace(); 396 if (this.selectedTreeElement.expanded) {
lushnikov 2016/04/06 00:22:36 Are there any changes in this if-else-if code? ni
allada 2016/04/09 00:42:48 Done.
397 if (event.altKey)
398 this.selectedTreeElement.collapseRecursively();
399 else
400 this.selectedTreeElement.collapse();
401
402 handled = true;
403 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) {
404 handled = true;
405 if (this.selectedTreeElement.parent.selectable) {
406 nextSelectedElement = this.selectedTreeElement.parent;
407 while (nextSelectedElement && !nextSelectedElement.selectabl e)
408 nextSelectedElement = nextSelectedElement.parent;
409
410 handled = nextSelectedElement ? true : false;
411 } else if (this.selectedTreeElement.parent) {
412 this.selectedTreeElement.parent.collapse();
413 }
414 }
415 break;
416 case WebInspector.KeyboardShortcut.Keys.Down.code:
417 if (!event.altKey)
418 handled = this.selectNext();
419 break;
420 case WebInspector.KeyboardShortcut.Keys.Up.code:
421 if (!event.altKey)
422 handled = this.selectPrevious();
423 break;
424 case WebInspector.KeyboardShortcut.Keys.Space.code:
425 if (!currentFilterString)
426 handled = this.selectedTreeElement.onspace();
427 break;
428 default:
429 if (isEnterKey(event)) {
430 if (this._interactiveFilterEnabled)
431 this._clearFilter();
432
433 handled = this.selectedTreeElement.onenter();
434 }
435 }
279 436
280 if (nextSelectedElement) { 437 if (nextSelectedElement) {
281 nextSelectedElement.reveal(); 438 nextSelectedElement.reveal();
282 nextSelectedElement.select(false, true); 439 nextSelectedElement.select(false, true);
283 } 440 }
284 441
285 if (handled) 442 if (handled)
286 event.consume(true); 443 event.consume(true);
287 }, 444 },
288 445
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 this._childrenListNode = createElement("ol"); 527 this._childrenListNode = createElement("ol");
371 this._childrenListNode.parentTreeElement = this; 528 this._childrenListNode.parentTreeElement = this;
372 this._childrenListNode.classList.add("children"); 529 this._childrenListNode.classList.add("children");
373 530
374 this._hidden = false; 531 this._hidden = false;
375 this._selectable = true; 532 this._selectable = true;
376 this.expanded = false; 533 this.expanded = false;
377 this.selected = false; 534 this.selected = false;
378 this.setExpandable(expandable || false); 535 this.setExpandable(expandable || false);
379 this._collapsible = true; 536 this._collapsible = true;
537
538 /** @type {!Array.<!Object>} */
539 this._highlightChanges = [];
380 } 540 }
381 541
382 /** @const */ 542 /** @const */
383 TreeElement._ArrowToggleWidth = 10; 543 TreeElement._ArrowToggleWidth = 10;
384 544
385 TreeElement.prototype = { 545 TreeElement.prototype = {
386 /** 546 /**
547 * @param {!RegExp} regex
548 * @return {boolean}
549 */
550 _applyHighlightFilter: function (regex) {
551 var textContent = this._listItemNode.textContent;
552 var ranges = [];
553
554 this._revertHighlightChanges();
555
556 var match = regex.exec(textContent);
557 while (match) {
558 ranges.push(new WebInspector.SourceRange(match.index, match[0].lengt h));
559 match = regex.exec(textContent);
560 }
561 if (ranges.length)
562 WebInspector.highlightRangesWithStyleClass(this._listItemNode, range s, "tree-text-interactive-highlight", this._highlightChanges);
563
564 if (this._highlightChanges.length)
lushnikov 2016/04/06 00:22:36 return !!this._highlightChanges.length;
allada 2016/04/09 00:42:47 Done.
565 return true;
566
567 return false;
568 },
569
570 _revertHighlightChanges: function ()
571 {
572 WebInspector.revertDomChanges(this._highlightChanges);
573 this._highlightChanges = [];
574 },
575
576 /**
387 * @param {?TreeElement} ancestor 577 * @param {?TreeElement} ancestor
388 * @return {boolean} 578 * @return {boolean}
389 */ 579 */
390 hasAncestor: function(ancestor) 580 hasAncestor: function(ancestor)
391 { 581 {
392 if (!ancestor) 582 if (!ancestor)
393 return false; 583 return false;
394 584
395 var currentNode = this.parent; 585 var currentNode = this.parent;
396 while (currentNode) { 586 while (currentNode) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 this.treeOutline._unbindTreeElement(child); 786 this.treeOutline._unbindTreeElement(child);
597 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) 787 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true))
598 this.treeOutline._unbindTreeElement(current); 788 this.treeOutline._unbindTreeElement(current);
599 child._detach(); 789 child._detach();
600 } 790 }
601 this._children = []; 791 this._children = [];
602 }, 792 },
603 793
604 get selectable() 794 get selectable()
605 { 795 {
606 if (this._hidden) 796 if (this._hidden || !this.treeOutline._checkFilter(this))
607 return false; 797 return false;
608 return this._selectable; 798 return this._selectable;
609 }, 799 },
610 800
611 set selectable(x) 801 set selectable(x)
612 { 802 {
613 this._selectable = x; 803 this._selectable = x;
614 }, 804 },
615 805
616 get listItemElement() 806 get listItemElement()
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 isEventWithinDisclosureTriangle: function(event) 1342 isEventWithinDisclosureTriangle: function(event)
1153 { 1343 {
1154 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446) 1344 // 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; 1345 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft;
1156 console.assert(paddingLeftValue.endsWith("px")); 1346 console.assert(paddingLeftValue.endsWith("px"));
1157 var computedLeftPadding = parseFloat(paddingLeftValue); 1347 var computedLeftPadding = parseFloat(paddingLeftValue);
1158 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; 1348 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding;
1159 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; 1349 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable;
1160 } 1350 }
1161 } 1351 }
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