33// found in the LICENSE file.
44
55import * as Common from '../../core/common/common.js' ;
6+ import * as Platform from '../../core/platform/platform.js' ;
67import * as Root from '../../core/root/root.js' ;
78import * as Trace from '../../models/trace/trace.js' ;
89import type * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js' ;
@@ -25,11 +26,12 @@ import {
2526import { TimingsTrackAppender } from './TimingsTrackAppender.js' ;
2627import * as TimelineUtils from './utils/utils.js' ;
2728
28- export type HighlightedEntryInfo = {
29+ export type PopoverInfo = {
2930 title : string ,
3031 formattedTime : string ,
31- warningElements ?: HTMLSpanElement [ ] ,
32- additionalElement ?: HTMLElement ,
32+ url : string | null ,
33+ warningElements : HTMLSpanElement [ ] ,
34+ additionalElements : HTMLElement [ ] ,
3335} ;
3436
3537let showPostMessageEvents : boolean | undefined ;
@@ -124,9 +126,9 @@ export interface TrackAppender {
124126 */
125127 titleForEvent ?( event : Trace . Types . Events . Event ) : string ;
126128 /**
127- * Returns the info shown when an event in the timeline is hovered .
129+ * Updates the standard popover (AKA tooltip) some appender specific details .
128130 */
129- highlightedEntryInfo ?( event : Trace . Types . Events . Event ) : Partial < HighlightedEntryInfo > ;
131+ setPopoverInfo ?( event : Trace . Types . Events . Event , info : PopoverInfo ) : void ;
130132 /**
131133 * Returns the a callback function to draw an event to overrides the normal rectangle draw operation.
132134 */
@@ -645,47 +647,42 @@ export class CompatibilityTracksAppender {
645647 /**
646648 * Returns the info shown when an event in the timeline is hovered.
647649 */
648- highlightedEntryInfo ( event : Trace . Types . Events . Event , level : number ) : HighlightedEntryInfo {
650+ popoverInfo ( event : Trace . Types . Events . Event , level : number ) : PopoverInfo {
649651 const track = this . #trackForLevel. get ( level ) ;
650652 if ( ! track ) {
651653 throw new Error ( 'Track not found for level' ) ;
652654 }
653655
654- // Add any warnings information to the tooltip. Done here to avoid duplicating this call in every appender.
655- // By doing this here, we ensure that any warnings that are
656- // added to the WarningsHandler are automatically used and added
657- // to the tooltip.
658- const warningElements : HTMLSpanElement [ ] =
659- TimelineComponents . DetailsView . buildWarningElementsForEvent ( event , this . #parsedTrace) ;
660-
661- let title = this . titleForEvent ( event , level ) ;
662- let formattedTime = getFormattedTime ( event . dur ) ;
663- let additionalElement ;
664-
665- // If the track defines a custom highlight, call it and use its values.
666- if ( track . highlightedEntryInfo ) {
667- const {
668- title : customTitle ,
669- formattedTime : customFormattedTime ,
670- warningElements : extraWarningElements ,
671- additionalElement : element ,
672- } = track . highlightedEntryInfo ( event ) ;
673- if ( customTitle ) {
674- title = customTitle ;
675- }
676- if ( customFormattedTime ) {
677- formattedTime = customFormattedTime ;
678- }
679- if ( extraWarningElements ) {
680- warningElements . push ( ...extraWarningElements ) ;
681- }
682- additionalElement = element ;
683- }
684- return {
685- title,
686- formattedTime,
687- warningElements,
688- additionalElement,
656+ // Defaults here, though tracks may chose to redefine title/formattedTime
657+ const info : PopoverInfo = {
658+ title : this . titleForEvent ( event , level ) ,
659+ formattedTime : getFormattedTime ( event . dur ) ,
660+ warningElements : TimelineComponents . DetailsView . buildWarningElementsForEvent ( event , this . #parsedTrace) ,
661+ additionalElements : [ ] ,
662+ url : null ,
689663 } ;
664+
665+ // If the track defines its own popoverInfo(), it'll update values within
666+ if ( track . setPopoverInfo ) {
667+ track . setPopoverInfo ( event , info ) ;
668+ }
669+
670+ // If there's a url associated, add into additionalElements
671+ const url = URL . parse (
672+ info . url ?? TimelineUtils . SourceMapsResolver . SourceMapsResolver . resolvedURLForEntry ( this . #parsedTrace, event ) ??
673+ '' ) ;
674+ if ( url ) {
675+ const MAX_PATH_LENGTH = 45 ;
676+ const MAX_ORIGIN_LENGTH = 30 ;
677+ const path = Platform . StringUtilities . trimMiddle ( url . href . replace ( url . origin , '' ) , MAX_PATH_LENGTH ) ;
678+ const origin =
679+ Platform . StringUtilities . trimEndWithMaxLength ( url . origin . replace ( 'https://' , '' ) , MAX_ORIGIN_LENGTH ) ;
680+ const urlElems = document . createElement ( 'div' ) ;
681+ urlElems . createChild ( 'span' , 'popoverinfo-url-path' ) . textContent = path ;
682+ urlElems . createChild ( 'span' , 'popoverinfo-url-origin' ) . textContent = `(${ origin } )` ;
683+ info . additionalElements . push ( urlElems ) ;
684+ }
685+
686+ return info ;
690687 }
691688}
0 commit comments