14#import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
15#import "flutter/shell/platform/darwin/ios/InternalFlutterSwift/InternalFlutterSwift.h"
24 const std::shared_ptr<IOSContext>&
context,
29 platform_views_controller_(platform_views_controller),
30 platform_message_handler_(
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_;
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) {
94 FML_DCHECK(owner_controller_.isViewLoaded) <<
"FlutterViewController's view should be loaded "
95 "before attaching to PlatformViewIOS.";
97 CALayer* ca_layer = flutter_view.layer;
101 if (accessibility_bridge_) {
102 accessibility_bridge_ = std::make_unique<AccessibilityBridge>(
103 owner_controller_,
this, owner_controller_.platformViewsController);
109 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
114 NSObject<FlutterTexture>*
texture) {
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();
145 if (accessibility_bridge_) {
146 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
148 object:owner_controller_];
154 application_locale_ = std::move(locale);
155 ApplyLocaleToOwnerController();
162 if (accessibility_bridge_) {
165 accessibility_bridge_ =
166 std::make_unique<AccessibilityBridge>(owner_controller_,
this, platform_views_controller_);
168 accessibility_bridge_.reset();
174 return std::make_unique<VsyncWaiterIOS>(
task_runners_, FlutterDisplayLinkManager.shared);
179 if (accessibility_bridge_) {
180 accessibility_bridge_.get()->clearState();
182 if (!owner_controller_) {
185 [owner_controller_.platformViewsController reset];
186 [owner_controller_.restorationPlugin reset];
187 [owner_controller_.textInputPlugin reset];
192 const std::vector<std::string>& supported_locale_data) {
193 size_t localeDataLength = 3;
194 NSMutableArray<NSString*>* supported_locale_identifiers =
195 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
196 for (
size_t i = 0;
i < supported_locale_data.size();
i += localeDataLength) {
197 NSDictionary<NSString*, NSString*>* dict = @{
198 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[
i].c_str()]
200 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[
i + 1].c_str()]
202 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[
i + 2].c_str()]
205 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
207 NSArray<NSString*>* result =
208 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
211 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
213 if (result !=
nullptr && [result count] > 0) {
214 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
215 NSString* languageCode = [locale languageCode];
216 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
217 NSString* countryCode = [locale countryCode];
218 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
219 NSString* scriptCode = [locale scriptCode];
220 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
225void PlatformViewIOS::ApplyLocaleToOwnerController() {
226 if (owner_controller_) {
227 owner_controller_.applicationLocale =
228 application_locale_.empty() ? nil : @(application_locale_.data());
232PlatformViewIOS::ScopedObserver::ScopedObserver() {}
234PlatformViewIOS::ScopedObserver::~ScopedObserver() {
236 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
240void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
241 if (observer != observer_) {
243 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
245 observer_ = observer;
FlutterView * view() const
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)
The interface for Engine to implement.
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
virtual bool RunsTasksOnCurrentThread()
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DLOG(severity)
#define FML_DCHECK(condition)
NSNotificationName const FlutterViewControllerWillDealloc
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
std::shared_ptr< ContextGLES > context