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