Skip to content

Commit f4c36fa

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[VE] Fix the debugPopover overflowing viewport
While trying to use the new debugger, I couldn't see some of the message under certain circumstances. Bug: 352484135 Change-Id: Ied8c76ebd6dab820705c837320b0b5ac8458ad15 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6182127 Reviewed-by: Danil Somsikov <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]> Commit-Queue: Danil Somsikov <[email protected]>
1 parent e33bb5d commit f4c36fa

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

front_end/ui/visual_logging/Debugging.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {getLoggingState, type LoggingState} from './LoggingState.js';
1010

1111
let veDebuggingEnabled = false;
1212
let debugPopover: HTMLElement|null = null;
13-
let hightlightedElement: HTMLElement|null = null;
13+
let highlightedElement: HTMLElement|null = null;
1414
const nonDomDebugElements = new WeakMap<Loggable, HTMLElement>();
1515
let onInspect: ((query: string) => void)|undefined = undefined;
1616

17-
export function setVeDebuggingEnabled(enabled: boolean, inpsect?: (query: string) => void): void {
17+
export function setVeDebuggingEnabled(enabled: boolean, inspect?: (query: string) => void): void {
1818
veDebuggingEnabled = enabled;
1919
if (enabled && !debugPopover) {
2020
debugPopover = document.createElement('div');
@@ -27,10 +27,10 @@ export function setVeDebuggingEnabled(enabled: boolean, inpsect?: (query: string
2727
debugPopover.style.zIndex = '100000';
2828
document.body.appendChild(debugPopover);
2929
}
30-
onInspect = inpsect;
31-
if (!enabled && hightlightedElement) {
32-
hightlightedElement.style.backgroundColor = '';
33-
hightlightedElement.style.outline = '';
30+
onInspect = inspect;
31+
if (!enabled && highlightedElement) {
32+
highlightedElement.style.backgroundColor = '';
33+
highlightedElement.style.outline = '';
3434
}
3535
}
3636

@@ -53,12 +53,33 @@ function showDebugPopover(content: string, rect?: DOMRect): void {
5353
if (!debugPopover) {
5454
return;
5555
}
56-
if (rect) {
57-
debugPopover.style.left = `${rect.left}px`;
58-
debugPopover.style.top = `${rect.bottom + 8}px`;
59-
}
56+
57+
// Set these first so we get the correct information from
58+
// getBoundingClientRect
6059
debugPopover.style.display = 'block';
6160
debugPopover.textContent = content;
61+
62+
if (rect) {
63+
const debugPopoverReact = debugPopover.getBoundingClientRect();
64+
65+
// If there is no space under the element
66+
// render render it above the element
67+
if (window.innerHeight < rect.bottom + debugPopoverReact.height + 8) {
68+
debugPopover.style.top = `${rect.top - debugPopoverReact.height - 8}px`;
69+
} else {
70+
debugPopover.style.top = `${rect.bottom + 8}px`;
71+
}
72+
73+
// If the element will go outside the viewport on the right
74+
// render it with it's and at the viewport end.
75+
if (window.innerWidth < rect.left + debugPopoverReact.width) {
76+
debugPopover.style.right = '0px';
77+
debugPopover.style.left = '';
78+
} else {
79+
debugPopover.style.right = '';
80+
debugPopover.style.left = `${rect.left}px`;
81+
}
82+
}
6283
}
6384

6485
function processElementForDebugging(element: HTMLElement, loggingState: LoggingState): void {
@@ -69,7 +90,7 @@ function processElementForDebugging(element: HTMLElement, loggingState: LoggingS
6990
}
7091
} else {
7192
element.addEventListener('mousedown', event => {
72-
if (event.currentTarget === hightlightedElement && onInspect && debugPopover && veDebuggingEnabled) {
93+
if (event.currentTarget === highlightedElement && onInspect && debugPopover && veDebuggingEnabled) {
7394
onInspect(debugPopover.textContent || '');
7495
event.stopImmediatePropagation();
7596
event.preventDefault();
@@ -79,13 +100,13 @@ function processElementForDebugging(element: HTMLElement, loggingState: LoggingS
79100
if (!veDebuggingEnabled) {
80101
return;
81102
}
82-
if (hightlightedElement) {
83-
hightlightedElement.style.backgroundColor = '';
84-
hightlightedElement.style.outline = '';
103+
if (highlightedElement) {
104+
highlightedElement.style.backgroundColor = '';
105+
highlightedElement.style.outline = '';
85106
}
86107
element.style.backgroundColor = '#A7C3E4';
87108
element.style.outline = 'dashed 1px #7327C6';
88-
hightlightedElement = element;
109+
highlightedElement = element;
89110
assertNotNullOrUndefined(debugPopover);
90111
const pathToRoot = [loggingState];
91112
let ancestor = loggingState.parent;
@@ -458,7 +479,7 @@ DEFINE MACRO Interaction STRUCT(${
458479
])});
459480
DEFINE MACRO Entry STRUCT($1, $2 AS interactions, $3 AS time);
460481
461-
// This fake entry put first fixes nested struct fiels names being lost
482+
// This fake entry put first fixes nested struct fields names being lost
462483
DEFINE MACRO FakeVeFields $VeFields("", $NullString, 0, 0, 0, $1);
463484
DEFINE MACRO FakeVe STRUCT($FakeVeFields($1));
464485
DEFINE MACRO FakeEntry $Entry($FakeVeFields($FakeVe($FakeVe($FakeVe($FakeVe($FakeVe($FakeVe($FakeVe(null)))))))), ([]), 0);
@@ -606,7 +627,7 @@ export function processStartLoggingForDebugging(): void {
606627

607628
// Compares the 'actual' log entry against the 'expected'.
608629
// For impressions events to match, all expected impressions need to be present
609-
// in the actual event. Unexected impressions in the actual event are ignored.
630+
// in the actual event. Unexpected impressions in the actual event are ignored.
610631
// Interaction events need to match exactly.
611632
function compareVeEvents(actual: TestLogEntry, expected: TestLogEntry): boolean {
612633
if ('interaction' in expected && 'interaction' in actual) {

0 commit comments

Comments
 (0)