[WebParagraph] Fix a property name on newer Chrome versions (#173477)
diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart index 3939217..dea6678 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/dom.dart
@@ -2607,9 +2607,16 @@ @JS('TextCluster') extension type DomTextCluster._(JSObject _) implements JSObject { - // TODO(jlavrova): This has been renamed to `start` in the spec. - // See: https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md - external int get begin; + @JS('begin') + external int? _begin; + @JS('start') + external int _start; + // The proposal had this `begin` then renamed it to `start`. Some versions of Chrome still have + // the old name. + // + // `_begin` can be removed once this feature is launched in a stable Chrome release. + int get start => _begin ?? _start; + external int get end; external double get x; external double get y;
diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/layout.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/layout.dart index b90b4dd..7a11af7 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/layout.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/layout.dart
@@ -60,7 +60,7 @@ final DomTextMetrics blockTextMetrics = layoutContext.measureText(text); for (final DomTextCluster cluster in blockTextMetrics.getTextClusters()) { final List<DomRectReadOnly> rects = blockTextMetrics.getSelectionRects( - cluster.begin, + cluster.start, cluster.end, ); final ui.Rect bounds = ui.Rect.fromLTWH( @@ -69,7 +69,7 @@ rects.first.width, rects.first.height, ); - for (int i = cluster.begin; i < cluster.end; i += 1) { + for (int i = cluster.start; i < cluster.end; i += 1) { textToClusterMap[i] = textClusters.length; } textClusters.add(ExtendedTextCluster(cluster, bounds, blockTextMetrics)); @@ -288,7 +288,7 @@ class ExtendedTextCluster { ExtendedTextCluster(this.cluster, this.bounds, this.textMetrics) - : start = cluster!.begin, + : start = cluster!.start, end = cluster.end; // TODO(jlavrova): Remove this.
diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart index a6ef5fef..5ae8434 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/web_paragraph/paragraph.dart
@@ -7,7 +7,6 @@ import '../canvaskit/canvaskit_canvas.dart'; import '../dom.dart'; -import '../util.dart'; import 'debug.dart'; import 'layout.dart'; import 'paint.dart'; @@ -307,16 +306,7 @@ @override void layout(ui.ParagraphConstraints constraints) { - try { - _layout.performLayout(constraints.width); - } catch (e) { - printWarning( - 'Canvas 2D threw an exception while laying ' - 'out the paragraph. ' - 'Exception:\n$e', - ); - rethrow; - } + _layout.performLayout(constraints.width); } /// Paints this paragraph instance on a [canvas] at the given [offset].