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();
44 PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate,
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 delegate.OnPlatformViewGetSettings()),
69 platform_views_controller,
76 platform_message_handler_->HandlePlatformMessage(std::move(message));
80 return owner_controller_;
84 FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
85 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
86 if (ios_surface_ || !owner_controller) {
89 accessibility_bridge_.Clear();
91 owner_controller_ = owner_controller;
95 dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
97 object:owner_controller_
98 queue:[NSOperationQueue mainQueue]
99 usingBlock:^(NSNotification* note) {
101 accessibility_bridge_.Clear();
102 owner_controller_ = nil;
105 if (owner_controller_ && owner_controller_.isViewLoaded) {
115 FML_DCHECK(owner_controller_);
116 FML_DCHECK(owner_controller_.isViewLoaded) <<
"FlutterViewController's view should be loaded "
117 "before attaching to PlatformViewIOS.";
119 CALayer* ca_layer = flutter_view.layer;
121 FML_DCHECK(ios_surface_ !=
nullptr);
123 if (accessibility_bridge_) {
124 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
125 owner_controller_,
this, owner_controller_.platformViewsController));
130 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
131 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
136 NSObject<FlutterTexture>* texture) {
137 RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, texture));
142 FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
143 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
145 FML_DLOG(INFO) <<
"Could not CreateRenderingSurface, this PlatformViewIOS "
146 "has no ViewController.";
149 return ios_surface_->CreateGPUSurface();
154 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
159 return ios_context_->GetImpellerContext();
164 if (!owner_controller_) {
165 FML_LOG(WARNING) <<
"Could not set semantics to enabled, this "
166 "PlatformViewIOS has no ViewController.";
169 if (enabled && !accessibility_bridge_) {
170 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
171 owner_controller_,
this, owner_controller_.platformViewsController));
172 }
else if (!enabled && accessibility_bridge_) {
173 accessibility_bridge_.Clear();
175 PlatformView::SetSemanticsEnabled(enabled);
181 PlatformView::SetAccessibilityFeatures(flags);
186 flutter::SemanticsNodeUpdates update,
187 flutter::CustomAccessibilityActionUpdates actions) {
188 FML_DCHECK(owner_controller_);
189 if (accessibility_bridge_) {
190 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
192 object:owner_controller_];
198 return std::make_unique<VsyncWaiterIOS>(task_runners_);
202 if (accessibility_bridge_) {
203 accessibility_bridge_.get()->clearState();
205 if (!owner_controller_) {
208 [owner_controller_.platformViewsController reset];
209 [owner_controller_.restorationPlugin reset];
213 const std::vector<std::string>& supported_locale_data) {
214 size_t localeDataLength = 3;
215 NSMutableArray<NSString*>* supported_locale_identifiers =
216 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
217 for (
size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
218 NSDictionary<NSString*, NSString*>* dict = @{
219 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
221 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
223 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
226 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
228 NSArray<NSString*>* result =
229 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
232 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
234 if (result !=
nullptr && [result count] > 0) {
235 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
236 NSString* languageCode = [locale languageCode];
237 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
238 NSString* countryCode = [locale countryCode];
239 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
240 NSString* scriptCode = [locale scriptCode];
241 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
246 PlatformViewIOS::ScopedObserver::ScopedObserver() {}
248 PlatformViewIOS::ScopedObserver::~ScopedObserver() {
250 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
254 void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
255 if (observer != observer_) {
257 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
259 observer_ = observer;
FLUTTER_DARWIN_EXPORT NSNotificationName const FlutterSemanticsUpdateNotification
NSNotificationName const FlutterViewControllerWillDealloc
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, CALayer *layer)