Add SemanticsFlag.isHidden (flutter/engine#5052)

This commit is contained in:
Michael Goderbauer
2018-04-20 10:37:02 -07:00
committed by GitHub
parent 602a3a3727
commit 3034fd831c
4 changed files with 59 additions and 19 deletions

View File

@@ -227,6 +227,7 @@ class SemanticsFlag {
static const int _kIsObscuredIndex = 1 << 10;
static const int _kScopesRouteIndex= 1 << 11;
static const int _kNamesRouteIndex = 1 << 12;
static const int _kIsHiddenIndex = 1 << 13;
const SemanticsFlag._(this.index);
@@ -311,42 +312,60 @@ class SemanticsFlag {
/// Whether the semantics node is the root of a subtree for which a route name
/// should be announced.
///
/// When a node with this flag is removed from the semantics tree, the
///
/// When a node with this flag is removed from the semantics tree, the
/// framework will select the last in depth-first, paint order node with this
/// flag. When a node with this flag is added to the semantics tree, it is
/// selected automatically, unless there were multiple nodes with this flag
/// added. In this case, the last added node in depth-first, paint order
/// will be selected.
///
///
/// From this selected node, the framework will search in depth-first, paint
/// order for the first node with a [namesRoute] flag and a non-null,
/// non-empty label. The [namesRoute] and [scopesRoute] flags may be on the
/// same node. The label of the found node will be announced as an edge
/// order for the first node with a [namesRoute] flag and a non-null,
/// non-empty label. The [namesRoute] and [scopesRoute] flags may be on the
/// same node. The label of the found node will be announced as an edge
/// transition. If no non-empty, non-null label is found then:
///
///
/// * VoiceOver will make a chime announcement.
/// * TalkBack will make no announcement
///
/// Semantic nodes annotated with this flag are generally not a11y focusable.
///
/// This is used in widgets such as Routes, Drawers, and Dialogs to
///
/// This is used in widgets such as Routes, Drawers, and Dialogs to
/// communicate significant changes in the visible screen.
static const SemanticsFlag scopesRoute = const SemanticsFlag._(_kScopesRouteIndex);
/// Whether the semantics node label is the name of a visually distinct
/// route.
///
///
/// This is used by certain widgets like Drawers and Dialogs, to indicate
/// that the node's semantic label can be used to announce an edge triggered
/// semantics update.
///
/// Semantic nodes annotated with this flag will still recieve a11y focus.
///
/// Updating this label within the same active route subtree will not cause
///
/// Updating this label within the same active route subtree will not cause
/// additional announcements.
static const SemanticsFlag namesRoute = const SemanticsFlag._(_kNamesRouteIndex);
/// Whether the semantics node is considered hidden.
///
/// Hidden elements are currently not visible on screen. They may be covered
/// by other elements or positioned outside of the visible area of a viewport.
///
/// Hidden elements cannot gain accessibility focus though regular touch. The
/// only way they can be focused is by moving the focus to them via linear
/// navigation.
///
/// Platforms are free to completely ignore hidden elements and new platforms
/// are encouraged to do so.
///
/// Instead of marking an element as hidden it should usually be excluded from
/// the semantics tree altogether. Hidden elements are only included in the
/// semantics tree to work around platform limitations and they are mainly
/// used to implement accessibility scrolling on iOS.
static const SemanticsFlag isHidden = const SemanticsFlag._(_kIsHiddenIndex);
/// The possible semantics flags.
///
/// The map's key is the [index] of the flag and the value is the flag itself.
@@ -364,6 +383,7 @@ class SemanticsFlag {
_kIsObscuredIndex: isObscured,
_kScopesRouteIndex: scopesRoute,
_kNamesRouteIndex: namesRoute,
_kIsHiddenIndex: isHidden,
};
@override
@@ -395,6 +415,8 @@ class SemanticsFlag {
return 'SemanticsFlag.scopesRoute';
case _kNamesRouteIndex:
return 'SemanticsFlag.namesRoute';
case _kIsHiddenIndex:
return 'SemanticsFlag.isHidden';
}
return null;
}

View File

@@ -58,6 +58,7 @@ enum class SemanticsFlags : int32_t {
kIsObscured = 1 << 10,
kScopesRoute = 1 << 11,
kNamesRoute = 1 << 12,
kIsHidden = 1 << 13,
};
struct SemanticsNode {

View File

@@ -91,6 +91,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
IS_OBSCURED(1 << 10),
SCOPES_ROUTE(1 << 11),
NAMES_ROUTE(1 << 12);
IS_HIDDEN(1 << 13);
Flag(int value) {
this.value = value;
@@ -264,7 +265,9 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
if (object.children != null) {
for (SemanticsObject child : object.children) {
result.addChild(mOwner, child.id);
if (!child.hasFlag(Flag.IS_HIDDEN)) {
result.addChild(mOwner, child.id);
}
}
}
@@ -472,9 +475,10 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
while (buffer.hasRemaining()) {
int id = buffer.getInt();
SemanticsObject object = getOrCreateObject(id);
boolean hadCheckedState = object.hasFlag(Flag.HAS_CHECKED_STATE);
boolean wasChecked = object.hasFlag(Flag.IS_CHECKED);
object.updateWith(buffer, strings);
if (object.hasFlag(Flag.IS_HIDDEN)) {
continue;
}
if (object.hasFlag(Flag.IS_FOCUSED)) {
mInputFocusedObject = object;
}
@@ -896,6 +900,9 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
final float[] transformedPoint = new float[4];
for (int i = children.size() - 1; i >= 0; i -= 1) {
final SemanticsObject child = children.get(i);
if (child.hasFlag(Flag.IS_HIDDEN)) {
continue;
}
child.ensureInverseTransform();
Matrix.multiplyMV(transformedPoint, 0, child.inverseTransform, 0, point, 0);
final SemanticsObject result = child.hitTest(transformedPoint);

View File

@@ -168,8 +168,8 @@ NSComparisonResult IntToComparisonResult(int32_t value) {
// We enforce in the framework that no other useful semantics are merged with these nodes.
if ([self node].HasFlag(blink::SemanticsFlags::kScopesRoute))
return false;
return [self node].flags != 0 || ![self node].label.empty() || ![self node].value.empty() ||
![self node].hint.empty() ||
return ([self node].flags != 0 && [self node].flags != static_cast<int32_t>(blink::SemanticsFlags::kIsHidden)) ||
![self node].label.empty() || ![self node].value.empty() || ![self node].hint.empty() ||
([self node].actions & ~blink::kScrollableSemanticsActions) != 0;
}
@@ -222,6 +222,13 @@ NSComparisonResult IntToComparisonResult(int32_t value) {
}
- (CGRect)accessibilityFrame {
if ([self node].HasFlag(blink::SemanticsFlags::kIsHidden)) {
return [super accessibilityFrame];
}
return [self globalRect];
}
- (CGRect) globalRect {
SkMatrix44 globalTransform = [self node].transform;
for (SemanticsObject* parent = [self parent]; parent; parent = parent.parent) {
globalTransform = parent.node.transform * globalTransform;
@@ -298,6 +305,9 @@ NSComparisonResult IntToComparisonResult(int32_t value) {
#pragma mark UIAccessibilityFocus overrides
- (void)accessibilityElementDidBecomeFocused {
if ([self node].HasFlag(blink::SemanticsFlags::kIsHidden)) {
[self bridge] -> DispatchSemanticsAction([self uid], blink::SemanticsAction::kShowOnScreen);
}
if ([self node].HasAction(blink::SemanticsAction::kDidGainAccessibilityFocus)) {
[self bridge] -> DispatchSemanticsAction([self uid],
blink::SemanticsAction::kDidGainAccessibilityFocus);
@@ -515,8 +525,8 @@ void AccessibilityBridge::UpdateSemantics(blink::SemanticsNodeUpdates nodes) {
for (SemanticsObject* object in childOrdersToUpdate) {
[object.children sortUsingComparator:^(SemanticsObject* a, SemanticsObject* b) {
// Should a go before b?
CGRect rectA = [a accessibilityFrame];
CGRect rectB = [b accessibilityFrame];
CGRect rectA = [a globalRect];
CGRect rectB = [b globalRect];
CGFloat top = rectA.origin.y - rectB.origin.y;
if (top == 0.0)
return IntToComparisonResult(rectA.origin.x - rectB.origin.x < 0.0);