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"
14 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
23 const std::shared_ptr<IOSContext>& context,
25 const flutter::TaskRunners& task_runners)
26 : PlatformView(delegate, task_runners),
27 ios_context_(context),
28 platform_views_controller_(platform_views_controller),
29 platform_message_handler_(
33 PlatformView::Delegate& delegate,
36 const flutter::TaskRunners& task_runners,
37 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
38 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
41 delegate.OnPlatformViewGetSettings().enable_impeller
44 is_gpu_disabled_sync_switch,
45 delegate.OnPlatformViewGetSettings()),
46 platform_views_controller,
53 platform_message_handler_->HandlePlatformMessage(std::move(message));
57 return owner_controller_;
61 FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
62 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
63 if (ios_surface_ || !owner_controller) {
66 accessibility_bridge_.reset();
68 owner_controller_ = owner_controller;
69 ApplyLocaleToOwnerController();
73 dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
75 object:owner_controller_
76 queue:[NSOperationQueue mainQueue]
77 usingBlock:^(NSNotification* note) {
79 accessibility_bridge_.reset();
80 owner_controller_ = nil;
83 if (owner_controller_ && owner_controller_.isViewLoaded) {
93 FML_DCHECK(owner_controller_);
94 FML_DCHECK(owner_controller_.isViewLoaded) <<
"FlutterViewController's view should be loaded "
95 "before attaching to PlatformViewIOS.";
97 CALayer* ca_layer = flutter_view.layer;
99 FML_DCHECK(ios_surface_ !=
nullptr);
101 if (accessibility_bridge_) {
102 accessibility_bridge_ = std::make_unique<AccessibilityBridge>(
103 owner_controller_,
this, owner_controller_.platformViewsController);
108 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
109 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
114 NSObject<FlutterTexture>* texture) {
115 RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, texture));
120 FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
121 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
123 FML_DLOG(INFO) <<
"Could not CreateRenderingSurface, this PlatformViewIOS "
124 "has no ViewController.";
127 return ios_surface_->CreateGPUSurface();
132 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
137 return ios_context_->GetImpellerContext();
142 PlatformView::SetSemanticsEnabled(enabled);
147 PlatformView::SetAccessibilityFeatures(flags);
152 flutter::SemanticsNodeUpdates update,
153 flutter::CustomAccessibilityActionUpdates actions) {
154 FML_DCHECK(owner_controller_);
155 FML_DCHECK(accessibility_bridge_);
156 if (accessibility_bridge_) {
157 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
159 object:owner_controller_];
165 application_locale_ = std::move(locale);
166 ApplyLocaleToOwnerController();
171 FML_DCHECK(owner_controller_);
173 if (accessibility_bridge_) {
176 accessibility_bridge_ =
177 std::make_unique<AccessibilityBridge>(owner_controller_,
this, platform_views_controller_);
179 accessibility_bridge_.reset();
185 return std::make_unique<VsyncWaiterIOS>(task_runners_);
190 if (accessibility_bridge_) {
191 accessibility_bridge_.get()->clearState();
193 if (!owner_controller_) {
196 [owner_controller_.platformViewsController reset];
197 [owner_controller_.restorationPlugin reset];
198 [owner_controller_.textInputPlugin reset];
203 const std::vector<std::string>& supported_locale_data) {
204 size_t localeDataLength = 3;
205 NSMutableArray<NSString*>* supported_locale_identifiers =
206 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
207 for (
size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
208 NSDictionary<NSString*, NSString*>* dict = @{
209 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
211 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
213 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
216 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
218 NSArray<NSString*>* result =
219 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
222 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
224 if (result !=
nullptr && [result count] > 0) {
225 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
226 NSString* languageCode = [locale languageCode];
227 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
228 NSString* countryCode = [locale countryCode];
229 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
230 NSString* scriptCode = [locale scriptCode];
231 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
236 void PlatformViewIOS::ApplyLocaleToOwnerController() {
237 if (owner_controller_) {
238 owner_controller_.applicationLocale =
239 application_locale_.empty() ? nil : @(application_locale_.data());
243 PlatformViewIOS::ScopedObserver::ScopedObserver() {}
245 PlatformViewIOS::ScopedObserver::~ScopedObserver() {
247 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
251 void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
252 if (observer != observer_) {
254 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
256 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)