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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js

Issue 2889833003: DevTools: Show badges instead of products in ConsoleContextSelector (Closed)
Patch Set: Don't use container Created 3 years, 7 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
OLDNEW
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 this._productRegistry = null;
15 14
16 ProductRegistry.instance().then(registry => { 15 /** @type {!Map<!SDK.ExecutionContext, !ProductRegistry.BadgePool>} */
17 this._productRegistry = registry; 16 this._badgePoolForExecutionContext = new Map();
18 this._list.refreshAllItems(); 17
19 });
20 this._toolbarItem.element.classList.add('toolbar-has-dropdown'); 18 this._toolbarItem.element.classList.add('toolbar-has-dropdown');
21 this._toolbarItem.element.tabIndex = 0; 19 this._toolbarItem.element.tabIndex = 0;
22 this._glassPane = new UI.GlassPane(); 20 this._glassPane = new UI.GlassPane();
23 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin); 21 this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin);
24 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); 22 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom);
25 this._glassPane.setOutsideClickCallback(this._hide.bind(this)); 23 this._glassPane.setOutsideClickCallback(this._hide.bind(this));
26 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior. BlockedByGlassPane); 24 this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior. BlockedByGlassPane);
27 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); 25 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems);
28 this._list.element.classList.add('context-list'); 26 this._list.element.classList.add('context-list');
29 this._list.element.tabIndex = -1; 27 this._list.element.tabIndex = -1;
30 this._rowHeight = 34; 28 this._rowHeight = 36;
31 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c onsoleContextSelector.css') 29 UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/c onsoleContextSelector.css')
32 .appendChild(this._list.element); 30 .appendChild(this._list.element);
33 31
34 this._listWasShowing200msAgo = false; 32 this._listWasShowing200msAgo = false;
35 this._toolbarItem.element.addEventListener('mousedown', event => { 33 this._toolbarItem.element.addEventListener('mousedown', event => {
36 if (this._listWasShowing200msAgo) 34 if (this._listWasShowing200msAgo)
37 this._hide(event); 35 this._hide(event);
38 else 36 else
39 this._show(event); 37 this._show(event);
40 }, false); 38 }, false);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 79
82 /** 80 /**
83 * @param {!Event} event 81 * @param {!Event} event
84 */ 82 */
85 _show(event) { 83 _show(event) {
86 if (this._glassPane.isShowing()) 84 if (this._glassPane.isShowing())
87 return; 85 return;
88 this._glassPane.setContentAnchorBox(this._toolbarItem.element.boxInWindow()) ; 86 this._glassPane.setContentAnchorBox(this._toolbarItem.element.boxInWindow()) ;
89 this._glassPane.show(/** @type {!Document} **/ (this._toolbarItem.element.ow nerDocument)); 87 this._glassPane.show(/** @type {!Document} **/ (this._toolbarItem.element.ow nerDocument));
90 this._updateGlasspaneSize(); 88 this._updateGlasspaneSize();
91 var selectedItem = this._list.selectedItem(); 89 var selectedContext = UI.context.flavor(SDK.ExecutionContext);
92 if (selectedItem) 90 if (selectedContext) {
93 this._list.scrollItemIntoView(selectedItem, true); 91 this._list.selectItem(selectedContext);
92 this._list.scrollItemIntoView(selectedContext, true);
93 }
94 this._toolbarItem.element.focus(); 94 this._toolbarItem.element.focus();
95 event.consume(true); 95 event.consume(true);
96 setTimeout(() => this._listWasShowing200msAgo = true, 200); 96 setTimeout(() => this._listWasShowing200msAgo = true, 200);
97 } 97 }
98 98
99 _updateGlasspaneSize() { 99 _updateGlasspaneSize() {
100 var maxHeight = this._rowHeight * (Math.min(this._list.length(), 9)); 100 var maxHeight = this._rowHeight * (Math.min(this._list.length(), 9));
101 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight)); 101 this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight));
102 this._list.viewportResized(); 102 this._list.viewportResized();
103 } 103 }
104 104
105 /** 105 /**
106 * @param {!Event} event 106 * @param {!Event} event
107 */ 107 */
108 _hide(event) { 108 _hide(event) {
109 setTimeout(() => this._listWasShowing200msAgo = false, 200); 109 setTimeout(() => this._listWasShowing200msAgo = false, 200);
110 this._glassPane.hide(); 110 this._glassPane.hide();
111 SDK.OverlayModel.hideDOMNodeHighlight(); 111 SDK.OverlayModel.hideDOMNodeHighlight();
112 var selectedContext = UI.context.flavor(SDK.ExecutionContext);
113 if (selectedContext)
114 this._list.selectItem(selectedContext);
115 event.consume(true); 112 event.consume(true);
116 } 113 }
117 114
118 /** 115 /**
119 * @param {!Event} event 116 * @param {!Event} event
120 */ 117 */
121 _onKeyDown(event) { 118 _onKeyDown(event) {
122 var handled = false; 119 var handled = false;
123 switch (event.key) { 120 switch (event.key) {
124 case 'ArrowUp': 121 case 'ArrowUp':
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 break; 256 break;
260 } 257 }
261 target = target.parentTarget(); 258 target = target.parentTarget();
262 } 259 }
263 depth += targetDepth; 260 depth += targetDepth;
264 return depth; 261 return depth;
265 } 262 }
266 263
267 /** 264 /**
268 * @param {!SDK.ExecutionContext} executionContext 265 * @param {!SDK.ExecutionContext} executionContext
266 * @return {?Element}
267 */
268 _badgeFor(executionContext) {
269 if (!executionContext.frameId || !executionContext.isDefault)
270 return null;
271 var resourceTreeModel = executionContext.target().model(SDK.ResourceTreeMode l);
272 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionConte xt.frameId);
273 if (!frame)
274 return null;
275 var badgePool = new ProductRegistry.BadgePool();
276 this._badgePoolForExecutionContext.set(executionContext, badgePool);
277 return badgePool.badgeForFrame(frame);
278 }
279
280 /**
281 * @param {!SDK.ExecutionContext} executionContext
282 */
283 _disposeExecutionContextBadge(executionContext) {
284 var badgePool = this._badgePoolForExecutionContext.get(executionContext);
285 if (!badgePool)
286 return;
287 badgePool.reset();
288 this._badgePoolForExecutionContext.delete(executionContext);
289 }
290
291 /**
292 * @param {!SDK.ExecutionContext} executionContext
269 */ 293 */
270 _executionContextCreated(executionContext) { 294 _executionContextCreated(executionContext) {
271 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend. 295 // FIXME(413886): We never want to show execution context for the main threa d of shadow page in service/shared worker frontend.
272 // This check could be removed once we do not send this context to frontend. 296 // This check could be removed once we do not send this context to frontend.
273 if (!executionContext.target().hasJSCapability()) 297 if (!executionContext.target().hasJSCapability())
274 return; 298 return;
275 299
276 this._list.insertItemWithComparator(executionContext, executionContext.runti meModel.executionContextComparator()); 300 this._list.insertItemWithComparator(executionContext, executionContext.runti meModel.executionContextComparator());
277 301
278 if (executionContext === UI.context.flavor(SDK.ExecutionContext)) { 302 if (executionContext === UI.context.flavor(SDK.ExecutionContext))
279 this._list.selectItem(executionContext); 303 this._updateSelectionTitle();
280 this._updateSelectedContext();
281 }
282 } 304 }
283 305
284 /** 306 /**
285 * @param {!Common.Event} event 307 * @param {!Common.Event} event
286 */ 308 */
287 _onExecutionContextCreated(event) { 309 _onExecutionContextCreated(event) {
288 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 310 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
289 this._executionContextCreated(executionContext); 311 this._executionContextCreated(executionContext);
290 this._updateSelectionWarning(); 312 this._updateSelectionTitle();
291 this._updateGlasspaneSize(); 313 this._updateGlasspaneSize();
292 } 314 }
293 315
294 /** 316 /**
295 * @param {!Common.Event} event 317 * @param {!Common.Event} event
296 */ 318 */
297 _onExecutionContextChanged(event) { 319 _onExecutionContextChanged(event) {
298 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
299 if (this._list.indexOfItem(executionContext) === -1) 321 if (this._list.indexOfItem(executionContext) === -1)
300 return; 322 return;
301 this._executionContextDestroyed(executionContext); 323 this._executionContextDestroyed(executionContext);
302 this._executionContextCreated(executionContext); 324 this._executionContextCreated(executionContext);
303 this._updateSelectionWarning(); 325 this._updateSelectionTitle();
304 } 326 }
305 327
306 /** 328 /**
307 * @param {!SDK.ExecutionContext} executionContext 329 * @param {!SDK.ExecutionContext} executionContext
308 */ 330 */
309 _executionContextDestroyed(executionContext) { 331 _executionContextDestroyed(executionContext) {
310 if (this._list.indexOfItem(executionContext) === -1) 332 if (this._list.indexOfItem(executionContext) === -1)
311 return; 333 return;
334 this._disposeExecutionContextBadge(executionContext);
312 this._list.removeItem(executionContext); 335 this._list.removeItem(executionContext);
313 this._updateGlasspaneSize(); 336 this._updateGlasspaneSize();
314 } 337 }
315 338
316 /** 339 /**
317 * @param {!Common.Event} event 340 * @param {!Common.Event} event
318 */ 341 */
319 _onExecutionContextDestroyed(event) { 342 _onExecutionContextDestroyed(event) {
320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 343 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
321 this._executionContextDestroyed(executionContext); 344 this._executionContextDestroyed(executionContext);
322 this._updateSelectionWarning(); 345 this._updateSelectionTitle();
323 } 346 }
324 347
325 /** 348 /**
326 * @param {!Common.Event} event 349 * @param {!Common.Event} event
327 */ 350 */
328 _executionContextChangedExternally(event) { 351 _executionContextChangedExternally(event) {
329 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data); 352 var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data);
330 if (!executionContext || this._list.indexOfItem(executionContext) === -1) 353 if (!executionContext || this._list.indexOfItem(executionContext) === -1)
331 return; 354 return;
332 this._list.selectItem(executionContext); 355 this._list.selectItem(executionContext);
333 this._updateSelectedContext(); 356 this._updateSelectedContext();
334 } 357 }
335 358
336 _updateSelectionWarning() { 359 _updateSelectionTitle() {
337 var executionContext = UI.context.flavor(SDK.ExecutionContext); 360 var executionContext = UI.context.flavor(SDK.ExecutionContext);
361 if (executionContext)
362 this._titleElement.textContent = this._titleFor(executionContext);
363 else
364 this._titleElement.textContent = '';
338 this._toolbarItem.element.classList.toggle( 365 this._toolbarItem.element.classList.toggle(
339 'warning', !this._isTopContext(executionContext) && this._hasTopContext( )); 366 'warning', !this._isTopContext(executionContext) && this._hasTopContext( ));
340 } 367 }
341 368
342 /** 369 /**
343 * @param {?SDK.ExecutionContext} executionContext 370 * @param {?SDK.ExecutionContext} executionContext
344 * @return {boolean} 371 * @return {boolean}
345 */ 372 */
346 _isTopContext(executionContext) { 373 _isTopContext(executionContext) {
347 if (!executionContext || !executionContext.isDefault) 374 if (!executionContext || !executionContext.isDefault)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 411 }
385 412
386 /** 413 /**
387 * @override 414 * @override
388 * @param {!SDK.ExecutionContext} item 415 * @param {!SDK.ExecutionContext} item
389 * @return {!Element} 416 * @return {!Element}
390 */ 417 */
391 createElementForItem(item) { 418 createElementForItem(item) {
392 var element = createElementWithClass('div', 'context'); 419 var element = createElementWithClass('div', 'context');
393 element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px'; 420 element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px';
394 element.createChild('div', 'title').textContent = this._titleFor(item).trimE nd(100); 421 // var titleArea = element.createChild('div', 'title-area');
395 element.createChild('div', 'subtitle').textContent = this._subtitleFor(item) ; 422 var title = element.createChild('div', 'title');
423 title.createTextChild(this._titleFor(item).trimEnd(100));
424 var subTitle = element.createChild('div', 'subtitle');
425 var badgeElement = this._badgeFor(item);
426 if (badgeElement) {
427 badgeElement.classList.add('badge');
428 subTitle.appendChild(badgeElement);
429 }
430 subTitle.createTextChild(this._subtitleFor(item));
396 element.addEventListener('mousemove', e => { 431 element.addEventListener('mousemove', e => {
397 if ((e.movementX || e.movementY) && this.isItemSelectable(item)) 432 if ((e.movementX || e.movementY) && this.isItemSelectable(item))
398 this._list.selectItem(item, false, /* Don't scroll */ true); 433 this._list.selectItem(item, false, /* Don't scroll */ true);
399 }); 434 });
400 element.classList.toggle('disabled', !this.isItemSelectable(item)); 435 element.classList.toggle('disabled', !this.isItemSelectable(item));
401 return element; 436 return element;
402 } 437 }
403 438
404 /** 439 /**
405 * @param {!SDK.ExecutionContext} executionContext 440 * @param {!SDK.ExecutionContext} executionContext
406 * @return {string} 441 * @return {string}
407 */ 442 */
408 _subtitleFor(executionContext) { 443 _subtitleFor(executionContext) {
409 var target = executionContext.target(); 444 var target = executionContext.target();
410 if (executionContext.frameId) { 445 if (executionContext.frameId) {
411 var resourceTreeModel = target.model(SDK.ResourceTreeModel); 446 var resourceTreeModel = target.model(SDK.ResourceTreeModel);
412 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionCon text.frameId); 447 var frame = resourceTreeModel && resourceTreeModel.frameForId(executionCon text.frameId);
413 } 448 }
414 if (executionContext.origin.startsWith('chrome-extension://')) 449 if (executionContext.origin.startsWith('chrome-extension://'))
415 return Common.UIString('Extension'); 450 return Common.UIString('Extension');
416 if (!frame || !frame.parentFrame || frame.parentFrame.securityOrigin !== exe cutionContext.origin) { 451 if (!frame || !frame.parentFrame || frame.parentFrame.securityOrigin !== exe cutionContext.origin) {
417 var url = executionContext.origin.asParsedURL(); 452 var url = executionContext.origin.asParsedURL();
418 if (url) { 453 if (url)
419 if (this._productRegistry) {
420 var product = this._productRegistry.nameForUrl(url);
421 if (product)
422 return product;
423 }
424 return url.domain(); 454 return url.domain();
425 }
426 } 455 }
427 456
428 if (frame) { 457 if (frame) {
429 var callFrame = frame.findCreationCallFrame(callFrame => !!callFrame.url); 458 var callFrame = frame.findCreationCallFrame(callFrame => !!callFrame.url);
430 if (callFrame) { 459 if (callFrame)
431 var url = new Common.ParsedURL(callFrame.url); 460 return new Common.ParsedURL(callFrame.url).domain();
432 if (this._productRegistry) { 461 return Common.UIString('IFrame');
433 var product = this._productRegistry.nameForUrl(url);
434 if (product)
435 return product;
436 }
437 return url.domain();
438 }
439 } 462 }
440 return ''; 463 return '';
441 } 464 }
442 465
443 /** 466 /**
444 * @override 467 * @override
445 * @param {!SDK.ExecutionContext} item 468 * @param {!SDK.ExecutionContext} item
446 * @return {number} 469 * @return {number}
447 */ 470 */
448 heightForItem(item) { 471 heightForItem(item) {
449 return 0; 472 return this._rowHeight;
450 } 473 }
451 474
452 /** 475 /**
453 * @override 476 * @override
454 * @param {!SDK.ExecutionContext} item 477 * @param {!SDK.ExecutionContext} item
455 * @return {boolean} 478 * @return {boolean}
456 */ 479 */
457 isItemSelectable(item) { 480 isItemSelectable(item) {
458 var callFrame = item.debuggerModel.selectedCallFrame(); 481 var callFrame = item.debuggerModel.selectedCallFrame();
459 var callFrameContext = callFrame && callFrame.script.executionContext(); 482 var callFrameContext = callFrame && callFrame.script.executionContext();
(...skipping 15 matching lines...) Expand all
475 SDK.OverlayModel.hideDOMNodeHighlight(); 498 SDK.OverlayModel.hideDOMNodeHighlight();
476 if (to && to.frameId) { 499 if (to && to.frameId) {
477 var resourceTreeModel = to.target().model(SDK.ResourceTreeModel); 500 var resourceTreeModel = to.target().model(SDK.ResourceTreeModel);
478 if (resourceTreeModel) 501 if (resourceTreeModel)
479 resourceTreeModel.domModel().overlayModel().highlightFrame(to.frameId); 502 resourceTreeModel.domModel().overlayModel().highlightFrame(to.frameId);
480 } 503 }
481 } 504 }
482 505
483 _updateSelectedContext() { 506 _updateSelectedContext() {
484 var context = this._list.selectedItem(); 507 var context = this._list.selectedItem();
485 if (context)
486 this._titleElement.textContent = this._titleFor(context);
487 else
488 this._titleElement.textContent = '';
489 UI.context.setFlavor(SDK.ExecutionContext, context); 508 UI.context.setFlavor(SDK.ExecutionContext, context);
490 this._updateSelectionWarning(); 509 this._updateSelectionTitle();
491 } 510 }
492 511
493 _callFrameSelectedInUI() { 512 _callFrameSelectedInUI() {
494 var callFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame); 513 var callFrame = UI.context.flavor(SDK.DebuggerModel.CallFrame);
495 var callFrameContext = callFrame && callFrame.script.executionContext(); 514 var callFrameContext = callFrame && callFrame.script.executionContext();
496 if (callFrameContext) 515 if (callFrameContext)
497 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext); 516 UI.context.setFlavor(SDK.ExecutionContext, callFrameContext);
498 } 517 }
499 518
500 /** 519 /**
501 * @param {!Common.Event} event 520 * @param {!Common.Event} event
502 */ 521 */
503 _callFrameSelectedInModel(event) { 522 _callFrameSelectedInModel(event) {
504 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data); 523 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
505 for (var i = 0; i < this._list.length(); i++) { 524 for (var i = 0; i < this._list.length(); i++) {
506 if (this._list.itemAtIndex(i).debuggerModel === debuggerModel) 525 if (this._list.itemAtIndex(i).debuggerModel === debuggerModel) {
526 this._disposeExecutionContextBadge(this._list.itemAtIndex(i));
507 this._list.refreshItemsInRange(i, i + 1); 527 this._list.refreshItemsInRange(i, i + 1);
528 }
508 } 529 }
509 } 530 }
510 531
511 /** 532 /**
512 * @param {!Common.Event} event 533 * @param {!Common.Event} event
513 */ 534 */
514 _frameNavigated(event) { 535 _frameNavigated(event) {
515 var frameId = event.data.id; 536 var frameId = event.data.id;
516 for (var i = 0; i < this._list.length(); i++) { 537 for (var i = 0; i < this._list.length(); i++) {
517 if (frameId === this._list.itemAtIndex(i).frameId) 538 if (frameId === this._list.itemAtIndex(i).frameId) {
539 this._disposeExecutionContextBadge(this._list.itemAtIndex(i));
518 this._list.refreshItemsInRange(i, i + 1); 540 this._list.refreshItemsInRange(i, i + 1);
541 }
519 } 542 }
520 } 543 }
521 }; 544 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698