Skip to content

Commit

Permalink
[web] Make glassPaneElement and glassPaneShadow non-nullable (#39692)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebbar authored Feb 17, 2023
1 parent 0a27673 commit e7fde3f
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 34 deletions.
16 changes: 7 additions & 9 deletions lib/web_ui/lib/src/engine/embedder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ class FlutterViewEmbedder {
/// which captures semantics input events. The semantics DOM tree must be a
/// child of the glass pane element so that events bubble up to the glass pane
/// if they are not handled by semantics.
DomElement? get glassPaneElement => _glassPaneElement;
DomElement? _glassPaneElement;
DomElement get glassPaneElement => _glassPaneElement;
late DomElement _glassPaneElement;

/// The [HostNode] of the [glassPaneElement], which contains the whole Flutter app.
HostNode? get glassPaneShadow => _glassPaneShadow;
HostNode? _glassPaneShadow;
HostNode get glassPaneShadow => _glassPaneShadow;
late HostNode _glassPaneShadow;

static const String defaultFontStyle = 'normal';
static const String defaultFontWeight = 'normal';
Expand All @@ -149,9 +149,7 @@ class FlutterViewEmbedder {
);

// Create and inject the [_glassPaneElement].
final DomElement glassPaneElement =
domDocument.createElement(glassPaneTagName);
_glassPaneElement = glassPaneElement;
_glassPaneElement = domDocument.createElement(glassPaneTagName);

// This must be attached to the DOM now, so the engine can create a host
// node (ShadowDOM or a fallback) next.
Expand Down Expand Up @@ -340,8 +338,8 @@ class FlutterViewEmbedder {
_embeddingStrategy.attachResourcesHost(resourcesHost,
nextTo: glassPaneElement);
} else {
glassPaneShadow!.node
.insertBefore(resourcesHost, glassPaneShadow!.node.firstChild);
glassPaneShadow.node
.insertBefore(resourcesHost, glassPaneShadow.node.firstChild);
}
_resourcesHost = resourcesHost;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/mouse_cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MouseCursor {

void activateSystemCursor(String? kind) {
setElementStyle(
flutterViewEmbedder.glassPaneElement!,
flutterViewEmbedder.glassPaneElement,
'cursor',
_mapKindToCssValue(kind),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
_platformViewMessageHandler ??= PlatformViewMessageHandler(
contentManager: platformViewManager,
contentHandler: (DomElement content) {
flutterViewEmbedder.glassPaneElement!.append(content);
flutterViewEmbedder.glassPaneElement.append(content);
},
);
_platformViewMessageHandler!.handlePlatformViewCall(data, callback!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class PlatformViewManager {
final DomElement slot = domDocument.createElement('slot')
..style.display = 'none'
..setAttribute('name', tombstoneName);
flutterViewEmbedder.glassPaneShadow!.append(slot);
flutterViewEmbedder.glassPaneShadow.append(slot);
// Link the element to the new slot
element.setAttribute('slot', tombstoneName);
// Delete both the element, and the new slot
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ class TextField extends RoleManager {
..height = '${semanticsObject.rect!.height}px';

if (semanticsObject.hasFocus) {
if (flutterViewEmbedder.glassPaneShadow!.activeElement !=
if (flutterViewEmbedder.glassPaneShadow.activeElement !=
activeEditableElement) {
semanticsObject.owner.addOneTimePostUpdateCallback(() {
activeEditableElement.focus();
});
}
SemanticsTextEditingStrategy.instance.activate(this);
} else if (flutterViewEmbedder.glassPaneShadow!.activeElement ==
} else if (flutterViewEmbedder.glassPaneShadow.activeElement ==
activeEditableElement) {
if (!isIosSafari) {
SemanticsTextEditingStrategy.instance.deactivate(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/text/measurement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RulerHost {
..height = '0';

if (root == null) {
flutterViewEmbedder.glassPaneShadow!.node.appendChild(_rulerHost);
flutterViewEmbedder.glassPaneShadow.node.appendChild(_rulerHost);
} else {
root.appendChild(_rulerHost);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void _emptyCallback(dynamic _) {}

/// The default [HostNode] that hosts all DOM required for text editing when a11y is not enabled.
@visibleForTesting
HostNode get defaultTextEditingRoot => flutterViewEmbedder.glassPaneShadow!;
HostNode get defaultTextEditingRoot => flutterViewEmbedder.glassPaneShadow;

/// These style attributes are constant throughout the life time of an input
/// element.
Expand Down
12 changes: 6 additions & 6 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void testMain() {
// The platform view is now split in two parts. The contents live
// as a child of the glassPane, and the slot lives in the glassPane
// shadow root. The slot is the one that has pointer events auto.
final DomElement contents = flutterViewEmbedder.glassPaneElement!
final DomElement contents = flutterViewEmbedder.glassPaneElement
.querySelector('#view-0')!;
final DomElement slot = flutterViewEmbedder.sceneElement!
.querySelector('slot')!;
Expand Down Expand Up @@ -598,7 +598,7 @@ void testMain() {
]);

expect(
flutterViewEmbedder.glassPaneElement!
flutterViewEmbedder.glassPaneElement
.querySelector('flt-platform-view'),
isNotNull,
);
Expand All @@ -614,7 +614,7 @@ void testMain() {
]);

expect(
flutterViewEmbedder.glassPaneElement!
flutterViewEmbedder.glassPaneElement
.querySelector('flt-platform-view'),
isNull,
);
Expand Down Expand Up @@ -685,7 +685,7 @@ void testMain() {
]);

expect(
flutterViewEmbedder.glassPaneElement!
flutterViewEmbedder.glassPaneElement
.querySelector('flt-platform-view'),
isNotNull,
);
Expand All @@ -703,7 +703,7 @@ void testMain() {
]);

expect(
flutterViewEmbedder.glassPaneElement!
flutterViewEmbedder.glassPaneElement
.querySelectorAll('flt-platform-view'),
hasLength(2));

Expand All @@ -719,7 +719,7 @@ void testMain() {
// The actual contents of the platform view are kept in the dom, until
// it's actually disposed of!
expect(
flutterViewEmbedder.glassPaneElement!
flutterViewEmbedder.glassPaneElement
.querySelectorAll('flt-platform-view'),
hasLength(2));
});
Expand Down
10 changes: 5 additions & 5 deletions lib/web_ui/test/embedder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void testMain() {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();

expect(
embedder.glassPaneShadow?.querySelectorAll('flt-semantics-placeholder'),
embedder.glassPaneShadow.querySelectorAll('flt-semantics-placeholder'),
isNotEmpty,
);
});

test('renders a shadowRoot by default', () {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final HostNode hostNode = embedder.glassPaneShadow!;
final HostNode hostNode = embedder.glassPaneShadow;
expect(domInstanceOfString(hostNode.node, 'ShadowRoot'), isTrue);
});

Expand All @@ -64,7 +64,7 @@ void testMain() {
attachShadow = null; // Break ShadowDOM

final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final HostNode hostNode = embedder.glassPaneShadow!;
final HostNode hostNode = embedder.glassPaneShadow;
expect(domInstanceOfString(hostNode.node, 'Element'), isTrue);
expect(
(hostNode.node as DomElement).tagName,
Expand Down Expand Up @@ -92,7 +92,7 @@ void testMain() {

regularTextField.focus();
DomCSSStyleDeclaration? style = domWindow.getComputedStyle(
embedder.glassPaneShadow!.querySelector('input')!,
embedder.glassPaneShadow.querySelector('input')!,
'::placeholder');
expect(style, isNotNull);
expect(style.opacity, isNot('0'));
Expand All @@ -104,7 +104,7 @@ void testMain() {

textField.focus();
style = domWindow.getComputedStyle(
embedder.glassPaneShadow!.querySelector('input.flt-text-editing')!,
embedder.glassPaneShadow.querySelector('input.flt-text-editing')!,
'::placeholder');
expect(style, isNotNull);
expect(style.opacity, '0');
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/pointer_binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void main() {

void testMain() {
ensureFlutterViewEmbedderInitialized();
final DomElement glassPane = flutterViewEmbedder.glassPaneElement!;
final DomElement glassPane = flutterViewEmbedder.glassPaneElement;
late double dpi;

setUp(() {
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/test/engine/semantics/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ void _testTappable() {
);
tester.apply();

expect(flutterViewEmbedder.glassPaneShadow!.activeElement, tester.getSemanticsObject(0).element);
expect(flutterViewEmbedder.glassPaneShadow.activeElement, tester.getSemanticsObject(0).element);
semantics().semanticsEnabled = false;
});
}
Expand Down Expand Up @@ -2007,7 +2007,7 @@ void _testPlatformView() {
expect(child3Rect.bottom, 60);

final DomElement platformViewElement =
flutterViewEmbedder.glassPaneElement!.querySelector('#view-0')!;
flutterViewEmbedder.glassPaneElement.querySelector('#view-0')!;
final DomRect platformViewRect = platformViewElement.getBoundingClientRect();
expect(platformViewRect.left, 0);
expect(platformViewRect.top, 15);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/semantics/semantics_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import '../../matchers.dart';
/// so we don't have to hardcode domDocument across the test. (The host of a
/// normal flutter app used to be domDocument, but now that the app is wrapped
/// in a Shadow DOM, that's not the case anymore.)
HostNode get appHostNode => flutterViewEmbedder.glassPaneShadow!;
HostNode get appHostNode => flutterViewEmbedder.glassPaneShadow;

/// CSS style applied to the root of the semantics tree.
// TODO(yjbanov): this should be handled internally by [expectSemanticsTree].
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/test/html/bitmap_canvas_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ Future<void> testMain() async {
testScene.style.transform = 'scale(0.3)';
}
testScene.append(canvas.rootElement);
flutterViewEmbedder.glassPaneShadow!.querySelector('flt-scene-host')!.append(testScene);
flutterViewEmbedder.glassPaneShadow.querySelector('flt-scene-host')!.append(testScene);
}

setUpStableTestFonts();

tearDown(() {
flutterViewEmbedder.glassPaneShadow?.querySelector('flt-scene')?.remove();
flutterViewEmbedder.glassPaneShadow.querySelector('flt-scene')?.remove();
});

/// Draws several lines, some aligned precisely with the pixel grid, and some
Expand Down Expand Up @@ -260,7 +260,7 @@ Future<void> testMain() async {
}

sceneElement.querySelector('flt-clip')!.append(canvas.rootElement);
flutterViewEmbedder.glassPaneShadow!.querySelector('flt-scene-host')!.append(sceneElement);
flutterViewEmbedder.glassPaneShadow.querySelector('flt-scene-host')!.append(sceneElement);

await matchGoldenFile(
'bitmap_canvas_draws_text_on_top_of_canvas.png',
Expand Down

0 comments on commit e7fde3f

Please sign in to comment.