Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a41339

Browse filesBrowse files
authored
[engine/web] Migrate many things to switch expressions (flutter#170096)
1 parent c958e83 commit 8a41339
Copy full SHA for 8a41339

File tree

Expand file treeCollapse file tree

10 files changed

+85
-138
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+85
-138
lines changed

‎engine/src/flutter/lib/web_ui/lib/painting.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/painting.dart
+17-29Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -531,35 +531,23 @@ _ColorTransform _getColorTransform(ColorSpace source, ColorSpace destination) {
531531
-0.109450321455370, //
532532
0.214813187718391, 0.054268702864647, 1.406898424029350, -0.364892765879631,
533533
]);
534-
switch (source) {
535-
case ColorSpace.sRGB:
536-
switch (destination) {
537-
case ColorSpace.sRGB:
538-
return const _IdentityColorTransform();
539-
case ColorSpace.extendedSRGB:
540-
return const _IdentityColorTransform();
541-
case ColorSpace.displayP3:
542-
return srgbToP3;
543-
}
544-
case ColorSpace.extendedSRGB:
545-
switch (destination) {
546-
case ColorSpace.sRGB:
547-
return const _ClampTransform(_IdentityColorTransform());
548-
case ColorSpace.extendedSRGB:
549-
return const _IdentityColorTransform();
550-
case ColorSpace.displayP3:
551-
return const _ClampTransform(srgbToP3);
552-
}
553-
case ColorSpace.displayP3:
554-
switch (destination) {
555-
case ColorSpace.sRGB:
556-
return const _ClampTransform(p3ToSrgb);
557-
case ColorSpace.extendedSRGB:
558-
return p3ToSrgb;
559-
case ColorSpace.displayP3:
560-
return const _IdentityColorTransform();
561-
}
562-
}
534+
return switch (source) {
535+
ColorSpace.sRGB => switch (destination) {
536+
ColorSpace.sRGB => const _IdentityColorTransform(),
537+
ColorSpace.extendedSRGB => const _IdentityColorTransform(),
538+
ColorSpace.displayP3 => srgbToP3,
539+
},
540+
ColorSpace.extendedSRGB => switch (destination) {
541+
ColorSpace.sRGB => const _ClampTransform(_IdentityColorTransform()),
542+
ColorSpace.extendedSRGB => const _IdentityColorTransform(),
543+
ColorSpace.displayP3 => const _ClampTransform(srgbToP3),
544+
},
545+
ColorSpace.displayP3 => switch (destination) {
546+
ColorSpace.sRGB => const _ClampTransform(p3ToSrgb),
547+
ColorSpace.extendedSRGB => p3ToSrgb,
548+
ColorSpace.displayP3 => const _IdentityColorTransform(),
549+
},
550+
};
563551
}
564552

565553
// This needs to be kept in sync with the "_FilterQuality" enum in skwasm's canvas.cpp

