Merge pull request #1498 from abarth/fix_analyzer
Fix analyzer warnings related to SemanticsListener
This commit is contained in:
@@ -65,8 +65,8 @@ abstract class Renderer extends Scheduler
|
||||
renderView.configuration = new ViewConfiguration(size: ui.window.size);
|
||||
}
|
||||
|
||||
mojom.SemanticsClient _semanticsClient;
|
||||
void setSemanticsClient(mojom.SemanticsClient client) {
|
||||
mojom.SemanticsListener _semanticsClient;
|
||||
void setSemanticsClient(mojom.SemanticsListener client) {
|
||||
assert(_semanticsClient == null);
|
||||
_semanticsClient = client;
|
||||
if (renderView != null)
|
||||
|
||||
@@ -208,7 +208,7 @@ class SemanticsNode extends AbstractNode {
|
||||
if (child.parent != this) {
|
||||
if (child.parent != null) {
|
||||
// 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.
|
||||
// TODO(ianh): Find a way to assert that the same node didn't
|
||||
// actually appear in the tree in two places.
|
||||
@@ -333,7 +333,7 @@ class SemanticsNode extends AbstractNode {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void sendSemanticsTreeTo(mojom.SemanticsClient client) {
|
||||
static void sendSemanticsTreeTo(mojom.SemanticsListener client) {
|
||||
for (SemanticsNode oldNode in _detachedNodes) {
|
||||
// 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
|
||||
@@ -359,7 +359,7 @@ class SemanticsNode extends AbstractNode {
|
||||
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
|
||||
}
|
||||
}
|
||||
_dirtyNodes.sort((SemanticsNode a, SemanticsNode b) => a.depth - b.depth);
|
||||
List<mojom.SemanticsNode> updatedNodes = <mojom.SemanticsNode>[];
|
||||
for (SemanticsNode node in _dirtyNodes) {
|
||||
@@ -427,6 +427,8 @@ class SemanticsNode extends AbstractNode {
|
||||
}
|
||||
|
||||
class SemanticsServer extends mojom.SemanticsServer {
|
||||
void addSemanticsListener(mojom.SemanticsListener listener) {
|
||||
}
|
||||
void tap(int nodeID) {
|
||||
SemanticsNode.getSemanticActionHandlerForId(nodeID, neededFlag: _SemanticFlags.canBeTapped)?.handleSemanticTap();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/painting.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 'framework.dart';
|
||||
@@ -22,11 +22,11 @@ class SemanticsDebugger extends StatefulComponent {
|
||||
class _SemanticsDebuggerState extends State<SemanticsDebugger> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_SemanticsDebuggerClient.ensureInstantiated();
|
||||
_SemanticsDebuggerClient.instance.addListener(_update);
|
||||
_SemanticsDebuggerListener.ensureInstantiated();
|
||||
_SemanticsDebuggerListener.instance.addListener(_update);
|
||||
}
|
||||
void dispose() {
|
||||
_SemanticsDebuggerClient.instance.removeListener(_update);
|
||||
_SemanticsDebuggerListener.instance.removeListener(_update);
|
||||
super.dispose();
|
||||
}
|
||||
void _update() {
|
||||
@@ -42,28 +42,28 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> {
|
||||
}
|
||||
void _handleTap() {
|
||||
assert(_lastPointerDownLocation != null);
|
||||
_SemanticsDebuggerClient.instance.handleTap(_lastPointerDownLocation);
|
||||
_SemanticsDebuggerListener.instance.handleTap(_lastPointerDownLocation);
|
||||
setState(() {
|
||||
_lastPointerDownLocation = null;
|
||||
});
|
||||
}
|
||||
void _handleLongPress() {
|
||||
assert(_lastPointerDownLocation != null);
|
||||
_SemanticsDebuggerClient.instance.handleLongPress(_lastPointerDownLocation);
|
||||
_SemanticsDebuggerListener.instance.handleLongPress(_lastPointerDownLocation);
|
||||
setState(() {
|
||||
_lastPointerDownLocation = null;
|
||||
});
|
||||
}
|
||||
void _handlePanEnd(Offset velocity) {
|
||||
assert(_lastPointerDownLocation != null);
|
||||
_SemanticsDebuggerClient.instance.handlePanEnd(_lastPointerDownLocation, velocity);
|
||||
_SemanticsDebuggerListener.instance.handlePanEnd(_lastPointerDownLocation, velocity);
|
||||
setState(() {
|
||||
_lastPointerDownLocation = null;
|
||||
});
|
||||
}
|
||||
Widget build(BuildContext context) {
|
||||
return new CustomPaint(
|
||||
foregroundPainter: new _SemanticsDebuggerPainter(_SemanticsDebuggerClient.instance.generation, _lastPointerDownLocation),
|
||||
foregroundPainter: new _SemanticsDebuggerPainter(_SemanticsDebuggerListener.instance.generation, _lastPointerDownLocation),
|
||||
child: new GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: _handleTap,
|
||||
@@ -233,16 +233,16 @@ class _SemanticsDebuggerEntry {
|
||||
}
|
||||
}
|
||||
|
||||
class _SemanticsDebuggerClient implements engine.SemanticsClient {
|
||||
_SemanticsDebuggerClient._() {
|
||||
class _SemanticsDebuggerListener implements mojom.SemanticsListener {
|
||||
_SemanticsDebuggerListener._() {
|
||||
Renderer.instance.setSemanticsClient(this);
|
||||
}
|
||||
|
||||
static _SemanticsDebuggerClient instance;
|
||||
static engine.SemanticsServer _server;
|
||||
static void ensureInstantiated({ engine.SemanticsServer server }) {
|
||||
static _SemanticsDebuggerListener instance;
|
||||
static mojom.SemanticsServer _server;
|
||||
static void ensureInstantiated({ mojom.SemanticsServer server }) {
|
||||
_server = server ?? new SemanticsServer();
|
||||
instance ??= new _SemanticsDebuggerClient._();
|
||||
instance ??= new _SemanticsDebuggerListener._();
|
||||
}
|
||||
|
||||
Set<VoidCallback> _listeners = new Set<VoidCallback>();
|
||||
@@ -256,7 +256,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
|
||||
|
||||
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));
|
||||
if (node.flags != null) {
|
||||
entry.canBeTapped = node.flags.canBeTapped;
|
||||
@@ -295,7 +295,7 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
|
||||
Set oldChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children ?? const <_SemanticsDebuggerEntry>[]);
|
||||
entry.children?.clear();
|
||||
entry.children ??= new List<_SemanticsDebuggerEntry>();
|
||||
for (engine.SemanticsNode child in node.children)
|
||||
for (mojom.SemanticsNode child in node.children)
|
||||
entry.children.add(_updateNode(child));
|
||||
Set newChildren = new Set<_SemanticsDebuggerEntry>.from(entry.children);
|
||||
Set<_SemanticsDebuggerEntry> removedChildren = oldChildren.difference(newChildren);
|
||||
@@ -307,9 +307,9 @@ class _SemanticsDebuggerClient implements engine.SemanticsClient {
|
||||
|
||||
int generation = 0;
|
||||
|
||||
updateSemanticsTree(List<engine.SemanticsNode> nodes) {
|
||||
updateSemanticsTree(List<mojom.SemanticsNode> nodes) {
|
||||
generation += 1;
|
||||
for (engine.SemanticsNode node in nodes)
|
||||
for (mojom.SemanticsNode node in nodes)
|
||||
_updateNode(node);
|
||||
for (VoidCallback listener in _listeners)
|
||||
listener();
|
||||
@@ -347,9 +347,9 @@ class _SemanticsDebuggerPainter extends CustomPainter {
|
||||
final int generation;
|
||||
final Point pointerPosition;
|
||||
void paint(Canvas canvas, Size size) {
|
||||
_SemanticsDebuggerClient.instance.nodes[0]?.paint(
|
||||
_SemanticsDebuggerListener.instance.nodes[0]?.paint(
|
||||
canvas,
|
||||
_SemanticsDebuggerClient.instance.nodes[0].findDepth()
|
||||
_SemanticsDebuggerListener.instance.nodes[0].findDepth()
|
||||
);
|
||||
if (pointerPosition != null) {
|
||||
Paint paint = new Paint();
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Does FlatButton contribute semantics', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
tester.pumpWidget(
|
||||
new Material(
|
||||
child: new Center(
|
||||
|
||||
@@ -13,7 +13,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Semantics 1', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
|
||||
// smoketest
|
||||
tester.pumpWidget(
|
||||
|
||||
@@ -13,7 +13,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Semantics 2', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
|
||||
// this test is the same as the test in Semantics 1, but
|
||||
// starting with the second branch being ignored and then
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Semantics 3', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
|
||||
// implicit annotators
|
||||
tester.pumpWidget(
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Semantics 4', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
|
||||
// O
|
||||
// / \ O=root
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'test_semantics.dart';
|
||||
void main() {
|
||||
test('Semantics 5', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
|
||||
tester.pumpWidget(
|
||||
new Stack(
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
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 {
|
||||
TestSemanticsClient() {
|
||||
class TestSemanticsListener implements mojom.SemanticsListener {
|
||||
TestSemanticsListener() {
|
||||
Renderer.instance.setSemanticsClient(this);
|
||||
}
|
||||
final List<engine.SemanticsNode> updates = <engine.SemanticsNode>[];
|
||||
updateSemanticsTree(List<engine.SemanticsNode> nodes) {
|
||||
assert(!nodes.any((engine.SemanticsNode node) => node == null));
|
||||
final List<mojom.SemanticsNode> updates = <mojom.SemanticsNode>[];
|
||||
updateSemanticsTree(List<mojom.SemanticsNode> nodes) {
|
||||
assert(!nodes.any((mojom.SemanticsNode node) => node == null));
|
||||
updates.addAll(nodes);
|
||||
updates.add(null);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ void main() {
|
||||
|
||||
test('Does tooltip contribute semantics', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
TestSemanticsClient client = new TestSemanticsClient();
|
||||
TestSemanticsListener client = new TestSemanticsListener();
|
||||
GlobalKey key = new GlobalKey();
|
||||
tester.pumpWidget(
|
||||
new Overlay(
|
||||
|
||||
Reference in New Issue
Block a user