Skip to content
Permalink
Browse files
Inspector window goes into an inactive state when extension tab is se…
…lected.

https://bugs.webkit.org/show_bug.cgi?id=241652
rdar://91768323

Reviewed by Devin Rousso.

* Source/WebInspectorUI/UserInterface/Base/Main.js:
(WI.contentLoaded): Update event listeners to use a single _updateWindowInactiveState
and listen to visibilitychange.
(WI._updateWindowInactiveState): Combined from WI._windowFocused and WI._windowBlurred.
Use document.hasFocus() to check for an active window, which works for child frames too.
When an iframe is the active element, we will not get any more focus or blur events for
the main window, so use a 250ms timeout to keep checking while the iframe is focused.

Canonical link: https://commits.webkit.org/251645@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
xeenon committed Jun 17, 2022
1 parent 898d71c commit 43ca250a881e0a0c30ecd09493d5cf73f1a28ebe
Showing 1 changed file with 11 additions and 14 deletions.
@@ -215,8 +215,9 @@ WI.contentLoaded = function()
document.addEventListener("dragover", WI._handleDragOver);
document.addEventListener("focus", WI._focusChanged, true);

window.addEventListener("focus", WI._windowFocused);
window.addEventListener("blur", WI._windowBlurred);
window.addEventListener("focus", WI._updateWindowInactiveState);
window.addEventListener("blur", WI._updateWindowInactiveState);
window.addEventListener("visibilitychange", WI._updateWindowInactiveState);
window.addEventListener("resize", WI._windowResized);
window.addEventListener("keydown", WI._windowKeyDown);
window.addEventListener("keyup", WI._windowKeyUp);
@@ -1821,22 +1822,18 @@ WI._saveCookieForOpenTabs = function()
}
};

WI._windowFocused = function(event)
WI._updateWindowInactiveState = function(event)
{
if (event.target.document.nodeType !== Node.DOCUMENT_NODE)
return;

// FIXME: We should use the :window-inactive pseudo class once https://webkit.org/b/38927 is fixed.
document.body.classList.remove(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive");
};

WI._windowBlurred = function(event)
{
if (event.target.document.nodeType !== Node.DOCUMENT_NODE)
return;
if (document.activeElement?.tagName === "IFRAME") {
// An active iframe means an extension tab is active and we can't tell when the window blurs due to cross-origin restrictions.
// In this case we need to keep checking to know if the window loses focus since there is no event we can use.
setTimeout(WI._updateWindowInactiveState, 250);
}

// FIXME: We should use the :window-inactive pseudo class once https://webkit.org/b/38927 is fixed.
document.body.classList.add(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive");
let inactive = !document.hasFocus();
document.body.classList.toggle(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive", inactive);
};

WI._windowResized = function(event)

0 comments on commit 43ca250

Please sign in to comment.