@@ -68,8 +68,8 @@ export class Highlighting {
6868 readonly #nodesForMatches = new Map < SDK . CSSPropertyParser . Match , Node [ ] [ ] > ( ) ;
6969 readonly #matchesForNodes = new Map < Node , SDK . CSSPropertyParser . Match [ ] > ( ) ;
7070 readonly #registry: Highlight ;
71- readonly #boundOnEnter: ( ev : MouseEvent ) => void ;
72- readonly #boundOnExit: ( ev : MouseEvent ) => void ;
71+ readonly #boundOnEnter: ( e : Event ) => void ;
72+ readonly #boundOnExit: ( e : Event ) => void ;
7373
7474 constructor ( ) {
7575 const registry = CSS . highlights . get ( Highlighting . REGISTRY_NAME ) ;
@@ -100,11 +100,14 @@ export class Highlighting {
100100 if ( node instanceof HTMLElement ) {
101101 node . onmouseenter = this . #boundOnEnter;
102102 node . onmouseleave = this . #boundOnExit;
103+ node . onfocus = this . #boundOnEnter;
104+ node . onblur = this . #boundOnExit;
105+ node . tabIndex = 0 ;
103106 }
104107 }
105108 }
106109
107- * #nodeRangesHitByMouseEvent( e : MouseEvent ) : Generator < Node [ ] > {
110+ * #nodeRangesHitByMouseEvent( e : Event ) : Generator < Node [ ] > {
108111 for ( const node of e . composedPath ( ) ) {
109112 const matches = this . #matchesForNodes. get ( node as Node ) ;
110113 if ( matches ) {
@@ -116,15 +119,19 @@ export class Highlighting {
116119 }
117120 }
118121
119- #onEnter( e : MouseEvent ) : void {
122+ #onEnter( e : Event ) : void {
120123 this . #registry. clear ( ) ;
121124 this . #activeHighlights. push ( [ ] ) ;
122125 for ( const nodeRange of this . #nodeRangesHitByMouseEvent( e ) ) {
123126 const range = new Range ( ) ;
124- range . setStartBefore ( nodeRange [ 0 ] ) ;
125- range . setEndAfter ( nodeRange [ nodeRange . length - 1 ] ) ;
126- this . #activeHighlights[ this . #activeHighlights. length - 1 ] . push ( range ) ;
127- this . #registry. add ( range ) ;
127+ const begin = nodeRange [ 0 ] ;
128+ const end = nodeRange [ nodeRange . length - 1 ] ;
129+ if ( begin . parentNode && end . parentNode ) {
130+ range . setStartBefore ( begin ) ;
131+ range . setEndAfter ( end ) ;
132+ this . #activeHighlights[ this . #activeHighlights. length - 1 ] . push ( range ) ;
133+ this . #registry. add ( range ) ;
134+ }
128135 }
129136 }
130137
@@ -413,10 +420,19 @@ export class Renderer extends SDK.CSSPropertyParser.TreeWalker {
413420 } ) } `) ;
414421 UI . ARIAUtils . setLabel ( valueElement , i18nString ( UIStrings . cssPropertyValue , { PH1 : property . value } ) ) ;
415422 valueElement . className = 'value' ;
423+ const { nodes, cssControls} = this . renderValueNodes ( property , matchedResult , renderers , tracing ) ;
424+ nodes . forEach ( node => valueElement . appendChild ( node ) ) ;
425+ valueElement . normalize ( ) ;
426+ return { valueElement, cssControls} ;
427+ }
416428
429+ static renderValueNodes (
430+ property : SDK . CSSProperty . CSSProperty | { name : string , value : string } ,
431+ matchedResult : SDK . CSSPropertyParser . BottomUpTreeMatching | null ,
432+ renderers : Array < MatchRenderer < SDK . CSSPropertyParser . Match > > ,
433+ tracing ?: TracingContext ) : { nodes : Node [ ] , cssControls : SDK . CSSPropertyParser . CSSControlMap } {
417434 if ( ! matchedResult ) {
418- valueElement . appendChild ( document . createTextNode ( property . value ) ) ;
419- return { valueElement, cssControls : new Map ( ) } ;
435+ return { nodes : [ document . createTextNode ( property . value ) ] , cssControls : new Map ( ) } ;
420436 }
421437 const rendererMap = new Map <
422438 Platform . Constructor . Constructor < SDK . CSSPropertyParser . Match > , MatchRenderer < SDK . CSSPropertyParser . Match > > ( ) ;
@@ -427,10 +443,7 @@ export class Renderer extends SDK.CSSPropertyParser.TreeWalker {
427443 const context = new RenderingContext (
428444 matchedResult . ast , property instanceof SDK . CSSProperty . CSSProperty ? property : null , rendererMap ,
429445 matchedResult , undefined , { } , tracing ) ;
430- const { nodes, cssControls} = Renderer . render ( [ matchedResult . ast . tree , ...matchedResult . ast . trailingNodes ] , context ) ;
431- nodes . forEach ( node => valueElement . appendChild ( node ) ) ;
432- valueElement . normalize ( ) ;
433- return { valueElement, cssControls} ;
446+ return Renderer . render ( [ matchedResult . ast . tree , ...matchedResult . ast . trailingNodes ] , context ) ;
434447 }
435448}
436449
0 commit comments