Skip to content

Commit

Permalink
fix: devtool select img element
Browse files Browse the repository at this point in the history
  • Loading branch information
xxrlzzz authored and jinwencan committed Dec 20, 2023
1 parent d21871a commit 31a8928
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions webf/lib/src/devtools/modules/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:webf/dom.dart';
import 'package:webf/rendering.dart';
import 'package:flutter/rendering.dart';
import 'package:webf/launcher.dart';
import 'package:webf/svg.dart';

const int DOCUMENT_NODE_ID = 0;
const String DEFAULT_FRAME_ID = 'main_frame';
Expand Down Expand Up @@ -47,8 +48,19 @@ class InspectDOMModule extends UIInspectorModule {
RenderBox rootRenderObject = document.renderer!;
BoxHitTestResult result = BoxHitTestResult();
rootRenderObject.hitTest(result, position: Offset(x.toDouble(), y.toDouble()));
if (result.path.first.target is RenderBoxModel) {
RenderBoxModel lastHitRenderBoxModel = result.path.first.target as RenderBoxModel;
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 = hitPath.first.target as RenderBoxModel;
int? targetId = lastHitRenderBoxModel.renderStyle.target.pointer!.address;
sendToFrontend(
id,
Expand Down
1 change: 0 additions & 1 deletion webf/lib/src/svg/svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:webf/dom.dart';
import 'package:webf/foundation.dart';
import 'package:webf/svg.dart';
import 'core/aspect_ratio.dart';
import 'rendering/root.dart';

const DEFAULT_VIEW_BOX_TOP = 0.0;
const DEFAULT_VIEW_BOX_LEFT = 0.0;
Expand Down
5 changes: 4 additions & 1 deletion webf/lib/src/svg/svg_render_object_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:webf/dom.dart';
import 'package:webf/painting.dart';
import 'package:webf/rendering.dart';
import 'package:webf/src/svg/rendering/container.dart';
import 'package:webf/src/svg/rendering/root.dart';
import 'package:webf/svg.dart';

// Those size is get from chrome. I cannot found any specs for that. @XGHeaven
Expand Down Expand Up @@ -109,10 +108,14 @@ class SVGRenderBoxBuilder {
element.renderStyle.height = CSSLengthValue.auto;
element.renderStyle.width = CSSLengthValue.auto;
}
element.tagName = tagName;
element.namespaceURI = SVG_ELEMENT_URI;
return element.renderBoxModel!;
}
print('Unknown SVG element $tagName');
final element = SVGUnknownElement(null);
element.tagName = tagName;
element.namespaceURI = SVG_ELEMENT_URI;
return element.renderBoxModel!;
}

Expand Down
2 changes: 2 additions & 0 deletions webf/lib/svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export 'src/svg/style.dart';
export 'src/svg/line.dart';
export 'src/svg/constants.dart';
export 'src/svg/svg_render_object_builder.dart';
export 'src/svg/rendering/root.dart';

0 comments on commit 31a8928

Please sign in to comment.