10 #include "flutter/common/task_runners.h"
11 #include "flutter/fml/synchronization/waitable_event.h"
12 #include "flutter/fml/trace_event.h"
13 #include "flutter/shell/common/shell_io_manager.h"
21 PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
22 const std::function<
void(
bool)>& set_semantics_enabled)
23 : AccessibilityBridgeManager(set_semantics_enabled, nullptr) {}
25 PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
26 const std::function<
void(
bool)>& set_semantics_enabled,
27 AccessibilityBridge* bridge)
28 : accessibility_bridge_(bridge), set_semantics_enabled_(set_semantics_enabled) {
30 set_semantics_enabled_(
true);
34 void PlatformViewIOS::AccessibilityBridgeManager::Set(std::unique_ptr<AccessibilityBridge> bridge) {
35 accessibility_bridge_ = std::move(bridge);
36 set_semantics_enabled_(
true);
39 void PlatformViewIOS::AccessibilityBridgeManager::Clear() {
40 set_semantics_enabled_(
false);
41 accessibility_bridge_.reset();
45 const std::shared_ptr<IOSContext>& context,
47 const flutter::TaskRunners& task_runners)
48 : PlatformView(delegate, task_runners),
49 ios_context_(context),
50 platform_views_controller_(platform_views_controller),
51 accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }),
52 platform_message_handler_(
56 PlatformView::Delegate& delegate,
59 const flutter::TaskRunners& task_runners,
60 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
61 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
64 delegate.OnPlatformViewGetSettings().enable_impeller
67 is_gpu_disabled_sync_switch),
68 platform_views_controller,
75 platform_message_handler_->HandlePlatformMessage(std::move(message));
79 return owner_controller_;
83 FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
84 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
85 if (ios_surface_ || !owner_controller) {
88 accessibility_bridge_.Clear();
90 owner_controller_ = owner_controller;
94 dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
96 object:owner_controller_
97 queue:[NSOperationQueue mainQueue]
98 usingBlock:^(NSNotification* note) {
100 accessibility_bridge_.Clear();
101 owner_controller_ = nil;
104 if (owner_controller_ && owner_controller_.isViewLoaded) {
114 FML_DCHECK(owner_controller_);
115 FML_DCHECK(owner_controller_.isViewLoaded) <<
"FlutterViewController's view should be loaded "
116 "before attaching to PlatformViewIOS.";
118 CALayer* ca_layer = flutter_view.layer;
120 FML_DCHECK(ios_surface_ !=
nullptr);
122 if (accessibility_bridge_) {
123 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
124 owner_controller_,
this, owner_controller_.platformViewsController));
129 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
130 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
135 NSObject<FlutterTexture>* texture) {
136 RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, texture));
141 FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
142 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
144 FML_DLOG(INFO) <<
"Could not CreateRenderingSurface, this PlatformViewIOS "
145 "has no ViewController.";
148 return ios_surface_->CreateGPUSurface();
153 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
158 return ios_context_->GetImpellerContext();
163 if (!owner_controller_) {
164 FML_LOG(WARNING) <<
"Could not set semantics to enabled, this "
165 "PlatformViewIOS has no ViewController.";
168 if (enabled && !accessibility_bridge_) {
169 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
170 owner_controller_,
this, owner_controller_.platformViewsController));
171 }
else if (!enabled && accessibility_bridge_) {
172 accessibility_bridge_.Clear();
174 PlatformView::SetSemanticsEnabled(enabled);
180 PlatformView::SetAccessibilityFeatures(flags);
185 flutter::CustomAccessibilityActionUpdates actions) {
186 FML_DCHECK(owner_controller_);
187 if (accessibility_bridge_) {
188 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
190 object:owner_controller_];
196 return std::make_unique<VsyncWaiterIOS>(task_runners_);
200 if (accessibility_bridge_) {
201 accessibility_bridge_.get()->clearState();
203 if (!owner_controller_) {
206 [owner_controller_.platformViewsController reset];
207 [owner_controller_.restorationPlugin reset];
211 const std::vector<std::string>& supported_locale_data) {
212 size_t localeDataLength = 3;
213 NSMutableArray<NSString*>* supported_locale_identifiers =
214 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
215 for (
size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
216 NSDictionary<NSString*, NSString*>* dict = @{
217 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
219 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
221 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
224 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
226 NSArray<NSString*>* result =
227 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
230 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
232 if (result !=
nullptr && [result count] > 0) {
233 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
234 NSString* languageCode = [locale languageCode];
235 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
236 NSString* countryCode = [locale countryCode];
237 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
238 NSString* scriptCode = [locale scriptCode];
239 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
244 PlatformViewIOS::ScopedObserver::ScopedObserver() {}
246 PlatformViewIOS::ScopedObserver::~ScopedObserver() {
248 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
252 void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
253 if (observer != observer_) {
255 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
257 observer_ = observer;