Skip to content

Commit 4e6e24f

Browse files
authored
[web] Cleanup everything HTML from the framework (#162837)
Things being removed: - Custom image filter logic in `cupertino/dialog.dart`. - Network image support for the HTML renderer. - Shader warm up guard for the HTML renderer. - Custom caret metrics logic in `text_painter.dart`.
1 parent c2229a8 commit 4e6e24f

File tree

4 files changed

+22
-75
lines changed

4 files changed

+22
-75
lines changed

packages/flutter/lib/src/cupertino/dialog.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ class CupertinoPopupSurface extends StatelessWidget {
684684
isVibrancePainted = debugIsVibrancePainted;
685685
return true;
686686
}());
687-
if ((kIsWeb && !isSkiaWeb) || !isVibrancePainted) {
687+
if (!isVibrancePainted) {
688688
if (blurSigma == 0) {
689689
return null;
690690
}

packages/flutter/lib/src/painting/_network_image_web.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:async';
66
import 'dart:js_interop';
77
import 'dart:ui' as ui;
8-
import 'dart:ui_web' as ui_web;
98

109
import 'package:flutter/foundation.dart';
1110

@@ -134,9 +133,6 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
134133
return collector;
135134
}
136135

137-
// HTML renderer does not support decoding network images to a specified size. The decode parameter
138-
// here is ignored and `ui_web.createImageCodecFromUrl` will be used directly
139-
// in place of the typical `instantiateImageCodec` method.
140136
Future<ImageStreamCompleter> _loadAsync(
141137
NetworkImage key,
142138
_SimpleDecoderCallback decode,
@@ -176,9 +172,6 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
176172
final bool containsNetworkImageHeaders = key.headers?.isNotEmpty ?? false;
177173
// When headers are set, the image can only be loaded by decoding.
178174
//
179-
// For the HTML renderer, `ui_web.createImageCodecFromUrl` method is not
180-
// capable of handling headers.
181-
//
182175
// For CanvasKit and Skwasm, it is not possible to load an <img> element and
183176
// pass the headers with the request to fetch the image. Since the user has
184177
// provided headers, this function should assume the headers are required to
@@ -188,32 +181,6 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
188181
return loadViaDecode();
189182
}
190183

191-
if (!isSkiaWeb) {
192-
// This branch is only hit by the HTML renderer, which is deprecated. The
193-
// HTML renderer supports loading images with CORS restrictions, so we
194-
// don't need to catch errors and try loading the image in an <img> tag
195-
// in this case.
196-
197-
// Resolve the Codec before passing it to
198-
// [MultiFrameImageStreamCompleter] so any errors aren't reported
199-
// twice (once from the MultiFrameImageStreamCompleter) and again
200-
// from the wrapping [ForwardingImageStreamCompleter].
201-
final Uri resolved = Uri.base.resolve(key.url);
202-
final ui.Codec codec = await ui_web.createImageCodecFromUrl(
203-
resolved,
204-
chunkCallback: (int bytes, int total) {
205-
chunkEvents.add(ImageChunkEvent(cumulativeBytesLoaded: bytes, expectedTotalBytes: total));
206-
},
207-
);
208-
return MultiFrameImageStreamCompleter(
209-
chunkEvents: chunkEvents.stream,
210-
codec: Future<ui.Codec>.value(codec),
211-
scale: key.scale,
212-
debugLabel: key.url,
213-
informationCollector: _imageStreamInformationCollector(key),
214-
);
215-
}
216-
217184
switch (webHtmlElementStrategy) {
218185
case image_provider.WebHtmlElementStrategy.never:
219186
return loadViaDecode();

packages/flutter/lib/src/painting/shader_warm_up.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,17 @@ abstract class ShaderWarmUp {
9090
await warmUpOnCanvas(canvas);
9191
final ui.Picture picture = recorder.endRecording();
9292
assert(debugCaptureShaderWarmUpPicture(picture));
93-
if (!kIsWeb || isSkiaWeb) {
94-
// Picture.toImage is not implemented on the html renderer.
95-
TimelineTask? debugShaderWarmUpTask;
93+
TimelineTask? debugShaderWarmUpTask;
94+
if (!kReleaseMode) {
95+
debugShaderWarmUpTask = TimelineTask()..start('Warm-up shader');
96+
}
97+
try {
98+
final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil());
99+
assert(debugCaptureShaderWarmUpImage(image));
100+
image.dispose();
101+
} finally {
96102
if (!kReleaseMode) {
97-
debugShaderWarmUpTask = TimelineTask()..start('Warm-up shader');
98-
}
99-
try {
100-
final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil());
101-
assert(debugCaptureShaderWarmUpImage(image));
102-
image.dispose();
103-
} finally {
104-
if (!kReleaseMode) {
105-
debugShaderWarmUpTask!.finish();
106-
}
103+
debugShaderWarmUpTask!.finish();
107104
}
108105
}
109106
picture.dispose();

packages/flutter/lib/src/painting/text_painter.dart

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,9 +1528,7 @@ class TextPainter {
15281528
final _TextPainterLayoutCacheWithOffset cachedLayout = _layoutCache!;
15291529
// If nothing is laid out, top start is the only reasonable place to place
15301530
// the cursor.
1531-
// The HTML renderer reports numberOfLines == 1 when the text is empty:
1532-
// https://github.com/flutter/flutter/issues/143331
1533-
if (cachedLayout.paragraph.numberOfLines < 1 || plainText.isEmpty) {
1531+
if (cachedLayout.paragraph.numberOfLines < 1) {
15341532
// TODO(LongCatIsLooong): assert when an invalid position is given.
15351533
return null;
15361534
}
@@ -1588,31 +1586,16 @@ class TextPainter {
15881586
boxHeightStyle: ui.BoxHeightStyle.strut,
15891587
);
15901588

1591-
if (boxes.isNotEmpty) {
1592-
final bool anchorToLeft = switch (glyphInfo.writingDirection) {
1593-
TextDirection.ltr => anchorToLeadingEdge,
1594-
TextDirection.rtl => !anchorToLeadingEdge,
1595-
};
1596-
final TextBox box = anchorToLeft ? boxes.first : boxes.last;
1597-
metrics = _LineCaretMetrics(
1598-
offset: Offset(anchorToLeft ? box.left : box.right, box.top),
1599-
writingDirection: box.direction,
1600-
height: box.bottom - box.top,
1601-
);
1602-
} else {
1603-
// Fall back to glyphInfo. This should only happen when using the HTML renderer.
1604-
assert(kIsWeb && !isSkiaWeb);
1605-
final Rect graphemeBounds = glyphInfo.graphemeClusterLayoutBounds;
1606-
final double dx = switch (glyphInfo.writingDirection) {
1607-
TextDirection.ltr => anchorToLeadingEdge ? graphemeBounds.left : graphemeBounds.right,
1608-
TextDirection.rtl => anchorToLeadingEdge ? graphemeBounds.right : graphemeBounds.left,
1609-
};
1610-
metrics = _LineCaretMetrics(
1611-
offset: Offset(dx, graphemeBounds.top),
1612-
writingDirection: glyphInfo.writingDirection,
1613-
height: graphemeBounds.height,
1614-
);
1615-
}
1589+
final bool anchorToLeft = switch (glyphInfo.writingDirection) {
1590+
TextDirection.ltr => anchorToLeadingEdge,
1591+
TextDirection.rtl => !anchorToLeadingEdge,
1592+
};
1593+
final TextBox box = anchorToLeft ? boxes.first : boxes.last;
1594+
metrics = _LineCaretMetrics(
1595+
offset: Offset(anchorToLeft ? box.left : box.right, box.top),
1596+
writingDirection: box.direction,
1597+
height: box.bottom - box.top,
1598+
);
16161599

16171600
cachedLayout._previousCaretPositionKey = caretPositionCacheKey;
16181601
return _caretMetrics = metrics;

0 commit comments

Comments
 (0)