Skip to content

Commit

Permalink
Revert "Adds semantics tooltip support (flutter#27893)" (flutter#28207)
Browse files Browse the repository at this point in the history
This reverts commit 14e27f9.
  • Loading branch information
zanderso authored Aug 19, 2021
1 parent c3c26c4 commit b20c1a3
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 303 deletions.
26 changes: 10 additions & 16 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,6 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 {
/// and `decreasedValue` respectively. Their contents must not be changed during
/// the semantics update.
///
/// The `tooltip` is a string that describe additional information when user
/// hover or long press on the backing widget of this semantics node.
///
/// The fields `textSelectionBase` and `textSelectionExtent` describe the
/// currently selected text within `value`. A value of -1 indicates no
/// current text selection base or extent.
Expand Down Expand Up @@ -860,16 +857,15 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 {
required double thickness,
required Rect rect,
required String label,
required List<StringAttribute> labelAttributes,
List<StringAttribute>? labelAttributes,
required String value,
required List<StringAttribute> valueAttributes,
List<StringAttribute>? valueAttributes,
required String increasedValue,
required List<StringAttribute> increasedValueAttributes,
List<StringAttribute>? increasedValueAttributes,
required String decreasedValue,
required List<StringAttribute> decreasedValueAttributes,
List<StringAttribute>? decreasedValueAttributes,
required String hint,
required List<StringAttribute> hintAttributes,
String? tooltip,
List<StringAttribute>? hintAttributes,
TextDirection? textDirection,
required Float64List transform,
required Int32List childrenInTraversalOrder,
Expand Down Expand Up @@ -911,7 +907,6 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 {
decreasedValueAttributes,
hint,
hintAttributes,
tooltip,
textDirection != null ? textDirection.index + 1 : 0,
transform,
childrenInTraversalOrder,
Expand Down Expand Up @@ -940,16 +935,15 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 {
double elevation,
double thickness,
String label,
List<StringAttribute> labelAttributes,
List<StringAttribute>? labelAttributes,
String value,
List<StringAttribute> valueAttributes,
List<StringAttribute>? valueAttributes,
String increasedValue,
List<StringAttribute> increasedValueAttributes,
List<StringAttribute>? increasedValueAttributes,
String decreasedValue,
List<StringAttribute> decreasedValueAttributes,
List<StringAttribute>? decreasedValueAttributes,
String hint,
List<StringAttribute> hintAttributes,
String? tooltip,
List<StringAttribute>? hintAttributes,
int textDirection,
Float64List transform,
Int32List childrenInTraversalOrder,
Expand Down
1 change: 0 additions & 1 deletion lib/ui/semantics/semantics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ struct SemanticsNode {
StringAttributes increasedValueAttributes;
std::string decreasedValue;
StringAttributes decreasedValueAttributes;
std::string tooltip;
int32_t textDirection = 0; // 0=unknown, 1=rtl, 2=ltr

SkRect rect = SkRect::MakeEmpty(); // Local space, relative to parent.
Expand Down
2 changes: 0 additions & 2 deletions lib/ui/semantics/semantics_update_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void SemanticsUpdateBuilder::updateNode(
std::vector<NativeStringAttribute*> decreasedValueAttributes,
std::string hint,
std::vector<NativeStringAttribute*> hintAttributes,
std::string tooltip,
int textDirection,
const tonic::Float64List& transform,
const tonic::Int32List& childrenInTraversalOrder,
Expand Down Expand Up @@ -115,7 +114,6 @@ void SemanticsUpdateBuilder::updateNode(
pushStringAttributes(node.decreasedValueAttributes, decreasedValueAttributes);
node.hint = hint;
pushStringAttributes(node.hintAttributes, hintAttributes);
node.tooltip = tooltip;
node.textDirection = textDirection;
SkScalar scalarTransform[16];
for (int i = 0; i < 16; ++i) {
Expand Down
1 change: 0 additions & 1 deletion lib/ui/semantics/semantics_update_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class SemanticsUpdateBuilder
std::vector<NativeStringAttribute*> decreasedValueAttributes,
std::string hint,
std::vector<NativeStringAttribute*> hintAttributes,
std::string tooltip,
int textDirection,
const tonic::Float64List& transform,
const tonic::Int32List& childrenInTraversalOrder,
Expand Down
24 changes: 10 additions & 14 deletions lib/web_ui/lib/src/engine/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ class SemanticsNodeUpdate {
required this.scrollExtentMin,
required this.rect,
required this.label,
required this.labelAttributes,
this.labelAttributes,
required this.hint,
required this.hintAttributes,
this.hintAttributes,
required this.value,
required this.valueAttributes,
this.valueAttributes,
required this.increasedValue,
required this.increasedValueAttributes,
this.increasedValueAttributes,
required this.decreasedValue,
required this.decreasedValueAttributes,
this.tooltip,
this.decreasedValueAttributes,
this.textDirection,
required this.transform,
required this.elevation,
Expand Down Expand Up @@ -143,34 +142,31 @@ class SemanticsNodeUpdate {
final String label;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final List<ui.StringAttribute> labelAttributes;
final List<ui.StringAttribute>? labelAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final String hint;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final List<ui.StringAttribute> hintAttributes;
final List<ui.StringAttribute>? hintAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final String value;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final List<ui.StringAttribute> valueAttributes;
final List<ui.StringAttribute>? valueAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final String increasedValue;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final List<ui.StringAttribute> increasedValueAttributes;
final List<ui.StringAttribute>? increasedValueAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final String decreasedValue;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final List<ui.StringAttribute> decreasedValueAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final String? tooltip;
final List<ui.StringAttribute>? decreasedValueAttributes;

/// See [ui.SemanticsUpdateBuilder.updateNode].
final ui.TextDirection? textDirection;
Expand Down
12 changes: 5 additions & 7 deletions lib/web_ui/lib/src/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,15 @@ class SemanticsUpdateBuilder {
required double thickness,
required Rect rect,
required String label,
required List<StringAttribute> labelAttributes,
List<StringAttribute>? labelAttributes,
required String value,
required List<StringAttribute> valueAttributes,
List<StringAttribute>? valueAttributes,
required String increasedValue,
required List<StringAttribute> increasedValueAttributes,
List<StringAttribute>? increasedValueAttributes,
required String decreasedValue,
required List<StringAttribute> decreasedValueAttributes,
List<StringAttribute>? decreasedValueAttributes,
required String hint,
required List<StringAttribute> hintAttributes,
String? tooltip,
List<StringAttribute>? hintAttributes,
TextDirection? textDirection,
required Float64List transform,
required Int32List childrenInTraversalOrder,
Expand Down Expand Up @@ -391,7 +390,6 @@ class SemanticsUpdateBuilder {
decreasedValueAttributes: decreasedValueAttributes,
hint: hint,
hintAttributes: hintAttributes,
tooltip: tooltip,
textDirection: textDirection,
transform: engine.toMatrix32(transform),
elevation: elevation,
Expand Down
12 changes: 0 additions & 12 deletions lib/web_ui/test/engine/semantics/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1488,16 +1488,10 @@ void updateNode(
double thickness = 0.0,
ui.Rect rect = ui.Rect.zero,
String label = '',
List<ui.StringAttribute> labelAttributes = const <ui.StringAttribute>[],
String hint = '',
List<ui.StringAttribute> hintAttributes = const <ui.StringAttribute>[],
String value = '',
List<ui.StringAttribute> valueAttributes = const <ui.StringAttribute>[],
String increasedValue = '',
List<ui.StringAttribute> increasedValueAttributes = const <ui.StringAttribute>[],
String decreasedValue = '',
List<ui.StringAttribute> decreasedValueAttributes = const <ui.StringAttribute>[],
String tooltip = '',
ui.TextDirection textDirection = ui.TextDirection.ltr,
Float64List? transform,
Int32List? childrenInTraversalOrder,
Expand Down Expand Up @@ -1526,16 +1520,10 @@ void updateNode(
thickness: thickness,
rect: rect,
label: label,
labelAttributes: labelAttributes,
hint: hint,
hintAttributes: hintAttributes,
value: value,
valueAttributes: valueAttributes,
increasedValue: increasedValue,
increasedValueAttributes: increasedValueAttributes,
decreasedValue: decreasedValue,
decreasedValueAttributes: decreasedValueAttributes,
tooltip: tooltip,
textDirection: textDirection,
transform: transform,
childrenInTraversalOrder: childrenInTraversalOrder,
Expand Down
12 changes: 0 additions & 12 deletions lib/web_ui/test/engine/semantics/semantics_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,10 @@ class SemanticsTester {
double? thickness,
ui.Rect? rect,
String? label,
List<ui.StringAttribute>? labelAttributes,
String? hint,
List<ui.StringAttribute>? hintAttributes,
String? value,
List<ui.StringAttribute>? valueAttributes,
String? increasedValue,
List<ui.StringAttribute>? increasedValueAttributes,
String? decreasedValue,
List<ui.StringAttribute>? decreasedValueAttributes,
String? tooltip,
ui.TextDirection? textDirection,
Float64List? transform,
Int32List? additionalActions,
Expand Down Expand Up @@ -312,16 +306,10 @@ class SemanticsTester {
scrollExtentMin: scrollExtentMin ?? 0,
rect: effectiveRect,
label: label ?? '',
labelAttributes: labelAttributes ?? const <ui.StringAttribute>[],
hint: hint ?? '',
hintAttributes: hintAttributes ?? const <ui.StringAttribute>[],
value: value ?? '',
valueAttributes: valueAttributes ?? const <ui.StringAttribute>[],
increasedValue: increasedValue ?? '',
increasedValueAttributes: increasedValueAttributes ?? const <ui.StringAttribute>[],
decreasedValue: decreasedValue ?? '',
decreasedValueAttributes: decreasedValueAttributes ?? const <ui.StringAttribute>[],
tooltip: tooltip ?? '',
transform: transform != null ? toMatrix32(transform) : Matrix4.identity().storage,
elevation: elevation ?? 0,
thickness: thickness ?? 0,
Expand Down
34 changes: 0 additions & 34 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,6 @@ public void onLongPress(int nodeId) {
/** The user has opened a tooltip. */
@Override
public void onTooltip(@NonNull String message) {
// Native Android tooltip is no longer announced when it pops up after API 28 and is
// handled by
// AccessibilityNodeInfo.setTooltipText instead.
//
// To reproduce native behavior, see
// https://developer.android.com/guide/topics/ui/tooltips.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return;
}
AccessibilityEvent e =
obtainAccessibilityEvent(ROOT_NODE_ID, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
e.getText().add(message);
Expand Down Expand Up @@ -829,31 +820,15 @@ && shouldSetCollectionInfo(semanticsNode)) {
result.setLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
}

// Scopes routes are not focusable, only need to set the content
// for non-scopes-routes semantics nodes.
if (semanticsNode.hasFlag(Flag.IS_TEXT_FIELD)) {
result.setText(semanticsNode.getValueLabelHint());
} else if (!semanticsNode.hasFlag(Flag.SCOPES_ROUTE)) {
CharSequence content = semanticsNode.getValueLabelHint();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
if (semanticsNode.tooltip != null) {
// For backward compatibility with Flutter SDK before Android API
// level 28, the tooltip is appended at the end of content description.
content = content != null ? content : "";
content = content + "\n" + semanticsNode.tooltip;
}
}
if (content != null) {
result.setContentDescription(content);
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (semanticsNode.tooltip != null) {
result.setTooltipText(semanticsNode.tooltip);
}
}

boolean hasCheckedState = semanticsNode.hasFlag(Flag.HAS_CHECKED_STATE);
boolean hasToggledState = semanticsNode.hasFlag(Flag.HAS_TOGGLED_STATE);
if (BuildConfig.DEBUG && (hasCheckedState && hasToggledState)) {
Expand Down Expand Up @@ -2213,12 +2188,6 @@ private static boolean nullableHasAncestor(
private String hint;
private List<StringAttribute> hintAttributes;

// The textual description of the backing widget's tooltip.
//
// The tooltip is attached through AccessibilityNodInfo.setTooltipText if
// API level >= 28; otherwise, this is attached to the end of content description.
@Nullable private String tooltip;

// The id of the sibling node that is before this node in traversal
// order.
//
Expand Down Expand Up @@ -2421,9 +2390,6 @@ private void updateWith(

hintAttributes = getStringAttributesFromBuffer(buffer, stringAttributeArgs);

stringIndex = buffer.getInt();
tooltip = stringIndex == -1 ? null : strings[stringIndex];

textDirection = TextDirection.fromInt(buffer.getInt());

left = buffer.getFloat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PlatformViewAndroidDelegate::PlatformViewAndroidDelegate(
void PlatformViewAndroidDelegate::UpdateSemantics(
flutter::SemanticsNodeUpdates update,
flutter::CustomAccessibilityActionUpdates actions) {
constexpr size_t kBytesPerNode = 47 * sizeof(int32_t);
constexpr size_t kBytesPerNode = 46 * sizeof(int32_t);
constexpr size_t kBytesPerChild = sizeof(int32_t);
constexpr size_t kBytesPerCustomAction = sizeof(int32_t);
constexpr size_t kBytesPerAction = 4 * sizeof(int32_t);
Expand Down Expand Up @@ -148,13 +148,6 @@ void PlatformViewAndroidDelegate::UpdateSemantics(
putStringAttributesIntoBuffer(node.hintAttributes, buffer_int32, position,
string_attribute_args);

if (node.tooltip.empty()) {
buffer_int32[position++] = -1;
} else {
buffer_int32[position++] = strings.size();
strings.push_back(node.tooltip);
}

buffer_int32[position++] = node.textDirection;
buffer_float32[position++] = node.rect.left();
buffer_float32[position++] = node.rect.top();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
flutter::SemanticsNode node0;
node0.id = 0;
node0.label = "label";
node0.tooltip = "tooltip";
update.insert(std::make_pair(0, std::move(node0)));

std::vector<uint8_t> expected_buffer(188);
std::vector<uint8_t> expected_buffer(184);
std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
size_t position = 0;
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
Expand Down Expand Up @@ -52,8 +51,6 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
buffer_int32[position++] = -1; // node0.decreasedValueAttributes
buffer_int32[position++] = -1; // node0.hint
buffer_int32[position++] = -1; // node0.hintAttributes
buffer_int32[position++] = expected_strings.size(); // node0.tooltip
expected_strings.push_back(node0.tooltip);
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down Expand Up @@ -96,7 +93,7 @@ TEST(PlatformViewShell,
node0.hintAttributes.push_back(locale_attribute);
update.insert(std::make_pair(0, std::move(node0)));

std::vector<uint8_t> expected_buffer(220);
std::vector<uint8_t> expected_buffer(216);
std::vector<std::vector<uint8_t>> expected_string_attribute_args;
size_t position = 0;
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
Expand Down Expand Up @@ -135,10 +132,9 @@ TEST(PlatformViewShell,
buffer_int32[position++] = 3; // node0.hintAttributes[0].end
buffer_int32[position++] = 1; // node0.hintAttributes[0].type
buffer_int32[position++] =
expected_string_attribute_args.size(); // node0.hintAttributes[0].args
expected_string_attribute_args.size(); // node0.labelAttributes[0].args
expected_string_attribute_args.push_back(
{locale_attribute->locale.begin(), locale_attribute->locale.end()});
buffer_int32[position++] = -1; // node0.tooltip
buffer_int32[position++] = node0.textDirection;
buffer_float32[position++] = node0.rect.left();
buffer_float32[position++] = node0.rect.top();
Expand Down
Loading

0 comments on commit b20c1a3

Please sign in to comment.