‎engine/src/flutter/lib/web_ui/lib/src/engine/color_filter.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/color_filter.dart
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,12 @@ class EngineColorFilter implements SceneImageFilter, ui.ColorFilter {
119119

120120
@override
121121
String toString() {
122-
switch (type) {
123-
case ColorFilterType.mode:
124-
return 'ColorFilter.mode($color, $blendMode)';
125-
case ColorFilterType.matrix:
126-
return 'ColorFilter.matrix($matrix)';
127-
case ColorFilterType.linearToSrgbGamma:
128-
return 'ColorFilter.linearToSrgbGamma()';
129-
case ColorFilterType.srgbToLinearGamma:
130-
return 'ColorFilter.srgbToLinearGamma()';
131-
}
122+
return switch (type) {
123+
ColorFilterType.mode => 'ColorFilter.mode($color, $blendMode)',
124+
ColorFilterType.matrix => 'ColorFilter.matrix($matrix)',
125+
ColorFilterType.linearToSrgbGamma => 'ColorFilter.linearToSrgbGamma()',
126+
ColorFilterType.srgbToLinearGamma => 'ColorFilter.srgbToLinearGamma()',
127+
};
132128
}
133129

134130
@override

‎engine/src/flutter/lib/web_ui/lib/src/engine/display.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/display.dart
+7-12Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,12 @@ class ScreenOrientation {
121121
//
122122
// See also: https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock
123123
static String? _deviceOrientationToLockType(String? deviceOrientation) {
124-
switch (deviceOrientation) {
125-
case 'DeviceOrientation.portraitUp':
126-
return lockTypePortraitPrimary;
127-
case 'DeviceOrientation.portraitDown':
128-
return lockTypePortraitSecondary;
129-
case 'DeviceOrientation.landscapeLeft':
130-
return lockTypeLandscapePrimary;
131-
case 'DeviceOrientation.landscapeRight':
132-
return lockTypeLandscapeSecondary;
133-
default:
134-
return null;
135-
}
124+
return switch (deviceOrientation) {
125+
'DeviceOrientation.portraitUp' => lockTypePortraitPrimary,
126+
'DeviceOrientation.portraitDown' => lockTypePortraitSecondary,
127+
'DeviceOrientation.landscapeLeft' => lockTypeLandscapePrimary,
128+
'DeviceOrientation.landscapeRight' => lockTypeLandscapeSecondary,
129+
_ => null,
130+
};
136131
}
137132
}

‎engine/src/flutter/lib/web_ui/lib/src/engine/font_fallbacks.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/font_fallbacks.dart
+9-14Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,15 @@ class FontFallbackManager {
247247
}
248248

249249
NotoFont _selectFont(List<NotoFont> fonts) {
250-
NotoFont? bestFont;
251-
// Priority is given to fonts that match the language
252-
switch (_language) {
253-
case 'zh-Hans' || 'zh-CN' || 'zh-SG' || 'zh-MY':
254-
bestFont = fonts.firstWhereOrNull(_isNotoSansSC);
255-
case 'zh-Hant' || 'zh-TW' || 'zh-MO':
256-
bestFont = fonts.firstWhereOrNull(_isNotoSansTC);
257-
case 'zh-HK':
258-
bestFont = fonts.firstWhereOrNull(_isNotoSansHK);
259-
case 'ja':
260-
bestFont = fonts.firstWhereOrNull(_isNotoSansJP);
261-
case 'ko':
262-
bestFont = fonts.firstWhereOrNull(_isNotoSansKR);
263-
}
250+
// Priority is given to fonts that match the language.
251+
NotoFont? bestFont = switch (_language) {
252+
'zh-Hans' || 'zh-CN' || 'zh-SG' || 'zh-MY' => fonts.firstWhereOrNull(_isNotoSansSC),
253+
'zh-Hant' || 'zh-TW' || 'zh-MO' => fonts.firstWhereOrNull(_isNotoSansTC),
254+
'zh-HK' => fonts.firstWhereOrNull(_isNotoSansHK),
255+
'ja' => fonts.firstWhereOrNull(_isNotoSansJP),
256+
'ko' => fonts.firstWhereOrNull(_isNotoSansKR),
257+
_ => null,
258+
};
264259

265260
if (bestFont != null) {
266261
return bestFont;

‎engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,14 @@ class KeyboardConverter {
234234
final locale_keymap.LocaleKeymap _mapping;
235235

236236
static locale_keymap.LocaleKeymap _mappingFromPlatform(ui_web.OperatingSystem platform) {
237-
switch (platform) {
238-
case ui_web.OperatingSystem.iOs:
239-
case ui_web.OperatingSystem.macOs:
240-
return locale_keymap.LocaleKeymap.darwin();
241-
case ui_web.OperatingSystem.windows:
242-
return locale_keymap.LocaleKeymap.win();
243-
case ui_web.OperatingSystem.android:
244-
case ui_web.OperatingSystem.linux:
245-
case ui_web.OperatingSystem.unknown:
246-
return locale_keymap.LocaleKeymap.linux();
247-
}
237+
return switch (platform) {
238+
ui_web.OperatingSystem.iOs ||
239+
ui_web.OperatingSystem.macOs => locale_keymap.LocaleKeymap.darwin(),
240+
ui_web.OperatingSystem.windows => locale_keymap.LocaleKeymap.win(),
241+
ui_web.OperatingSystem.android ||
242+
ui_web.OperatingSystem.linux ||
243+
ui_web.OperatingSystem.unknown => locale_keymap.LocaleKeymap.linux(),
244+
};
248245
}
249246

250247
// The `performDispatchKeyData` wrapped with tracking logic.

‎engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart
+7-12Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,18 +666,13 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
666666
const int vibrateHeavyImpact = 30;
667667
const int vibrateSelectionClick = 10;
668668

669-
switch (type) {
670-
case 'HapticFeedbackType.lightImpact':
671-
return vibrateLightImpact;
672-
case 'HapticFeedbackType.mediumImpact':
673-
return vibrateMediumImpact;
674-
case 'HapticFeedbackType.heavyImpact':
675-
return vibrateHeavyImpact;
676-
case 'HapticFeedbackType.selectionClick':
677-
return vibrateSelectionClick;
678-
default:
679-
return vibrateLongPress;
680-
}
669+
return switch (type) {
670+
'HapticFeedbackType.lightImpact' => vibrateLightImpact,
671+
'HapticFeedbackType.mediumImpact' => vibrateMediumImpact,
672+
'HapticFeedbackType.heavyImpact' => vibrateHeavyImpact,
673+
'HapticFeedbackType.selectionClick' => vibrateSelectionClick,
674+
_ => vibrateLongPress,
675+
};
681676
}
682677

683678
/// Requests that, at the next appropriate opportunity, the [onBeginFrame]

‎engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart
+12-20Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,12 @@ int _nthButton(int n) => 0x1 << n;
6969
@visibleForTesting
7070
int convertButtonToButtons(int button) {
7171
assert(button >= 0, 'Unexpected negative button $button.');
72-
switch (button) {
73-
case 0:
74-
return _kPrimaryMouseButton;
75-
case 1:
76-
return _kMiddleMouseButton;
77-
case 2:
78-
return _kSecondaryMouseButton;
79-
default:
80-
return _nthButton(button);
81-
}
72+
return switch (button) {
73+
0 => _kPrimaryMouseButton,
74+
1 => _kMiddleMouseButton,
75+
2 => _kSecondaryMouseButton,
76+
_ => _nthButton(button),
77+
};
8278
}
8379

8480
/// Wrapping the Safari iOS workaround that adds a dummy event listener
@@ -1119,16 +1115,12 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
11191115
}
11201116

11211117
ui.PointerDeviceKind _pointerTypeToDeviceKind(String pointerType) {
1122-
switch (pointerType) {
1123-
case 'mouse':
1124-
return ui.PointerDeviceKind.mouse;
1125-
case 'pen':
1126-
return ui.PointerDeviceKind.stylus;
1127-
case 'touch':
1128-
return ui.PointerDeviceKind.touch;
1129-
default:
1130-
return ui.PointerDeviceKind.unknown;
1131-
}
1118+
return switch (pointerType) {
1119+
'mouse' => ui.PointerDeviceKind.mouse,
1120+
'pen' => ui.PointerDeviceKind.stylus,
1121+
'touch' => ui.PointerDeviceKind.touch,
1122+
_ => ui.PointerDeviceKind.unknown,
1123+
};
11321124
}
11331125

11341126
int _getPointerId(DomPointerEvent event) {

‎engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ class AccessibilityAnnouncements {
5959

6060
/// Looks up the element used to announce messages of the given [assertiveness].
6161
DomHTMLElement ariaLiveElementFor(Assertiveness assertiveness) {
62-
switch (assertiveness) {
63-
case Assertiveness.polite:
64-
return _politeElement;
65-
case Assertiveness.assertive:
66-
return _assertiveElement;
67-
}
62+
return switch (assertiveness) {
63+
Assertiveness.polite => _politeElement,
64+
Assertiveness.assertive => _assertiveElement,
65+
};
6866
}
6967

7068
/// Makes an accessibity announcement from a message sent by the framework

‎engine/src/flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart
+7-12Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,13 @@ class SemanticTextField extends SemanticRole {
354354
if (semanticsObject.hasFlag(ui.SemanticsFlag.isObscured)) {
355355
input.type = 'password';
356356
} else {
357-
switch (semanticsObject.inputType) {
358-
case ui.SemanticsInputType.search:
359-
input.type = 'search';
360-
case ui.SemanticsInputType.email:
361-
input.type = 'email';
362-
case ui.SemanticsInputType.url:
363-
input.type = 'url';
364-
case ui.SemanticsInputType.phone:
365-
input.type = 'tel';
366-
default:
367-
input.type = 'text';
368-
}
357+
input.type = switch (semanticsObject.inputType) {
358+
ui.SemanticsInputType.search => 'search',
359+
ui.SemanticsInputType.email => 'email',
360+
ui.SemanticsInputType.url => 'url',
361+
ui.SemanticsInputType.phone => 'tel',
362+
_ => 'text',
363+
};
369364
}
370365
}
371366

‎engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart
+8-12Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,15 @@ String textAlignToCssValue(ui.TextAlign? align, ui.TextDirection textDirection)
144144
case ui.TextAlign.justify:
145145
return 'justify';
146146
case ui.TextAlign.end:
147-
switch (textDirection) {
148-
case ui.TextDirection.ltr:
149-
return 'end';
150-
case ui.TextDirection.rtl:
151-
return 'left';
152-
}
147+
return switch (textDirection) {
148+
ui.TextDirection.ltr => 'end',
149+
ui.TextDirection.rtl => 'left',
150+
};
153151
case ui.TextAlign.start:
154-
switch (textDirection) {
155-
case ui.TextDirection.ltr:
156-
return ''; // it's the default
157-
case ui.TextDirection.rtl:
158-
return 'right';
159-
}
152+
return switch (textDirection) {
153+
ui.TextDirection.ltr => '', // it's the default
154+
ui.TextDirection.rtl => 'right',
155+
};
160156
case null:
161157
// If align is not specified return default.
162158
return '';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.