Add table related semantics role (#162339)
issue: https://github.com/flutter/flutter/issues/45205 This PR added roles: table,cell,row,columnheader in engine side. Also added table, cell , columnheader in framework widgets `Table` and `DataTable`. This PR didn't add `row` in framework side because right now TableCell is ParentDataWidget expecting its parent to be a Table, tableRow is not a widget or a renderObject, but just some data. If we want to add a role to `row`, we need to do some refactor to `TableCell`, `TableRow` and `Table`. If we need to add row, I will do that in another PR. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
@@ -42731,6 +42731,7 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/route.dart + ../../
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/table.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/tabs.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/tappable.dart + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart + ../../../flutter/LICENSE
|
||||
@@ -45705,6 +45706,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/route.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/scrollable.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/table.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/tabs.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/tappable.dart
|
||||
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart
|
||||
|
||||
@@ -348,14 +348,14 @@ enum SemanticsRole {
|
||||
|
||||
/// A tab button.
|
||||
///
|
||||
/// see also:
|
||||
/// See also:
|
||||
///
|
||||
/// * [tabBar], which is the role for containers of tab buttons.
|
||||
tab,
|
||||
|
||||
/// Contains tab buttons.
|
||||
///
|
||||
/// see also:
|
||||
/// See also:
|
||||
///
|
||||
/// * [tab], which is the role for tab buttons.
|
||||
tabBar,
|
||||
@@ -368,6 +368,34 @@ enum SemanticsRole {
|
||||
|
||||
/// An alert dialog.
|
||||
alertDialog,
|
||||
|
||||
/// A table structure containing data arranged in rows and columns.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [cell], [row], [columnHeader] for table related roles.
|
||||
table,
|
||||
|
||||
/// A cell in a [table] that does not contain column or row header information.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [table],[row], [columnHeader] for table related roles.
|
||||
cell,
|
||||
|
||||
/// A row of [cell]s or or [columnHeader]s in a [table].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [table] ,[cell],[columnHeader] for table related roles.
|
||||
row,
|
||||
|
||||
/// A cell in a [table] contains header information for a column.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [table] ,[cell], [row] for table related roles.
|
||||
columnHeader,
|
||||
}
|
||||
|
||||
/// A Boolean value that can be associated with a semantics node.
|
||||
|
||||
@@ -68,6 +68,10 @@ enum class SemanticsRole : int32_t {
|
||||
kTab = 1,
|
||||
kTabBar = 2,
|
||||
kTabPanel = 3,
|
||||
kTable = 4,
|
||||
kCell = 5,
|
||||
kRow = 6,
|
||||
kColumnHeader = 7,
|
||||
};
|
||||
|
||||
/// C/C++ representation of `SemanticsFlags` defined in
|
||||
|
||||
@@ -256,7 +256,19 @@ class SemanticsFlag {
|
||||
}
|
||||
|
||||
// Mirrors engine/src/flutter/lib/ui/semantics.dart
|
||||
enum SemanticsRole { none, tab, tabBar, tabPanel, dialog, alertDialog }
|
||||
|
||||
enum SemanticsRole {
|
||||
none,
|
||||
tab,
|
||||
tabBar,
|
||||
tabPanel,
|
||||
dialog,
|
||||
alertDialog,
|
||||
table,
|
||||
cell,
|
||||
row,
|
||||
columnHeader,
|
||||
}
|
||||
|
||||
// When adding a new StringAttributeType, the classes in these file must be
|
||||
// updated as well.
|
||||
|
||||
@@ -160,6 +160,7 @@ export 'engine/semantics/route.dart';
|
||||
export 'engine/semantics/scrollable.dart';
|
||||
export 'engine/semantics/semantics.dart';
|
||||
export 'engine/semantics/semantics_helper.dart';
|
||||
export 'engine/semantics/table.dart';
|
||||
export 'engine/semantics/tabs.dart';
|
||||
export 'engine/semantics/tappable.dart';
|
||||
export 'engine/semantics/text_field.dart';
|
||||
|
||||
@@ -16,6 +16,7 @@ export 'semantics/platform_view.dart';
|
||||
export 'semantics/scrollable.dart';
|
||||
export 'semantics/semantics.dart';
|
||||
export 'semantics/semantics_helper.dart';
|
||||
export 'semantics/table.dart';
|
||||
export 'semantics/tabs.dart';
|
||||
export 'semantics/tappable.dart';
|
||||
export 'semantics/text_field.dart';
|
||||
|
||||
@@ -32,6 +32,7 @@ import 'platform_view.dart';
|
||||
import 'route.dart';
|
||||
import 'scrollable.dart';
|
||||
import 'semantics_helper.dart';
|
||||
import 'table.dart';
|
||||
import 'tabs.dart';
|
||||
import 'tappable.dart';
|
||||
import 'text_field.dart';
|
||||
@@ -422,6 +423,18 @@ enum EngineSemanticsRole {
|
||||
/// An alert dialog.
|
||||
alertDialog,
|
||||
|
||||
/// A table structure containing data arranged in rows and columns.
|
||||
table,
|
||||
|
||||
/// A cell in a [table] that does not contain column or row header information.
|
||||
cell,
|
||||
|
||||
/// A row of [cell]s or or [columnHeader]s in a [table].
|
||||
row,
|
||||
|
||||
/// A cell in a [table] contains header information for a column.
|
||||
columnHeader,
|
||||
|
||||
/// A role used when a more specific role cannot be assigend to
|
||||
/// a [SemanticsObject].
|
||||
///
|
||||
@@ -1755,6 +1768,14 @@ class SemanticsObject {
|
||||
return EngineSemanticsRole.dialog;
|
||||
case ui.SemanticsRole.alertDialog:
|
||||
return EngineSemanticsRole.alertDialog;
|
||||
case ui.SemanticsRole.table:
|
||||
return EngineSemanticsRole.table;
|
||||
case ui.SemanticsRole.cell:
|
||||
return EngineSemanticsRole.cell;
|
||||
case ui.SemanticsRole.row:
|
||||
return EngineSemanticsRole.row;
|
||||
case ui.SemanticsRole.columnHeader:
|
||||
return EngineSemanticsRole.columnHeader;
|
||||
case ui.SemanticsRole.none:
|
||||
// fallback to checking semantics properties.
|
||||
}
|
||||
@@ -1806,6 +1827,10 @@ class SemanticsObject {
|
||||
EngineSemanticsRole.tabPanel => SemanticTabPanel(this),
|
||||
EngineSemanticsRole.dialog => SemanticDialog(this),
|
||||
EngineSemanticsRole.alertDialog => SemanticAlertDialog(this),
|
||||
EngineSemanticsRole.table => SemanticTable(this),
|
||||
EngineSemanticsRole.cell => SemanticCell(this),
|
||||
EngineSemanticsRole.row => SemanticRow(this),
|
||||
EngineSemanticsRole.columnHeader => SemanticColumnHeader(this),
|
||||
EngineSemanticsRole.generic => GenericRole(this),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'label_and_value.dart';
|
||||
import 'semantics.dart';
|
||||
|
||||
/// Indicates a table element.
|
||||
///
|
||||
/// Uses aria table role to convey this semantic information to the element.
|
||||
///
|
||||
/// Screen-readers takes advantage of "aria-label" to describe the visual.
|
||||
class SemanticTable extends SemanticRole {
|
||||
SemanticTable(SemanticsObject semanticsObject)
|
||||
: super.withBasics(
|
||||
EngineSemanticsRole.table,
|
||||
semanticsObject,
|
||||
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
|
||||
) {
|
||||
setAriaRole('table');
|
||||
}
|
||||
|
||||
@override
|
||||
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
|
||||
}
|
||||
|
||||
/// Indicates a table cell element.
|
||||
///
|
||||
/// Uses aria cell role to convey this semantic information to the element.
|
||||
///
|
||||
/// Screen-readers takes advantage of "aria-label" to describe the visual.
|
||||
class SemanticCell extends SemanticRole {
|
||||
SemanticCell(SemanticsObject semanticsObject)
|
||||
: super.withBasics(
|
||||
EngineSemanticsRole.cell,
|
||||
semanticsObject,
|
||||
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
|
||||
) {
|
||||
setAriaRole('cell');
|
||||
}
|
||||
|
||||
@override
|
||||
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
|
||||
}
|
||||
|
||||
/// Indicates a table row element.
|
||||
///
|
||||
/// Uses aria row role to convey this semantic information to the element.
|
||||
///
|
||||
/// Screen-readers takes advantage of "aria-label" to describe the visual.
|
||||
class SemanticRow extends SemanticRole {
|
||||
SemanticRow(SemanticsObject semanticsObject)
|
||||
: super.withBasics(
|
||||
EngineSemanticsRole.row,
|
||||
semanticsObject,
|
||||
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
|
||||
) {
|
||||
setAriaRole('row');
|
||||
}
|
||||
|
||||
@override
|
||||
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
|
||||
}
|
||||
|
||||
/// Indicates a table column header element.
|
||||
///
|
||||
/// Uses aria columnheader role to convey this semantic information to the element.
|
||||
///
|
||||
/// Screen-readers takes advantage of "aria-label" to describe the visual.
|
||||
class SemanticColumnHeader extends SemanticRole {
|
||||
SemanticColumnHeader(SemanticsObject semanticsObject)
|
||||
: super.withBasics(
|
||||
EngineSemanticsRole.columnHeader,
|
||||
semanticsObject,
|
||||
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
|
||||
) {
|
||||
setAriaRole('columnheader');
|
||||
}
|
||||
|
||||
@override
|
||||
bool focusAsRouteDefault() => focusable?.focusAsRouteDefault() ?? false;
|
||||
}
|
||||
@@ -123,6 +123,9 @@ void runSemanticsTests() {
|
||||
group('tabs', () {
|
||||
_testTabs();
|
||||
});
|
||||
group('table', () {
|
||||
_testTables();
|
||||
});
|
||||
}
|
||||
|
||||
void _testSemanticRole() {
|
||||
@@ -3723,6 +3726,94 @@ void _testTabs() {
|
||||
});
|
||||
}
|
||||
|
||||
void _testTables() {
|
||||
test('nodes with table role', () {
|
||||
semantics()
|
||||
..debugOverrideTimestampFunction(() => _testTime)
|
||||
..semanticsEnabled = true;
|
||||
|
||||
SemanticsObject pumpSemantics() {
|
||||
final SemanticsTester tester = SemanticsTester(owner());
|
||||
tester.updateNode(
|
||||
id: 0,
|
||||
role: ui.SemanticsRole.table,
|
||||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
|
||||
);
|
||||
tester.apply();
|
||||
return tester.getSemanticsObject(0);
|
||||
}
|
||||
|
||||
final SemanticsObject object = pumpSemantics();
|
||||
expect(object.semanticRole?.kind, EngineSemanticsRole.table);
|
||||
expect(object.element.getAttribute('role'), 'table');
|
||||
});
|
||||
|
||||
test('nodes with cell role', () {
|
||||
semantics()
|
||||
..debugOverrideTimestampFunction(() => _testTime)
|
||||
..semanticsEnabled = true;
|
||||
|
||||
SemanticsObject pumpSemantics() {
|
||||
final SemanticsTester tester = SemanticsTester(owner());
|
||||
tester.updateNode(
|
||||
id: 0,
|
||||
role: ui.SemanticsRole.cell,
|
||||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
|
||||
);
|
||||
tester.apply();
|
||||
return tester.getSemanticsObject(0);
|
||||
}
|
||||
|
||||
final SemanticsObject object = pumpSemantics();
|
||||
expect(object.semanticRole?.kind, EngineSemanticsRole.cell);
|
||||
expect(object.element.getAttribute('role'), 'cell');
|
||||
});
|
||||
|
||||
test('nodes with row role', () {
|
||||
semantics()
|
||||
..debugOverrideTimestampFunction(() => _testTime)
|
||||
..semanticsEnabled = true;
|
||||
|
||||
SemanticsObject pumpSemantics() {
|
||||
final SemanticsTester tester = SemanticsTester(owner());
|
||||
tester.updateNode(
|
||||
id: 0,
|
||||
role: ui.SemanticsRole.row,
|
||||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
|
||||
);
|
||||
tester.apply();
|
||||
return tester.getSemanticsObject(0);
|
||||
}
|
||||
|
||||
final SemanticsObject object = pumpSemantics();
|
||||
expect(object.semanticRole?.kind, EngineSemanticsRole.row);
|
||||
expect(object.element.getAttribute('role'), 'row');
|
||||
});
|
||||
|
||||
test('nodes with column header role', () {
|
||||
semantics()
|
||||
..debugOverrideTimestampFunction(() => _testTime)
|
||||
..semanticsEnabled = true;
|
||||
|
||||
SemanticsObject pumpSemantics() {
|
||||
final SemanticsTester tester = SemanticsTester(owner());
|
||||
tester.updateNode(
|
||||
id: 0,
|
||||
role: ui.SemanticsRole.columnHeader,
|
||||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
|
||||
);
|
||||
tester.apply();
|
||||
return tester.getSemanticsObject(0);
|
||||
}
|
||||
|
||||
final SemanticsObject object = pumpSemantics();
|
||||
expect(object.semanticRole?.kind, EngineSemanticsRole.columnHeader);
|
||||
expect(object.element.getAttribute('role'), 'columnheader');
|
||||
});
|
||||
|
||||
semantics().semanticsEnabled = false;
|
||||
}
|
||||
|
||||
/// A facade in front of [ui.SemanticsUpdateBuilder.updateNode] that
|
||||
/// supplies default values for semantics attributes.
|
||||
void updateNode(
|
||||
|
||||
Reference in New Issue
Block a user