Web Inspector: switching tabs should re-focus the previously focused element
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Nov 2019 01:27:14 +0000 (01:27 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Nov 2019 01:27:14 +0000 (01:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203744

Reviewed by Brian Burg.

* UserInterface/Views/TabBrowser.js:
(WI.TabBrowser.prototype._tabBarItemSelected):
(WI.TabBrowser.prototype._saveFocusedNodeForTabContentView): Added.
(WI.TabBrowser.prototype._restoreFocusedNodeForTabContentView): Added.
Store the `document.activeElement` on the `WI.TabContentView` and `.focus()` it after we're
done showing the newly selected tab, but only if there isn't already something focused.

* UserInterface/Views/TabBar.js:
(WI.TabBar.prototype.set selectedTabBarItem):
* UserInterface/Views/LegacyTabBar.js:
(WI.LegacyTabBar.prototype.set selectedTabBarItem):
Include the previously selected tab bar item when dispatching selection change events.

* UserInterface/Views/ContentBrowserTabContentView.js:
(WI.ContentBrowserTabContentView.prototype._revealAndSelectRepresentedObject):
Don't omit focus when revealing represented objects.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251962 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js
Source/WebInspectorUI/UserInterface/Views/LegacyTabBar.js
Source/WebInspectorUI/UserInterface/Views/TabBar.js
Source/WebInspectorUI/UserInterface/Views/TabBrowser.js

index 1d81b42..d493cd5 100644 (file)
@@ -1,5 +1,29 @@
 2019-11-01  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: switching tabs should re-focus the previously focused element
+        https://bugs.webkit.org/show_bug.cgi?id=203744
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Views/TabBrowser.js:
+        (WI.TabBrowser.prototype._tabBarItemSelected):
+        (WI.TabBrowser.prototype._saveFocusedNodeForTabContentView): Added.
+        (WI.TabBrowser.prototype._restoreFocusedNodeForTabContentView): Added.
+        Store the `document.activeElement` on the `WI.TabContentView` and `.focus()` it after we're
+        done showing the newly selected tab, but only if there isn't already something focused.
+
+        * UserInterface/Views/TabBar.js:
+        (WI.TabBar.prototype.set selectedTabBarItem):
+        * UserInterface/Views/LegacyTabBar.js:
+        (WI.LegacyTabBar.prototype.set selectedTabBarItem):
+        Include the previously selected tab bar item when dispatching selection change events.
+
+        * UserInterface/Views/ContentBrowserTabContentView.js:
+        (WI.ContentBrowserTabContentView.prototype._revealAndSelectRepresentedObject):
+        Don't omit focus when revealing represented objects.
+
+2019-11-01  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Timelines: add a timeline that shows information about any recorded CSS animation/transition
         https://bugs.webkit.org/show_bug.cgi?id=203651
         <rdar://problem/56128726>
index b6ba055..2d75c0d 100644 (file)
@@ -314,12 +314,9 @@ WI.ContentBrowserTabContentView = class ContentBrowserTabContentView extends WI.
 
         let treeElement = this.treeElementForRepresentedObject(representedObject);
 
-        if (treeElement) {
-            const omitFocus = true;
-            const selectedByUser = false;
-            const suppressNotification = false;
-            treeElement.revealAndSelect(omitFocus, selectedByUser, suppressNotification);
-        } else if (this.navigationSidebarPanel && this.navigationSidebarPanel.contentTreeOutline.selectedTreeElement)
+        if (treeElement)
+            treeElement.revealAndSelect();
+        else if (this.navigationSidebarPanel && this.navigationSidebarPanel.contentTreeOutline.selectedTreeElement)
             this.navigationSidebarPanel.contentTreeOutline.selectedTreeElement.deselect(true);
     }
 
index 10e07b0..64fe23d 100644 (file)
@@ -371,6 +371,8 @@ WI.LegacyTabBar = class LegacyTabBar extends WI.View
         if (this._selectedTabBarItem === tabBarItem)
             return;
 
+        let previousTabBarItem = this._selectedTabBarItem;
+
         if (this._selectedTabBarItem)
             this._selectedTabBarItem.selected = false;
 
@@ -382,7 +384,7 @@ WI.LegacyTabBar = class LegacyTabBar extends WI.View
                 this.needsLayout();
         }
 
-        this.dispatchEventToListeners(WI.TabBar.Event.TabBarItemSelected);
+        this.dispatchEventToListeners(WI.TabBar.Event.TabBarItemSelected, {previousTabBarItem});
     }
 
     get tabBarItems()
index 8ff7c5e..a2b5cb0 100644 (file)
@@ -344,6 +344,8 @@ WI.TabBar = class TabBar extends WI.View
         if (this._selectedTabBarItem === tabBarItem)
             return;
 
+        let previousTabBarItem = this._selectedTabBarItem;
+
         if (this._selectedTabBarItem)
             this._selectedTabBarItem.selected = false;
 
@@ -355,7 +357,7 @@ WI.TabBar = class TabBar extends WI.View
                 this.needsLayout();
         }
 
-        this.dispatchEventToListeners(WI.TabBar.Event.TabBarItemSelected);
+        this.dispatchEventToListeners(WI.TabBar.Event.TabBarItemSelected, {previousTabBarItem});
     }
 
     get tabBarItems()
index 2de7592..688bff7 100644 (file)
@@ -226,6 +226,8 @@ WI.TabBrowser = class TabBrowser extends WI.View
 
     _tabBarItemSelected(event)
     {
+        this._saveFocusedNodeForTabContentView(event.data.previousTabBarItem ? event.data.previousTabBarItem.representedObject : null);
+
         let tabContentView = this._tabBar.selectedTabBarItem ? this._tabBar.selectedTabBarItem.representedObject : null;
 
         if (tabContentView) {
@@ -256,6 +258,8 @@ WI.TabBrowser = class TabBrowser extends WI.View
         }
 
         this.dispatchEventToListeners(WI.TabBrowser.Event.SelectedTabContentViewDidChange);
+
+        this._restoreFocusedNodeForTabContentView(tabContentView);
     }
 
     _tabBarItemAdded(event)
@@ -341,6 +345,29 @@ WI.TabBrowser = class TabBrowser extends WI.View
         }
     }
 
+    _saveFocusedNodeForTabContentView(tabContentView)
+    {
+        if (!tabContentView)
+            return;
+
+        if (!WI.isContentAreaFocused())
+            return;
+
+        tabContentView[WI.TabBrowser.FocusedNodeSymbol] = document.activeElement;
+    }
+
+    _restoreFocusedNodeForTabContentView(tabContentView)
+    {
+        if (!tabContentView)
+            return;
+
+        let node = tabContentView[WI.TabBrowser.FocusedNodeSymbol];
+        if (node && !WI.isContentAreaFocused())
+            node.focus();
+
+        tabContentView[WI.TabBrowser.FocusedNodeSymbol] = null;
+    }
+
     _showNavigationSidebarPanelForTabContentView(tabContentView)
     {
         if (!this._navigationSidebar)
@@ -456,6 +483,7 @@ WI.TabBrowser = class TabBrowser extends WI.View
 };
 
 WI.TabBrowser.NeedsResizeLayoutSymbol = Symbol("needs-resize-layout");
+WI.TabBrowser.FocusedNodeSymbol = Symbol("focused-node");
 
 WI.TabBrowser.Event = {
     SelectedTabContentViewDidChange: "tab-browser-selected-tab-content-view-did-change"