mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[engine/web] Migrate many things to switch expressions (#170096)
This commit is contained in:
parent
c958e8313c
commit
8a41339418
@ -531,35 +531,23 @@ _ColorTransform _getColorTransform(ColorSpace source, ColorSpace destination) {
|
||||
-0.109450321455370, //
|
||||
0.214813187718391, 0.054268702864647, 1.406898424029350, -0.364892765879631,
|
||||
]);
|
||||
switch (source) {
|
||||
case ColorSpace.sRGB:
|
||||
switch (destination) {
|
||||
case ColorSpace.sRGB:
|
||||
return const _IdentityColorTransform();
|
||||
case ColorSpace.extendedSRGB:
|
||||
return const _IdentityColorTransform();
|
||||
case ColorSpace.displayP3:
|
||||
return srgbToP3;
|
||||
}
|
||||
case ColorSpace.extendedSRGB:
|
||||
switch (destination) {
|
||||
case ColorSpace.sRGB:
|
||||
return const _ClampTransform(_IdentityColorTransform());
|
||||
case ColorSpace.extendedSRGB:
|
||||
return const _IdentityColorTransform();
|
||||
case ColorSpace.displayP3:
|
||||
return const _ClampTransform(srgbToP3);
|
||||
}
|
||||
case ColorSpace.displayP3:
|
||||
switch (destination) {
|
||||
case ColorSpace.sRGB:
|
||||
return const _ClampTransform(p3ToSrgb);
|
||||
case ColorSpace.extendedSRGB:
|
||||
return p3ToSrgb;
|
||||
case ColorSpace.displayP3:
|
||||
return const _IdentityColorTransform();
|
||||
}
|
||||
}
|
||||
return switch (source) {
|
||||
ColorSpace.sRGB => switch (destination) {
|
||||
ColorSpace.sRGB => const _IdentityColorTransform(),
|
||||
ColorSpace.extendedSRGB => const _IdentityColorTransform(),
|
||||
ColorSpace.displayP3 => srgbToP3,
|
||||
},
|
||||
ColorSpace.extendedSRGB => switch (destination) {
|
||||
ColorSpace.sRGB => const _ClampTransform(_IdentityColorTransform()),
|
||||
ColorSpace.extendedSRGB => const _IdentityColorTransform(),
|
||||
ColorSpace.displayP3 => const _ClampTransform(srgbToP3),
|
||||
},
|
||||
ColorSpace.displayP3 => switch (destination) {
|
||||
ColorSpace.sRGB => const _ClampTransform(p3ToSrgb),
|
||||
ColorSpace.extendedSRGB => p3ToSrgb,
|
||||
ColorSpace.displayP3 => const _IdentityColorTransform(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// This needs to be kept in sync with the "_FilterQuality" enum in skwasm's canvas.cpp
|
||||
|
||||
@ -119,16 +119,12 @@ class EngineColorFilter implements SceneImageFilter, ui.ColorFilter {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
switch (type) {
|
||||
case ColorFilterType.mode:
|
||||
return 'ColorFilter.mode($color, $blendMode)';
|
||||
case ColorFilterType.matrix:
|
||||
return 'ColorFilter.matrix($matrix)';
|
||||
case ColorFilterType.linearToSrgbGamma:
|
||||
return 'ColorFilter.linearToSrgbGamma()';
|
||||
case ColorFilterType.srgbToLinearGamma:
|
||||
return 'ColorFilter.srgbToLinearGamma()';
|
||||
}
|
||||
return switch (type) {
|
||||
ColorFilterType.mode => 'ColorFilter.mode($color, $blendMode)',
|
||||
ColorFilterType.matrix => 'ColorFilter.matrix($matrix)',
|
||||
ColorFilterType.linearToSrgbGamma => 'ColorFilter.linearToSrgbGamma()',
|
||||
ColorFilterType.srgbToLinearGamma => 'ColorFilter.srgbToLinearGamma()',
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -121,17 +121,12 @@ class ScreenOrientation {
|
||||
//
|
||||
// See also: https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock
|
||||
static String? _deviceOrientationToLockType(String? deviceOrientation) {
|
||||
switch (deviceOrientation) {
|
||||
case 'DeviceOrientation.portraitUp':
|
||||
return lockTypePortraitPrimary;
|
||||
case 'DeviceOrientation.portraitDown':
|
||||
return lockTypePortraitSecondary;
|
||||
case 'DeviceOrientation.landscapeLeft':
|
||||
return lockTypeLandscapePrimary;
|
||||
case 'DeviceOrientation.landscapeRight':
|
||||
return lockTypeLandscapeSecondary;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (deviceOrientation) {
|
||||
'DeviceOrientation.portraitUp' => lockTypePortraitPrimary,
|
||||
'DeviceOrientation.portraitDown' => lockTypePortraitSecondary,
|
||||
'DeviceOrientation.landscapeLeft' => lockTypeLandscapePrimary,
|
||||
'DeviceOrientation.landscapeRight' => lockTypeLandscapeSecondary,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,20 +247,15 @@ class FontFallbackManager {
|
||||
}
|
||||
|
||||
NotoFont _selectFont(List<NotoFont> fonts) {
|
||||
NotoFont? bestFont;
|
||||
// Priority is given to fonts that match the language
|
||||
switch (_language) {
|
||||
case 'zh-Hans' || 'zh-CN' || 'zh-SG' || 'zh-MY':
|
||||
bestFont = fonts.firstWhereOrNull(_isNotoSansSC);
|
||||
case 'zh-Hant' || 'zh-TW' || 'zh-MO':
|
||||
bestFont = fonts.firstWhereOrNull(_isNotoSansTC);
|
||||
case 'zh-HK':
|
||||
bestFont = fonts.firstWhereOrNull(_isNotoSansHK);
|
||||
case 'ja':
|
||||
bestFont = fonts.firstWhereOrNull(_isNotoSansJP);
|
||||
case 'ko':
|
||||
bestFont = fonts.firstWhereOrNull(_isNotoSansKR);
|
||||
}
|
||||
// Priority is given to fonts that match the language.
|
||||
NotoFont? bestFont = switch (_language) {
|
||||
'zh-Hans' || 'zh-CN' || 'zh-SG' || 'zh-MY' => fonts.firstWhereOrNull(_isNotoSansSC),
|
||||
'zh-Hant' || 'zh-TW' || 'zh-MO' => fonts.firstWhereOrNull(_isNotoSansTC),
|
||||
'zh-HK' => fonts.firstWhereOrNull(_isNotoSansHK),
|
||||
'ja' => fonts.firstWhereOrNull(_isNotoSansJP),
|
||||
'ko' => fonts.firstWhereOrNull(_isNotoSansKR),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (bestFont != null) {
|
||||
return bestFont;
|
||||
|
||||
@ -234,17 +234,14 @@ class KeyboardConverter {
|
||||
final locale_keymap.LocaleKeymap _mapping;
|
||||
|
||||
static locale_keymap.LocaleKeymap _mappingFromPlatform(ui_web.OperatingSystem platform) {
|
||||
switch (platform) {
|
||||
case ui_web.OperatingSystem.iOs:
|
||||
case ui_web.OperatingSystem.macOs:
|
||||
return locale_keymap.LocaleKeymap.darwin();
|
||||
case ui_web.OperatingSystem.windows:
|
||||
return locale_keymap.LocaleKeymap.win();
|
||||
case ui_web.OperatingSystem.android:
|
||||
case ui_web.OperatingSystem.linux:
|
||||
case ui_web.OperatingSystem.unknown:
|
||||
return locale_keymap.LocaleKeymap.linux();
|
||||
}
|
||||
return switch (platform) {
|
||||
ui_web.OperatingSystem.iOs ||
|
||||
ui_web.OperatingSystem.macOs => locale_keymap.LocaleKeymap.darwin(),
|
||||
ui_web.OperatingSystem.windows => locale_keymap.LocaleKeymap.win(),
|
||||
ui_web.OperatingSystem.android ||
|
||||
ui_web.OperatingSystem.linux ||
|
||||
ui_web.OperatingSystem.unknown => locale_keymap.LocaleKeymap.linux(),
|
||||
};
|
||||
}
|
||||
|
||||
// The `performDispatchKeyData` wrapped with tracking logic.
|
||||
|
||||
@ -666,18 +666,13 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
const int vibrateHeavyImpact = 30;
|
||||
const int vibrateSelectionClick = 10;
|
||||
|
||||
switch (type) {
|
||||
case 'HapticFeedbackType.lightImpact':
|
||||
return vibrateLightImpact;
|
||||
case 'HapticFeedbackType.mediumImpact':
|
||||
return vibrateMediumImpact;
|
||||
case 'HapticFeedbackType.heavyImpact':
|
||||
return vibrateHeavyImpact;
|
||||
case 'HapticFeedbackType.selectionClick':
|
||||
return vibrateSelectionClick;
|
||||
default:
|
||||
return vibrateLongPress;
|
||||
}
|
||||
return switch (type) {
|
||||
'HapticFeedbackType.lightImpact' => vibrateLightImpact,
|
||||
'HapticFeedbackType.mediumImpact' => vibrateMediumImpact,
|
||||
'HapticFeedbackType.heavyImpact' => vibrateHeavyImpact,
|
||||
'HapticFeedbackType.selectionClick' => vibrateSelectionClick,
|
||||
_ => vibrateLongPress,
|
||||
};
|
||||
}
|
||||
|
||||
/// Requests that, at the next appropriate opportunity, the [onBeginFrame]
|
||||
|
||||
@ -69,16 +69,12 @@ int _nthButton(int n) => 0x1 << n;
|
||||
@visibleForTesting
|
||||
int convertButtonToButtons(int button) {
|
||||
assert(button >= 0, 'Unexpected negative button $button.');
|
||||
switch (button) {
|
||||
case 0:
|
||||
return _kPrimaryMouseButton;
|
||||
case 1:
|
||||
return _kMiddleMouseButton;
|
||||
case 2:
|
||||
return _kSecondaryMouseButton;
|
||||
default:
|
||||
return _nthButton(button);
|
||||
}
|
||||
return switch (button) {
|
||||
0 => _kPrimaryMouseButton,
|
||||
1 => _kMiddleMouseButton,
|
||||
2 => _kSecondaryMouseButton,
|
||||
_ => _nthButton(button),
|
||||
};
|
||||
}
|
||||
|
||||
/// Wrapping the Safari iOS workaround that adds a dummy event listener
|
||||
@ -1119,16 +1115,12 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
|
||||
}
|
||||
|
||||
ui.PointerDeviceKind _pointerTypeToDeviceKind(String pointerType) {
|
||||
switch (pointerType) {
|
||||
case 'mouse':
|
||||
return ui.PointerDeviceKind.mouse;
|
||||
case 'pen':
|
||||
return ui.PointerDeviceKind.stylus;
|
||||
case 'touch':
|
||||
return ui.PointerDeviceKind.touch;
|
||||
default:
|
||||
return ui.PointerDeviceKind.unknown;
|
||||
}
|
||||
return switch (pointerType) {
|
||||
'mouse' => ui.PointerDeviceKind.mouse,
|
||||
'pen' => ui.PointerDeviceKind.stylus,
|
||||
'touch' => ui.PointerDeviceKind.touch,
|
||||
_ => ui.PointerDeviceKind.unknown,
|
||||
};
|
||||
}
|
||||
|
||||
int _getPointerId(DomPointerEvent event) {
|
||||
|
||||
@ -59,12 +59,10 @@ class AccessibilityAnnouncements {
|
||||
|
||||
/// Looks up the element used to announce messages of the given [assertiveness].
|
||||
DomHTMLElement ariaLiveElementFor(Assertiveness assertiveness) {
|
||||
switch (assertiveness) {
|
||||
case Assertiveness.polite:
|
||||
return _politeElement;
|
||||
case Assertiveness.assertive:
|
||||
return _assertiveElement;
|
||||
}
|
||||
return switch (assertiveness) {
|
||||
Assertiveness.polite => _politeElement,
|
||||
Assertiveness.assertive => _assertiveElement,
|
||||
};
|
||||
}
|
||||
|
||||
/// Makes an accessibity announcement from a message sent by the framework
|
||||
|
||||
@ -354,18 +354,13 @@ class SemanticTextField extends SemanticRole {
|
||||
if (semanticsObject.hasFlag(ui.SemanticsFlag.isObscured)) {
|
||||
input.type = 'password';
|
||||
} else {
|
||||
switch (semanticsObject.inputType) {
|
||||
case ui.SemanticsInputType.search:
|
||||
input.type = 'search';
|
||||
case ui.SemanticsInputType.email:
|
||||
input.type = 'email';
|
||||
case ui.SemanticsInputType.url:
|
||||
input.type = 'url';
|
||||
case ui.SemanticsInputType.phone:
|
||||
input.type = 'tel';
|
||||
default:
|
||||
input.type = 'text';
|
||||
}
|
||||
input.type = switch (semanticsObject.inputType) {
|
||||
ui.SemanticsInputType.search => 'search',
|
||||
ui.SemanticsInputType.email => 'email',
|
||||
ui.SemanticsInputType.url => 'url',
|
||||
ui.SemanticsInputType.phone => 'tel',
|
||||
_ => 'text',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -144,19 +144,15 @@ String textAlignToCssValue(ui.TextAlign? align, ui.TextDirection textDirection)
|
||||
case ui.TextAlign.justify:
|
||||
return 'justify';
|
||||
case ui.TextAlign.end:
|
||||
switch (textDirection) {
|
||||
case ui.TextDirection.ltr:
|
||||
return 'end';
|
||||
case ui.TextDirection.rtl:
|
||||
return 'left';
|
||||
}
|
||||
return switch (textDirection) {
|
||||
ui.TextDirection.ltr => 'end',
|
||||
ui.TextDirection.rtl => 'left',
|
||||
};
|
||||
case ui.TextAlign.start:
|
||||
switch (textDirection) {
|
||||
case ui.TextDirection.ltr:
|
||||
return ''; // it's the default
|
||||
case ui.TextDirection.rtl:
|
||||
return 'right';
|
||||
}
|
||||
return switch (textDirection) {
|
||||
ui.TextDirection.ltr => '', // it's the default
|
||||
ui.TextDirection.rtl => 'right',
|
||||
};
|
||||
case null:
|
||||
// If align is not specified return default.
|
||||
return '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user