Skip to content

Commit 58d7b84

Browse files
authored
Re-land Adding Link Semantics (flutter#12972)
1 parent 5b31822 commit 58d7b84

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

lib/ui/semantics.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class SemanticsFlag {
291291
static const int _kIsMultilineIndex = 1 << 19;
292292
static const int _kIsReadOnlyIndex = 1 << 20;
293293
static const int _kIsFocusableIndex = 1 << 21;
294+
static const int _kIsLinkIndex = 1 << 22;
294295

295296
const SemanticsFlag._(this.index);
296297

@@ -333,7 +334,7 @@ class SemanticsFlag {
333334

334335
/// Whether the semantic node represents a button.
335336
///
336-
/// Platforms has special handling for buttons, for example Android's TalkBack
337+
/// Platforms have special handling for buttons, for example Android's TalkBack
337338
/// and iOS's VoiceOver provides an additional hint when the focused object is
338339
/// a button.
339340
static const SemanticsFlag isButton = SemanticsFlag._(_kIsButtonIndex);
@@ -349,6 +350,13 @@ class SemanticsFlag {
349350
/// Only applicable when [isTextField] is true.
350351
static const SemanticsFlag isReadOnly = SemanticsFlag._(_kIsReadOnlyIndex);
351352

353+
/// Whether the semantic node is an interactive link.
354+
///
355+
/// Platforms have special handling for links, for example iOS's VoiceOver
356+
/// provides an additional hint when the focused object is a link, as well as
357+
/// the ability to parse the links through another navigation menu.
358+
static const SemanticsFlag isLink = SemanticsFlag._(_kIsLinkIndex);
359+
352360
/// Whether the semantic node is able to hold the user's focus.
353361
///
354362
/// The focused element is usually the current receiver of keyboard inputs.
@@ -528,6 +536,7 @@ class SemanticsFlag {
528536
_kHasImplicitScrollingIndex: hasImplicitScrolling,
529537
_kIsMultilineIndex: isMultiline,
530538
_kIsReadOnlyIndex: isReadOnly,
539+
_kIsLinkIndex: isLink,
531540
};
532541

533542
@override
@@ -575,6 +584,8 @@ class SemanticsFlag {
575584
return 'SemanticsFlag.isMultiline';
576585
case _kIsReadOnlyIndex:
577586
return 'SemanticsFlag.isReadOnly';
587+
case _kIsLinkIndex:
588+
return 'SemanticsFlag.isLink';
578589
}
579590
return null;
580591
}

lib/ui/semantics/semantics_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum class SemanticsFlags : int32_t {
7373
// kIsMultiline = 1 << 19,
7474
kIsReadOnly = 1 << 20,
7575
kIsFocusable = 1 << 21,
76+
kIsLink = 1 << 22,
7677
};
7778

7879
const int kScrollableSemanticsFlags =

shell/platform/android/io/flutter/view/AccessibilityBridge.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
591591
}
592592
}
593593

594-
if (semanticsNode.hasFlag(Flag.IS_BUTTON)) {
594+
if (semanticsNode.hasFlag(Flag.IS_BUTTON) || semanticsNode.hasFlag(Flag.IS_LINK)) {
595595
result.setClassName("android.widget.Button");
596596
}
597597
if (semanticsNode.hasFlag(Flag.IS_IMAGE)) {
@@ -1648,7 +1648,8 @@ private enum Flag {
16481648
// The Dart API defines the following flag but it isn't used in Android.
16491649
// IS_MULTILINE(1 << 19);
16501650
IS_READ_ONLY(1 << 20),
1651-
IS_FOCUSABLE(1 << 21);
1651+
IS_FOCUSABLE(1 << 21),
1652+
IS_LINK(1 << 22);
16521653

16531654
final int value;
16541655

shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ - (UIAccessibilityTraits)accessibilityTraits {
407407
if ([self node].HasFlag(flutter::SemanticsFlags::kIsLiveRegion)) {
408408
traits |= UIAccessibilityTraitUpdatesFrequently;
409409
}
410+
if ([self node].HasFlag(flutter::SemanticsFlags::kIsLink)) {
411+
traits |= UIAccessibilityTraitLink;
412+
}
410413
return traits;
411414
}
412415

shell/platform/embedder/embedder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ typedef enum {
6363
/// Must match the `SemanticsAction` enum in semantics.dart.
6464
typedef enum {
6565
/// The equivalent of a user briefly tapping the screen with the finger
66-
/// without
67-
/// moving it.
66+
/// without moving it.
6867
kFlutterSemanticsActionTap = 1 << 0,
6968
/// The equivalent of a user pressing and holding the screen with the finger
7069
/// for a few seconds without moving it.
@@ -172,6 +171,8 @@ typedef enum {
172171
kFlutterSemanticsFlagIsReadOnly = 1 << 20,
173172
/// Whether the semantic node can hold the user's focus.
174173
kFlutterSemanticsFlagIsFocusable = 1 << 21,
174+
/// Whether the semantics node represents a link.
175+
kFlutterSemanticsFlagIsLink = 1 << 22,
175176
} FlutterSemanticsFlag;
176177

177178
typedef enum {

0 commit comments

Comments
 (0)