Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js (243213 => 243214)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js 2019-03-20 17:43:05 UTC (rev 243213)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js 2019-03-20 17:45:02 UTC (rev 243214)
@@ -75,6 +75,8 @@
// Public
+ get inspectedNode() { return this._inspectedNode; }
+
get eventListenerBreakpoints()
{
return Array.from(this._breakpointsForEventListeners.values());
@@ -554,6 +556,8 @@
return;
this._inspectedNode = node;
+
+ this.dispatchEventToListeners(WI.DOMManager.Event.InspectedNodeChanged);
};
// COMPATIBILITY (iOS 11): DOM.setInspectedNode did not exist.
@@ -666,4 +670,5 @@
ChildNodeCountUpdated: "dom-manager-child-node-count-updated",
DOMNodeWasInspected: "dom-manager-dom-node-was-inspected",
InspectModeStateChanged: "dom-manager-inspect-mode-state-changed",
+ InspectedNodeChanged: "dom-manager-inspected-node-changed",
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js (243213 => 243214)
--- trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js 2019-03-20 17:43:05 UTC (rev 243213)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js 2019-03-20 17:45:02 UTC (rev 243214)
@@ -32,13 +32,16 @@
this._toggleOrFocusKeyboardShortcut = new WI.KeyboardShortcut(null, WI.KeyboardShortcut.Key.Escape, this._toggleOrFocus.bind(this));
this._toggleOrFocusKeyboardShortcut.implicitlyPreventsDefault = false;
+ this._automaticExecutionContextPathComponent = this._createExecutionContextPathComponent(null, WI.UIString("Auto"));
+ this._automaticExecutionContextPathComponent.tooltip = WI.UIString("Execution context for $0");
+
this._mainExecutionContextPathComponent = null;
- this.initializeMainExecutionContextPathComponent();
+ this._otherExecutionContextPathComponents = [];
- this._otherExecutionContextPathComponents = [];
this._frameToPathComponent = new Map;
this._targetToPathComponent = new Map;
+ this._shouldAutomaticallySelectExecutionContext = true;
this._restoreSelectedExecutionContextForFrame = false;
this.element.classList.add("quick-console");
@@ -64,7 +67,7 @@
this._executionContextSelectorDivider = new WI.DividerNavigationItem;
this._navigationBar.addNavigationItem(this._executionContextSelectorDivider);
- this._rebuildExecutionContextPathComponents();
+ this.initializeMainExecutionContextPathComponent();
WI.consoleDrawer.toggleButtonShortcutTooltip(this._toggleOrFocusKeyboardShortcut);
WI.consoleDrawer.addEventListener(WI.ConsoleDrawer.Event.CollapsedStateChanged, this._updateStyles, this);
@@ -79,6 +82,8 @@
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetAdded, this._targetAdded, this);
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._targetRemoved, this);
+ WI.domManager.addEventListener(WI.DOMManager.Event.InspectedNodeChanged, this._handleInspectedNodeChanged, this);
+
WI.TabBrowser.addEventListener(WI.TabBrowser.Event.SelectedTabContentViewDidChange, this._updateStyles, this);
}
@@ -89,16 +94,6 @@
return this._navigationBar;
}
- get selectedExecutionContext()
- {
- return WI.runtimeManager.activeExecutionContext;
- }
-
- set selectedExecutionContext(executionContext)
- {
- WI.runtimeManager.activeExecutionContext = executionContext;
- }
-
closed()
{
WI.Frame.removeEventListener(null, null, this);
@@ -117,6 +112,13 @@
return;
this._mainExecutionContextPathComponent = this._createExecutionContextPathComponent(WI.mainTarget.executionContext);
+ this._mainExecutionContextPathComponent.previousSibling = this._automaticExecutionContextPathComponent;
+
+ this._automaticExecutionContextPathComponent.nextSibling = this._mainExecutionContextPathComponent;
+
+ this._shouldAutomaticallySelectExecutionContext = true;
+ this._selectExecutionContext(WI.mainTarget.executionContext);
+ this._rebuildExecutionContextPathComponents();
}
// Protected
@@ -130,6 +132,37 @@
// Private
+ _preferredNameForFrame(frame)
+ {
+ if (frame.name)
+ return WI.UIString("%s (%s)").format(frame.name, frame.mainResource.displayName);
+ return frame.mainResource.displayName;
+ }
+
+ _selectExecutionContext(executionContext)
+ {
+ let preferredName = null;
+
+ let inspectedNode = WI.domManager.inspectedNode;
+ if (inspectedNode) {
+ let frame = inspectedNode.ownerDocument.frame;
+ if (frame) {
+ if (this._shouldAutomaticallySelectExecutionContext)
+ executionContext = frame.pageExecutionContext;
+
+ preferredName = this._preferredNameForFrame(frame);
+ }
+ }
+
+ console.assert(executionContext);
+ if (!executionContext)
+ executionContext = WI.mainTarget.executionContext;
+
+ WI.runtimeManager.activeExecutionContext = executionContext;
+
+ this._automaticExecutionContextPathComponent.displayName = WI.UIString("Auto - %s").format(preferredName || executionContext.name);
+ }
+
_handleMouseDown(event)
{
if (event.target !== this.element)
@@ -149,10 +182,13 @@
if (!this._otherExecutionContextPathComponents.length)
return [];
- if (this.selectedExecutionContext === WI.mainTarget.executionContext)
+ if (this._shouldAutomaticallySelectExecutionContext)
+ return [this._automaticExecutionContextPathComponent];
+
+ if (WI.runtimeManager.activeExecutionContext === WI.mainTarget.executionContext)
return [this._mainExecutionContextPathComponent];
- return this._otherExecutionContextPathComponents.filter((component) => component.representedObject === this.selectedExecutionContext);
+ return this._otherExecutionContextPathComponents.filter((component) => component.representedObject === WI.runtimeManager.activeExecutionContext);
}
_rebuildExecutionContextPathComponents()
@@ -160,10 +196,12 @@
let components = this._executionContextPathComponentsToDisplay();
let isEmpty = !components.length;
+ this._executionContextSelectorItem.element.classList.toggle("automatic-execution-context", this._shouldAutomaticallySelectExecutionContext);
this._executionContextSelectorItem.components = components;
this._executionContextSelectorItem.hidden = isEmpty;
this._executionContextSelectorDivider.hidden = isEmpty;
+
}
_framePageExecutionContextsChanged(event)
@@ -170,13 +208,12 @@
{
let frame = event.target;
- let shouldAutomaticallySelect = this._restoreSelectedExecutionContextForFrame === frame;
+ let newExecutionContextPathComponent = this._insertExecutionContextPathComponentForFrame(frame);
- let newExecutionContextPathComponent = this._insertExecutionContextPathComponentForFrame(frame, shouldAutomaticallySelect);
+ if (this._restoreSelectedExecutionContextForFrame === frame) {
+ this._restoreSelectedExecutionContextForFrame = null;
- if (shouldAutomaticallySelect) {
- this._restoreSelectedExecutionContextForFrame = null;
- this.selectedExecutionContext = newExecutionContextPathComponent.representedObject;
+ this._selectExecutionContext(newExecutionContextPathComponent.representedObject);
}
}
@@ -187,10 +224,12 @@
// If this frame is navigating and it is selected in the UI we want to reselect its new item after navigation.
if (event.data.committingProvisionalLoad && !this._restoreSelectedExecutionContextForFrame) {
let executionContextPathComponent = this._frameToPathComponent.get(frame);
- if (executionContextPathComponent && executionContextPathComponent.representedObject === this.selectedExecutionContext) {
+ if (executionContextPathComponent && executionContextPathComponent.representedObject === WI.runtimeManager.activeExecutionContext) {
this._restoreSelectedExecutionContextForFrame = frame;
// As a fail safe, if the frame never gets an execution context, clear the restore value.
- setTimeout(() => { this._restoreSelectedExecutionContextForFrame = false; }, 10);
+ setTimeout(() => {
+ this._restoreSelectedExecutionContextForFrame = false;
+ }, 10);
}
}
@@ -200,13 +239,11 @@
_activeExecutionContextChanged(event)
{
this._rebuildExecutionContextPathComponents();
-
- this._executionContextSelectorItem.element.classList.toggle("non-default-execution-context", this.selectedExecutionContext !== WI.mainTarget.executionContext);
}
_createExecutionContextPathComponent(executionContext, preferredName)
{
- console.assert(executionContext instanceof WI.ExecutionContext);
+ console.assert(!executionContext || executionContext instanceof WI.ExecutionContext);
let pathComponent = new WI.HierarchicalPathComponent(preferredName || executionContext.name, "execution-context", executionContext, true, true);
pathComponent.addEventListener(WI.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this);
@@ -215,12 +252,6 @@
return pathComponent;
}
- _createExecutionContextPathComponentFromFrame(frame)
- {
- let preferredName = frame.name ? WI.UIString("%s (%s)").format(frame.name, frame.mainResource.displayName) : frame.mainResource.displayName;
- return this._createExecutionContextPathComponent(frame.pageExecutionContext, preferredName);
- }
-
_compareExecutionContextPathComponents(a, b)
{
let aExecutionContext = a.representedObject;
@@ -255,7 +286,7 @@
return a.displayName.extendedLocaleCompare(b.displayName);
}
- _insertOtherExecutionContextPathComponent(executionContextPathComponent, skipRebuild)
+ _insertOtherExecutionContextPathComponent(executionContextPathComponent)
{
let index = insertionIndexForObjectInListSortedByFunction(executionContextPathComponent, this._otherExecutionContextPathComponents, this._compareExecutionContextPathComponents);
@@ -272,11 +303,10 @@
this._otherExecutionContextPathComponents.splice(index, 0, executionContextPathComponent);
- if (!skipRebuild)
- this._rebuildExecutionContextPathComponents();
+ this._rebuildExecutionContextPathComponents();
}
- _removeOtherExecutionContextPathComponent(executionContextPathComponent, skipRebuild)
+ _removeOtherExecutionContextPathComponent(executionContextPathComponent)
{
executionContextPathComponent.removeEventListener(WI.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this);
executionContextPathComponent.removeEventListener(WI.HierarchicalPathComponent.Event.Clicked, this._pathComponentClicked, this);
@@ -290,29 +320,29 @@
this._otherExecutionContextPathComponents.remove(executionContextPathComponent, true);
- if (!skipRebuild)
- this._rebuildExecutionContextPathComponents();
+ this._rebuildExecutionContextPathComponents();
}
- _insertExecutionContextPathComponentForFrame(frame, skipRebuild)
+ _insertExecutionContextPathComponentForFrame(frame)
{
if (frame.isMainFrame())
return this._mainExecutionContextPathComponent;
- let executionContextPathComponent = this._createExecutionContextPathComponentFromFrame(frame);
- this._insertOtherExecutionContextPathComponent(executionContextPathComponent, skipRebuild);
+ let executionContextPathComponent = this._createExecutionContextPathComponent(frame.pageExecutionContext, this._preferredNameForFrame(frame));
+ this._insertOtherExecutionContextPathComponent(executionContextPathComponent);
this._frameToPathComponent.set(frame, executionContextPathComponent);
-
return executionContextPathComponent;
}
- _removeExecutionContextPathComponentForFrame(frame, skipRebuild)
+ _removeExecutionContextPathComponentForFrame(frame)
{
- if (frame.isMainFrame())
+ if (frame.isMainFrame()) {
+ this._shouldAutomaticallySelectExecutionContext = true;
return;
+ }
let executionContextPathComponent = this._frameToPathComponent.take(frame);
- this._removeOtherExecutionContextPathComponent(executionContextPathComponent, skipRebuild);
+ this._removeOtherExecutionContextPathComponent(executionContextPathComponent);
}
_targetAdded(event)
@@ -336,16 +366,19 @@
return;
let executionContextPathComponent = this._targetToPathComponent.take(target);
+
+ if (WI.runtimeManager.activeExecutionContext === executionContextPathComponent.representedObject) {
+ this._shouldAutomaticallySelectExecutionContext = true;
+ this._selectExecutionContext();
+ }
+
this._removeOtherExecutionContextPathComponent(executionContextPathComponent);
-
- if (this.selectedExecutionContext === executionContextPathComponent.representedObject)
- this.selectedExecutionContext = WI.mainTarget.executionContext;
}
_pathComponentSelected(event)
{
- let executionContext = event.data.pathComponent.representedObject;
- this.selectedExecutionContext = executionContext;
+ this._shouldAutomaticallySelectExecutionContext = event.data.pathComponent === this._automaticExecutionContextPathComponent;
+ this._selectExecutionContext(event.data.pathComponent.representedObject);
}
_pathComponentClicked(event)
@@ -373,4 +406,9 @@
{
this.element.classList.toggle("showing-log", WI.isShowingConsoleTab() || WI.isShowingSplitConsole());
}
+
+ _handleInspectedNodeChanged(event)
+ {
+ this._selectExecutionContext(WI.runtimeManager.activeExecutionContext);
+ }
};