Introduce platform services interface

This commit is contained in:
2026-06-03 03:59:59 +02:00
parent 6960bd3410
commit 4ed72ebc80
10 changed files with 259 additions and 38 deletions

View File

@@ -2,6 +2,7 @@
#include "app.h"
#include "app_core/document_platform_io.h"
#include "app_core/document_sharing.h"
#include "platform_api/platform_services.h"
#include "renderer_gl/opengl_capabilities.h"
namespace {
@@ -60,21 +61,84 @@ void webgl_pick_file_save(const std::string& path,
void webgl_sync();
#endif
namespace {
class LegacyPlatformServices final : public pp::platform::PlatformServices {
public:
[[nodiscard]] std::string clipboard_text() override
{
#if _WIN32
return win32_clipboard_get_text();
#elif __IOS__
return [App::I->ios_view clipboard_get_string];
#elif __OSX__
return [App::I->osx_view clipboard_get_string];
#elif __ANDROID__
return android_get_clipboard();
#else
return {};
#endif
}
[[nodiscard]] bool set_clipboard_text(std::string_view text) override
{
const std::string value(text);
#if _WIN32
return win32_clipboard_set_text(value);
#elif __IOS__
return [App::I->ios_view clipboard_set_string:value];
#elif __OSX__
return [App::I->osx_view clipboard_set_string:value];
#elif __ANDROID__
return android_set_clipboard(value);
#else
return false;
#endif
}
void set_cursor_visible(bool visible) override
{
#ifdef _WIN32
win32_show_cursor(visible);
#elif __OSX__
[App::I->osx_view show_cursor:visible];
#else
(void)visible;
#endif
}
void set_virtual_keyboard_visible(bool visible) override
{
#ifdef __IOS__
dispatch_async(dispatch_get_main_queue(), ^{
if (visible)
[App::I->ios_view show_keyboard];
else
[App::I->ios_view hide_keyboard];
});
#elif __ANDROID__
displayKeyboard(visible);
#else
(void)visible;
#endif
}
};
[[nodiscard]] pp::platform::PlatformServices& legacy_platform_services()
{
static LegacyPlatformServices services;
return services;
}
}
std::string App::clipboard_get_text()
{
if (pp::app::plan_clipboard_read() != pp::app::ClipboardReadAction::read_text)
return {};
#if _WIN32
return win32_clipboard_get_text();
#elif __IOS__
return [ios_view clipboard_get_string];
#elif __OSX__
return [osx_view clipboard_get_string];
#elif __ANDROID__
return android_get_clipboard();
#endif
return legacy_platform_services().clipboard_text();
}
bool App::clipboard_set_text(const std::string& s)
@@ -82,15 +146,7 @@ bool App::clipboard_set_text(const std::string& s)
if (pp::app::plan_clipboard_write(s) != pp::app::ClipboardWriteAction::write_text)
return false;
#if _WIN32
return win32_clipboard_set_text(s);
#elif __IOS__
return [ios_view clipboard_set_string:s];
#elif __OSX__
return [osx_view clipboard_set_string:s];
#elif __ANDROID__
return android_set_clipboard(s);
#endif
return legacy_platform_services().set_clipboard_text(s);
}
void App::stacktrace()
@@ -138,9 +194,9 @@ void App::show_cursor()
return;
#ifdef _WIN32
win32_show_cursor(true);
legacy_platform_services().set_cursor_visible(true);
#elif __OSX__
[osx_view show_cursor:true];
legacy_platform_services().set_cursor_visible(true);
#endif
}
@@ -150,9 +206,9 @@ void App::hide_cursor()
return;
#ifdef _WIN32
win32_show_cursor(false);
legacy_platform_services().set_cursor_visible(false);
#elif __OSX__
[osx_view show_cursor:false];
legacy_platform_services().set_cursor_visible(false);
#endif
}
@@ -163,11 +219,9 @@ void App::showKeyboard()
if (!should_dispatch_keyboard_visibility(true))
return;
#ifdef __IOS__
dispatch_async(dispatch_get_main_queue(), ^{
[ios_view show_keyboard];
});
legacy_platform_services().set_virtual_keyboard_visible(true);
#elif __ANDROID__
displayKeyboard(true);
legacy_platform_services().set_virtual_keyboard_visible(true);
#endif
}
@@ -178,11 +232,9 @@ void App::hideKeyboard()
if (!should_dispatch_keyboard_visibility(false))
return;
#ifdef __IOS__
dispatch_async(dispatch_get_main_queue(), ^{
[ios_view hide_keyboard];
});
legacy_platform_services().set_virtual_keyboard_visible(false);
#elif __ANDROID__
displayKeyboard(false);
legacy_platform_services().set_virtual_keyboard_visible(false);
#endif
}