Commit 04a86be7 authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Add context menu item to focus a node

Brings the inspected page to front and focuses it

Change-Id: I0e6b18b079091fe2b0dfccbc69829470dcfaeeec
Reviewed-on: https://chromium-review.googlesource.com/761057Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517221}
parent c5d3db64
...@@ -682,6 +682,7 @@ Response PageHandler::BringToFront() { ...@@ -682,6 +682,7 @@ Response PageHandler::BringToFront() {
WebContentsImpl* wc = GetWebContents(); WebContentsImpl* wc = GetWebContents();
if (wc) { if (wc) {
wc->Activate(); wc->Activate();
wc->Focus();
return Response::OK(); return Response::OK();
} }
return Response::InternalError(); return Response::InternalError();
......
...@@ -473,6 +473,9 @@ Elements.ElementsTreeElement = class extends UI.TreeElement { ...@@ -473,6 +473,9 @@ Elements.ElementsTreeElement = class extends UI.TreeElement {
this.populateNodeContextMenu(contextMenu); this.populateNodeContextMenu(contextMenu);
Elements.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu, treeElement.node()); Elements.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu, treeElement.node());
this.populateScrollIntoView(contextMenu); this.populateScrollIntoView(contextMenu);
contextMenu.viewSection().appendItem(Common.UIString('Focus'), async () => {
await this._node.focus();
});
} }
/** /**
......
...@@ -907,9 +907,10 @@ SDK.DOMNode = class { ...@@ -907,9 +907,10 @@ SDK.DOMNode = class {
async scrollIntoView() { async scrollIntoView() {
var node = this.enclosingElementOrSelf(); var node = this.enclosingElementOrSelf();
var object = await node.resolveToObject(''); var object = await node.resolveToObject();
if (object) if (!object)
object.callFunction(scrollIntoView); return;
object.callFunction(scrollIntoView);
object.release(); object.release();
node.highlightForTwoSeconds(); node.highlightForTwoSeconds();
...@@ -921,6 +922,25 @@ SDK.DOMNode = class { ...@@ -921,6 +922,25 @@ SDK.DOMNode = class {
this.scrollIntoViewIfNeeded(true); this.scrollIntoViewIfNeeded(true);
} }
} }
async focus() {
var node = this.enclosingElementOrSelf();
var object = await node.resolveToObject();
if (!object)
return;
await object.callFunctionPromise(focusInPage);
object.release();
node.highlightForTwoSeconds();
this._domModel.target().pageAgent().bringToFront();
/**
* @suppressReceiverCheck
* @this {!Element}
*/
function focusInPage() {
this.focus();
}
}
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment