5#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
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/ios/framework/Source/FlutterViewController_Internal.h"
15#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
19PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
21 : AccessibilityBridgeManager(set_semantics_enabled, nullptr) {}
23PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
25 AccessibilityBridge* bridge)
26 : accessibility_bridge_(bridge), set_semantics_enabled_(set_semantics_enabled) {
28 set_semantics_enabled_(
true);
32void PlatformViewIOS::AccessibilityBridgeManager::Set(std::unique_ptr<AccessibilityBridge> bridge) {
33 accessibility_bridge_ = std::move(bridge);
34 set_semantics_enabled_(
true);
37void PlatformViewIOS::AccessibilityBridgeManager::Clear() {
38 set_semantics_enabled_(
false);
39 accessibility_bridge_.reset();
42PlatformViewIOS::PlatformViewIOS(
44 const std::shared_ptr<IOSContext>& context,
45 const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
48 ios_context_(context),
49 platform_views_controller_(platform_views_controller),
51 platform_message_handler_(
57 const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
59 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
60 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch)
63 delegate.OnPlatformViewGetSettings().enable_impeller
66 is_gpu_disabled_sync_switch),
67 platform_views_controller,
73void PlatformViewIOS::HandlePlatformMessage(std::unique_ptr<flutter::PlatformMessage>
message) {
74 platform_message_handler_->HandlePlatformMessage(std::move(
message));
78 return owner_controller_;
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(
96 object:owner_controller_.get()
97 queue:[NSOperationQueue mainQueue]
98 usingBlock:^(NSNotification* note) {
100 accessibility_bridge_.Clear();
101 owner_controller_.reset();
104 if (owner_controller_ && [owner_controller_.get() isViewLoaded]) {
115 FML_DCHECK(owner_controller_.get().isViewLoaded)
116 <<
"FlutterViewController's view should be loaded "
117 "before attaching to PlatformViewIOS.";
118 auto flutter_view =
static_cast<FlutterView*
>(owner_controller_.get().view);
123 if (accessibility_bridge_) {
124 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
125 owner_controller_.get(),
this, [owner_controller_.get() platformViewsController]));
131 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
136 NSObject<FlutterTexture>*
texture) {
142std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
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(ios_context_->GetMainContext().get());
154std::shared_ptr<ExternalViewEmbedder> PlatformViewIOS::CreateExternalViewEmbedder() {
155 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
160 return ios_context_->CreateResourceContext();
164std::shared_ptr<impeller::Context> PlatformViewIOS::GetImpellerContext()
const {
165 return ios_context_->GetImpellerContext();
170 if (!owner_controller_) {
171 FML_LOG(WARNING) <<
"Could not set semantics to enabled, this "
172 "PlatformViewIOS has no ViewController.";
175 if (enabled && !accessibility_bridge_) {
176 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
177 owner_controller_.get(),
this, [owner_controller_.get() platformViewsController]));
178 }
else if (!enabled && accessibility_bridge_) {
179 accessibility_bridge_.Clear();
186void PlatformViewIOS::SetAccessibilityFeatures(int32_t
flags) {
194 if (accessibility_bridge_) {
195 accessibility_bridge_.get()->UpdateSemantics(std::move(
update), actions);
197 object:owner_controller_.get()];
202std::unique_ptr<VsyncWaiter> PlatformViewIOS::CreateVSyncWaiter() {
206void PlatformViewIOS::OnPreEngineRestart()
const {
207 if (accessibility_bridge_) {
208 accessibility_bridge_.get()->clearState();
210 if (!owner_controller_) {
213 [owner_controller_.get() platformViewsController]->Reset();
214 [[owner_controller_.get() restorationPlugin]
reset];
217std::unique_ptr<std::vector<std::string>> PlatformViewIOS::ComputePlatformResolvedLocales(
218 const std::vector<std::string>& supported_locale_data) {
219 size_t localeDataLength = 3;
220 NSMutableArray<NSString*>* supported_locale_identifiers =
221 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
222 for (
size_t i = 0;
i < supported_locale_data.size();
i += localeDataLength) {
223 NSDictionary<NSString*, NSString*>* dict = @{
224 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[
i].c_str()]
226 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[
i + 1].c_str()]
228 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[
i + 2].c_str()]
231 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
233 NSArray<NSString*>*
result =
234 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
237 std::unique_ptr<std::vector<std::string>>
out = std::make_unique<std::vector<std::string>>();
240 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[
result firstObject]];
241 NSString* languageCode = [locale languageCode];
242 out->emplace_back(languageCode ==
nullptr ?
"" : languageCode.UTF8String);
243 NSString* countryCode = [locale countryCode];
244 out->emplace_back(countryCode ==
nullptr ?
"" : countryCode.UTF8String);
245 NSString* scriptCode = [locale scriptCode];
246 out->emplace_back(scriptCode ==
nullptr ?
"" : scriptCode.UTF8String);
251PlatformViewIOS::ScopedObserver::ScopedObserver() {}
253PlatformViewIOS::ScopedObserver::~ScopedObserver() {
255 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
261 if (observer != observer_) {
263 [[NSNotificationCenter defaultCenter] removeObserver:observer_];
266 observer_ = observer;
static sk_sp< Effect > Create()
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, const fml::scoped_nsobject< CALayer > &layer)
The interface for Engine to implement.
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
virtual bool RunsTasksOnCurrentThread()
FlutterSemanticsFlag flags
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_DCHECK(condition)
Dart_NativeFunction function
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.