Unverified Commit 616a2ad6 authored by amirh's avatar amirh Committed by GitHub

Move semantics stuff from rendering to a top-level semantics/ library (#12793)

parent 79862a72
...@@ -28,6 +28,7 @@ export 'package:flutter/foundation.dart' show ...@@ -28,6 +28,7 @@ export 'package:flutter/foundation.dart' show
ValueGetter, ValueGetter,
ValueSetter, ValueSetter,
DiagnosticLevel; DiagnosticLevel;
export 'package:flutter/semantics.dart';
export 'package:vector_math/vector_math_64.dart' show Matrix4; export 'package:vector_math/vector_math_64.dart' show Matrix4;
export 'src/rendering/animated_size.dart'; export 'src/rendering/animated_size.dart';
...@@ -47,7 +48,6 @@ export 'src/rendering/paragraph.dart'; ...@@ -47,7 +48,6 @@ export 'src/rendering/paragraph.dart';
export 'src/rendering/performance_overlay.dart'; export 'src/rendering/performance_overlay.dart';
export 'src/rendering/proxy_box.dart'; export 'src/rendering/proxy_box.dart';
export 'src/rendering/rotated_box.dart'; export 'src/rendering/rotated_box.dart';
export 'src/rendering/semantics.dart';
export 'src/rendering/shifted_box.dart'; export 'src/rendering/shifted_box.dart';
export 'src/rendering/sliver.dart'; export 'src/rendering/sliver.dart';
export 'src/rendering/sliver_fill.dart'; export 'src/rendering/sliver_fill.dart';
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// The Flutter semantics package.
///
/// To use, import `package:flutter/semantics.dart`.
///
/// The [SemanticsEvent] classes define the protocol for sending semantic events
/// to the platform.
///
/// The [SemanticsNode] hierarchy represents the semantic structure of the UI
/// and is used to by the platform-specific accessibility services.
library semantics;
export 'src/semantics/semantics.dart';
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'basic_types.dart'; import 'basic_types.dart';
...@@ -169,3 +170,51 @@ class MatrixUtils { ...@@ -169,3 +170,51 @@ class MatrixUtils {
return transformRect(transform, rect); return transformRect(transform, rect);
} }
} }
/// Returns a list of strings representing the given transform in a format
/// useful for [TransformProperty].
///
/// If the argument is null, returns a list with the single string "null".
List<String> debugDescribeTransform(Matrix4 transform) {
if (transform == null)
return const <String>['null'];
final List<String> matrix = transform.toString().split('\n').map((String s) => ' $s').toList();
matrix.removeLast();
return matrix;
}
/// Property which handles [Matrix4] that represent transforms.
class TransformProperty extends DiagnosticsProperty<Matrix4> {
/// Create a diagnostics property for [Matrix4] objects.
///
/// The [showName] and [level] arguments must not be null.
TransformProperty(String name, Matrix4 value, {
bool showName: true,
Object defaultValue: kNoDefaultValue,
DiagnosticLevel level: DiagnosticLevel.info,
}) : assert(showName != null),
assert(level != null),
super(
name,
value,
showName: showName,
defaultValue: defaultValue,
level: level,
);
@override
String valueToString({ TextTreeConfiguration parentConfiguration }) {
if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) {
// Format the value on a single line to be compatible with the parent's
// style.
final List<Vector4> rows = <Vector4>[
value.getRow(0),
value.getRow(1),
value.getRow(2),
value.getRow(3),
];
return '[${rows.join("; ")}]';
}
return debugDescribeTransform(value).join('\n');
}
}
...@@ -9,12 +9,12 @@ import 'dart:ui' as ui show window; ...@@ -9,12 +9,12 @@ import 'dart:ui' as ui show window;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'box.dart'; import 'box.dart';
import 'debug.dart'; import 'debug.dart';
import 'object.dart'; import 'object.dart';
import 'semantics.dart';
import 'view.dart'; import 'view.dart';
export 'package:flutter/gestures.dart' show HitTestResult; export 'package:flutter/gestures.dart' show HitTestResult;
......
...@@ -4,30 +4,12 @@ ...@@ -4,30 +4,12 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:vector_math/vector_math_64.dart';
export 'package:flutter/foundation.dart' show debugPrint; export 'package:flutter/foundation.dart' show debugPrint;
// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset() // Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset()
// function below. // function below.
/// Used by [debugDumpSemanticsTree] to specify the order in which child nodes
/// are printed.
enum DebugSemanticsDumpOrder {
/// Print nodes in inverse hit test order.
///
/// In inverse hit test order, the last child of a [SemanticsNode] will be
/// asked first if it wants to respond to a user's interaction, followed by
/// the second last, etc. until a taker is found.
inverseHitTest,
/// Print nodes in traversal order.
///
/// Traversal order defines how the user can move the accessibility focus from
/// one node to another.
traversal,
}
const HSVColor _kDebugDefaultRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0); const HSVColor _kDebugDefaultRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0);
/// Causes each RenderBox to paint a box around its bounds, and some extra /// Causes each RenderBox to paint a box around its bounds, and some extra
...@@ -130,54 +112,6 @@ bool debugCheckIntrinsicSizes = false; ...@@ -130,54 +112,6 @@ bool debugCheckIntrinsicSizes = false;
bool debugProfilePaintsEnabled = false; bool debugProfilePaintsEnabled = false;
/// Returns a list of strings representing the given transform in a format
/// useful for [TransformProperty].
///
/// If the argument is null, returns a list with the single string "null".
List<String> debugDescribeTransform(Matrix4 transform) {
if (transform == null)
return const <String>['null'];
final List<String> matrix = transform.toString().split('\n').map((String s) => ' $s').toList();
matrix.removeLast();
return matrix;
}
/// Property which handles [Matrix4] that represent transforms.
class TransformProperty extends DiagnosticsProperty<Matrix4> {
/// Create a diagnostics property for [Matrix4] objects.
///
/// The [showName] and [level] arguments must not be null.
TransformProperty(String name, Matrix4 value, {
bool showName: true,
Object defaultValue: kNoDefaultValue,
DiagnosticLevel level: DiagnosticLevel.info,
}) : assert(showName != null),
assert(level != null),
super(
name,
value,
showName: showName,
defaultValue: defaultValue,
level: level,
);
@override
String valueToString({ TextTreeConfiguration parentConfiguration }) {
if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) {
// Format the value on a single line to be compatible with the parent's
// style.
final List<Vector4> rows = <Vector4>[
value.getRow(0),
value.getRow(1),
value.getRow(2),
value.getRow(3),
];
return '[${rows.join("; ")}]';
}
return debugDescribeTransform(value).join('\n');
}
}
void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) { void _debugDrawDoubleRect(Canvas canvas, Rect outerRect, Rect innerRect, Color color) {
final Path path = new Path() final Path path = new Path()
..fillType = PathFillType.evenOdd ..fillType = PathFillType.evenOdd
......
...@@ -7,11 +7,11 @@ import 'dart:ui' as ui show TextBox; ...@@ -7,11 +7,11 @@ import 'dart:ui' as ui show TextBox;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
import 'semantics.dart';
import 'viewport_offset.dart'; import 'viewport_offset.dart';
const double _kCaretGap = 1.0; // pixels const double _kCaretGap = 1.0; // pixels
......
...@@ -10,8 +10,6 @@ import 'package:flutter/foundation.dart'; ...@@ -10,8 +10,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'debug.dart';
/// A composited layer. /// A composited layer.
/// ///
/// During painting, the render tree generates a tree of composited layers that /// During painting, the render tree generates a tree of composited layers that
......
...@@ -9,12 +9,12 @@ import 'package:flutter/foundation.dart'; ...@@ -9,12 +9,12 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/semantics.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'binding.dart'; import 'binding.dart';
import 'debug.dart'; import 'debug.dart';
import 'layer.dart'; import 'layer.dart';
import 'semantics.dart';
export 'package:flutter/foundation.dart' show FlutterError, InformationCollector, DiagnosticsNode, DiagnosticsProperty, StringProperty, DoubleProperty, EnumProperty, FlagProperty, IntProperty, DiagnosticPropertiesBuilder; export 'package:flutter/foundation.dart' show FlutterError, InformationCollector, DiagnosticsNode, DiagnosticsProperty, StringProperty, DoubleProperty, EnumProperty, FlagProperty, IntProperty, DiagnosticPropertiesBuilder;
export 'package:flutter/gestures.dart' show HitTestEntry, HitTestResult; export 'package:flutter/gestures.dart' show HitTestEntry, HitTestResult;
......
...@@ -6,13 +6,13 @@ import 'dart:ui' as ui show Gradient, Shader, TextBox; ...@@ -6,13 +6,13 @@ import 'dart:ui' as ui show Gradient, Shader, TextBox;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'box.dart'; import 'box.dart';
import 'debug.dart'; import 'debug.dart';
import 'object.dart'; import 'object.dart';
import 'semantics.dart';
/// How overflowing text should be handled. /// How overflowing text should be handled.
enum TextOverflow { enum TextOverflow {
......
...@@ -7,15 +7,14 @@ import 'dart:ui' as ui show ImageFilter, Gradient; ...@@ -7,15 +7,14 @@ import 'dart:ui' as ui show ImageFilter, Gradient;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
import 'debug.dart';
import 'layer.dart'; import 'layer.dart';
import 'object.dart'; import 'object.dart';
import 'semantics.dart';
export 'package:flutter/gestures.dart' show export 'package:flutter/gestures.dart' show
PointerEvent, PointerEvent,
......
...@@ -8,13 +8,13 @@ import 'package:flutter/animation.dart'; ...@@ -8,13 +8,13 @@ import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/semantics.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'binding.dart'; import 'binding.dart';
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
import 'proxy_box.dart'; import 'proxy_box.dart';
import 'semantics.dart';
import 'sliver.dart'; import 'sliver.dart';
import 'viewport_offset.dart'; import 'viewport_offset.dart';
......
...@@ -6,13 +6,13 @@ import 'dart:math' as math; ...@@ -6,13 +6,13 @@ import 'dart:math' as math;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/semantics.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'binding.dart'; import 'binding.dart';
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
import 'proxy_box.dart'; import 'proxy_box.dart';
import 'semantics.dart';
import 'sliver.dart'; import 'sliver.dart';
import 'viewport_offset.dart'; import 'viewport_offset.dart';
......
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:ui' show Rect, SemanticsAction, SemanticsFlags; import 'dart:ui' show Offset, Rect, SemanticsAction, SemanticsFlags,
TextDirection;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart' show MatrixUtils, TransformProperty;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'debug.dart';
import 'semantics_event.dart'; import 'semantics_event.dart';
export 'dart:ui' show SemanticsAction; export 'dart:ui' show SemanticsAction;
...@@ -197,7 +198,7 @@ class SemanticsData extends Diagnosticable { ...@@ -197,7 +198,7 @@ class SemanticsData extends Diagnosticable {
} }
@override @override
int get hashCode => hashValues(flags, actions, label, textDirection, rect, tags, transform); int get hashCode => ui.hashValues(flags, actions, label, textDirection, rect, tags, transform);
} }
class _SemanticsDiagnosticableNode extends DiagnosticableNode<SemanticsNode> { class _SemanticsDiagnosticableNode extends DiagnosticableNode<SemanticsNode> {
...@@ -1376,6 +1377,23 @@ class SemanticsConfiguration { ...@@ -1376,6 +1377,23 @@ class SemanticsConfiguration {
} }
} }
/// Used by [debugDumpSemanticsTree] to specify the order in which child nodes
/// are printed.
enum DebugSemanticsDumpOrder {
/// Print nodes in inverse hit test order.
///
/// In inverse hit test order, the last child of a [SemanticsNode] will be
/// asked first if it wants to respond to a user's interaction, followed by
/// the second last, etc. until a taker is found.
inverseHitTest,
/// Print nodes in traversal order.
///
/// Traversal order defines how the user can move the accessibility focus from
/// one node to another.
traversal,
}
String _concatStrings({ String _concatStrings({
@required String thisString, @required String thisString,
@required String otherString, @required String otherString,
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/semantics.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'rendering_tester.dart'; import '../rendering/rendering_tester.dart';
void main() { void main() {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/rendering.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
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