Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate compat info changes into flutter engine #19606

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/web_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ analyzer:
missing_required_param: warning
missing_return: warning
native_function_body_in_non_sdk_code: ignore
unnecessary_non_null_assertion: ignore
unnecessary_null_comparison: ignore
todo: ignore

linter:
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AssetManager {
.warn('Asset manifest does not exist at `$url` – ignoring.');
return Uint8List.fromList(utf8.encode('{}')).buffer.asByteData();
}
throw AssetManagerException(url, target.status);
throw AssetManagerException(url, target.status!);
}

html.window.console.warn('Caught ProgressEvent with target: $target');
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/bitmap_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class BitmapCanvas extends EngineCanvas {
}

html.ImageElement _reuseOrCreateImage(HtmlImage htmlImage) {
final String cacheKey = htmlImage.imgElement.src;
final String cacheKey = htmlImage.imgElement.src!;
if (_elementCache != null) {
html.ImageElement? imageElement = _elementCache!.reuse(cacheKey) as html.ImageElement?;
if (imageElement != null) {
Expand Down Expand Up @@ -674,7 +674,7 @@ class BitmapCanvas extends EngineCanvas {
for (int i = 0; i < len; i++) {
final String char = line.displayText![i];
ctx!.fillText(char, x, y);
x += letterSpacing + ctx.measureText(char).width;
x += letterSpacing + ctx.measureText(char).width!;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/browser_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ OperatingSystem get operatingSystem {
OperatingSystem? debugOperatingSystemOverride;

OperatingSystem _detectOperatingSystem() {
final String platform = html.window.navigator.platform;
final String platform = html.window.navigator.platform!;
final String userAgent = html.window.navigator.userAgent;

if (platform.startsWith('Mac')) {
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/browser_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ class BrowserPlatformLocation extends PlatformLocation {
}

@override
String get pathname => _location.pathname;
String get pathname => _location.pathname!;

@override
String get search => _location.search;
String get search => _location.search!;

@override
String get hash => _location.hash;
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/clipboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy {
@override
Future<bool> setData(String? text) async {
try {
await html.window.navigator.clipboard.writeText(text!);
await html.window.navigator.clipboard!.writeText(text!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we no longer need to use _unsafeIsNull on line 95 to check for clipboard presence. Also, I imagine window.navigator.clipboard is a singleton, and so we can store it in a final non-null field, null check it in the initializer once, and remove the null assertions here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to check whether it's null in order to determine what "Strategy" class to initialize, right?

I don't think clipboard can be made a singleton since _Clipboard is a private class (unless we declared the field as dynamic).

} catch (error) {
print('copy is not successful $error');
return Future.value(false);
Expand All @@ -127,7 +127,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy {
class ClipboardAPIPasteStrategy implements PasteFromClipboardStrategy {
@override
Future<String> getData() async {
return html.window.navigator.clipboard.readText();
return html.window.navigator.clipboard!.readText();
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/dom_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ flt-glass-pane * {
// Firefox returns correct values for innerHeight, innerWidth.
// Firefox also triggers html.window.onResize therefore we don't need this
// timer setup for Firefox.
final int initialInnerWidth = html.window.innerWidth;
final int initialInnerWidth = html.window.innerWidth!;
// Counts how many times we checked screen size. We check up to 5 times.
int checkCount = 0;
Timer.periodic(const Duration(milliseconds: 100), (Timer t) {
Expand Down Expand Up @@ -534,10 +534,10 @@ flt-glass-pane * {
///
/// See w3c screen api: https://www.w3.org/TR/screen-orientation/
Future<bool> setPreferredOrientation(List<dynamic>? orientations) {
final html.Screen screen = html.window.screen;
final html.Screen screen = html.window.screen!;
if (!_unsafeIsNull(screen)) {
final html.ScreenOrientation screenOrientation =
screen.orientation;
screen.orientation!;
if (!_unsafeIsNull(screenOrientation)) {
if (orientations!.isEmpty) {
screenOrientation.unlock();
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Keyboard {
event.preventDefault();
}

final String timerKey = keyboardEvent.code;
final String timerKey = keyboardEvent.code!;

// Don't synthesize a keyup event for modifier keys because the browser always
// sends a keyup event for those.
Expand Down Expand Up @@ -181,7 +181,7 @@ int _getMetaState(html.KeyboardEvent event) {
/// Modifier keys are shift, alt, ctrl and meta/cmd/win. These are the keys used
/// to perform keyboard shortcuts (e.g. `cmd+c`, `cmd+l`).
bool _isModifierKey(html.KeyboardEvent event) {
final String key = event.key;
final String key = event.key!;
return key == 'Meta' || key == 'Shift' || key == 'Alt' || key == 'Control';
}

Expand Down
64 changes: 32 additions & 32 deletions lib/web_ui/lib/src/engine/pointer_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ mixin _WheelEventListenerMixin on _BaseAdapter {
_pointerDataConverter.convert(
data,
change: ui.PointerChange.hover,
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp),
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.scroll,
device: _mouseDeviceId,
physicalX: event.client.x * ui.window.devicePixelRatio as double,
physicalY: event.client.y * ui.window.devicePixelRatio as double,
buttons: event.buttons,
buttons: event.buttons!,
pressure: 1.0,
pressureMin: 0.0,
pressureMax: 1.0,
Expand Down Expand Up @@ -444,23 +444,23 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
@override
void setup() {
_addPointerEventListener('pointerdown', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails details =
_ensureSanitizer(device).sanitizeDownEvent(
button: event.button,
buttons: event.buttons,
buttons: event.buttons!,
);
_convertEventsToPointerData(data: pointerData, event: event, details: details);
_callback(pointerData);
});

_addPointerEventListener('pointermove', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final _ButtonSanitizer sanitizer = _ensureSanitizer(device);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final Iterable<_SanitizedDetails> detailsList = _expandEvents(event).map(
(html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons),
(html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons!),
);
for (_SanitizedDetails details in detailsList) {
_convertEventsToPointerData(data: pointerData, event: event, details: details);
Expand All @@ -469,7 +469,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
}, acceptOutsideGlasspane: true);

_addPointerEventListener('pointerup', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails? details = _getSanitizer(device).sanitizeUpEvent();
_removePointerIfUnhoverable(event);
Expand All @@ -482,7 +482,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
// A browser fires cancel event if it concludes the pointer will no longer
// be able to generate events (example: device is deactivated)
_addPointerEventListener('pointercancel', (html.PointerEvent event) {
final int device = event.pointerId;
final int device = event.pointerId!;
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails details = _getSanitizer(device).sanitizeCancelEvent();
_removePointerIfUnhoverable(event);
Expand Down Expand Up @@ -512,13 +512,13 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
assert(data != null); // ignore: unnecessary_null_comparison
assert(event != null); // ignore: unnecessary_null_comparison
assert(details != null); // ignore: unnecessary_null_comparison
final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType);
final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType!);
// We force `device: _mouseDeviceId` on mouse pointers because Wheel events
// might come before any PointerEvents, and since wheel events don't contain
// pointerId we always assign `device: _mouseDeviceId` to them.
final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId;
final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId!;
final double tilt = _computeHighestTilt(event);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
_pointerDataConverter.convert(
data,
change: details.change,
Expand Down Expand Up @@ -566,7 +566,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {

/// Tilt angle is -90 to + 90. Take maximum deflection and convert to radians.
double _computeHighestTilt(html.PointerEvent e) =>
(e.tiltX.abs() > e.tiltY.abs() ? e.tiltX : e.tiltY).toDouble() /
(e.tiltX!.abs() > e.tiltY!.abs() ? e.tiltX : e.tiltY)!.toDouble() /
180.0 *
math.pi;
}
Expand Down Expand Up @@ -596,12 +596,12 @@ class _TouchAdapter extends _BaseAdapter {
@override
void setup() {
_addTouchEventListener('touchstart', (html.TouchEvent event) {
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (!nowPressed) {
_pressTouch(touch.identifier);
_pressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.down,
Expand All @@ -616,10 +616,10 @@ class _TouchAdapter extends _BaseAdapter {

_addTouchEventListener('touchmove', (html.TouchEvent event) {
event.preventDefault(); // Prevents standard overscroll on iOS/Webkit.
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_convertEventToPointerData(
data: pointerData,
Expand All @@ -637,12 +637,12 @@ class _TouchAdapter extends _BaseAdapter {
// On Safari Mobile, the keyboard does not show unless this line is
// added.
event.preventDefault();
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_unpressTouch(touch.identifier);
_unpressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.up,
Expand All @@ -656,12 +656,12 @@ class _TouchAdapter extends _BaseAdapter {
});

_addTouchEventListener('touchcancel', (html.TouchEvent event) {
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp);
final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!);
final List<ui.PointerData> pointerData = <ui.PointerData>[];
for (html.Touch touch in event.changedTouches) {
final nowPressed = _isTouchPressed(touch.identifier);
for (html.Touch touch in event.changedTouches!) {
final nowPressed = _isTouchPressed(touch.identifier!);
if (nowPressed) {
_unpressTouch(touch.identifier);
_unpressTouch(touch.identifier!);
_convertEventToPointerData(
data: pointerData,
change: ui.PointerChange.cancel,
Expand All @@ -688,7 +688,7 @@ class _TouchAdapter extends _BaseAdapter {
timeStamp: timeStamp,
kind: ui.PointerDeviceKind.touch,
signalKind: ui.PointerSignalKind.none,
device: touch.identifier,
device: touch.identifier!,
physicalX: touch.client.x * ui.window.devicePixelRatio as double,
physicalY: touch.client.y * ui.window.devicePixelRatio as double,
buttons: pressed ? _kPrimaryMouseButton : 0,
Expand Down Expand Up @@ -746,15 +746,15 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
final _SanitizedDetails sanitizedDetails =
_sanitizer.sanitizeDownEvent(
button: event.button,
buttons: event.buttons,
buttons: event.buttons!,
);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
});

_addMouseEventListener('mousemove', (html.MouseEvent event) {
final List<ui.PointerData> pointerData = <ui.PointerData>[];
final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons);
final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons!);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
}, acceptOutsideGlasspane: true);
Expand All @@ -764,7 +764,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
final bool isEndOfDrag = event.buttons == 0;
final _SanitizedDetails sanitizedDetails = isEndOfDrag ?
_sanitizer.sanitizeUpEvent()! :
_sanitizer.sanitizeMoveEvent(buttons: event.buttons);
_sanitizer.sanitizeMoveEvent(buttons: event.buttons!);
_convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails);
_callback(pointerData);
}, acceptOutsideGlasspane: true);
Expand Down Expand Up @@ -794,7 +794,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin {
_pointerDataConverter.convert(
data,
change: details.change,
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp),
timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!),
kind: ui.PointerDeviceKind.mouse,
signalKind: ui.PointerSignalKind.none,
device: _mouseDeviceId,
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/lib/src/engine/semantics/incrementable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class Incrementable extends RoleManager {
_element.setAttribute('role', 'slider');

_element.addEventListener('change', (_) {
if (_element.disabled) {
if (_element.disabled!) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this property is nullable. Even the most ancient browsers should have this property, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Here, it's a limitation of the language: there is a class that extends InputElement that has disabled marked as nullable (probably due to some incompatibility), so this InputElement.disabled needs to also be nullable.

return;
}
_pendingResync = true;
final int newInputValue = int.parse(_element.value);
final int newInputValue = int.parse(_element.value!);
if (newInputValue > _currentSurrogateValue) {
_currentSurrogateValue += 1;
window.invokeOnSemanticsAction(
Expand Down Expand Up @@ -84,7 +84,7 @@ class Incrementable extends RoleManager {

void _enableBrowserGestureHandling() {
assert(semanticsObject.owner.gestureMode == GestureMode.browserGestures);
if (!_element.disabled) {
if (!_element.disabled!) {
return;
}
_element.disabled = false;
Expand Down Expand Up @@ -123,7 +123,7 @@ class Incrementable extends RoleManager {
}

void _disableBrowserGestureHandling() {
if (_element.disabled) {
if (_element.disabled!) {
return;
}
_element.disabled = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/semantics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
case 'touchstart':
case 'touchend':
final html.TouchEvent touch = event as html.TouchEvent;
activationPoint = touch.changedTouches.first.client;
activationPoint = touch.changedTouches!.first.client;
break;
default:
// The event is not relevant, forward to framework as normal.
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ class TextField extends RoleManager {
_textFieldElement.addEventListener('touchstart', (html.Event event) {
textEditing.useCustomEditableElement(textEditingElement);
final html.TouchEvent touchEvent = event as html.TouchEvent;
lastTouchStartOffsetX = touchEvent.changedTouches.last.client.x;
lastTouchStartOffsetY = touchEvent.changedTouches.last.client.y;
lastTouchStartOffsetX = touchEvent.changedTouches!.last.client.x;
lastTouchStartOffsetY = touchEvent.changedTouches!.last.client.y;
}, true);

_textFieldElement.addEventListener('touchend', (html.Event event) {
final html.TouchEvent touchEvent = event as html.TouchEvent;

if (lastTouchStartOffsetX != null) {
assert(lastTouchStartOffsetY != null);
final num offsetX = touchEvent.changedTouches.last.client.x;
final num offsetY = touchEvent.changedTouches.last.client.y;
final num offsetX = touchEvent.changedTouches!.last.client.x;
final num offsetY = touchEvent.changedTouches!.last.client.y;

// This should match the similar constant define in:
//
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/surface/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class PersistedScene extends PersistedContainerSurface {
// TODO(yjbanov): in the add2app scenario where we might be hosted inside
// a custom element, this will be different. We will need to
// update this code when we add add2app support.
final double screenWidth = html.window.innerWidth.toDouble();
final double screenHeight = html.window.innerHeight.toDouble();
final double screenWidth = html.window.innerWidth!.toDouble();
final double screenHeight = html.window.innerHeight!.toDouble();
_localClipBounds = ui.Rect.fromLTRB(0, 0, screenWidth, screenHeight);
_localTransformInverse = Matrix4.identity();
_projectedClip = null;
Expand Down
Loading