OLD | NEW |
---|---|
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 Loading... | |
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) | |
lushnikov
2016/03/25 17:15:59
style: extra space after function keyword
allada
2016/04/05 00:16:22
Done.
lushnikov
2016/04/06 00:22:36
This seems to be not done.
allada
2016/04/08 17:26:07
Sorry must have stashed and not committed my chang
| |
90 { | |
91 if (!enable) | |
lushnikov
2016/03/25 17:15:59
let's do nothing if the state doesn't change
allada
2016/04/05 00:16:22
Done.
lushnikov
2016/04/06 00:22:36
This seems to be not done.
allada
2016/04/08 17:26:07
Done.
| |
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) | |
lushnikov
2016/03/25 17:15:59
despite the JavaScript class RegExp, we always abb
allada
2016/04/05 00:16:22
Done.
lushnikov
2016/04/06 00:22:36
This seems to be not done.
allada
2016/04/08 17:26:07
Done.
| |
111 { | |
112 return new RegExp(filterString.escapeForRegExp(), "gi") | |
113 }, | |
114 | |
115 _refreshHighlighting: function () | |
116 { | |
117 if (!this._rootElement) | |
118 return; | |
119 | |
120 var filterRegExp = this._makeFilterRegExpFromString(this._currentSelecti onFilterString); | |
lushnikov
2016/03/25 17:15:59
let's move this closer to the point where it is ac
allada
2016/04/05 00:16:22
Done.
| |
121 | |
122 for (var changedNode of this._highlightChangedNodes) | |
123 changedNode._revertHighlightChanges(); | |
124 | |
125 this._highlightChanges = []; | |
lushnikov
2016/03/25 17:15:59
this seems to be not used
allada
2016/04/05 00:16:22
Done.
| |
126 | |
127 if (!this._currentSelectionFilterString) | |
128 return; | |
129 | |
130 if (this.selectedTreeElement && !this.selectedTreeElement.selectable) { | |
lushnikov
2016/03/25 17:15:59
why do you need this?
allada
2016/04/05 00:16:22
Because this function is executed after a new filt
| |
131 if (!this.selectNext()) | |
132 this.selectPrevious(); | |
133 } | |
134 | |
135 var node = this._rootElement.firstChild(); | |
136 do { | |
137 var textContent = node._listItemNode.textContent; | |
lushnikov
2016/03/25 17:16:00
let's move this logic into TreeElement.
The treeE
allada
2016/04/05 00:16:22
Done.
| |
138 var match = filterRegExp.exec(textContent); | |
139 var ranges = []; | |
140 var changes = []; | |
141 while (true) { | |
142 if (!match) | |
143 break; | |
144 ranges.push(new WebInspector.SourceRange(match.index, match[0].l ength)); | |
145 match = filterRegExp.exec(textContent); | |
146 } | |
147 if (ranges.length) | |
148 WebInspector.highlightRangesWithStyleClass(node._listItemNode, r anges, "tree-text-interactive-highlight", changes); | |
149 | |
150 if (changes.length) { | |
151 node._setHighlightChanges(changes); | |
152 this._highlightChangedNodes.push(node); | |
153 } | |
154 | |
155 node = node.traverseNextTreeElement(true, null, true); | |
156 } while(node); | |
157 }, | |
158 | |
159 /** | |
160 * @param {!TreeElement} treeElement | |
161 * @return {boolean} | |
162 */ | |
163 _checkFilter: function (treeElement) | |
164 { | |
165 return this._currentSelectionFilterString ? this._makeFilterRegExpFromSt ring(this._currentSelectionFilterString).test(treeElement._titleElement.textCont ent) : true; | |
166 }, | |
167 | |
168 _clearFilter: function () | |
169 { | |
170 if (this._interactiveFilterEnabled) | |
171 this._setCurrentSelectionFilterString(""); | |
172 }, | |
173 | |
174 /** | |
175 * @param {!Event} event | |
176 */ | |
177 _handleKeyPressForHighlighting: function (event) | |
178 { | |
179 if (!this._interactiveFilterEnabled) | |
180 return; | |
181 | |
182 if (event.target !== this._contentElement) | |
183 return; | |
184 | |
185 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) | |
186 return; | |
187 | |
188 var currentFilterString = this._currentSelectionFilterString; | |
189 | |
190 switch (event.data) { | |
lushnikov
2016/03/25 17:15:59
I think this switch could be simplified
if (key =
allada
2016/04/05 00:16:22
Done.
lushnikov
2016/04/06 00:22:36
This seems to be not done.
allada
2016/04/08 17:26:07
Done.
| |
191 case "\r": | |
192 case "\n": | |
193 break; | |
194 case " ": | |
195 if (!currentFilterString) | |
196 break; | |
lushnikov
2016/03/25 17:16:00
we do not use fall-through as they are confusing.
allada
2016/04/05 00:16:22
Done.
| |
197 default: | |
198 this._setCurrentSelectionFilterString(currentFilterString + event.da ta); | |
199 } | |
200 }, | |
201 | |
202 /** | |
78 * @return {?TreeElement} | 203 * @return {?TreeElement} |
79 */ | 204 */ |
80 firstChild: function() | 205 firstChild: function() |
81 { | 206 { |
82 return this._rootElement.firstChild(); | 207 return this._rootElement.firstChild(); |
83 }, | 208 }, |
84 | 209 |
85 /** | 210 /** |
86 * @param {!TreeElement} child | 211 * @param {!TreeElement} child |
87 */ | 212 */ |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 * @param {!Event} event | 347 * @param {!Event} event |
223 */ | 348 */ |
224 _treeKeyDown: function(event) | 349 _treeKeyDown: function(event) |
225 { | 350 { |
226 if (event.target !== this._contentElement) | 351 if (event.target !== this._contentElement) |
227 return; | 352 return; |
228 | 353 |
229 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) | 354 if (!this.selectedTreeElement || event.shiftKey || event.metaKey || even t.ctrlKey) |
230 return; | 355 return; |
231 | 356 |
357 var currentFilterString = this._currentSelectionFilterString; | |
232 var handled = false; | 358 var handled = false; |
359 var key = event.keyCode; | |
233 var nextSelectedElement; | 360 var nextSelectedElement; |
234 if (event.keyIdentifier === "Up" && !event.altKey) { | 361 |
235 handled = this.selectPrevious(); | 362 switch (key) { |
236 } else if (event.keyIdentifier === "Down" && !event.altKey) { | 363 case WebInspector.KeyboardShortcut.Keys.Esc.code: |
237 handled = this.selectNext(); | 364 if (this._interactiveFilterEnabled) { |
238 } else if (event.keyIdentifier === "Left") { | 365 if (currentFilterString) |
239 if (this.selectedTreeElement.expanded) { | 366 // Consider the item handled if the filter string is already set (this will keep the console from triggering) |
240 if (event.altKey) | 367 handled = true; |
241 this.selectedTreeElement.collapseRecursively(); | 368 this._clearFilter(); |
242 else | 369 } |
243 this.selectedTreeElement.collapse(); | 370 break; |
371 case WebInspector.KeyboardShortcut.Keys.Delete.code: | |
372 if (this._interactiveFilterEnabled && currentFilterString) { | |
244 handled = true; | 373 handled = true; |
245 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { | 374 this._clearFilter(); |
375 } else | |
376 handled = this.selectedTreeElement.ondelete(); | |
377 break; | |
378 case WebInspector.KeyboardShortcut.Keys.Backspace.code: | |
379 if (this._interactiveFilterEnabled && currentFilterString) { | |
246 handled = true; | 380 handled = true; |
247 if (this.selectedTreeElement.parent.selectable) { | 381 this._setCurrentSelectionFilterString(currentFilterString.substr (0, currentFilterString.length - 1)); |
248 nextSelectedElement = this.selectedTreeElement.parent; | 382 } else |
249 while (nextSelectedElement && !nextSelectedElement.selectabl e) | 383 handled = this.selectedTreeElement.ondelete(); |
250 nextSelectedElement = nextSelectedElement.parent; | 384 break; |
251 handled = nextSelectedElement ? true : false; | 385 case WebInspector.KeyboardShortcut.Keys.Right.code: |
252 } else if (this.selectedTreeElement.parent) | 386 if (this._interactiveFilterEnabled) |
253 this.selectedTreeElement.parent.collapse(); | 387 this._clearFilter(); |
254 } | 388 |
255 } else if (event.keyIdentifier === "Right") { | |
256 if (!this.selectedTreeElement.revealed()) { | 389 if (!this.selectedTreeElement.revealed()) { |
257 this.selectedTreeElement.reveal(); | 390 this.selectedTreeElement.reveal(); |
258 handled = true; | 391 handled = true; |
259 } else if (this.selectedTreeElement._expandable) { | 392 } else if (this.selectedTreeElement._expandable) { |
260 handled = true; | 393 handled = true; |
261 if (this.selectedTreeElement.expanded) { | 394 if (this.selectedTreeElement.expanded) { |
262 nextSelectedElement = this.selectedTreeElement.firstChild(); | 395 nextSelectedElement = this.selectedTreeElement.firstChild(); |
263 while (nextSelectedElement && !nextSelectedElement.selectabl e) | 396 while (nextSelectedElement && !nextSelectedElement.selectabl e) |
264 nextSelectedElement = nextSelectedElement.nextSibling; | 397 nextSelectedElement = nextSelectedElement.nextSibling; |
265 handled = nextSelectedElement ? true : false; | 398 handled = nextSelectedElement ? true : false; |
266 } else { | 399 } else { |
267 if (event.altKey) | 400 if (event.altKey) |
268 this.selectedTreeElement.expandRecursively(); | 401 this.selectedTreeElement.expandRecursively(); |
269 else | 402 else |
270 this.selectedTreeElement.expand(); | 403 this.selectedTreeElement.expand(); |
271 } | 404 } |
272 } | 405 } |
273 } else if (event.keyCode === 8 /* Backspace */ || event.keyCode === 46 / * Delete */) | 406 break; |
274 handled = this.selectedTreeElement.ondelete(); | 407 case WebInspector.KeyboardShortcut.Keys.Left.code: |
275 else if (isEnterKey(event)) | 408 if (this._interactiveFilterEnabled) |
276 handled = this.selectedTreeElement.onenter(); | 409 this._clearFilter(); |
277 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code ) | 410 |
278 handled = this.selectedTreeElement.onspace(); | 411 if (this.selectedTreeElement.expanded) { |
412 if (event.altKey) | |
413 this.selectedTreeElement.collapseRecursively(); | |
414 else | |
415 this.selectedTreeElement.collapse(); | |
416 handled = true; | |
417 } else if (this.selectedTreeElement.parent && !this.selectedTreeElem ent.parent.root) { | |
418 handled = true; | |
419 if (this.selectedTreeElement.parent.selectable) { | |
420 nextSelectedElement = this.selectedTreeElement.parent; | |
421 while (nextSelectedElement && !nextSelectedElement.selectabl e) | |
422 nextSelectedElement = nextSelectedElement.parent; | |
423 handled = nextSelectedElement ? true : false; | |
424 } else if (this.selectedTreeElement.parent) | |
425 this.selectedTreeElement.parent.collapse(); | |
426 } | |
427 break; | |
428 case WebInspector.KeyboardShortcut.Keys.Down.code: | |
429 if (!event.altKey) | |
430 handled = this.selectNext(); | |
431 break; | |
432 case WebInspector.KeyboardShortcut.Keys.Up.code: | |
433 if (!event.altKey) | |
434 handled = this.selectPrevious(); | |
435 break; | |
436 case WebInspector.KeyboardShortcut.Keys.Space.code: | |
437 // Do not send space key event if the search filter has stuff in buf fer | |
438 if (!currentFilterString) | |
439 handled = this.selectedTreeElement.onspace(); | |
440 break; | |
441 default: | |
442 if (isEnterKey(event)) { | |
443 if (this._interactiveFilterEnabled) | |
444 this._clearFilter(); | |
445 | |
446 handled = this.selectedTreeElement.onenter(); | |
447 } | |
448 } | |
279 | 449 |
280 if (nextSelectedElement) { | 450 if (nextSelectedElement) { |
281 nextSelectedElement.reveal(); | 451 nextSelectedElement.reveal(); |
282 nextSelectedElement.select(false, true); | 452 nextSelectedElement.select(false, true); |
283 } | 453 } |
284 | 454 |
285 if (handled) | 455 if (handled) |
286 event.consume(true); | 456 event.consume(true); |
287 }, | 457 }, |
288 | 458 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 this._childrenListNode = createElement("ol"); | 540 this._childrenListNode = createElement("ol"); |
371 this._childrenListNode.parentTreeElement = this; | 541 this._childrenListNode.parentTreeElement = this; |
372 this._childrenListNode.classList.add("children"); | 542 this._childrenListNode.classList.add("children"); |
373 | 543 |
374 this._hidden = false; | 544 this._hidden = false; |
375 this._selectable = true; | 545 this._selectable = true; |
376 this.expanded = false; | 546 this.expanded = false; |
377 this.selected = false; | 547 this.selected = false; |
378 this.setExpandable(expandable || false); | 548 this.setExpandable(expandable || false); |
379 this._collapsible = true; | 549 this._collapsible = true; |
550 | |
551 /** @type {!Array.<!Object>} */ | |
552 this._highlightChanges = []; | |
380 } | 553 } |
381 | 554 |
382 /** @const */ | 555 /** @const */ |
383 TreeElement._ArrowToggleWidth = 10; | 556 TreeElement._ArrowToggleWidth = 10; |
384 | 557 |
385 TreeElement.prototype = { | 558 TreeElement.prototype = { |
386 /** | 559 /** |
560 * @param {!Array.<!Object>} changes | |
561 */ | |
562 _setHighlightChanges: function (changes) | |
563 { | |
564 this._highlightChanges = changes; | |
565 }, | |
566 | |
567 _revertHighlightChanges: function () | |
568 { | |
569 WebInspector.revertDomChanges(this._highlightChanges); | |
570 this._highlightChanges = []; | |
571 }, | |
572 | |
573 /** | |
387 * @param {?TreeElement} ancestor | 574 * @param {?TreeElement} ancestor |
388 * @return {boolean} | 575 * @return {boolean} |
389 */ | 576 */ |
390 hasAncestor: function(ancestor) | 577 hasAncestor: function(ancestor) |
391 { | 578 { |
392 if (!ancestor) | 579 if (!ancestor) |
393 return false; | 580 return false; |
394 | 581 |
395 var currentNode = this.parent; | 582 var currentNode = this.parent; |
396 while (currentNode) { | 583 while (currentNode) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 this.treeOutline._unbindTreeElement(child); | 783 this.treeOutline._unbindTreeElement(child); |
597 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) | 784 for (var current = child.firstChild(); this.treeOutline && current; current = current.traverseNextTreeElement(false, child, true)) |
598 this.treeOutline._unbindTreeElement(current); | 785 this.treeOutline._unbindTreeElement(current); |
599 child._detach(); | 786 child._detach(); |
600 } | 787 } |
601 this._children = []; | 788 this._children = []; |
602 }, | 789 }, |
603 | 790 |
604 get selectable() | 791 get selectable() |
605 { | 792 { |
606 if (this._hidden) | 793 if (this._hidden || !this.treeOutline._checkFilter(this)) |
607 return false; | 794 return false; |
608 return this._selectable; | 795 return this._selectable; |
609 }, | 796 }, |
610 | 797 |
611 set selectable(x) | 798 set selectable(x) |
612 { | 799 { |
613 this._selectable = x; | 800 this._selectable = x; |
614 }, | 801 }, |
615 | 802 |
616 get listItemElement() | 803 get listItemElement() |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 isEventWithinDisclosureTriangle: function(event) | 1339 isEventWithinDisclosureTriangle: function(event) |
1153 { | 1340 { |
1154 // FIXME: We should not use getComputedStyle(). For that we need to get rid of using ::before for disclosure triangle. (http://webk.it/74446) | 1341 // 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; | 1342 var paddingLeftValue = window.getComputedStyle(this._listItemNode).paddi ngLeft; |
1156 console.assert(paddingLeftValue.endsWith("px")); | 1343 console.assert(paddingLeftValue.endsWith("px")); |
1157 var computedLeftPadding = parseFloat(paddingLeftValue); | 1344 var computedLeftPadding = parseFloat(paddingLeftValue); |
1158 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; | 1345 var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding; |
1159 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; | 1346 return event.pageX >= left && event.pageX <= left + TreeElement._ArrowTo ggleWidth && this._expandable; |
1160 } | 1347 } |
1161 } | 1348 } |
OLD | NEW |