Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39ce615

Browse filesBrowse files
authored
Add landmark roles (flutter#168931)
This PR is to add ARIA landmark roles to `SemanticsRole`: complementary, contentInfo, main, navigation and region. I skipped `sectionhead` because it is an abstract role based on the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/sectionhead_role#:~:text=The%20structural%20sectionhead%20role%20is%20an%20abstract%20role%20for%20the%20subclass%20roles%20that%20identify%20the%20labels%20or%20summaries%20of%20the%20sections%20they%20label.%20The%20role%20must%20not%20be%20used.) . Fixes flutter#162138 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent ce058e0 commit 39ce615
Copy full SHA for 39ce615

File tree

Expand file treeCollapse file tree

11 files changed

+948
-0
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+948
-0
lines changed

‎engine/src/flutter/ci/licenses_golden/licenses_flutter

Copy file name to clipboardExpand all lines: engine/src/flutter/ci/licenses_golden/licenses_flutter
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52255,6 +52255,7 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/heading.dart + ../.
5225552255
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/image.dart + ../../../flutter/LICENSE
5225652256
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/incrementable.dart + ../../../flutter/LICENSE
5225752257
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/label_and_value.dart + ../../../flutter/LICENSE
52258+
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/landmarks.dart + ../../../flutter/LICENSE
5225852259
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/link.dart + ../../../flutter/LICENSE
5225952260
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/list.dart + ../../../flutter/LICENSE
5226052261
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/live_region.dart + ../../../flutter/LICENSE
@@ -55281,6 +55282,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/heading.dart
5528155282
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/image.dart
5528255283
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/incrementable.dart
5528355284
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/label_and_value.dart
55285+
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/landmarks.dart
5528455286
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/link.dart
5528555287
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/list.dart
5528655288
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/live_region.dart

‎engine/src/flutter/lib/ui/semantics.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/ui/semantics.dart
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,44 @@ enum SemanticsRole {
501501
/// * The connection to the server was lost so local changes will not be
502502
/// saved.
503503
alert,
504+
505+
/// A supporting section that relates to the main content.
506+
///
507+
/// The compelementary role is one of landmark roles. This role can be used to
508+
/// describe sidebars, or call-out boxes.
509+
///
510+
/// For more information, see: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/complementary_role
511+
complementary,
512+
513+
/// A section for a footer, containing identifying information such as
514+
/// copyright information, navigation links and privacy statements.
515+
///
516+
/// The contentInfo role is one of landmark roles. For more information, see:
517+
/// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/contentinfo_role
518+
contentInfo,
519+
520+
/// The primary content of a document.
521+
///
522+
/// The section consists of content that is directly related to or expands on
523+
/// the central topic of a document, or the main function of an application.
524+
///
525+
/// This role is one of landmark roles. For more information, see:
526+
/// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/main_role
527+
main,
528+
529+
/// A region of a web page that contains navigation links.
530+
///
531+
/// This role is one of landmark roles. For more information, see:
532+
/// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/navigation_role
533+
navigation,
534+
535+
/// A section of content sufficiently important but cannot be descrived by one
536+
/// of the other landmark roles, such as main, contentinfo, complementary, or
537+
/// navigation.
538+
///
539+
/// For more information, see:
540+
/// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/region_role
541+
region,
504542
}
505543

506544
/// Describe the type of data for an input field.

‎engine/src/flutter/lib/ui/semantics/semantics_node.h

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/ui/semantics/semantics_node.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ enum class SemanticsRole : int32_t {
9797
kRadioGroup = 25,
9898
kStatus = 26,
9999
kAlert = 27,
100+
kComplementary = 28,
101+
kContentInfo = 29,
102+
kMain = 30,
103+
kNavigation = 31,
104+
kRegion = 32,
100105
};
101106

102107
/// C/C++ representation of `SemanticsValidationResult` defined in

‎engine/src/flutter/lib/web_ui/lib/semantics.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/semantics.dart
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,11 @@ enum SemanticsRole {
612612
radioGroup,
613613
status,
614614
alert,
615+
complementary,
616+
contentInfo,
617+
main,
618+
navigation,
619+
region,
615620
}
616621

617622
// Mirrors engine/src/flutter/lib/ui/semantics.dart

‎engine/src/flutter/lib/web_ui/lib/src/engine.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine.dart
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export 'engine/semantics/heading.dart';
114114
export 'engine/semantics/image.dart';
115115
export 'engine/semantics/incrementable.dart';
116116
export 'engine/semantics/label_and_value.dart';
117+
export 'engine/semantics/landmarks.dart';
117118
export 'engine/semantics/link.dart';
118119
export 'engine/semantics/list.dart';
119120
export 'engine/semantics/live_region.dart';

‎engine/src/flutter/lib/web_ui/lib/src/engine/semantics.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/semantics.dart
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export 'semantics/heading.dart';
1313
export 'semantics/image.dart';
1414
export 'semantics/incrementable.dart';
1515
export 'semantics/label_and_value.dart';
16+
export 'semantics/landmarks.dart';
1617
export 'semantics/link.dart';
1718
export 'semantics/list.dart';
1819
export 'semantics/live_region.dart';
+101Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'label_and_value.dart';
6+
import 'semantics.dart';
7+
8+
/// Indicates a complementary element.
9+
///
10+
/// Uses aria complementary role to convey this semantic information to the element.
11+
///
12+
/// Screen-readers takes advantage of "aria-label" to describe the visual.
13+
class SemanticComplementary extends SemanticRole {
14+
SemanticComplementary(SemanticsObject semanticsObject)
15+
: super.withBasics(
16+
EngineSemanticsRole.complementary,
17+
semanticsObject,
18+
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
19+
) {
20+
setAriaRole('complementary');
21+
}
22+
23+
@override
24+
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
25+
}
26+
27+
/// Indicates a content info element.
28+
///
29+
/// Uses aria contentinfo role to convey this semantic information to the element.
30+
///
31+
/// Screen-readers takes advantage of "aria-label" to describe the visual.
32+
class SemanticContentInfo extends SemanticRole {
33+
SemanticContentInfo(SemanticsObject semanticsObject)
34+
: super.withBasics(
35+
EngineSemanticsRole.contentInfo,
36+
semanticsObject,
37+
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
38+
) {
39+
setAriaRole('contentinfo');
40+
}
41+
42+
@override
43+
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
44+
}
45+
46+
/// Indicates a main element.
47+
///
48+
/// Uses aria main role to convey this semantic information to the element.
49+
///
50+
/// Screen-readers takes advantage of "aria-label" to describe the visual.
51+
class SemanticMain extends SemanticRole {
52+
SemanticMain(SemanticsObject semanticsObject)
53+
: super.withBasics(
54+
EngineSemanticsRole.main,
55+
semanticsObject,
56+
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
57+
) {
58+
setAriaRole('main');
59+
}
60+
61+
@override
62+
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
63+
}
64+
65+
/// Indicates a navigation element.
66+
///
67+
/// Uses aria navigation role to convey this semantic information to the element.
68+
///
69+
/// Screen-readers takes advantage of "aria-label" to describe the visual.
70+
class SemanticNavigation extends SemanticRole {
71+
SemanticNavigation(SemanticsObject semanticsObject)
72+
: super.withBasics(
73+
EngineSemanticsRole.navigation,
74+
semanticsObject,
75+
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
76+
) {
77+
setAriaRole('navigation');
78+
}
79+
80+
@override
81+
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
82+
}
83+
84+
/// Indicates a region element.
85+
///
86+
/// Uses aria region role to convey this semantic information to the element.
87+
///
88+
/// Screen-readers takes advantage of "aria-label" to describe the visual.
89+
class SemanticRegion extends SemanticRole {
90+
SemanticRegion(SemanticsObject semanticsObject)
91+
: super.withBasics(
92+
EngineSemanticsRole.region,
93+
semanticsObject,
94+
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
95+
) {
96+
setAriaRole('region');
97+
}
98+
99+
@override
100+
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
101+
}

‎engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart

Copy file name to clipboardExpand all lines: engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import 'heading.dart';
3030
import 'image.dart';
3131
import 'incrementable.dart';
3232
import 'label_and_value.dart';
33+
import 'landmarks.dart';
3334
import 'link.dart';
3435
import 'list.dart';
3536
import 'live_region.dart';
@@ -501,6 +502,24 @@ enum EngineSemanticsRole {
501502

502503
/// An option with a radio button in a set of choices contained by a [menu] or [menuBar].
503504
menuItemRadio,
505+
506+
/// A supporting section of a web page.
507+
complementary,
508+
509+
/// A section containing identifying information such as copyright
510+
/// information, navigation links and privacy statements.
511+
contentInfo,
512+
513+
/// The primary content of a document.
514+
main,
515+
516+
/// A region of a web page that contains navigation links.
517+
navigation,
518+
519+
/// A section of content sufficiently important but cannot be descrived by one
520+
/// of the other landmark roles, such as main, contentinfo, complementary, or
521+
/// navigation.
522+
region,
504523
}
505524

506525
/// Responsible for setting the `role` ARIA attribute, for attaching
@@ -1962,6 +1981,16 @@ class SemanticsObject {
19621981
return EngineSemanticsRole.list;
19631982
case ui.SemanticsRole.listItem:
19641983
return EngineSemanticsRole.listItem;
1984+
case ui.SemanticsRole.complementary:
1985+
return EngineSemanticsRole.complementary;
1986+
case ui.SemanticsRole.contentInfo:
1987+
return EngineSemanticsRole.contentInfo;
1988+
case ui.SemanticsRole.main:
1989+
return EngineSemanticsRole.main;
1990+
case ui.SemanticsRole.navigation:
1991+
return EngineSemanticsRole.navigation;
1992+
case ui.SemanticsRole.region:
1993+
return EngineSemanticsRole.region;
19651994
// TODO(chunhtai): implement these roles.
19661995
// https://github.com/flutter/flutter/issues/159741.
19671996
case ui.SemanticsRole.dragHandle:
@@ -2038,6 +2067,11 @@ class SemanticsObject {
20382067
EngineSemanticsRole.alert => SemanticAlert(this),
20392068
EngineSemanticsRole.status => SemanticStatus(this),
20402069
EngineSemanticsRole.generic => GenericRole(this),
2070+
EngineSemanticsRole.complementary => SemanticComplementary(this),
2071+
EngineSemanticsRole.contentInfo => SemanticContentInfo(this),
2072+
EngineSemanticsRole.main => SemanticMain(this),
2073+
EngineSemanticsRole.navigation => SemanticNavigation(this),
2074+
EngineSemanticsRole.region => SemanticRegion(this),
20412075
};
20422076
}
20432077

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.