Commit f8342c7a authored by Adam Barth's avatar Adam Barth

Fix analyzer warnings related to SemanticsListener

These were introduced by the recent engine roll.
parent 4bec05ad
...@@ -65,8 +65,8 @@ abstract class Renderer extends Scheduler ...@@ -65,8 +65,8 @@ abstract class Renderer extends Scheduler
renderView.configuration = new ViewConfiguration(size: ui.window.size); renderView.configuration = new ViewConfiguration(size: ui.window.size);
} }
mojom.SemanticsClient _semanticsClient; mojom.SemanticsListener _semanticsClient;
void setSemanticsClient(mojom.SemanticsClient client) { void setSemanticsClient(mojom.SemanticsListener client) {
assert(_semanticsClient == null); assert(_semanticsClient == null);
_semanticsClient = client; _semanticsClient = client;
if (renderView != null) if (renderView != null)
......
...@@ -208,7 +208,7 @@ class SemanticsNode extends AbstractNode { ...@@ -208,7 +208,7 @@ class SemanticsNode extends AbstractNode {
if (child.parent != this) { if (child.parent != this) {
if (child.parent != null) { if (child.parent != null) {
// we're rebuilding the tree from the bottom up, so it's possible // we're rebuilding the tree from the bottom up, so it's possible
// that our child was, in the last pass, a child of one of our // that our child was, in the last pass, a child of one of our
// ancestors. In that case, we drop the child eagerly here. // ancestors. In that case, we drop the child eagerly here.
// TODO(ianh): Find a way to assert that the same node didn't // TODO(ianh): Find a way to assert that the same node didn't
// actually appear in the tree in two places. // actually appear in the tree in two places.
...@@ -333,7 +333,7 @@ class SemanticsNode extends AbstractNode { ...@@ -333,7 +333,7 @@ class SemanticsNode extends AbstractNode {
return result; return result;
} }
static void sendSemanticsTreeTo(mojom.SemanticsClient client) { static void sendSemanticsTreeTo(mojom.SemanticsListener client) {
for (SemanticsNode oldNode in _detachedNodes) { for (SemanticsNode oldNode in _detachedNodes) {
// The other side will have forgotten this node if we even send // The other side will have forgotten this node if we even send
// it again, so make sure to mark it dirty so that it'll get // it again, so make sure to mark it dirty so that it'll get
...@@ -359,7 +359,7 @@ class SemanticsNode extends AbstractNode { ...@@ -359,7 +359,7 @@ class SemanticsNode extends AbstractNode {
child.mergeAllDescendantsIntoThisNode = true; // this can add the node to the dirty list child.mergeAllDescendantsIntoThisNode = true; // this can add the node to the dirty list
} }
assert(_dirtyNodes[index] == node); // make sure nothing went in front of us in the list assert(_dirtyNodes[index] == node); // make sure nothing went in front of us in the list
} }
_dirtyNodes.sort((SemanticsNode a, SemanticsNode b) => a.depth - b.depth); _dirtyNodes.sort((SemanticsNode a, SemanticsNode b) => a.depth - b.depth);
List<mojom.SemanticsNode> updatedNodes = <mojom.SemanticsNode>[]; List<mojom.SemanticsNode> updatedNodes = <mojom.SemanticsNode>[];
for (SemanticsNode node in _dirtyNodes) { for (SemanticsNode node in _dirtyNodes) {
...@@ -427,6 +427,8 @@ class SemanticsNode extends AbstractNode { ...@@ -427,6 +427,8 @@ class SemanticsNode extends AbstractNode {
} }
class SemanticsServer extends mojom.SemanticsServer { class SemanticsServer extends mojom.SemanticsServer {
void addSemanticsListener(mojom.SemanticsListener listener) {
}
void tap(int nodeID) { void tap(int nodeID) {
SemanticsNode.getSemanticActionHandlerForId(nodeID, neededFlag: _SemanticFlags.canBeTapped)?.handleSemanticTap(); SemanticsNode.getSemanticActionHandlerForId(nodeID, neededFlag: _SemanticFlags.canBeTapped)?.handleSemanticTap();
} }
......
...@@ -7,7 +7,7 @@ import 'dart:ui' as ui; ...@@ -7,7 +7,7 @@ import 'dart:ui' as ui;
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:sky_services/semantics/semantics.mojom.dart' as engine; import 'package:sky_services/semantics/semantics.mojom.dart' as mojom;
import 'basic.dart'; import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
...@@ -22,11 +22,11 @@ class SemanticsDebugger extends StatefulComponent { ...@@ -22,11 +22,11 @@ class SemanticsDebugger extends StatefulComponent {
class _SemanticsDebuggerState extends State<SemanticsDebugger> { class _SemanticsDebuggerState extends State<SemanticsDebugger> {
void initState() { void initState() {
super.initState(); super.initState();
_SemanticsDebuggerClient.ensureInstantiated(); _SemanticsDebuggerListener.ensureInstantiated();
_SemanticsDebuggerClient.instance.addListener(_update); _SemanticsDebuggerListener.instance.addListener(_update);
} }
void dispose() { void dispose() {
_SemanticsDebuggerClient.instance.removeListener(_update); _SemanticsDebuggerListener.instance.removeListener(_update);
super.dispose(); super.dispose();
} }
void _update() { void _update() {
...@@ -42,28 +42,28 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> { ...@@ -42,28 +42,28 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> {
} }
void _handleTap() { void _handleTap() {
assert(_lastPointerDownLocation != null); assert(_lastPointerDownLocation != null);
_SemanticsDebuggerClient.instance.handleTap(_lastPointerDownLocation); _SemanticsDebuggerListener.instance.handleTap(_lastPointerDownLocation);
setState(() { setState(() {
_lastPointerDownLocation = null; _lastPointerDownLocation = null;
}); });
} }
void _handleLongPress() { void _handleLongPress() {
assert(_lastPointerDownLocation != null); assert(_lastPointerDownLocation != null);
_SemanticsDebuggerClient.instance.handleLongPress(_lastPointerDownLocation); _SemanticsDebuggerListener.instance.handleLongPress(_lastPointerDownLocation);
setState(() { setState(() {
_lastPointerDownLocation = null; _lastPointerDownLocation = null;
}); });
} }
void _handlePanEnd(Offset velocity) { void _handlePanEnd(Offset velocity) {
assert(_lastPointerDownLocation != null); assert(_lastPointerDownLocation != null);
_SemanticsDebuggerClient.instance.handlePanEnd(_lastPointerDownLocation, velocity); _SemanticsDebuggerListener.instance.handlePanEnd(_lastPointerDownLocation, velocity);
setState(() { setState(() {
_lastPointerDownLocation = null; _lastPointerDownLocation = null;
}); });
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new CustomPaint( return new CustomPaint(
foregroundPainter: new _SemanticsDebuggerPainter(_SemanticsDebuggerClient.instance.generation, _lastPointerDownLocation), foregroundPainter: new _SemanticsDebuggerPainter(_SemanticsDebuggerListener.instance.generation, _lastPointerDownLocation),
child: new GestureDetector( child: new GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: _handleTap, onTap: _handleTap,
...@@ -233,16 +233,16 @@ class _SemanticsDebuggerEntry { ...@@ -233,16 +233,16 @@ class _SemanticsDebuggerEntry {
} }
} }
class _SemanticsDebuggerClient implements engine.SemanticsClient { class _SemanticsDebuggerListener implements mojom.SemanticsListener {
_SemanticsDebuggerClient._() { _SemanticsDebuggerListener._() {
Renderer.instance.setSemanticsClient(this); Renderer.instance.setSemanticsClient(this);
} }
static _SemanticsDebuggerClient instance; static _SemanticsDebuggerListener instance;
static engine.SemanticsServer _server; static mojom.SemanticsServer _server;
static void ensureInstantiated({ engine.SemanticsServer server }) { static void ensureInstantiated({ mojom.SemanticsServer server }) {
_server = server ?? new SemanticsServer(); _server = server ?? new SemanticsServer();
instance ??= new _SemanticsDebuggerClient._(); instance ??= new _SemanticsDebuggerListener._();
} }
Set<VoidCallback> _listeners = new Set<VoidCallback>(); Set<VoidCallback> _listeners = new Set<VoidCallback>();
...@@ -256,7 +256,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient { ...@@ -256,7 +256,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
Map<int, _SemanticsDebuggerEntry> nodes = <int, _SemanticsDebuggerEntry>{}; Map<int, _SemanticsDebuggerEntry> nodes = <int, _SemanticsDebuggerEntry>{};
_SemanticsDebuggerEntry _updateNode(engine.SemanticsNode node) { _SemanticsDebuggerEntry _updateNode(mojom.SemanticsNode node) {
_SemanticsDebuggerEntry entry = nodes.putIfAbsent(node.id, () => new _SemanticsDebuggerEntry(node.id)); _SemanticsDebuggerEntry entry = nodes.putIfAbsent(node.id, () => new _SemanticsDebuggerEntry(node.id));
if (node.flags != null) { if (node.flags != null) {
entry.canBeTapped = node.flags.canBeTapped; entry.canBeTapped = node.flags.canBeTapped;
...@@ -295,7 +295,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient { ...@@ -295,7 +295,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
Set oldChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children ?? const <_SemanticsDebuggerEntry>[]); Set oldChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children ?? const <_SemanticsDebuggerEntry>[]);
entry.children?.clear(); entry.children?.clear();
entry.children ??= new List<_SemanticsDebuggerEntry>(); entry.children ??= new List<_SemanticsDebuggerEntry>();
for (engine.SemanticsNode child in node.children) for (mojom.SemanticsNode child in node.children)
entry.children.add(_updateNode(child)); entry.children.add(_updateNode(child));
Set newChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children); Set newChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children);
Set<_SemanticsDebuggerEntry> removedChildren = oldChildren.difference(newChildren); Set<_SemanticsDebuggerEntry> removedChildren = oldChildren.difference(newChildren);
...@@ -307,9 +307,9 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient { ...@@ -307,9 +307,9 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
int generation = 0; int generation = 0;
updateSemanticsTree(List<engine.SemanticsNode> nodes) { updateSemanticsTree(List<mojom.SemanticsNode> nodes) {
generation += 1; generation += 1;
for (engine.SemanticsNode node in nodes) for (mojom.SemanticsNode node in nodes)
_updateNode(node); _updateNode(node);
for (VoidCallback listener in _listeners) for (VoidCallback listener in _listeners)
listener(); listener();
...@@ -347,9 +347,9 @@ class _SemanticsDebuggerPainter extends CustomPainter { ...@@ -347,9 +347,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
final int generation; final int generation;
final Point pointerPosition; final Point pointerPosition;
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
_SemanticsDebuggerClient.instance.nodes[0]?.paint( _SemanticsDebuggerListener.instance.nodes[0]?.paint(
canvas, canvas,
_SemanticsDebuggerClient.instance.nodes[0].findDepth() _SemanticsDebuggerListener.instance.nodes[0].findDepth()
); );
if (pointerPosition != null) { if (pointerPosition != null) {
Paint paint = new Paint(); Paint paint = new Paint();
......
...@@ -12,7 +12,7 @@ import 'test_semantics.dart'; ...@@ -12,7 +12,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Does FlatButton contribute semantics', () { test('Does FlatButton contribute semantics', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
tester.pumpWidget( tester.pumpWidget(
new Material( new Material(
child: new Center( child: new Center(
......
...@@ -13,7 +13,7 @@ import 'test_semantics.dart'; ...@@ -13,7 +13,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Semantics 1', () { test('Semantics 1', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
// smoketest // smoketest
tester.pumpWidget( tester.pumpWidget(
......
...@@ -13,7 +13,7 @@ import 'test_semantics.dart'; ...@@ -13,7 +13,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Semantics 2', () { test('Semantics 2', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
// this test is the same as the test in Semantics 1, but // this test is the same as the test in Semantics 1, but
// starting with the second branch being ignored and then // starting with the second branch being ignored and then
......
...@@ -12,7 +12,7 @@ import 'test_semantics.dart'; ...@@ -12,7 +12,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Semantics 3', () { test('Semantics 3', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
// implicit annotators // implicit annotators
tester.pumpWidget( tester.pumpWidget(
......
...@@ -12,7 +12,7 @@ import 'test_semantics.dart'; ...@@ -12,7 +12,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Semantics 4', () { test('Semantics 4', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
// O // O
// / \ O=root // / \ O=root
......
...@@ -12,7 +12,7 @@ import 'test_semantics.dart'; ...@@ -12,7 +12,7 @@ import 'test_semantics.dart';
void main() { void main() {
test('Semantics 5', () { test('Semantics 5', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
tester.pumpWidget( tester.pumpWidget(
new Stack( new Stack(
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:sky_services/semantics/semantics.mojom.dart' as engine; import 'package:sky_services/semantics/semantics.mojom.dart' as mojom;
class TestSemanticsClient implements engine.SemanticsClient { class TestSemanticsListener implements mojom.SemanticsListener {
TestSemanticsClient() { TestSemanticsListener() {
Renderer.instance.setSemanticsClient(this); Renderer.instance.setSemanticsClient(this);
} }
final List<engine.SemanticsNode> updates = <engine.SemanticsNode>[]; final List<mojom.SemanticsNode> updates = <mojom.SemanticsNode>[];
updateSemanticsTree(List<engine.SemanticsNode> nodes) { updateSemanticsTree(List<mojom.SemanticsNode> nodes) {
assert(!nodes.any((engine.SemanticsNode node) => node == null)); assert(!nodes.any((mojom.SemanticsNode node) => node == null));
updates.addAll(nodes); updates.addAll(nodes);
updates.add(null); updates.add(null);
} }
......
...@@ -359,7 +359,7 @@ void main() { ...@@ -359,7 +359,7 @@ void main() {
test('Does tooltip contribute semantics', () { test('Does tooltip contribute semantics', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
TestSemanticsClient client = new TestSemanticsClient(); TestSemanticsListener client = new TestSemanticsListener();
GlobalKey key = new GlobalKey(); GlobalKey key = new GlobalKey();
tester.pumpWidget( tester.pumpWidget(
new Overlay( new Overlay(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment