| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>} | 5 * @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>} |
| 6 * @implements {UI.ListDelegate<!SDK.ExecutionContext>} | 6 * @implements {UI.ListDelegate<!SDK.ExecutionContext>} |
| 7 */ | 7 */ |
| 8 Console.ConsoleContextSelector = class { | 8 Console.ConsoleContextSelector = class { |
| 9 constructor() { | 9 constructor() { |
| 10 this._toolbarItem = new UI.ToolbarItem(createElementWithClass('button', 'con
sole-context')); | 10 this._toolbarItem = new UI.ToolbarItem(createElementWithClass('button', 'con
sole-context')); |
| 11 var shadowRoot = | 11 var shadowRoot = |
| 12 UI.createShadowRootWithCoreStyles(this._toolbarItem.element, 'console/co
nsoleContextSelectorButton.css'); | 12 UI.createShadowRootWithCoreStyles(this._toolbarItem.element, 'console/co
nsoleContextSelectorButton.css'); |
| 13 this._titleElement = shadowRoot.createChild('span', 'title'); | 13 this._titleElement = shadowRoot.createChild('span', 'title'); |
| 14 | 14 |
| 15 /** @type {!Map<!SDK.ExecutionContext, !ProductRegistry.BadgePool>} */ | 15 /** @type {!Map<!SDK.ExecutionContext, !ProductRegistry.BadgePool>} */ |
| 16 this._badgePoolForExecutionContext = new Map(); | 16 this._badgePoolForExecutionContext = new Map(); |
| 17 | 17 |
| 18 this._toolbarItem.element.classList.add('toolbar-has-dropdown'); | 18 this._toolbarItem.element.classList.add('toolbar-has-dropdown'); |
| 19 this._toolbarItem.element.tabIndex = 0; | 19 this._toolbarItem.element.tabIndex = 0; |
| 20 this._glassPane = new UI.GlassPane(); | 20 this._glassPane = new UI.GlassPane(); |
| 21 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin); | 21 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin); |
| 22 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); | 22 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); |
| 23 this._glassPane.setOutsideClickCallback(this._hide.bind(this)); | 23 this._glassPane.setOutsideClickCallback(this._hide.bind(this)); |
| 24 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.
BlockedByGlassPane); | 24 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.
BlockedByGlassPane); |
| 25 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); | 25 /** @type {!UI.ListModel<!SDK.ExecutionContext>} */ |
| 26 this._items = new UI.ListModel(); |
| 27 /** @type {!UI.ListControl<!SDK.ExecutionContext>} */ |
| 28 this._list = new UI.ListControl(this._items, this, UI.ListMode.EqualHeightIt
ems); |
| 26 this._list.element.classList.add('context-list'); | 29 this._list.element.classList.add('context-list'); |
| 27 this._rowHeight = 36; | 30 this._rowHeight = 36; |
| 28 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c
onsoleContextSelector.css') | 31 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c
onsoleContextSelector.css') |
| 29 .appendChild(this._list.element); | 32 .appendChild(this._list.element); |
| 30 | 33 |
| 31 this._listWasShowing200msAgo = false; | 34 this._listWasShowing200msAgo = false; |
| 32 this._toolbarItem.element.addEventListener('mousedown', event => { | 35 this._toolbarItem.element.addEventListener('mousedown', event => { |
| 33 if (this._listWasShowing200msAgo) | 36 if (this._listWasShowing200msAgo) |
| 34 this._hide(event); | 37 this._hide(event); |
| 35 else | 38 else |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (selectedContext) { | 92 if (selectedContext) { |
| 90 this._list.selectItem(selectedContext); | 93 this._list.selectItem(selectedContext); |
| 91 this._list.scrollItemIntoView(selectedContext, true); | 94 this._list.scrollItemIntoView(selectedContext, true); |
| 92 } | 95 } |
| 93 this._toolbarItem.element.focus(); | 96 this._toolbarItem.element.focus(); |
| 94 event.consume(true); | 97 event.consume(true); |
| 95 setTimeout(() => this._listWasShowing200msAgo = true, 200); | 98 setTimeout(() => this._listWasShowing200msAgo = true, 200); |
| 96 } | 99 } |
| 97 | 100 |
| 98 _updateGlasspaneSize() { | 101 _updateGlasspaneSize() { |
| 99 var maxHeight = this._rowHeight * (Math.min(this._list.length(), 9)); | 102 var maxHeight = this._rowHeight * (Math.min(this._items.length(), 9)); |
| 100 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight)); | 103 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight)); |
| 101 this._list.viewportResized(); | 104 this._list.viewportResized(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 /** | 107 /** |
| 105 * @param {!Event} event | 108 * @param {!Event} event |
| 106 */ | 109 */ |
| 107 _hide(event) { | 110 _hide(event) { |
| 108 setTimeout(() => this._listWasShowing200msAgo = false, 200); | 111 setTimeout(() => this._listWasShowing200msAgo = false, 200); |
| 109 this._glassPane.hide(); | 112 this._glassPane.hide(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 case 'ArrowUp': | 123 case 'ArrowUp': |
| 121 handled = this._list.selectPreviousItem(false, false); | 124 handled = this._list.selectPreviousItem(false, false); |
| 122 break; | 125 break; |
| 123 case 'ArrowDown': | 126 case 'ArrowDown': |
| 124 handled = this._list.selectNextItem(false, false); | 127 handled = this._list.selectNextItem(false, false); |
| 125 break; | 128 break; |
| 126 case 'ArrowRight': | 129 case 'ArrowRight': |
| 127 var currentExecutionContext = this._list.selectedItem(); | 130 var currentExecutionContext = this._list.selectedItem(); |
| 128 if (!currentExecutionContext) | 131 if (!currentExecutionContext) |
| 129 break; | 132 break; |
| 130 var nextExecutionContext = this._list.itemAtIndex(this._list.selectedInd
ex() + 1); | 133 var nextExecutionContext = this._items.itemAtIndex(this._list.selectedIn
dex() + 1); |
| 131 if (nextExecutionContext && this._depthFor(currentExecutionContext) < th
is._depthFor(nextExecutionContext)) | 134 if (nextExecutionContext && this._depthFor(currentExecutionContext) < th
is._depthFor(nextExecutionContext)) |
| 132 handled = this._list.selectNextItem(false, false); | 135 handled = this._list.selectNextItem(false, false); |
| 133 break; | 136 break; |
| 134 case 'ArrowLeft': | 137 case 'ArrowLeft': |
| 135 var currentExecutionContext = this._list.selectedItem(); | 138 var currentExecutionContext = this._list.selectedItem(); |
| 136 if (!currentExecutionContext) | 139 if (!currentExecutionContext) |
| 137 break; | 140 break; |
| 138 var depth = this._depthFor(currentExecutionContext); | 141 var depth = this._depthFor(currentExecutionContext); |
| 139 for (var i = this._list.selectedIndex() - 1; i >= 0; i--) { | 142 for (var i = this._list.selectedIndex() - 1; i >= 0; i--) { |
| 140 if (this._depthFor(this._list.itemAtIndex(i)) < depth) { | 143 if (this._depthFor(this._items.itemAtIndex(i)) < depth) { |
| 141 handled = true; | 144 handled = true; |
| 142 this._list.selectItem(this._list.itemAtIndex(i), false); | 145 this._list.selectItem(this._items.itemAtIndex(i), false); |
| 143 break; | 146 break; |
| 144 } | 147 } |
| 145 } | 148 } |
| 146 break; | 149 break; |
| 147 case 'PageUp': | 150 case 'PageUp': |
| 148 handled = this._list.selectItemPreviousPage(false); | 151 handled = this._list.selectItemPreviousPage(false); |
| 149 break; | 152 break; |
| 150 case 'PageDown': | 153 case 'PageDown': |
| 151 handled = this._list.selectItemNextPage(false); | 154 handled = this._list.selectItemNextPage(false); |
| 152 break; | 155 break; |
| 153 case 'Home': | 156 case 'Home': |
| 154 for (var i = 0; i < this._list.length(); i++) { | 157 for (var i = 0; i < this._items.length(); i++) { |
| 155 if (this.isItemSelectable(this._list.itemAtIndex(i))) { | 158 if (this.isItemSelectable(this._items.itemAtIndex(i))) { |
| 156 this._list.selectItem(this._list.itemAtIndex(i)); | 159 this._list.selectItem(this._items.itemAtIndex(i)); |
| 157 handled = true; | 160 handled = true; |
| 158 break; | 161 break; |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 break; | 164 break; |
| 162 case 'End': | 165 case 'End': |
| 163 for (var i = this._list.length() - 1; i >= 0; i--) { | 166 for (var i = this._items.length() - 1; i >= 0; i--) { |
| 164 if (this.isItemSelectable(this._list.itemAtIndex(i))) { | 167 if (this.isItemSelectable(this._items.itemAtIndex(i))) { |
| 165 this._list.selectItem(this._list.itemAtIndex(i)); | 168 this._list.selectItem(this._items.itemAtIndex(i)); |
| 166 handled = true; | 169 handled = true; |
| 167 break; | 170 break; |
| 168 } | 171 } |
| 169 } | 172 } |
| 170 break; | 173 break; |
| 171 case 'Escape': | 174 case 'Escape': |
| 172 this._hide(event); | 175 this._hide(event); |
| 173 break; | 176 break; |
| 174 case 'Tab': | 177 case 'Tab': |
| 175 if (!this._glassPane.isShowing()) | 178 if (!this._glassPane.isShowing()) |
| 176 break; | 179 break; |
| 177 this._updateSelectedContext(); | 180 this._updateSelectedContext(); |
| 178 this._hide(event); | 181 this._hide(event); |
| 179 break; | 182 break; |
| 180 case 'Enter': | 183 case 'Enter': |
| 181 if (!this._glassPane.isShowing()) { | 184 if (!this._glassPane.isShowing()) { |
| 182 this._show(event); | 185 this._show(event); |
| 183 break; | 186 break; |
| 184 } | 187 } |
| 185 this._updateSelectedContext(); | 188 this._updateSelectedContext(); |
| 186 this._hide(event); | 189 this._hide(event); |
| 187 break; | 190 break; |
| 188 case ' ': | 191 case ' ': |
| 189 this._show(event); | 192 this._show(event); |
| 190 break; | 193 break; |
| 191 default: | 194 default: |
| 192 if (event.key.length === 1) { | 195 if (event.key.length === 1) { |
| 193 var selectedIndex = this._list.selectedIndex(); | 196 var selectedIndex = this._list.selectedIndex(); |
| 194 var letter = event.key.toUpperCase(); | 197 var letter = event.key.toUpperCase(); |
| 195 for (var i = 0; i < this._list.length(); i++) { | 198 for (var i = 0; i < this._items.length(); i++) { |
| 196 var context = this._list.itemAtIndex((selectedIndex + i + 1) % this.
_list.length()); | 199 var context = this._items.itemAtIndex((selectedIndex + i + 1) % this
._items.length()); |
| 197 if (this._titleFor(context).toUpperCase().startsWith(letter)) { | 200 if (this._titleFor(context).toUpperCase().startsWith(letter)) { |
| 198 this._list.selectItem(context); | 201 this._list.selectItem(context); |
| 199 break; | 202 break; |
| 200 } | 203 } |
| 201 } | 204 } |
| 202 handled = true; | 205 handled = true; |
| 203 } | 206 } |
| 204 break; | 207 break; |
| 205 } | 208 } |
| 206 | 209 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 292 |
| 290 /** | 293 /** |
| 291 * @param {!SDK.ExecutionContext} executionContext | 294 * @param {!SDK.ExecutionContext} executionContext |
| 292 */ | 295 */ |
| 293 _executionContextCreated(executionContext) { | 296 _executionContextCreated(executionContext) { |
| 294 // FIXME(413886): We never want to show execution context for the main threa
d of shadow page in service/shared worker frontend. | 297 // FIXME(413886): We never want to show execution context for the main threa
d of shadow page in service/shared worker frontend. |
| 295 // This check could be removed once we do not send this context to frontend. | 298 // This check could be removed once we do not send this context to frontend. |
| 296 if (!executionContext.target().hasJSCapability()) | 299 if (!executionContext.target().hasJSCapability()) |
| 297 return; | 300 return; |
| 298 | 301 |
| 299 this._list.insertItemWithComparator(executionContext, executionContext.runti
meModel.executionContextComparator()); | 302 this._items.insertItemWithComparator(executionContext, executionContext.runt
imeModel.executionContextComparator()); |
| 300 | 303 |
| 301 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) | 304 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) |
| 302 this._updateSelectionTitle(); | 305 this._updateSelectionTitle(); |
| 303 } | 306 } |
| 304 | 307 |
| 305 /** | 308 /** |
| 306 * @param {!Common.Event} event | 309 * @param {!Common.Event} event |
| 307 */ | 310 */ |
| 308 _onExecutionContextCreated(event) { | 311 _onExecutionContextCreated(event) { |
| 309 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 312 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 310 this._executionContextCreated(executionContext); | 313 this._executionContextCreated(executionContext); |
| 311 this._updateSelectionTitle(); | 314 this._updateSelectionTitle(); |
| 312 this._updateGlasspaneSize(); | 315 this._updateGlasspaneSize(); |
| 313 } | 316 } |
| 314 | 317 |
| 315 /** | 318 /** |
| 316 * @param {!Common.Event} event | 319 * @param {!Common.Event} event |
| 317 */ | 320 */ |
| 318 _onExecutionContextChanged(event) { | 321 _onExecutionContextChanged(event) { |
| 319 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 322 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 320 if (this._list.indexOfItem(executionContext) === -1) | 323 if (this._items.indexOfItem(executionContext) === -1) |
| 321 return; | 324 return; |
| 322 this._executionContextDestroyed(executionContext); | 325 this._executionContextDestroyed(executionContext); |
| 323 this._executionContextCreated(executionContext); | 326 this._executionContextCreated(executionContext); |
| 324 this._updateSelectionTitle(); | 327 this._updateSelectionTitle(); |
| 325 } | 328 } |
| 326 | 329 |
| 327 /** | 330 /** |
| 328 * @param {!SDK.ExecutionContext} executionContext | 331 * @param {!SDK.ExecutionContext} executionContext |
| 329 */ | 332 */ |
| 330 _executionContextDestroyed(executionContext) { | 333 _executionContextDestroyed(executionContext) { |
| 331 if (this._list.indexOfItem(executionContext) === -1) | 334 if (this._items.indexOfItem(executionContext) === -1) |
| 332 return; | 335 return; |
| 333 this._disposeExecutionContextBadge(executionContext); | 336 this._disposeExecutionContextBadge(executionContext); |
| 334 this._list.removeItem(executionContext); | 337 this._items.removeItem(executionContext); |
| 335 this._updateGlasspaneSize(); | 338 this._updateGlasspaneSize(); |
| 336 } | 339 } |
| 337 | 340 |
| 338 /** | 341 /** |
| 339 * @param {!Common.Event} event | 342 * @param {!Common.Event} event |
| 340 */ | 343 */ |
| 341 _onExecutionContextDestroyed(event) { | 344 _onExecutionContextDestroyed(event) { |
| 342 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 345 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 343 this._executionContextDestroyed(executionContext); | 346 this._executionContextDestroyed(executionContext); |
| 344 this._updateSelectionTitle(); | 347 this._updateSelectionTitle(); |
| 345 } | 348 } |
| 346 | 349 |
| 347 /** | 350 /** |
| 348 * @param {!Common.Event} event | 351 * @param {!Common.Event} event |
| 349 */ | 352 */ |
| 350 _executionContextChangedExternally(event) { | 353 _executionContextChangedExternally(event) { |
| 351 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data); | 354 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data); |
| 352 if (!executionContext || this._list.indexOfItem(executionContext) === -1) | 355 if (!executionContext || this._items.indexOfItem(executionContext) === -1) |
| 353 return; | 356 return; |
| 354 this._list.selectItem(executionContext); | 357 this._list.selectItem(executionContext); |
| 355 this._updateSelectedContext(); | 358 this._updateSelectedContext(); |
| 356 } | 359 } |
| 357 | 360 |
| 358 _updateSelectionTitle() { | 361 _updateSelectionTitle() { |
| 359 var executionContext = UI.context.flavor(SDK.ExecutionContext); | 362 var executionContext = UI.context.flavor(SDK.ExecutionContext); |
| 360 if (executionContext) | 363 if (executionContext) |
| 361 this._titleElement.textContent = this._titleFor(executionContext); | 364 this._titleElement.textContent = this._titleFor(executionContext); |
| 362 else | 365 else |
| (...skipping 13 matching lines...) Expand all Loading... |
| 376 var frame = executionContext.frameId && resourceTreeModel && resourceTreeMod
el.frameForId(executionContext.frameId); | 379 var frame = executionContext.frameId && resourceTreeModel && resourceTreeMod
el.frameForId(executionContext.frameId); |
| 377 if (!frame) | 380 if (!frame) |
| 378 return false; | 381 return false; |
| 379 return frame.isMainFrame(); | 382 return frame.isMainFrame(); |
| 380 } | 383 } |
| 381 | 384 |
| 382 /** | 385 /** |
| 383 * @return {boolean} | 386 * @return {boolean} |
| 384 */ | 387 */ |
| 385 _hasTopContext() { | 388 _hasTopContext() { |
| 386 for (var i = 0; i < this._list.length(); i++) { | 389 for (var i = 0; i < this._items.length(); i++) { |
| 387 if (this._isTopContext(this._list.itemAtIndex(i))) | 390 if (this._isTopContext(this._items.itemAtIndex(i))) |
| 388 return true; | 391 return true; |
| 389 } | 392 } |
| 390 return false; | 393 return false; |
| 391 } | 394 } |
| 392 | 395 |
| 393 /** | 396 /** |
| 394 * @override | 397 * @override |
| 395 * @param {!SDK.RuntimeModel} runtimeModel | 398 * @param {!SDK.RuntimeModel} runtimeModel |
| 396 */ | 399 */ |
| 397 modelAdded(runtimeModel) { | 400 modelAdded(runtimeModel) { |
| 398 runtimeModel.executionContexts().forEach(this._executionContextCreated, this
); | 401 runtimeModel.executionContexts().forEach(this._executionContextCreated, this
); |
| 399 } | 402 } |
| 400 | 403 |
| 401 /** | 404 /** |
| 402 * @override | 405 * @override |
| 403 * @param {!SDK.RuntimeModel} runtimeModel | 406 * @param {!SDK.RuntimeModel} runtimeModel |
| 404 */ | 407 */ |
| 405 modelRemoved(runtimeModel) { | 408 modelRemoved(runtimeModel) { |
| 406 for (var i = 0; i < this._list.length(); i++) { | 409 for (var i = 0; i < this._items.length(); i++) { |
| 407 if (this._list.itemAtIndex(i).runtimeModel === runtimeModel) | 410 if (this._items.itemAtIndex(i).runtimeModel === runtimeModel) |
| 408 this._executionContextDestroyed(this._list.itemAtIndex(i)); | 411 this._executionContextDestroyed(this._items.itemAtIndex(i)); |
| 409 } | 412 } |
| 410 } | 413 } |
| 411 | 414 |
| 412 /** | 415 /** |
| 413 * @override | 416 * @override |
| 414 * @param {!SDK.ExecutionContext} item | 417 * @param {!SDK.ExecutionContext} item |
| 415 * @return {!Element} | 418 * @return {!Element} |
| 416 */ | 419 */ |
| 417 createElementForItem(item) { | 420 createElementForItem(item) { |
| 418 var element = createElementWithClass('div', 'context'); | 421 var element = createElementWithClass('div', 'context'); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 var callFrameContext = callFrame && callFrame.script.executionContext(); | 516 var callFrameContext = callFrame && callFrame.script.executionContext(); |
| 514 if (callFrameContext) | 517 if (callFrameContext) |
| 515 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext); | 518 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext); |
| 516 } | 519 } |
| 517 | 520 |
| 518 /** | 521 /** |
| 519 * @param {!Common.Event} event | 522 * @param {!Common.Event} event |
| 520 */ | 523 */ |
| 521 _callFrameSelectedInModel(event) { | 524 _callFrameSelectedInModel(event) { |
| 522 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); | 525 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); |
| 523 for (var i = 0; i < this._list.length(); i++) { | 526 for (var i = 0; i < this._items.length(); i++) { |
| 524 if (this._list.itemAtIndex(i).debuggerModel === debuggerModel) { | 527 var executionContext = this._items.itemAtIndex(i); |
| 525 this._disposeExecutionContextBadge(this._list.itemAtIndex(i)); | 528 if (executionContext.debuggerModel === debuggerModel) { |
| 526 this._list.refreshItemsInRange(i, i + 1); | 529 this._disposeExecutionContextBadge(executionContext); |
| 530 this._list.refreshItem(executionContext); |
| 527 } | 531 } |
| 528 } | 532 } |
| 529 } | 533 } |
| 530 | 534 |
| 531 /** | 535 /** |
| 532 * @param {!Common.Event} event | 536 * @param {!Common.Event} event |
| 533 */ | 537 */ |
| 534 _frameNavigated(event) { | 538 _frameNavigated(event) { |
| 535 var frameId = event.data.id; | 539 var frameId = event.data.id; |
| 536 for (var i = 0; i < this._list.length(); i++) { | 540 for (var i = 0; i < this._items.length(); i++) { |
| 537 if (frameId === this._list.itemAtIndex(i).frameId) { | 541 var executionContext = this._items.itemAtIndex(i); |
| 538 this._disposeExecutionContextBadge(this._list.itemAtIndex(i)); | 542 if (frameId === executionContext.frameId) { |
| 539 this._list.refreshItemsInRange(i, i + 1); | 543 this._disposeExecutionContextBadge(executionContext); |
| 544 this._list.refreshItem(executionContext); |
| 540 } | 545 } |
| 541 } | 546 } |
| 542 } | 547 } |
| 543 }; | 548 }; |
| OLD | NEW |