mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[engine, web] return switch expressions in many places (#162336)
This commit is contained in:
parent
60182c5e21
commit
1ba0561963
@ -269,14 +269,10 @@ const List<String> kAllBrowserNames = <String>[kChrome, kEdge, kFirefox, kSafari
|
||||
///
|
||||
/// The [browserName] matches the browser name passed as the `--browser` option.
|
||||
BrowserEnvironment getBrowserEnvironment(BrowserName browserName, {required bool useDwarf}) {
|
||||
switch (browserName) {
|
||||
case BrowserName.chrome:
|
||||
return ChromeEnvironment(useDwarf: useDwarf);
|
||||
case BrowserName.edge:
|
||||
return EdgeEnvironment();
|
||||
case BrowserName.firefox:
|
||||
return FirefoxEnvironment();
|
||||
case BrowserName.safari:
|
||||
return SafariMacOsEnvironment();
|
||||
}
|
||||
return switch (browserName) {
|
||||
BrowserName.chrome => ChromeEnvironment(useDwarf: useDwarf),
|
||||
BrowserName.edge => EdgeEnvironment(),
|
||||
BrowserName.firefox => FirefoxEnvironment(),
|
||||
BrowserName.safari => SafariMacOsEnvironment(),
|
||||
};
|
||||
}
|
||||
|
@ -64,22 +64,20 @@ class CompileBundleStep implements PipelineStep {
|
||||
}
|
||||
|
||||
TestCompiler _createCompiler(CompileConfiguration config) {
|
||||
switch (config.compiler) {
|
||||
case Compiler.dart2js:
|
||||
return Dart2JSCompiler(
|
||||
testSetDirectory,
|
||||
outputBundleDirectory,
|
||||
renderer: config.renderer,
|
||||
isVerbose: isVerbose,
|
||||
);
|
||||
case Compiler.dart2wasm:
|
||||
return Dart2WasmCompiler(
|
||||
testSetDirectory,
|
||||
outputBundleDirectory,
|
||||
renderer: config.renderer,
|
||||
isVerbose: isVerbose,
|
||||
);
|
||||
}
|
||||
return switch (config.compiler) {
|
||||
Compiler.dart2js => Dart2JSCompiler(
|
||||
testSetDirectory,
|
||||
outputBundleDirectory,
|
||||
renderer: config.renderer,
|
||||
isVerbose: isVerbose,
|
||||
),
|
||||
Compiler.dart2wasm => Dart2WasmCompiler(
|
||||
testSetDirectory,
|
||||
outputBundleDirectory,
|
||||
renderer: config.renderer,
|
||||
isVerbose: isVerbose,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -477,14 +477,11 @@ class BrowserPlatform extends PlatformPlugin {
|
||||
}
|
||||
|
||||
String getCanvasKitVariant() {
|
||||
switch (suite.runConfig.variant) {
|
||||
case CanvasKitVariant.full:
|
||||
return 'full';
|
||||
case CanvasKitVariant.chromium:
|
||||
return 'chromium';
|
||||
case null:
|
||||
return 'auto';
|
||||
}
|
||||
return switch (suite.runConfig.variant) {
|
||||
CanvasKitVariant.full => 'full',
|
||||
CanvasKitVariant.chromium => 'chromium',
|
||||
null => 'auto',
|
||||
};
|
||||
}
|
||||
|
||||
String _makeBuildConfigString(String scriptBase, CompileConfiguration config) {
|
||||
|
@ -133,55 +133,33 @@ class KeyData {
|
||||
// JavaScript only support 32-bit bitwise operations and needs to use
|
||||
// division instead.
|
||||
final int planeNum = (logical / 0x100000000).floor();
|
||||
final String planeDescription =
|
||||
(() {
|
||||
switch (planeNum) {
|
||||
case 0x000:
|
||||
return ' (Unicode)';
|
||||
case 0x001:
|
||||
return ' (Unprintable)';
|
||||
case 0x002:
|
||||
return ' (Flutter)';
|
||||
case 0x011:
|
||||
return ' (Android)';
|
||||
case 0x012:
|
||||
return ' (Fuchsia)';
|
||||
case 0x013:
|
||||
return ' (iOS)';
|
||||
case 0x014:
|
||||
return ' (macOS)';
|
||||
case 0x015:
|
||||
return ' (GTK)';
|
||||
case 0x016:
|
||||
return ' (Windows)';
|
||||
case 0x017:
|
||||
return ' (Web)';
|
||||
case 0x018:
|
||||
return ' (GLFW)';
|
||||
}
|
||||
return '';
|
||||
})();
|
||||
final String planeDescription = switch (planeNum) {
|
||||
0x000 => ' (Unicode)',
|
||||
0x001 => ' (Unprintable)',
|
||||
0x002 => ' (Flutter)',
|
||||
0x011 => ' (Android)',
|
||||
0x012 => ' (Fuchsia)',
|
||||
0x013 => ' (iOS)',
|
||||
0x014 => ' (macOS)',
|
||||
0x015 => ' (GTK)',
|
||||
0x016 => ' (Windows)',
|
||||
0x017 => ' (Web)',
|
||||
0x018 => ' (GLFW)',
|
||||
_ => '',
|
||||
};
|
||||
return '$result$planeDescription';
|
||||
}
|
||||
|
||||
String? _escapeCharacter() {
|
||||
if (character == null) {
|
||||
return '<none>';
|
||||
}
|
||||
switch (character!) {
|
||||
case '\n':
|
||||
return r'"\n"';
|
||||
case '\t':
|
||||
return r'"\t"';
|
||||
case '\r':
|
||||
return r'"\r"';
|
||||
case '\b':
|
||||
return r'"\b"';
|
||||
case '\f':
|
||||
return r'"\f"';
|
||||
default:
|
||||
return '"$character"';
|
||||
}
|
||||
return switch (character) {
|
||||
null => '<none>',
|
||||
'\n' => r'"\n"',
|
||||
'\t' => r'"\t"',
|
||||
'\r' => r'"\r"',
|
||||
'\b' => r'"\b"',
|
||||
'\f' => r'"\f"',
|
||||
_ => '"$character"',
|
||||
};
|
||||
}
|
||||
|
||||
String? _quotedCharCode() {
|
||||
|
@ -705,15 +705,12 @@ Future<void> _decodeImageFromListAsync(Uint8List list, ImageDecoderCallback call
|
||||
// to right, then from top to down. The order of the 4 bytes of pixels is
|
||||
// decided by `format`.
|
||||
Future<Codec> createBmp(Uint8List pixels, int width, int height, int rowBytes, PixelFormat format) {
|
||||
late bool swapRedBlue;
|
||||
switch (format) {
|
||||
case PixelFormat.bgra8888:
|
||||
swapRedBlue = true;
|
||||
case PixelFormat.rgba8888:
|
||||
swapRedBlue = false;
|
||||
case PixelFormat.rgbaFloat32:
|
||||
throw UnimplementedError('RGB conversion from rgbaFloat32 data is not implemented');
|
||||
}
|
||||
final bool swapRedBlue = switch (format) {
|
||||
PixelFormat.bgra8888 => true,
|
||||
PixelFormat.rgba8888 => false,
|
||||
PixelFormat.rgbaFloat32 =>
|
||||
throw UnimplementedError('RGB conversion from rgbaFloat32 data is not implemented'),
|
||||
};
|
||||
|
||||
// See https://en.wikipedia.org/wiki/BMP_file_format for format examples.
|
||||
// The header is in the 108-byte BITMAPV4HEADER format, or as called by
|
||||
|
@ -911,7 +911,7 @@ class ContextStateHandle {
|
||||
strokeCap ??= ui.StrokeCap.butt;
|
||||
if (strokeCap != _currentStrokeCap) {
|
||||
_currentStrokeCap = strokeCap;
|
||||
context.lineCap = stringForStrokeCap(strokeCap)!;
|
||||
context.lineCap = strokeCap.name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -928,7 +928,7 @@ class ContextStateHandle {
|
||||
strokeJoin ??= ui.StrokeJoin.miter;
|
||||
if (strokeJoin != _currentStrokeJoin) {
|
||||
_currentStrokeJoin = strokeJoin;
|
||||
context.lineJoin = stringForStrokeJoin(strokeJoin);
|
||||
context.lineJoin = strokeJoin.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3431,17 +3431,14 @@ String get _canvasKitBaseUrl => configuration.canvasKitBaseUrl;
|
||||
|
||||
@visibleForTesting
|
||||
List<String> getCanvasKitJsFileNames(CanvasKitVariant variant) {
|
||||
switch (variant) {
|
||||
case CanvasKitVariant.auto:
|
||||
return <String>[
|
||||
if (_enableCanvasKitChromiumInAutoMode) _kChromiumCanvasKitJsFileName,
|
||||
_kFullCanvasKitJsFileName,
|
||||
];
|
||||
case CanvasKitVariant.full:
|
||||
return <String>[_kFullCanvasKitJsFileName];
|
||||
case CanvasKitVariant.chromium:
|
||||
return <String>[_kChromiumCanvasKitJsFileName];
|
||||
}
|
||||
return switch (variant) {
|
||||
CanvasKitVariant.auto => <String>[
|
||||
if (_enableCanvasKitChromiumInAutoMode) _kChromiumCanvasKitJsFileName,
|
||||
_kFullCanvasKitJsFileName,
|
||||
],
|
||||
CanvasKitVariant.full => <String>[_kFullCanvasKitJsFileName],
|
||||
CanvasKitVariant.chromium => <String>[_kChromiumCanvasKitJsFileName],
|
||||
};
|
||||
}
|
||||
|
||||
Iterable<String> get _canvasKitJsUrls {
|
||||
|
@ -614,12 +614,10 @@ class HtmlViewEmbedder {
|
||||
}
|
||||
|
||||
DomElement _getElement(RenderingEntity entity) {
|
||||
switch (entity) {
|
||||
case RenderingRenderCanvas():
|
||||
return entity.displayCanvas!.hostElement;
|
||||
case RenderingPlatformView():
|
||||
return _viewClipChains[entity.viewId]!.root;
|
||||
}
|
||||
return switch (entity) {
|
||||
RenderingRenderCanvas() => entity.displayCanvas!.hostElement,
|
||||
RenderingPlatformView() => _viewClipChains[entity.viewId]!.root,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns a [List] of ints mapping elements from the [next] rendering to
|
||||
@ -796,18 +794,13 @@ class Mutator {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case MutatorType.clipRect:
|
||||
return rect == typedOther.rect;
|
||||
case MutatorType.clipRRect:
|
||||
return rrect == typedOther.rrect;
|
||||
case MutatorType.clipPath:
|
||||
return path == typedOther.path;
|
||||
case MutatorType.transform:
|
||||
return matrix == typedOther.matrix;
|
||||
case MutatorType.opacity:
|
||||
return alpha == typedOther.alpha;
|
||||
}
|
||||
return switch (type) {
|
||||
MutatorType.clipRect => rect == typedOther.rect,
|
||||
MutatorType.clipRRect => rrect == typedOther.rrect,
|
||||
MutatorType.clipPath => path == typedOther.path,
|
||||
MutatorType.transform => matrix == typedOther.matrix,
|
||||
MutatorType.opacity => alpha == typedOther.alpha,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -899,13 +899,10 @@ class CkParagraph implements ui.Paragraph {
|
||||
@override
|
||||
ui.TextRange getWordBoundary(ui.TextPosition position) {
|
||||
assert(!_disposed, 'Paragraph has been disposed.');
|
||||
final int characterPosition;
|
||||
switch (position.affinity) {
|
||||
case ui.TextAffinity.upstream:
|
||||
characterPosition = position.offset - 1;
|
||||
case ui.TextAffinity.downstream:
|
||||
characterPosition = position.offset;
|
||||
}
|
||||
final int characterPosition = switch (position.affinity) {
|
||||
ui.TextAffinity.upstream => position.offset - 1,
|
||||
ui.TextAffinity.downstream => position.offset,
|
||||
};
|
||||
final SkTextRange skRange = skiaObject.getWordBoundary(characterPosition.toDouble());
|
||||
return ui.TextRange(start: skRange.start.toInt(), end: skRange.end.toInt());
|
||||
}
|
||||
|
@ -1323,31 +1323,6 @@ SvgBlendMode? blendModeToSvgEnum(ui.BlendMode? blendMode) {
|
||||
}
|
||||
}
|
||||
|
||||
String? stringForStrokeCap(ui.StrokeCap? strokeCap) {
|
||||
if (strokeCap == null) {
|
||||
return null;
|
||||
}
|
||||
switch (strokeCap) {
|
||||
case ui.StrokeCap.butt:
|
||||
return 'butt';
|
||||
case ui.StrokeCap.round:
|
||||
return 'round';
|
||||
case ui.StrokeCap.square:
|
||||
return 'square';
|
||||
}
|
||||
}
|
||||
|
||||
String stringForStrokeJoin(ui.StrokeJoin strokeJoin) {
|
||||
switch (strokeJoin) {
|
||||
case ui.StrokeJoin.round:
|
||||
return 'round';
|
||||
case ui.StrokeJoin.bevel:
|
||||
return 'bevel';
|
||||
case ui.StrokeJoin.miter:
|
||||
return 'miter';
|
||||
}
|
||||
}
|
||||
|
||||
/// Clips the content element against a stack of clip operations and returns
|
||||
/// root of a tree that contains content node.
|
||||
///
|
||||
|
@ -14,7 +14,6 @@ import '../svg.dart';
|
||||
import '../text/canvas_paragraph.dart';
|
||||
import '../util.dart';
|
||||
import '../vector_math.dart';
|
||||
import 'bitmap_canvas.dart';
|
||||
import 'painting.dart';
|
||||
import 'path/path.dart';
|
||||
import 'path/path_to_svg.dart';
|
||||
@ -351,8 +350,8 @@ SVGSVGElement pathToSvgElement(SurfacePath path, SurfacePaintData paint) {
|
||||
paint.strokeWidth != null)) {
|
||||
svgPath.setAttribute('stroke', colorValueToCssString(paint.color));
|
||||
svgPath.setAttribute('stroke-width', '${paint.strokeWidth ?? 1.0}');
|
||||
if (paint.strokeCap != null) {
|
||||
svgPath.setAttribute('stroke-linecap', '${stringForStrokeCap(paint.strokeCap)}');
|
||||
if (paint.strokeCap case final value?) {
|
||||
svgPath.setAttribute('stroke-linecap', value.name);
|
||||
}
|
||||
svgPath.setAttribute('fill', 'none');
|
||||
} else {
|
||||
|
@ -453,14 +453,11 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
|
||||
/// [readValueOfType].
|
||||
int readSize(ReadBuffer buffer) {
|
||||
final int value = buffer.getUint8();
|
||||
switch (value) {
|
||||
case 254:
|
||||
return buffer.getUint16();
|
||||
case 255:
|
||||
return buffer.getUint32();
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
return switch (value) {
|
||||
254 => buffer.getUint16(),
|
||||
255 => buffer.getUint32(),
|
||||
_ => value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,33 +118,20 @@ enum UniformType {
|
||||
}
|
||||
|
||||
UniformType? uniformTypeFromJson(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return UniformType.Boolean;
|
||||
case 1:
|
||||
return UniformType.SByte;
|
||||
case 2:
|
||||
return UniformType.UByte;
|
||||
case 3:
|
||||
return UniformType.Short;
|
||||
case 4:
|
||||
return UniformType.UShort;
|
||||
case 5:
|
||||
return UniformType.Int;
|
||||
case 6:
|
||||
return UniformType.Uint;
|
||||
case 7:
|
||||
return UniformType.Int64;
|
||||
case 8:
|
||||
return UniformType.Uint64;
|
||||
case 9:
|
||||
return UniformType.Half;
|
||||
case 10:
|
||||
return UniformType.Float;
|
||||
case 11:
|
||||
return UniformType.Double;
|
||||
case 12:
|
||||
return UniformType.SampledImage;
|
||||
}
|
||||
return null;
|
||||
return switch (value) {
|
||||
0 => UniformType.Boolean,
|
||||
1 => UniformType.SByte,
|
||||
2 => UniformType.UByte,
|
||||
3 => UniformType.Short,
|
||||
4 => UniformType.UShort,
|
||||
5 => UniformType.Int,
|
||||
6 => UniformType.Uint,
|
||||
7 => UniformType.Int64,
|
||||
8 => UniformType.Uint64,
|
||||
9 => UniformType.Half,
|
||||
10 => UniformType.Float,
|
||||
11 => UniformType.Double,
|
||||
12 => UniformType.SampledImage,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
@ -225,13 +225,10 @@ class CanvasParagraph implements ui.Paragraph {
|
||||
|
||||
@override
|
||||
ui.TextRange getWordBoundary(ui.TextPosition position) {
|
||||
final int characterPosition;
|
||||
switch (position.affinity) {
|
||||
case ui.TextAffinity.upstream:
|
||||
characterPosition = position.offset - 1;
|
||||
case ui.TextAffinity.downstream:
|
||||
characterPosition = position.offset;
|
||||
}
|
||||
final int characterPosition = switch (position.affinity) {
|
||||
ui.TextAffinity.upstream => position.offset - 1,
|
||||
ui.TextAffinity.downstream => position.offset,
|
||||
};
|
||||
final int start = WordBreaker.prevBreakIndex(plainText, characterPosition + 1);
|
||||
final int end = WordBreaker.nextBreakIndex(plainText, characterPosition);
|
||||
return ui.TextRange(start: start, end: end);
|
||||
|
@ -587,18 +587,13 @@ class LineBuilder {
|
||||
final double emptySpace = maxWidth - width;
|
||||
final ui.TextAlign textAlign = paragraph.paragraphStyle.effectiveTextAlign;
|
||||
|
||||
switch (textAlign) {
|
||||
case ui.TextAlign.center:
|
||||
return emptySpace / 2.0;
|
||||
case ui.TextAlign.right:
|
||||
return emptySpace;
|
||||
case ui.TextAlign.start:
|
||||
return _paragraphDirection == ui.TextDirection.rtl ? emptySpace : 0.0;
|
||||
case ui.TextAlign.end:
|
||||
return _paragraphDirection == ui.TextDirection.rtl ? 0.0 : emptySpace;
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
return switch (textAlign) {
|
||||
ui.TextAlign.center => emptySpace / 2.0,
|
||||
ui.TextAlign.right => emptySpace,
|
||||
ui.TextAlign.start => _paragraphDirection == ui.TextDirection.rtl ? emptySpace : 0.0,
|
||||
ui.TextAlign.end => _paragraphDirection == ui.TextDirection.rtl ? 0.0 : emptySpace,
|
||||
_ => 0.0,
|
||||
};
|
||||
}
|
||||
|
||||
bool get isOverflowing => width > maxWidth;
|
||||
|
@ -1108,26 +1108,11 @@ String? _textDecorationToCssString(
|
||||
}
|
||||
}
|
||||
if (decorationStyle != null) {
|
||||
decorations.write(_decorationStyleToCssString(decorationStyle));
|
||||
decorations.write(decorationStyle.name);
|
||||
}
|
||||
return decorations.isEmpty ? null : decorations.toString();
|
||||
}
|
||||
|
||||
String? _decorationStyleToCssString(ui.TextDecorationStyle decorationStyle) {
|
||||
switch (decorationStyle) {
|
||||
case ui.TextDecorationStyle.dashed:
|
||||
return 'dashed';
|
||||
case ui.TextDecorationStyle.dotted:
|
||||
return 'dotted';
|
||||
case ui.TextDecorationStyle.double:
|
||||
return 'double';
|
||||
case ui.TextDecorationStyle.solid:
|
||||
return 'solid';
|
||||
case ui.TextDecorationStyle.wavy:
|
||||
return 'wavy';
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [align] to its corresponding CSS value.
|
||||
///
|
||||
/// This value is used as the "text-align" CSS property, e.g.:
|
||||
|
@ -166,16 +166,11 @@ FragmentFlow _getFragmentFlow(String text, int i) {
|
||||
}
|
||||
|
||||
final ui.TextDirection? textDirection = _textDirectionLookup.findForChar(codePoint);
|
||||
switch (textDirection) {
|
||||
case ui.TextDirection.ltr:
|
||||
return FragmentFlow.ltr;
|
||||
|
||||
case ui.TextDirection.rtl:
|
||||
return FragmentFlow.rtl;
|
||||
|
||||
case null:
|
||||
return FragmentFlow.sandwich;
|
||||
}
|
||||
return switch (textDirection) {
|
||||
ui.TextDirection.ltr => FragmentFlow.ltr,
|
||||
ui.TextDirection.rtl => FragmentFlow.rtl,
|
||||
null => FragmentFlow.sandwich,
|
||||
};
|
||||
}
|
||||
|
||||
bool _isDigit(int codePoint) {
|
||||
|
@ -345,20 +345,14 @@ String colorValueToCssString(int value) {
|
||||
if ((0xff000000 & value) == 0xff000000) {
|
||||
final String hexValue = (value & 0xFFFFFF).toRadixString(16);
|
||||
final int hexValueLength = hexValue.length;
|
||||
switch (hexValueLength) {
|
||||
case 1:
|
||||
return '#00000$hexValue';
|
||||
case 2:
|
||||
return '#0000$hexValue';
|
||||
case 3:
|
||||
return '#000$hexValue';
|
||||
case 4:
|
||||
return '#00$hexValue';
|
||||
case 5:
|
||||
return '#0$hexValue';
|
||||
default:
|
||||
return '#$hexValue';
|
||||
}
|
||||
return switch (hexValueLength) {
|
||||
1 => '#00000$hexValue',
|
||||
2 => '#0000$hexValue',
|
||||
3 => '#000$hexValue',
|
||||
4 => '#00$hexValue',
|
||||
5 => '#0$hexValue',
|
||||
_ => '#$hexValue',
|
||||
};
|
||||
} else {
|
||||
final double alpha = ((value >> 24) & 0xFF) / 255.0;
|
||||
final StringBuffer sb = StringBuffer();
|
||||
@ -889,20 +883,7 @@ class LruCache<K extends Object, V extends Object> {
|
||||
}
|
||||
|
||||
/// Returns the VM-compatible string for the tile mode.
|
||||
String tileModeString(ui.TileMode? tileMode) {
|
||||
switch (tileMode) {
|
||||
case ui.TileMode.clamp:
|
||||
return 'clamp';
|
||||
case ui.TileMode.mirror:
|
||||
return 'mirror';
|
||||
case ui.TileMode.repeated:
|
||||
return 'repeated';
|
||||
case ui.TileMode.decal:
|
||||
return 'decal';
|
||||
case null:
|
||||
return 'unspecified';
|
||||
}
|
||||
}
|
||||
String tileModeString(ui.TileMode? tileMode) => tileMode?.name ?? 'unspecified';
|
||||
|
||||
/// A size where both the width and height are integers.
|
||||
class BitmapSize {
|
||||
|
Loading…
Reference in New Issue
Block a user