A11y callback (flutter/engine#8005)
* implement callback for a11y readiness * use FlutterSemanticsUpdateNotification from header, move to VC header
This commit is contained in:
@@ -133,6 +133,26 @@ FLUTTER_EXPORT
|
|||||||
*/
|
*/
|
||||||
- (void)destroyContext;
|
- (void)destroyContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that Flutter will generate a semantics tree.
|
||||||
|
*
|
||||||
|
* This is enabled by default if certain accessibility services are turned on by
|
||||||
|
* the user, or when using a Simulator. This method allows a user to turn
|
||||||
|
* semantics on when they would not ordinarily be generated and the performance
|
||||||
|
* overhead is not a concern, e.g. for UI testing. Note that semantics should
|
||||||
|
* never be programatically turned off, as it would potentially disable
|
||||||
|
* accessibility services an end user has requested.
|
||||||
|
*
|
||||||
|
* This method must only be called after launching the engine via
|
||||||
|
* `-runWithEntrypoint:` or `-runWithEntryPoint:libraryURI`.
|
||||||
|
*
|
||||||
|
* You can subscribe to semantics updates via `NSNotificationCenter` by adding
|
||||||
|
* an observer for the name `FlutterSemanticsUpdateNotification`. The `object`
|
||||||
|
* parameter will be the `FlutterViewController` associated with the semantics
|
||||||
|
* update.
|
||||||
|
*/
|
||||||
|
- (void)ensureSemanticsEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the `FlutterViewController` for this instance. The FlutterEngine must be
|
* Sets the `FlutterViewController` for this instance. The FlutterEngine must be
|
||||||
* running (e.g. a successful call to `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI`)
|
* running (e.g. a successful call to `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI`)
|
||||||
|
|||||||
@@ -17,6 +17,14 @@
|
|||||||
|
|
||||||
@class FlutterEngine;
|
@class FlutterEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name used for semantic update nofications via `NSNotificationCenter`.
|
||||||
|
*
|
||||||
|
* The object passed as the sender is the `FlutterViewController` associated
|
||||||
|
* with the update.
|
||||||
|
*/
|
||||||
|
const NSNotificationName FlutterSemanticsUpdateNotification = @"FlutterSemanticsUpdate";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `UIViewController` implementation for Flutter views.
|
* A `UIViewController` implementation for Flutter views.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -146,6 +146,10 @@
|
|||||||
return _shell->GetTaskRunners().GetPlatformTaskRunner();
|
return _shell->GetTaskRunners().GetPlatformTaskRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)ensureSemanticsEnabled {
|
||||||
|
self.iosPlatformView->SetSemanticsEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setViewController:(FlutterViewController*)viewController {
|
- (void)setViewController:(FlutterViewController*)viewController {
|
||||||
FML_DCHECK(self.iosPlatformView);
|
FML_DCHECK(self.iosPlatformView);
|
||||||
_viewController = [viewController getWeakPtr];
|
_viewController = [viewController getWeakPtr];
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class PlatformViewIOS final : public PlatformView {
|
|||||||
|
|
||||||
void SetTextInputPlugin(fml::scoped_nsprotocol<FlutterTextInputPlugin*> plugin);
|
void SetTextInputPlugin(fml::scoped_nsprotocol<FlutterTextInputPlugin*> plugin);
|
||||||
|
|
||||||
|
// |shell::PlatformView|
|
||||||
|
void SetSemanticsEnabled(bool enabled) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
fml::WeakPtr<FlutterViewController> owner_controller_;
|
fml::WeakPtr<FlutterViewController> owner_controller_;
|
||||||
std::unique_ptr<IOSSurface> ios_surface_;
|
std::unique_ptr<IOSSurface> ios_surface_;
|
||||||
@@ -57,9 +60,6 @@ class PlatformViewIOS final : public PlatformView {
|
|||||||
// |shell::PlatformView|
|
// |shell::PlatformView|
|
||||||
sk_sp<GrContext> CreateResourceContext() const override;
|
sk_sp<GrContext> CreateResourceContext() const override;
|
||||||
|
|
||||||
// |shell::PlatformView|
|
|
||||||
void SetSemanticsEnabled(bool enabled) override;
|
|
||||||
|
|
||||||
// |shell::PlatformView|
|
// |shell::PlatformView|
|
||||||
void SetAccessibilityFeatures(int32_t flags) override;
|
void SetAccessibilityFeatures(int32_t flags) override;
|
||||||
|
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ sk_sp<GrContext> PlatformViewIOS::CreateResourceContext() const {
|
|||||||
// |shell::PlatformView|
|
// |shell::PlatformView|
|
||||||
void PlatformViewIOS::SetSemanticsEnabled(bool enabled) {
|
void PlatformViewIOS::SetSemanticsEnabled(bool enabled) {
|
||||||
if (!owner_controller_) {
|
if (!owner_controller_) {
|
||||||
FML_DLOG(WARNING) << "Could not set semantics to enabled, this "
|
FML_LOG(WARNING) << "Could not set semantics to enabled, this "
|
||||||
"PlatformViewIOS has no ViewController.";
|
"PlatformViewIOS has no ViewController.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (enabled && !accessibility_bridge_) {
|
if (enabled && !accessibility_bridge_) {
|
||||||
@@ -111,8 +111,11 @@ void PlatformViewIOS::SetAccessibilityFeatures(int32_t flags) {
|
|||||||
// |shell::PlatformView|
|
// |shell::PlatformView|
|
||||||
void PlatformViewIOS::UpdateSemantics(blink::SemanticsNodeUpdates update,
|
void PlatformViewIOS::UpdateSemantics(blink::SemanticsNodeUpdates update,
|
||||||
blink::CustomAccessibilityActionUpdates actions) {
|
blink::CustomAccessibilityActionUpdates actions) {
|
||||||
|
FML_DCHECK(owner_controller_);
|
||||||
if (accessibility_bridge_) {
|
if (accessibility_bridge_) {
|
||||||
accessibility_bridge_->UpdateSemantics(std::move(update), std::move(actions));
|
accessibility_bridge_->UpdateSemantics(std::move(update), std::move(actions));
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
|
||||||
|
object:owner_controller_.get()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user