Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macOS]Support SemanticsService.announce #40585

Merged
merged 16 commits into from
Mar 30, 2023
Merged

Conversation

hannah-hyj
Copy link
Member

@hannah-hyj hannah-hyj commented Mar 24, 2023

issue:flutter/flutter#99715

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 and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@hannah-hyj hannah-hyj changed the title Support SemanticsService.announce in macos [macOS]Support SemanticsService.announce Mar 24, 2023
@cbracken cbracken self-requested a review March 24, 2023 19:28
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor nits, otherwise looking good!

Comment on lines 999 to 1003
NSAccessibilityPostNotificationWithUserInfo(
[self viewControllerForId:kFlutterDefaultViewId].flutterView,
NSAccessibilityAnnouncementRequestedNotification,
@{NSAccessibilityAnnouncementKey : message, NSAccessibilityPriorityKey : @(priority)});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top-level AppKit API functions are always a bit tricky to test. There are a few tricks you can use for this. A simple one in this case is:

  1. Extract this to a method like:
- (void)announceAccessibilityMessage:(NSString*)withPriority:(NSAccessibilityPrioirityKey);
  1. Use CreateMockFlutterEngine() to create a partial mock in your test.
  2. Verify the method got called in the test:
[[engineMock expect] announceAccessibilityMessage:@"Foo" withPriority:...];

// Fire an event here.

[engineMock verify];

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks!


OCMStub([engineMock announceAccessibilityMessage:[OCMArg any] withPriority:[OCMArg any]])
.andDo((^(NSInvocation* invocation) {
announced = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also double check message and priority?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. You can get these via [invocation getArgument:AtIndex:].

NSString* type = annotatedEvent[@"type"];
if ([type isEqualToString:@"announce"]) {
NSString* message = annotatedEvent[@"data"][@"message"];
NSNumber* assertiveness = annotatedEvent[@"data"][@"assertiveness"];
Copy link
Member

@loic-sharma loic-sharma Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this crash if data, message, or assertiveness properties are missing? A malformed message should be ignored, though an error can be logged.

(Asking as there was a recent crash on Windows embedder due to the framework sending unexpected clipboard messages)

Copy link
Member

@cbracken cbracken Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will result in nil, so the current code handles the cases where any/all of these are missing.

To add a bit of detail:

  • We guard against a nil message below since announcing nil makes no sense.
  • In the case of nil assertiveness we set the default priority; since messages to nil evaluate to nil, the ternary evaluates to NSAccessibilityPriorityMedium.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK perfect! :)

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
) (flutter#123745)

Roll Flutter Engine from 047fc60dd0a9 to 89c1b23cc6cd (1 revision)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants