-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] DomRenderer becomes FlutterViewEmbedder #29994
Conversation
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.
LGTM with some minor suggestions!
@@ -350,7 +350,7 @@ class PersistedPicture extends PersistedLeafSurface { | |||
oldSurface._canvas = null; | |||
} | |||
if (rootElement != null) { | |||
domRenderer.removeAllChildren(rootElement!); | |||
flutterViewEmbedder.removeAllChildren(rootElement!); |
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.
removeAllChildren
should also move to util.dart
?
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.
Done.
bool? _ellipseFeatureDetected; | ||
|
||
/// Draws CanvasElement ellipse with fallback. | ||
void drawEllipse( | ||
html.CanvasRenderingContext2D context, | ||
double centerX, | ||
double centerY, | ||
double radiusX, | ||
double radiusY, | ||
double rotation, | ||
double startAngle, | ||
double endAngle, | ||
bool antiClockwise) { | ||
// ignore: implicit_dynamic_function | ||
_ellipseFeatureDetected ??= js_util.getProperty(context, 'ellipse') != null; | ||
if (_ellipseFeatureDetected!) { |
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.
Can this be:
bool? _ellipseFeatureDetected; | |
/// Draws CanvasElement ellipse with fallback. | |
void drawEllipse( | |
html.CanvasRenderingContext2D context, | |
double centerX, | |
double centerY, | |
double radiusX, | |
double radiusY, | |
double rotation, | |
double startAngle, | |
double endAngle, | |
bool antiClockwise) { | |
// ignore: implicit_dynamic_function | |
_ellipseFeatureDetected ??= js_util.getProperty(context, 'ellipse') != null; | |
if (_ellipseFeatureDetected!) { | |
// ignore: implicit_dynamic_function | |
late final bool _ellipseFeatureDetected = js_util.getProperty(context, 'ellipse') != null; | |
/// Draws CanvasElement ellipse with fallback. | |
void drawEllipse( | |
html.CanvasRenderingContext2D context, | |
double centerX, | |
double centerY, | |
double radiusX, | |
double radiusY, | |
double rotation, | |
double startAngle, | |
double endAngle, | |
bool antiClockwise) { | |
if (_ellipseFeatureDetected) { |
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.
No, because context
is an argument to drawEllipse
.
@@ -17,41 +17,26 @@ void main() { | |||
|
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 file be renamed?
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.
Done.
test('can set style properties on elements', () { | ||
final DomRenderer renderer = DomRenderer(); | ||
final html.Element element = renderer.createElement('div'); | ||
DomRenderer.setElementStyle(element, 'color', 'red'); | ||
final html.Element element = html.document.createElement('div'); | ||
setElementStyle(element, 'color', 'red'); | ||
expect(element.style.color, 'red'); | ||
}); |
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.
Some of these tests should probably move to util_test.dart
now.
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.
Done.
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.
LGTM! Thanks for the cleanup!
lib/web_ui/test/clipboard_test.dart
Outdated
await ui.webOnlyInitializeTestDomRenderer(); | ||
await ui.webOnlyInitializeTestFlutterViewEmbedder(); |
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 is a potentially user-breaking change, but if all tests pass... no problem!
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.
Good catch! While it's not a breaking change, I realized that this method doesn't need to be in dart:ui
and it doesn't need the webOnly
prefix. It exists only for the engine's own tests. Framework-side tests use ui.debugEmulateFlutterTesterEnvironment = true;
.
I moved it to the engine test_embedding.dart
and deleted the dart:ui
-side code.
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.
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.
|
Final step in turning
DomRenderer
from a kitchen sink of various DOM manipulation utilities and a manager of Flutter Web's top elements into a single-purpose class - to manage the placement of Flutter views (currently only one). This PR achieves this in two steps:DomRenderer
toFlutterViewEmbedder
(9bdb6e3)