-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Use v8BreakIterator where possible #37317
Conversation
lib/web_ui/lib/src/engine/dom.dart
Outdated
class DomIntl {} | ||
|
||
extension DomIntlExtension on DomIntl { | ||
/// This is a Chrome-only API for segmenting text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically V8, not Chrome. It's also available in Edge, Opera, Samsung, Brave, etc.
} | ||
|
||
@override | ||
List<LineBreakFragment> fragment() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be abstract?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Good catch.
const LineBreakFragmenter(super.text); | ||
abstract class LineBreakFragmenter extends TextFragmenter { | ||
factory LineBreakFragmenter(String text) { | ||
if (domWindow.Intl.v8BreakIterator != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be any value in running tests in the non-v8BreakIterator mode in Chrome? If so, we may need a way to override this in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are running all line breaker tests with both our fragmenter and v8BreakIterator. That should be good enough IMHO.
Other text tests are testing other aspects of text layout, not line breaks specifically. So I don't think there's value in running non-v8BreakIterator mode in Chrome. We could always change this in the future of course.
// Calculate trailing newlines and spaces. | ||
for (int i = fragmentStart; i < fragmentEnd; i++) { | ||
final int codeUnit = text.codeUnitAt(i); | ||
if (_kNewlines.contains(codeUnit)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a premature optimization, but is there a way to avoid list iteration in most cases by checking that the code unit is not even in the new line or space character code range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which iteration do you want to avoid? I'm assuming Set.contains()
is constant, is it not the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize they were constants, so assumed .contains
would scan. LGTM.
// Calculate trailing newlines and spaces. | ||
for (int i = fragmentStart; i < fragmentEnd; i++) { | ||
final int codeUnit = text.codeUnitAt(i); | ||
if (_kNewlines.contains(codeUnit)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize they were constants, so assumed .contains
would scan. LGTM.
* [web] Use v8BreakIterator where possible * address review comments
…115008) * de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265) * 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400) * 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402) * dc7cb20ad Fix boolean json property. (flutter/engine#37403) * 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397) * 0af87071f Add test for image readback (flutter/engine#37401) * c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327) * 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409) * 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429) * 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (#37409)" (flutter/engine#37430) * 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432) * c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317) * 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435) * c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
* [web] Use v8BreakIterator where possible * address review comments
…lutter#115008) * de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265) * 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400) * 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402) * dc7cb20ad Fix boolean json property. (flutter/engine#37403) * 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397) * 0af87071f Add test for image readback (flutter/engine#37401) * c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327) * 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409) * 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429) * 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter#37409)" (flutter/engine#37430) * 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432) * c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317) * 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435) * c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
…lutter#115008) * de0b58e82 clang-tidy: added the ability to shard jobs (flutter/engine#37265) * 8aefb8b61 Roll Dart SDK from d97d5ad98893 to b22b36c0f52e (1 revision) (flutter/engine#37400) * 2f043090f Roll Skia from aef6d301c0b5 to 0c8127b3dd7d (6 revisions) (flutter/engine#37402) * dc7cb20ad Fix boolean json property. (flutter/engine#37403) * 512fa40b6 Adding release_build:true property to windows builders. (flutter/engine#37397) * 0af87071f Add test for image readback (flutter/engine#37401) * c6f26e035 Update display_list_image_filter_unittests to be permit Skia roll (flutter/engine#37327) * 4e9e97b4b Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter/engine#37409) * 42c2940ff Pass the correct name for gclient variables in ci.yaml (flutter/engine#37429) * 2e2a2fd97 Revert "Roll Skia from 0c8127b3dd7d to 8b19fb0f57d4 (1 revision) (flutter#37409)" (flutter/engine#37430) * 02cb78905 Roll Fuchsia Mac SDK from sa5bVGimNo3JwLV27... to d4l6A1aPw6Z0YjxmA... (flutter/engine#37432) * c24ae1872 [web] Use v8BreakIterator where possible (flutter/engine#37317) * 306b0fe9c Add rects to accumulator rather than bounds (flutter/engine#37435) * c76035429 Roll Dart SDK from b22b36c0f52e to c15cdb978761 (2 revisions) (flutter/engine#37437)
This PR introduces the usage of Chromium's
v8BreakIterator
to find line breaks in text. This should lead to more correct line breaking, especially around South Eastern Asian languages that need dictionaries for correct line breaks.Related to flutter/flutter#112820