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"
22 PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
23 const std::function<
void(
bool)>& set_semantics_enabled)
24 : AccessibilityBridgeManager(set_semantics_enabled, nullptr) {}
26 PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
27 const std::function<
void(
bool)>& set_semantics_enabled,
28 AccessibilityBridge* bridge)
29 : accessibility_bridge_(bridge), set_semantics_enabled_(set_semantics_enabled) {
31 set_semantics_enabled_(
true);
35 void PlatformViewIOS::AccessibilityBridgeManager::Set(std::unique_ptr<AccessibilityBridge> bridge) {
36 accessibility_bridge_ = std::move(bridge);
37 set_semantics_enabled_(
true);
40 void PlatformViewIOS::AccessibilityBridgeManager::Clear() {
41 set_semantics_enabled_(
false);
42 accessibility_bridge_.reset();
45 PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate,
46 const std::shared_ptr<IOSContext>& context,
48 const flutter::TaskRunners& task_runners)
49 : PlatformView(delegate, task_runners),
50 ios_context_(context),
51 platform_views_controller_(platform_views_controller),
52 accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }),
53 platform_message_handler_(
57 PlatformView::Delegate& delegate,
60 const flutter::TaskRunners& task_runners,
61 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
62 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
65 delegate.OnPlatformViewGetSettings().enable_impeller
68 is_gpu_disabled_sync_switch,
69 delegate.OnPlatformViewGetSettings()),
70 platform_views_controller,
77 platform_message_handler_->HandlePlatformMessage(std::move(message));
81 return owner_controller_;
85 FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
86 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
87 if (ios_surface_ || !owner_controller) {
90 accessibility_bridge_.Clear();
92 owner_controller_ = owner_controller;
96 dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
98 object:owner_controller_
99 queue:[NSOperationQueue mainQueue]
100 usingBlock:^(NSNotification* note) {
102 accessibility_bridge_.Clear();
103 owner_controller_ = nil;
106 if (owner_controller_ && owner_controller_.isViewLoaded) {
116 FML_DCHECK(owner_controller_);
117 FML_DCHECK(owner_controller_.isViewLoaded) <<
"FlutterViewController's view should be loaded "
118 "before attaching to PlatformViewIOS.";
120 CALayer* ca_layer = flutter_view.layer;
122 FML_DCHECK(ios_surface_ !=
nullptr);
124 if (accessibility_bridge_) {
125 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
126 owner_controller_,
this, owner_controller_.platformViewsController));
131 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
132 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
137 NSObject<FlutterTexture>* texture) {
138 RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, texture));
143 FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
144 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
146 FML_DLOG(INFO) <<
"Could not CreateRenderingSurface, this PlatformViewIOS "
147 "has no ViewController.";
150 return ios_surface_->CreateGPUSurface();
155 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
160 return ios_context_->GetImpellerContext();
165 if (!owner_controller_) {
166 [FlutterLogger logWarning:
@"Could not set semantics to enabled, this PlatformViewIOS has no "
170 if (enabled && !accessibility_bridge_) {
171 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
172 owner_controller_,
this, owner_controller_.platformViewsController));
173 }
else if (!enabled && accessibility_bridge_) {
174 accessibility_bridge_.Clear();
176 PlatformView::SetSemanticsEnabled(enabled);
182 PlatformView::SetAccessibilityFeatures(flags);
187 flutter::SemanticsNodeUpdates update,
188 flutter::CustomAccessibilityActionUpdates actions) {
189 FML_DCHECK(owner_controller_);
190 if (accessibility_bridge_) {
191 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
193 object:owner_controller_];
199 return std::make_unique<VsyncWaiterIOS>(task_runners_);
203 if (accessibility_bridge_) {
204 accessibility_bridge_.get()->clearState();
206 if (!owner_controller_) {
209 [owner_controller_.platformViewsController reset];
210 [owner_controller_.restorationPlugin reset];
211 [owner_controller_.textInputPlugin reset];
215 const std::vector<std::string>& supported_locale_data) {
216 size_t localeDataLength = 3;
217 NSMutableArray<NSString*>* supported_locale_identifiers =
218 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
219 for (
size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
220 NSDictionary<NSString*, NSString*>* dict = @{
221 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
223 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
225 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
228 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
230 NSArray<NSString*>* result =
231 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
234 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
236 if (result !=
nullptr && [result count] > 0) {
237 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
238 NSString* languageCode = [locale languageCode];
239 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
240 NSString* countryCode = [locale countryCode];
241 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
242 NSString* scriptCode = [locale scriptCode];
243 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
248 PlatformViewIOS::ScopedObserver::ScopedObserver() {}
250 PlatformViewIOS::ScopedObserver::~ScopedObserver() {
252 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
256 void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
257 if (observer != observer_) {
259 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
261 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)