onGetNodeForLocation method
void
onGetNodeForLocation(
- int? id,
- Map<String, dynamic> params
)
Implementation
void onGetNodeForLocation(int? id, Map<String, dynamic> params) {
int x = params['x'];
int y = params['y'];
RenderBox rootRenderObject = document.renderer!;
BoxHitTestResult result = BoxHitTestResult();
rootRenderObject.hitTest(result, position: Offset(x.toDouble(), y.toDouble()));
var hitPath = result.path;
if (hitPath.isEmpty) {
sendToFrontend(id, null);
return;
}
// find real img element.
if (hitPath.first.target is WebFRenderImage ||
(hitPath.first.target is RenderSVGRoot &&
(hitPath.first.target as RenderBoxModel).renderStyle.target.pointer == null)) {
hitPath = hitPath.skip(1);
}
if (hitPath.isNotEmpty && hitPath.first.target is RenderBoxModel) {
RenderBoxModel lastHitRenderBoxModel = result.path.first.target as RenderBoxModel;
int? targetId = view.forDevtoolsNodeId(lastHitRenderBoxModel.renderStyle.target);
sendToFrontend(
id,
JSONEncodableMap({
'backendId': targetId,
'frameId': DEFAULT_FRAME_ID,
'nodeId': targetId,
}));
} else {
sendToFrontend(id, null);
}
}