Title: [295640] trunk/Source/WebInspectorUI/UserInterface/Base/Main.js
Revision
295640
Author
timo...@apple.com
Date
2022-06-17 11:03:22 -0700 (Fri, 17 Jun 2022)

Log Message

Inspector window goes into an inactive state when extension tab is selected.
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

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (295639 => 295640)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2022-06-17 17:42:19 UTC (rev 295639)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2022-06-17 18:03:22 UTC (rev 295640)
@@ -215,8 +215,9 @@
     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._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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to