提交 0d2c049f 编写于 作者: A Adam Barth 提交者: GitHub

Conditionally enable accessibility (#2785)

Previously we enabled accessibility unconditionally on iOS, which is more
expensive than necessary. We still enable it unconditionally on the simulator
because there's no API for determining whether accessibility is needed on the
simulator.
上级 304881d6
......@@ -5,14 +5,10 @@
#ifndef SKY_SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTER_VIEW_H_
#define SKY_SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTER_VIEW_H_
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include <UIKit/UIKit.h>
@interface FlutterView : UIView
- (void)withAccessibility:(mojo::ServiceProvider*)serviceProvider;
@end
#endif // SKY_SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTER_VIEW_H_
......@@ -4,20 +4,11 @@
#include "sky/shell/platform/ios/framework/Source/FlutterView.h"
#include "base/memory/weak_ptr.h"
#include "sky/shell/platform/ios/framework/Source/accessibility_bridge.h"
@interface FlutterView ()<UIInputViewAudioFeedback>
@end
@implementation FlutterView {
std::unique_ptr<sky::shell::AccessibilityBridge> _accessibilityBridge;
}
- (void)withAccessibility:(mojo::ServiceProvider*)serviceProvider {
_accessibilityBridge.reset(new sky::shell::AccessibilityBridge(self, serviceProvider));
}
@implementation FlutterView
- (void)layoutSubviews {
CGFloat screenScale = [UIScreen mainScreen].scale;
......
......@@ -18,6 +18,7 @@
#include "sky/services/platform/app_messages.mojom.h"
#include "sky/services/platform/ios/system_chrome_impl.h"
#include "sky/services/semantics/semantics.mojom.h"
#include "sky/shell/platform/ios/framework/Source/accessibility_bridge.h"
#include "sky/shell/platform/ios/framework/Source/application_messages_impl.h"
#include "sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h"
#include "sky/shell/platform/ios/framework/Source/FlutterDartProject_Internal.h"
......@@ -50,6 +51,7 @@ void FlutterInit(int argc, const char* argv[]) {
std::unique_ptr<sky::shell::ShellView> _shellView;
sky::SkyEnginePtr _engine;
mojo::ServiceProviderPtr _dartServices;
std::unique_ptr<sky::shell::AccessibilityBridge> _accessibilityBridge;
flutter::platform::ApplicationMessagesPtr _appMessageSender;
sky::shell::ApplicationMessagesImpl _appMessageReceiver;
BOOL _initialized;
......@@ -147,6 +149,11 @@ void FlutterInit(int argc, const char* argv[]) {
selector:@selector(onLocaleUpdated:)
name:NSCurrentLocaleDidChangeNotification
object:nil];
[center addObserver:self
selector:@selector(onVoiceOverChanged:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
}
#pragma mark - Initializing the engine
......@@ -226,13 +233,14 @@ static void DynamicServiceResolve(void* baton,
- (void)loadView {
FlutterView* surface = [[FlutterView alloc] init];
[surface withAccessibility:_dartServices.get()];
self.view = surface;
self.view.multipleTouchEnabled = YES;
self.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self onVoiceOverChanged:nil];
[surface release];
}
......@@ -420,6 +428,27 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
return _orientationPreferences;
}
#pragma mark - Accessibility
- (void)onVoiceOverChanged:(NSNotification*)notification {
#if TARGET_OS_SIMULATOR
// There doesn't appear to be any way to determine whether the accessibility
// inspector is enabled on the simulator. We conservatively always turn on the
// accessibility bridge in the simulator.
bool enable = true;
#else
bool enable = UIAccessibilityIsVoiceOverRunning();
#endif
if (enable) {
if (!_accessibilityBridge) {
_accessibilityBridge.reset(
new sky::shell::AccessibilityBridge(self.view, _dartServices.get()));
}
} else {
_accessibilityBridge = nullptr;
}
}
#pragma mark - Locale updates
- (void)onLocaleUpdated:(NSNotification*)notification {
......
......@@ -49,12 +49,12 @@ namespace shell {
class AccessibilityBridge final : public semantics::SemanticsListener {
public:
AccessibilityBridge(FlutterView*, mojo::ServiceProvider*);
AccessibilityBridge(UIView*, mojo::ServiceProvider*);
~AccessibilityBridge() override;
void UpdateSemanticsTree(mojo::Array<semantics::SemanticsNodePtr>) override;
FlutterView* view() { return view_; }
UIView* view() { return view_; }
semantics::SemanticsServer* server() { return semantics_server_.get(); }
private:
......@@ -65,7 +65,7 @@ class AccessibilityBridge final : public semantics::SemanticsListener {
void RemoveSemanticObject(SemanticObject* node,
std::set<SemanticObject*>* updated_objects);
FlutterView* view_;
UIView* view_;
semantics::SemanticsServerPtr semantics_server_;
std::unordered_map<int, SemanticObject*> objects_;
......
......@@ -283,7 +283,7 @@ struct Geometry {
namespace sky {
namespace shell {
AccessibilityBridge::AccessibilityBridge(FlutterView* view,
AccessibilityBridge::AccessibilityBridge(UIView* view,
mojo::ServiceProvider* serviceProvider)
: view_(view), binding_(this) {
mojo::ConnectToService(serviceProvider, mojo::GetProxy(&semantics_server_));
......@@ -302,6 +302,7 @@ AccessibilityBridge::~AccessibilityBridge() {
void AccessibilityBridge::UpdateSemanticsTree(
mojo::Array<semantics::SemanticsNodePtr> nodes) {
LOG(INFO) << "UpdateSemanticsTree";
std::set<SemanticObject*> updated_objects;
std::set<SemanticObject*> removed_objects;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册