mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Move semantics stuff from rendering to a top-level semantics/ library (#12793)
This commit is contained in:
parent
79862a7262
commit
616a2ad6da
@ -28,6 +28,7 @@ export 'package:flutter/foundation.dart' show
|
||||
ValueGetter,
|
||||
ValueSetter,
|
||||
DiagnosticLevel;
|
||||
export 'package:flutter/semantics.dart';
|
||||
export 'package:vector_math/vector_math_64.dart' show Matrix4;
|
||||
|
||||
export 'src/rendering/animated_size.dart';
|
||||
@ -47,7 +48,6 @@ export 'src/rendering/paragraph.dart';
|
||||
export 'src/rendering/performance_overlay.dart';
|
||||
export 'src/rendering/proxy_box.dart';
|
||||
export 'src/rendering/rotated_box.dart';
|
||||
export 'src/rendering/semantics.dart';
|
||||
export 'src/rendering/shifted_box.dart';
|
||||
export 'src/rendering/sliver.dart';
|
||||
export 'src/rendering/sliver_fill.dart';
|
||||
|
||||
16
packages/flutter/lib/semantics.dart
Normal file
16
packages/flutter/lib/semantics.dart
Normal file
@ -0,0 +1,16 @@
|
||||
// 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 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'basic_types.dart';
|
||||
@ -169,3 +170,51 @@ class MatrixUtils {
|
||||
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;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'box.dart';
|
||||
import 'debug.dart';
|
||||
import 'object.dart';
|
||||
import 'semantics.dart';
|
||||
import 'view.dart';
|
||||
|
||||
export 'package:flutter/gestures.dart' show HitTestResult;
|
||||
|
||||
@ -4,30 +4,12 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
export 'package:flutter/foundation.dart' show debugPrint;
|
||||
|
||||
// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset()
|
||||
// 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);
|
||||
|
||||
/// Causes each RenderBox to paint a box around its bounds, and some extra
|
||||
@ -130,54 +112,6 @@ bool debugCheckIntrinsicSizes = 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) {
|
||||
final Path path = new Path()
|
||||
..fillType = PathFillType.evenOdd
|
||||
|
||||
@ -7,11 +7,11 @@ import 'dart:ui' as ui show TextBox;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'box.dart';
|
||||
import 'object.dart';
|
||||
import 'semantics.dart';
|
||||
import 'viewport_offset.dart';
|
||||
|
||||
const double _kCaretGap = 1.0; // pixels
|
||||
|
||||
@ -10,8 +10,6 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'debug.dart';
|
||||
|
||||
/// A composited layer.
|
||||
///
|
||||
/// During painting, the render tree generates a tree of composited layers that
|
||||
|
||||
@ -9,12 +9,12 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'binding.dart';
|
||||
import 'debug.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/gestures.dart' show HitTestEntry, HitTestResult;
|
||||
|
||||
@ -6,13 +6,13 @@ import 'dart:ui' as ui show Gradient, Shader, TextBox;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
|
||||
import 'box.dart';
|
||||
import 'debug.dart';
|
||||
import 'object.dart';
|
||||
import 'semantics.dart';
|
||||
|
||||
/// How overflowing text should be handled.
|
||||
enum TextOverflow {
|
||||
|
||||
@ -7,15 +7,14 @@ import 'dart:ui' as ui show ImageFilter, Gradient;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'box.dart';
|
||||
import 'debug.dart';
|
||||
import 'layer.dart';
|
||||
import 'object.dart';
|
||||
import 'semantics.dart';
|
||||
|
||||
export 'package:flutter/gestures.dart' show
|
||||
PointerEvent,
|
||||
|
||||
@ -8,13 +8,13 @@ import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'binding.dart';
|
||||
import 'box.dart';
|
||||
import 'object.dart';
|
||||
import 'proxy_box.dart';
|
||||
import 'semantics.dart';
|
||||
import 'sliver.dart';
|
||||
import 'viewport_offset.dart';
|
||||
|
||||
|
||||
@ -6,13 +6,13 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'binding.dart';
|
||||
import 'box.dart';
|
||||
import 'object.dart';
|
||||
import 'proxy_box.dart';
|
||||
import 'semantics.dart';
|
||||
import 'sliver.dart';
|
||||
import 'viewport_offset.dart';
|
||||
|
||||
|
||||
@ -4,14 +4,15 @@
|
||||
|
||||
import 'dart:typed_data';
|
||||
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/painting.dart';
|
||||
import 'package:flutter/painting.dart' show MatrixUtils, TransformProperty;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'debug.dart';
|
||||
|
||||
import 'semantics_event.dart';
|
||||
|
||||
export 'dart:ui' show SemanticsAction;
|
||||
@ -197,7 +198,7 @@ class SemanticsData extends Diagnosticable {
|
||||
}
|
||||
|
||||
@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> {
|
||||
@ -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({
|
||||
@required String thisString,
|
||||
@required String otherString,
|
||||
@ -3,10 +3,11 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'rendering_tester.dart';
|
||||
import '../rendering/rendering_tester.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user