WinUWP: Remove WinUWP sources, targets (flutter/engine#33019)

This removes:
* The Windows UWP emebedder sources and targets
* UWP-specific build targets
* UWP-specific code behind WINUWP #ifdefs
* UWP-specific TODOs.
* uwptool.exe sources and targets used for installing, uninstalling, and
  launching UWP apps.

This is a straight removal patch, and does not land any refactorings
made possible by removal of UWP support. Those patches will land in
followup refactorings.

Tool support was removed in:
https://github.com/flutter/flutter/pull/102174

The CI target was removed in:
https://github.com/flutter/engine/pull/33012

The Recipe was removed in:
https://flutter-review.googlesource.com/c/recipes/+/29500

GN build support was removed in:
https://github.com/flutter/engine/pull/33016

Issue: https://github.com/flutter/flutter/issues/102172
This commit is contained in:
Chris Bracken
2022-04-29 18:39:36 -07:00
committed by GitHub
parent 1ce6601c03
commit 0a84242538
53 changed files with 102 additions and 3528 deletions

View File

@@ -2206,8 +2206,6 @@ FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h
FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_delegate_win32.cc
FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_delegate_win32.h
FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_delegate_win32_unittests.cc
FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_delegate_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/accessibility_bridge_delegate_winuwp.h
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.h
FILE: ../../../flutter/shell/platform/windows/client_wrapper/dart_project_unittests.cc
@@ -2224,8 +2222,6 @@ FILE: ../../../flutter/shell/platform/windows/client_wrapper/include/flutter/plu
FILE: ../../../flutter/shell/platform/windows/client_wrapper/plugin_registrar_windows_unittests.cc
FILE: ../../../flutter/shell/platform/windows/cursor_handler.cc
FILE: ../../../flutter/shell/platform/windows/cursor_handler.h
FILE: ../../../flutter/shell/platform/windows/display_helper_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/display_helper_winuwp.h
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32.cc
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32.h
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32_unittests.cc
@@ -2236,16 +2232,12 @@ FILE: ../../../flutter/shell/platform/windows/external_texture_gl.h
FILE: ../../../flutter/shell/platform/windows/flutter_key_map.cc
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_win32.cc
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_win32.h
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_winuwp.h
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_window_win32.cc
FILE: ../../../flutter/shell/platform/windows/flutter_window_win32.h
FILE: ../../../flutter/shell/platform/windows/flutter_window_win32_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_window_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/flutter_window_winuwp.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_engine.h
@@ -2257,11 +2249,6 @@ FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view_unittests.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_win32.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/game_pad_cursor_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/game_pad_cursor_winuwp.h
FILE: ../../../flutter/shell/platform/windows/game_pad_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/game_pad_winuwp.h
FILE: ../../../flutter/shell/platform/windows/keyboard_handler_base.h
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h
@@ -2281,8 +2268,6 @@ FILE: ../../../flutter/shell/platform/windows/platform_handler.h
FILE: ../../../flutter/shell/platform/windows/platform_handler_unittests.cc
FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.cc
FILE: ../../../flutter/shell/platform/windows/platform_handler_win32.h
FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/platform_handler_winuwp.h
FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h
FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.cc
FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.h
@@ -2292,12 +2277,9 @@ FILE: ../../../flutter/shell/platform/windows/settings_plugin.h
FILE: ../../../flutter/shell/platform/windows/settings_plugin_unittests.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_win32.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_win32.h
FILE: ../../../flutter/shell/platform/windows/settings_plugin_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_winuwp.h
FILE: ../../../flutter/shell/platform/windows/system_utils.h
FILE: ../../../flutter/shell/platform/windows/system_utils_unittests.cc
FILE: ../../../flutter/shell/platform/windows/system_utils_win32.cc
FILE: ../../../flutter/shell/platform/windows/system_utils_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/task_runner.cc
FILE: ../../../flutter/shell/platform/windows/task_runner.h
FILE: ../../../flutter/shell/platform/windows/task_runner_unittests.cc
@@ -2305,20 +2287,12 @@ FILE: ../../../flutter/shell/platform/windows/task_runner_win32.cc
FILE: ../../../flutter/shell/platform/windows/task_runner_win32.h
FILE: ../../../flutter/shell/platform/windows/task_runner_win32_window.cc
FILE: ../../../flutter/shell/platform/windows/task_runner_win32_window.h
FILE: ../../../flutter/shell/platform/windows/task_runner_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/task_runner_winuwp.h
FILE: ../../../flutter/shell/platform/windows/text_input_manager_win32.cc
FILE: ../../../flutter/shell/platform/windows/text_input_manager_win32.h
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h
FILE: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h
FILE: ../../../flutter/shell/platform/windows/text_input_plugin_unittest.cc
FILE: ../../../flutter/shell/platform/windows/uwptool_commands.cc
FILE: ../../../flutter/shell/platform/windows/uwptool_commands.h
FILE: ../../../flutter/shell/platform/windows/uwptool_main.cc
FILE: ../../../flutter/shell/platform/windows/uwptool_utils.cc
FILE: ../../../flutter/shell/platform/windows/uwptool_utils.h
FILE: ../../../flutter/shell/platform/windows/uwptool_utils_unittests.cc
FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h
FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager_win32.cc

View File

@@ -71,7 +71,7 @@ if (is_ios || is_mac) {
_platform_name = host_os
if (_platform_name == "mac") {
_platform_name = "darwin"
} else if (_platform_name == "win" || _platform_name == "winuwp") {
} else if (_platform_name == "win") {
_platform_name = "windows"
}
@@ -80,8 +80,7 @@ full_platform_name = "$_platform_name-$host_cpu"
_platform_target_name = target_os
if (_platform_target_name == "mac") {
_platform_target_name = "darwin"
} else if (_platform_target_name == "win" ||
_platform_target_name == "winuwp") {
} else if (_platform_target_name == "win") {
_platform_target_name = "windows"
}
@@ -93,14 +92,14 @@ if (flutter_prebuilt_dart_sdk) {
_target_os_name = target_os
if (_target_os_name == "mac") {
_target_os_name = "macos"
} else if (_target_os_name == "win" || _target_os_name == "winuwp") {
} else if (_target_os_name == "win") {
_target_os_name = "windows"
}
_host_os_name = host_os
if (_host_os_name == "mac") {
_host_os_name = "macos"
} else if (_host_os_name == "win" || _host_os_name == "winuwp") {
} else if (_host_os_name == "win") {
_host_os_name = "windows"
}

View File

@@ -25,34 +25,6 @@
namespace fml {
static std::string GetFullHandlePath(const fml::UniqueFD& handle) {
// Although the documentation claims that GetFinalPathNameByHandle is
// supported for UWP apps, turns out it returns ACCESS_DENIED in this case
// hence the need to workaround it by maintaining a map of file handles to
// absolute paths populated by fml::OpenDirectory.
#ifdef WINUWP
std::optional<fml::internal::os_win::DirCacheEntry> found =
fml::internal::os_win::UniqueFDTraits::GetCacheEntry(handle.get());
if (found) {
FILE_ID_INFO info;
BOOL result = GetFileInformationByHandleEx(
handle.get(), FILE_INFO_BY_HANDLE_CLASS::FileIdInfo, &info,
sizeof(FILE_ID_INFO));
// Assuming it was possible to retrieve fileinfo, compare the id field. The
// handle hasn't been reused if the file identifier is the same as when it
// was cached
if (result && memcmp(found.value().id.Identifier, info.FileId.Identifier,
sizeof(FILE_ID_INFO))) {
return WideStringToUtf8(found.value().filename);
} else {
fml::internal::os_win::UniqueFDTraits::RemoveCacheEntry(handle.get());
}
}
return std::string();
#else
wchar_t buffer[MAX_PATH] = {0};
const DWORD buffer_size = ::GetFinalPathNameByHandle(
handle.get(), buffer, MAX_PATH, FILE_NAME_NORMALIZED);
@@ -60,7 +32,6 @@ static std::string GetFullHandlePath(const fml::UniqueFD& handle) {
return {};
}
return WideStringToUtf8({buffer, buffer_size});
#endif
}
static std::string GetAbsolutePath(const fml::UniqueFD& base_directory,
@@ -250,22 +221,6 @@ fml::UniqueFD OpenDirectory(const char* path,
return {};
}
#ifdef WINUWP
FILE_ID_INFO info;
BOOL result = GetFileInformationByHandleEx(
handle, FILE_INFO_BY_HANDLE_CLASS::FileIdInfo, &info,
sizeof(FILE_ID_INFO));
// Only cache if it is possible to get valid a fileinformation to extract the
// fileid to ensure correct handle versioning.
if (result) {
fml::internal::os_win::DirCacheEntry fc{file_name, info.FileId};
fml::internal::os_win::UniqueFDTraits::StoreCacheEntry(handle, fc);
}
#endif
return fml::UniqueFD{handle};
}

View File

@@ -40,15 +40,7 @@ static void WaitForRaster(Shell* shell) {
raster_task_finished.get_future().wait();
}
TEST_F(PersistentCacheTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_CacheSkSLWorks
#else
CacheSkSLWorks
#endif // defined(WINUWP)
) {
TEST_F(PersistentCacheTest, CacheSkSLWorks) {
// Create a temp dir to store the persistent cache
fml::ScopedTemporaryDirectory dir;
PersistentCache::SetCacheDirectoryPath(dir.path());
@@ -211,15 +203,7 @@ static void CheckTwoSkSLsAreLoaded() {
ASSERT_EQ(shaders.size(), 2u);
}
TEST_F(PersistentCacheTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_CanLoadSkSLsFromAsset
#else
CanLoadSkSLsFromAsset
#endif // defined(WINUWP)
) {
TEST_F(PersistentCacheTest, CanLoadSkSLsFromAsset) {
// Avoid polluting unit tests output by hiding INFO level logging.
fml::LogSettings warning_only = {fml::LOG_WARNING};
fml::ScopedSetLogSettings scoped_set_log_settings(warning_only);
@@ -283,15 +267,7 @@ TEST_F(PersistentCacheTest,
fml::UnlinkFile(asset_dir.fd(), PersistentCache::kAssetFileName);
}
TEST_F(PersistentCacheTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_CanRemoveOldPersistentCache
#else
CanRemoveOldPersistentCache
#endif // defined(WINUWP)
) {
TEST_F(PersistentCacheTest, CanRemoveOldPersistentCache) {
fml::ScopedTemporaryDirectory base_dir;
ASSERT_TRUE(base_dir.fd().is_valid());
@@ -321,15 +297,7 @@ TEST_F(PersistentCacheTest,
fml::RemoveFilesInDirectory(base_dir.fd());
}
TEST_F(PersistentCacheTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_CanPurgePersistentCache
#else
CanPurgePersistentCache
#endif // defined(WINUWP)
) {
TEST_F(PersistentCacheTest, CanPurgePersistentCache) {
fml::ScopedTemporaryDirectory base_dir;
ASSERT_TRUE(base_dir.fd().is_valid());
auto cache_dir = fml::CreateDirectory(
@@ -361,15 +329,7 @@ TEST_F(PersistentCacheTest,
DestroyShell(std::move(shell));
}
TEST_F(PersistentCacheTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_PurgeAllowsFutureSkSLCache
#else
PurgeAllowsFutureSkSLCache
#endif // defined(WINUWP)
) {
TEST_F(PersistentCacheTest, PurgeAllowsFutureSkSLCache) {
sk_sp<SkData> shader_key = SkData::MakeWithCString("key");
sk_sp<SkData> shader_value = SkData::MakeWithCString("value");
std::string shader_filename = PersistentCache::SkKeyToFilePath(*shader_key);

View File

@@ -511,14 +511,7 @@ TEST_F(ShellTest, LastEntrypointArgs) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_DisallowedDartVMFlag
#else
DisallowedDartVMFlag
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, DisallowedDartVMFlag) {
// Run this test in a thread-safe manner, otherwise gtest will complain.
::testing::FLAGS_gtest_death_test_style = "threadsafe";
@@ -532,14 +525,7 @@ TEST_F(ShellTest,
ASSERT_DEATH(flutter::SettingsFromCommandLine(command_line), expected);
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_AllowedDartVMFlag
#else
AllowedDartVMFlag
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, AllowedDartVMFlag) {
std::vector<const char*> flags = {
"--enable-isolate-groups",
"--no-enable-isolate-groups",
@@ -837,7 +823,7 @@ TEST_F(ShellTest,
}
TEST_F(ShellTest,
#if defined(OS_FUCHSIA) || defined(WINUWP)
#if defined(OS_FUCHSIA)
// TODO(dworsham): https://github.com/flutter/flutter/issues/59816
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_OnPlatformViewDestroyDisablesThreadMerger
@@ -1369,14 +1355,7 @@ TEST_F(ShellTest, ReloadSystemFonts) {
shell.reset();
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_WaitForFirstFrame
#else
WaitForFirstFrame
#endif
) {
TEST_F(ShellTest, WaitForFirstFrame) {
auto settings = CreateSettingsForFixture();
std::unique_ptr<Shell> shell = CreateShell(settings);
@@ -1431,15 +1410,7 @@ TEST_F(ShellTest, WaitForFirstFrameTimeout) {
DestroyShell(std::move(shell));
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_WaitForFirstFrameMultiple
#else
WaitForFirstFrameMultiple
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, WaitForFirstFrameMultiple) {
auto settings = CreateSettingsForFixture();
std::unique_ptr<Shell> shell = CreateShell(settings);
@@ -1463,15 +1434,7 @@ TEST_F(ShellTest,
/// Makes sure that WaitForFirstFrame works if we rendered a frame with the
/// single-thread setup.
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_WaitForFirstFrameInlined
#else
WaitForFirstFrameInlined
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, WaitForFirstFrameInlined) {
Settings settings = CreateSettingsForFixture();
auto task_runner = CreateNewThread();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
@@ -2258,14 +2221,7 @@ TEST_F(ShellTest, CanRegisterImageDecoders) {
DestroyShell(std::move(shell));
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_OnServiceProtocolGetSkSLsWorks
#else
OnServiceProtocolGetSkSLsWorks
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, OnServiceProtocolGetSkSLsWorks) {
fml::ScopedTemporaryDirectory base_dir;
ASSERT_TRUE(base_dir.fd().is_valid());
PersistentCache::SetCacheDirectoryPath(base_dir.path());
@@ -2728,15 +2684,7 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) {
DestroyShell(std::move(shell), std::move(task_runners));
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_OnServiceProtocolSetAssetBundlePathWorks
#else
OnServiceProtocolSetAssetBundlePathWorks
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, OnServiceProtocolSetAssetBundlePathWorks) {
Settings settings = CreateSettingsForFixture();
std::unique_ptr<Shell> shell = CreateShell(settings);
RunConfiguration configuration =
@@ -2808,15 +2756,7 @@ TEST_F(ShellTest, EngineRootIsolateLaunchesDontTakeVMDataSettings) {
isolate_create_latch.Wait();
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_AssetManagerSingle
#else
AssetManagerSingle
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, AssetManagerSingle) {
fml::ScopedTemporaryDirectory asset_dir;
fml::UniqueFD asset_dir_fd = fml::OpenDirectory(
asset_dir.path().c_str(), false, fml::FilePermission::kRead);
@@ -2841,15 +2781,7 @@ TEST_F(ShellTest,
ASSERT_TRUE(result == content);
}
TEST_F(ShellTest,
#if defined(WINUWP)
// TODO(cbracken): https://github.com/flutter/flutter/issues/90481
DISABLED_AssetManagerMulti
#else
AssetManagerMulti
#endif // defined(WINUWP)
) {
TEST_F(ShellTest, AssetManagerMulti) {
fml::ScopedTemporaryDirectory asset_dir;
fml::UniqueFD asset_dir_fd = fml::OpenDirectory(
asset_dir.path().c_str(), false, fml::FilePermission::kRead);

View File

@@ -16,7 +16,6 @@ std::vector<std::string> GetSwitchesFromEnvironment() {
// Read engine switches from the environment in debug/profile. If release mode
// support is needed in the future, it should likely use a whitelist.
#ifndef FLUTTER_RELEASE
#ifndef WINUWP
const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
const int kMaxSwitchCount = 50;
const char* switch_count_string = std::getenv(switch_count_key);
@@ -37,7 +36,6 @@ std::vector<std::string> GetSwitchesFromEnvironment() {
<< ", but " << switch_key.str() << " is missing." << std::endl;
}
}
#endif // !WINUWP
#endif // !FLUTTER_RELEASE
return switches;
}

View File

@@ -49,15 +49,25 @@ source_set("flutter_windows_headers") {
source_set("flutter_windows_source") {
# Common Windows sources.
sources = [
"accessibility_bridge_delegate_win32.cc",
"accessibility_bridge_delegate_win32.h",
"angle_surface_manager.cc",
"angle_surface_manager.h",
"cursor_handler.cc",
"cursor_handler.h",
"dpi_utils_win32.cc",
"dpi_utils_win32.h",
"event_watcher_win32.cc",
"event_watcher_win32.h",
"external_texture_gl.cc",
"external_texture_gl.h",
"flutter_key_map.cc",
"flutter_platform_node_delegate_win32.cc",
"flutter_platform_node_delegate_win32.h",
"flutter_project_bundle.cc",
"flutter_project_bundle.h",
"flutter_window_win32.cc",
"flutter_window_win32.h",
"flutter_windows.cc",
"flutter_windows_engine.cc",
"flutter_windows_engine.h",
@@ -65,6 +75,7 @@ source_set("flutter_windows_source") {
"flutter_windows_texture_registrar.h",
"flutter_windows_view.cc",
"flutter_windows_view.h",
"flutter_windows_win32.cc",
"keyboard_handler_base.h",
"keyboard_key_channel_handler.cc",
"keyboard_key_channel_handler.h",
@@ -77,84 +88,39 @@ source_set("flutter_windows_source") {
"keyboard_win32_common.h",
"platform_handler.cc",
"platform_handler.h",
"platform_handler_win32.cc",
"platform_handler_win32.h",
"sequential_id_generator.cc",
"sequential_id_generator.h",
"settings_plugin.cc",
"settings_plugin.h",
"settings_plugin_win32.cc",
"settings_plugin_win32.h",
"system_utils.h",
"system_utils_win32.cc",
"task_runner.cc",
"task_runner.h",
"task_runner_win32.cc",
"task_runner_win32.h",
"task_runner_win32_window.cc",
"task_runner_win32_window.h",
"text_input_manager_win32.cc",
"text_input_manager_win32.h",
"text_input_plugin.cc",
"text_input_plugin.h",
"window_binding_handler.h",
"window_binding_handler_delegate.h",
"window_proc_delegate_manager_win32.cc",
"window_proc_delegate_manager_win32.h",
"window_state.h",
"window_win32.cc",
"window_win32.h",
]
# Target-specific sources.
if (target_os == "winuwp") {
sources += [
"accessibility_bridge_delegate_winuwp.cc",
"accessibility_bridge_delegate_winuwp.h",
"display_helper_winuwp.cc",
"display_helper_winuwp.h",
"flutter_platform_node_delegate_winuwp.cc",
"flutter_platform_node_delegate_winuwp.h",
"flutter_window_winuwp.cc",
"flutter_window_winuwp.h",
"flutter_windows_winuwp.cc",
"game_pad_cursor_winuwp.cc",
"game_pad_cursor_winuwp.h",
"game_pad_winuwp.cc",
"game_pad_winuwp.h",
"platform_handler_winuwp.cc",
"platform_handler_winuwp.h",
"settings_plugin_winuwp.cc",
"settings_plugin_winuwp.h",
"system_utils_winuwp.cc",
"task_runner_winuwp.cc",
"task_runner_winuwp.h",
]
} else {
sources += [
"accessibility_bridge_delegate_win32.cc",
"accessibility_bridge_delegate_win32.h",
"dpi_utils_win32.cc",
"dpi_utils_win32.h",
"event_watcher_win32.cc",
"event_watcher_win32.h",
"flutter_platform_node_delegate_win32.cc",
"flutter_platform_node_delegate_win32.h",
"flutter_window_win32.cc",
"flutter_window_win32.h",
"flutter_windows_win32.cc",
"platform_handler_win32.cc",
"platform_handler_win32.h",
"settings_plugin_win32.cc",
"settings_plugin_win32.h",
"system_utils_win32.cc",
"task_runner_win32.cc",
"task_runner_win32.h",
"task_runner_win32_window.cc",
"task_runner_win32_window.h",
"text_input_manager_win32.cc",
"text_input_manager_win32.h",
"window_proc_delegate_manager_win32.cc",
"window_proc_delegate_manager_win32.h",
"window_win32.cc",
"window_win32.h",
]
libs = [
"dwmapi.lib",
"imm32.lib",
]
}
if (target_os == "winuwp") {
configs += [ ":cppwinrt_defs" ]
cflags = [ "/EHsc" ]
}
libs = [
"dwmapi.lib",
"imm32.lib",
]
configs += [
"//flutter/shell/platform/common:desktop_library_implementation",
@@ -163,14 +129,7 @@ source_set("flutter_windows_source") {
public_configs = [ ":relative_angle_headers" ]
if (target_os == "winuwp") {
defines = [
"_SILENCE_CLANG_COROUTINE_MESSAGE",
"FLUTTER_ENGINE_NO_PROTOTYPES",
]
} else {
defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ]
}
defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ]
public_deps = [
"//flutter/fml:string_conversion",
@@ -209,12 +168,6 @@ shared_library("flutter_windows") {
public_configs = [ "//flutter:config" ]
}
shared_library("flutter_windows_winuwp") {
deps = [ ":flutter_windows_source" ]
libs = [ "windowsapp.lib" ]
public_configs = [ "//flutter:config" ]
}
test_fixtures("flutter_windows_fixtures") {
fixtures = []
}
@@ -222,64 +175,46 @@ test_fixtures("flutter_windows_fixtures") {
executable("flutter_windows_unittests") {
testonly = true
if (target_os == "winuwp") {
libs = [
"windowsapp.lib",
"user32.lib",
]
}
# Common Windows test sources.
sources = [
# "flutter_project_bundle_unittests.cc", //TODO failing due to switches test failing. Blocked on https://github.com/flutter/flutter/issues/74153
# "flutter_windows_engine_unittests.cc", //TODO failing to send / receive platform message get plugins working first. Blocked on https://github.com/flutter/flutter/issues/74155
"accessibility_bridge_delegate_win32_unittests.cc",
"dpi_utils_win32_unittests.cc",
"flutter_project_bundle_unittests.cc",
"flutter_window_win32_unittests.cc",
"flutter_windows_engine_unittests.cc",
"flutter_windows_texture_registrar_unittests.cc",
"flutter_windows_view_unittests.cc",
"keyboard_key_channel_handler_unittests.cc",
"keyboard_key_embedder_handler_unittests.cc",
"keyboard_key_handler_unittests.cc",
"keyboard_win32_unittests.cc",
"platform_handler_unittests.cc",
"sequential_id_generator_unittests.cc",
"settings_plugin_unittests.cc",
"system_utils_unittests.cc",
"task_runner_unittests.cc",
"testing/engine_modifier.h",
"testing/flutter_window_win32_test.cc",
"testing/flutter_window_win32_test.h",
"testing/mock_gl_functions.h",
"testing/mock_text_input_manager_win32.cc",
"testing/mock_text_input_manager_win32.h",
"testing/mock_window_binding_handler.cc",
"testing/mock_window_binding_handler.h",
"testing/mock_window_win32.cc",
"testing/mock_window_win32.h",
"testing/test_keyboard.cc",
"testing/test_keyboard.h",
"testing/test_keyboard_unittests.cc",
"testing/wm_builders.cc",
"testing/wm_builders.h",
"text_input_plugin_unittest.cc",
"window_proc_delegate_manager_win32_unittests.cc",
"window_win32_unittests.cc",
]
# Target-specific sources.
if (target_os == "winuwp") {
sources += [ "uwptool_utils_unittests.cc" ]
# TODO(clarkezone) add UWP tests
# https://github.com/flutter/flutter/issues/70197
} else {
sources += [
# TODO move first two tests to common once above TODO's unblocked.
"accessibility_bridge_delegate_win32_unittests.cc",
"dpi_utils_win32_unittests.cc",
"flutter_project_bundle_unittests.cc",
"flutter_window_win32_unittests.cc",
"flutter_windows_engine_unittests.cc",
"flutter_windows_texture_registrar_unittests.cc",
"flutter_windows_view_unittests.cc",
"keyboard_key_channel_handler_unittests.cc",
"keyboard_key_embedder_handler_unittests.cc",
"keyboard_key_handler_unittests.cc",
"keyboard_win32_unittests.cc",
"platform_handler_unittests.cc",
"testing/flutter_window_win32_test.cc",
"testing/flutter_window_win32_test.h",
"testing/mock_text_input_manager_win32.cc",
"testing/mock_text_input_manager_win32.h",
"testing/mock_window_binding_handler.cc",
"testing/mock_window_binding_handler.h",
"testing/mock_window_win32.cc",
"testing/mock_window_win32.h",
"testing/test_keyboard.cc",
"testing/test_keyboard.h",
"testing/test_keyboard_unittests.cc",
"testing/wm_builders.cc",
"testing/wm_builders.h",
"text_input_plugin_unittest.cc",
"window_proc_delegate_manager_win32_unittests.cc",
"window_win32_unittests.cc",
]
}
public_configs = [ "//flutter:config" ]
deps = [
@@ -292,10 +227,6 @@ executable("flutter_windows_unittests") {
"//flutter/testing",
"//third_party/rapidjson",
]
if (target_os == "winuwp") {
deps += [ ":uwptool_utils" ]
}
}
shared_library("flutter_windows_glfw") {
@@ -314,64 +245,13 @@ group("windows_glfw") {
}
group("windows") {
if (target_os == "winuwp") {
deps = [
":flutter_windows_winuwp",
":publish_headers_windows",
":uwptool",
"//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows",
]
} else {
deps = [
":flutter_windows",
":publish_headers_windows",
"//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows",
]
}
deps = [
":flutter_windows",
":publish_headers_windows",
"//flutter/shell/platform/windows/client_wrapper:publish_wrapper_windows",
]
if (build_glfw_shell) {
deps += [ ":windows_glfw" ]
}
}
# uwptool utilities.
source_set("uwptool_utils") {
if (target_os == "winuwp") {
configs += [ ":cppwinrt_defs" ]
cflags = [ "/EHsc" ]
}
sources = [
"uwptool_commands.cc",
"uwptool_commands.h",
"uwptool_utils.cc",
"uwptool_utils.h",
]
deps = [ "//flutter/fml:string_conversion" ]
defines = [ "_SILENCE_CLANG_COROUTINE_MESSAGE" ]
}
# Command-line tool used by the flutter tool that serves a similar purpose to
# adb for Android or libimobiledevice for iOS apps. Supports installing,
# uninstalling, launching apps.
executable("uwptool") {
if (target_os == "winuwp") {
configs += [ ":cppwinrt_defs" ]
cflags = [ "/EHsc" ]
libs = [
"windowsapp.lib",
"user32.lib",
]
}
sources = [ "uwptool_main.cc" ]
deps = [
":uwptool_utils",
"//flutter/fml:command_line",
"//flutter/fml:string_conversion",
]
defines = [ "_SILENCE_CLANG_COROUTINE_MESSAGE" ]
}

View File

@@ -1,37 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/accessibility_bridge_delegate_winuwp.h"
#include "flutter/shell/platform/windows/flutter_platform_node_delegate_winuwp.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h"
namespace flutter {
AccessibilityBridgeDelegateWinUWP::AccessibilityBridgeDelegateWinUWP(
FlutterWindowsEngine* engine)
: engine_(engine) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
assert(engine_);
}
void AccessibilityBridgeDelegateWinUWP::OnAccessibilityEvent(
ui::AXEventGenerator::TargetedEvent targeted_event) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
}
void AccessibilityBridgeDelegateWinUWP::DispatchAccessibilityAction(
AccessibilityNodeId target,
FlutterSemanticsAction action,
fml::MallocMapping data) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
}
std::shared_ptr<FlutterPlatformNodeDelegate>
AccessibilityBridgeDelegateWinUWP::CreateFlutterPlatformNodeDelegate() {
return std::make_shared<FlutterPlatformNodeDelegateWinUWP>(engine_);
}
} // namespace flutter

View File

@@ -1,47 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_BRIDGE_DELEGATE_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_BRIDGE_DELEGATE_H_
#include "flutter/shell/platform/common/accessibility_bridge.h"
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
namespace flutter {
class FlutterWindowsEngine;
// The Windows UWP implementation of AccessibilityBridgeDelegate.
//
// Handles requests from the accessibility bridge to interact with Windows
// accessibility APIs. This includes routing accessibility events fired from
// the framework to Windows, routing native Windows accessibility events to the
// framework, and creating Windows-specific FlutterPlatformNodeDelegate objects
// for each node in the semantics tree.
class AccessibilityBridgeDelegateWinUWP
: public AccessibilityBridge::AccessibilityBridgeDelegate {
public:
explicit AccessibilityBridgeDelegateWinUWP(FlutterWindowsEngine* engine);
virtual ~AccessibilityBridgeDelegateWinUWP() = default;
// |AccessibilityBridge::AccessibilityBridgeDelegate|
void OnAccessibilityEvent(
ui::AXEventGenerator::TargetedEvent targeted_event) override;
// |AccessibilityBridge::AccessibilityBridgeDelegate|
void DispatchAccessibilityAction(AccessibilityNodeId target,
FlutterSemanticsAction action,
fml::MallocMapping data) override;
// |AccessibilityBridge::AccessibilityBridgeDelegate|
std::shared_ptr<FlutterPlatformNodeDelegate>
CreateFlutterPlatformNodeDelegate() override;
private:
FlutterWindowsEngine* engine_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ACCESSIBILITY_BRIDGE_DELEGATE_H_

View File

@@ -7,15 +7,6 @@
#include <iostream>
#include <vector>
#ifdef WINUWP
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
#include <windows.ui.core.h>
#endif
#if defined(WINUWP) && defined(USECOREWINDOW)
#include <winrt/Windows.UI.Core.h>
#endif
// Logs an EGL error to stderr. This automatically calls eglGetError()
// and logs the error code.
static void LogEglError(std::string message) {
@@ -221,31 +212,14 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target,
EGLSurface surface = EGL_NO_SURFACE;
#ifdef WINUWP
const EGLint surfaceAttributes[] = {EGL_NONE};
#else
const EGLint surfaceAttributes[] = {
EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width,
EGL_HEIGHT, height, EGL_NONE};
#endif
#ifdef WINUWP
#ifdef USECOREWINDOW
auto target = std::get<winrt::Windows::UI::Core::CoreWindow>(*render_target);
#else
auto target =
std::get<winrt::Windows::UI::Composition::SpriteVisual>(*render_target);
#endif
surface = eglCreateWindowSurface(
egl_display_, egl_config_,
static_cast<EGLNativeWindowType>(winrt::get_abi(target)),
surfaceAttributes);
#else
surface = eglCreateWindowSurface(
egl_display_, egl_config_,
static_cast<EGLNativeWindowType>(std::get<HWND>(*render_target)),
surfaceAttributes);
#endif
if (surface == EGL_NO_SURFACE) {
LogEglError("Surface creation failed.");
}
@@ -265,23 +239,12 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target,
surface_width_ = width;
surface_height_ = height;
// TODO(clarkezone) convert ifdef to use use final implementation of angle
// resize API prototyped here
// https://github.com/clarkezone/angle/tree/resizeswapchaintest to eliminate
// unnecessary surface creation / desctruction by use ResizeSwapchain
// https://github.com/flutter/flutter/issues/79427
#ifdef WINUWP
// Resize render_surface_. Internaly this calls mSwapChain->ResizeBuffers
// avoiding the need to destory and recreate the underlying SwapChain.
eglPostSubBufferNV(egl_display_, render_surface_, 1, 1, width, height);
#else
ClearContext();
DestroySurface();
if (!CreateSurface(render_target, width, height)) {
std::cerr << "AngleSurfaceManager::ResizeSurface failed to create surface"
<< std::endl;
}
#endif
}
}

View File

@@ -64,11 +64,9 @@ void FlutterEngine::ShutDown() {
engine_ = nullptr;
}
#ifndef WINUWP
std::chrono::nanoseconds FlutterEngine::ProcessMessages() {
return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_));
}
#endif
void FlutterEngine::ReloadSystemFonts() {
FlutterDesktopEngineReloadSystemFonts(engine_);

View File

@@ -9,22 +9,6 @@
namespace flutter {
#ifdef WINUWP
FlutterViewController::FlutterViewController(
ABI::Windows::ApplicationModel::Core::CoreApplicationView* applicationview,
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
const DartProject& project) {
engine_ = std::make_unique<FlutterEngine>(project);
controller_ = FlutterDesktopViewControllerCreateFromCoreApplicationView(
applicationview, args, engine_->RelinquishEngine());
if (!controller_) {
std::cerr << "Failed to create view controller." << std::endl;
return;
}
view_ = std::make_unique<FlutterView>(
FlutterDesktopViewControllerGetView(controller_));
}
#else
FlutterViewController::FlutterViewController(int width,
int height,
const DartProject& project) {
@@ -38,7 +22,6 @@ FlutterViewController::FlutterViewController(int width,
view_ = std::make_unique<FlutterView>(
FlutterDesktopViewControllerGetView(controller_));
}
#endif
FlutterViewController::~FlutterViewController() {
if (controller_) {
@@ -46,7 +29,6 @@ FlutterViewController::~FlutterViewController() {
}
}
#ifndef WINUWP
std::optional<LRESULT> FlutterViewController::HandleTopLevelWindowProc(
HWND hwnd,
UINT message,
@@ -57,6 +39,5 @@ std::optional<LRESULT> FlutterViewController::HandleTopLevelWindowProc(
controller_, hwnd, message, wparam, lparam, &result);
return handled ? result : std::optional<LRESULT>(std::nullopt);
}
#endif
} // namespace flutter

View File

@@ -19,8 +19,8 @@ class DartProject {
// - icu_data_path: Path to the icudtl.dat file.
// - aot_library_path: Path to the AOT snapshot file.
//
// The paths must be absolute in a UWP app. In a win32 app, they can be
// relative to the directory containing the running executable.
// The paths may either be absolute or relative to the directory containing
// the running executable.
explicit DartProject(const std::wstring& assets_path,
const std::wstring& icu_data_path,
const std::wstring& aot_library_path) {
@@ -29,7 +29,6 @@ class DartProject {
aot_library_path_ = aot_library_path;
}
#ifndef WINUWP
// Creates a DartProject from a directory path. The directory should contain
// the following top-level items:
// - icudtl.dat (provided as a resource by the Flutter tool)
@@ -43,7 +42,6 @@ class DartProject {
icu_data_path_ = path + L"\\icudtl.dat";
aot_library_path_ = path + L"\\app.so";
}
#endif
~DartProject() = default;

View File

@@ -20,15 +20,8 @@ class FlutterView {
FlutterView(FlutterView const&) = delete;
FlutterView& operator=(FlutterView const&) = delete;
#ifdef WINUWP
// Returns the backing CoreApplicationView for the view.
ABI::Windows::ApplicationModel::Core::CoreApplicationView* GetNativeWindow() {
return FlutterDesktopViewGetCoreApplicationView(view_);
}
#else
// Returns the backing HWND for the view.
HWND GetNativeWindow() { return FlutterDesktopViewGetHWND(view_); }
#endif
private:
// Handle for interacting with the C API's view.

View File

@@ -17,11 +17,6 @@
#include "plugin_registrar.h"
#include "plugin_registry.h"
#ifdef WINUWP
#include <windows.applicationmodel.activation.h>
#include <windows.ui.core.h>
#endif
namespace flutter {
// A controller for a view displaying Flutter content.
@@ -31,7 +26,6 @@ namespace flutter {
// methods in the C API directly, as this class will do that internally.
class FlutterViewController {
public:
#ifndef WINUWP
// Creates a FlutterView that can be parented into a Windows View hierarchy
// either using HWNDs.
//
@@ -39,19 +33,6 @@ class FlutterViewController {
explicit FlutterViewController(int width,
int height,
const DartProject& project);
#else
// Creates a FlutterView that can be parented into a Windows View hierarchy
// either using CoreWindow.
//
// |dart_project| will be used to configure the engine backing this view.
// |IActivatedEventArgs| will be used to configure the engine switches. Can
// be set to nullptr.
explicit FlutterViewController(
ABI::Windows::ApplicationModel::Core::CoreApplicationView*
applicationview,
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
const DartProject& project);
#endif
virtual ~FlutterViewController();
@@ -65,7 +46,6 @@ class FlutterViewController {
// Returns the view managed by this controller.
FlutterView* view() { return view_.get(); }
#ifndef WINUWP
// Allows the Flutter engine and any interested plugins an opportunity to
// handle the given message.
//
@@ -75,7 +55,6 @@ class FlutterViewController {
UINT message,
WPARAM wparam,
LPARAM lparam);
#endif
private:
// Handle for interacting with the C API's view controller, if any.

View File

@@ -49,7 +49,6 @@ class PluginRegistrarWindows : public PluginRegistrar {
FlutterView* GetView() { return view_.get(); }
#ifndef WINUWP
// Registers |delegate| to receive WindowProc callbacks for the top-level
// window containing this Flutter instance. Returns an ID that can be used to
// unregister the handler.
@@ -81,10 +80,8 @@ class PluginRegistrarWindows : public PluginRegistrar {
registrar(), PluginRegistrarWindows::OnTopLevelWindowProc);
}
}
#endif
private:
#ifndef WINUWP
// A FlutterDesktopWindowProcCallback implementation that forwards back to
// a PluginRegistarWindows instance provided as |user_data|.
static bool OnTopLevelWindowProc(HWND hwnd,
@@ -116,17 +113,14 @@ class PluginRegistrarWindows : public PluginRegistrar {
}
return result;
}
#endif
// The associated FlutterView, if any.
std::unique_ptr<FlutterView> view_;
#ifndef WINUWP
// The next ID to return from RegisterWindowProcDelegate.
int next_window_proc_delegate_id_ = 1;
std::map<int, WindowProcDelegate> window_proc_delegates_;
#endif
};
} // namespace flutter

View File

@@ -1,97 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/display_helper_winuwp.h"
namespace flutter {
DisplayHelperWinUWP::DisplayHelperWinUWP() {
current_display_info_ = winrt::Windows::Graphics::Display::
DisplayInformation::GetForCurrentView();
ConfigureXboxSpecific();
}
bool DisplayHelperWinUWP::IsRunningOnLargeScreenDevice() {
return large_screen_device_;
}
float DisplayHelperWinUWP::GetRenderTargetXOffset() {
return render_target_x_offset_;
}
float DisplayHelperWinUWP::GetRenderTargetYOffset() {
return render_target_y_offset_;
}
WindowBoundsWinUWP DisplayHelperWinUWP::GetPhysicalBounds() {
return GetBounds(current_display_info_, true);
}
WindowBoundsWinUWP DisplayHelperWinUWP::GetLogicalBounds() {
return GetBounds(current_display_info_, false);
}
WindowBoundsWinUWP DisplayHelperWinUWP::GetBounds(
winrt::Windows::Graphics::Display::DisplayInformation const& disp,
bool physical) {
winrt::Windows::UI::ViewManagement::ApplicationView app_view =
winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
winrt::Windows::Foundation::Rect bounds = app_view.VisibleBounds();
if (large_screen_device_) {
return {bounds.Width + (bounds.X), bounds.Height + (bounds.Y)};
}
if (physical) {
// Return the height in physical pixels
return {bounds.Width * static_cast<float>(disp.RawPixelsPerViewPixel()),
bounds.Height * static_cast<float>(disp.RawPixelsPerViewPixel())};
}
return {bounds.Width, bounds.Height};
}
void DisplayHelperWinUWP::ConfigureXboxSpecific() {
bool running_on_xbox =
winrt::Windows::System::Profile::AnalyticsInfo::VersionInfo()
.DeviceFamily() == L"Windows.Xbox";
if (running_on_xbox) {
large_screen_device_ = running_on_xbox;
bool result =
winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()
.SetDesiredBoundsMode(winrt::Windows::UI::ViewManagement::
ApplicationViewBoundsMode::UseCoreWindow);
if (!result) {
OutputDebugString(L"Couldn't set bounds mode.");
}
winrt::Windows::UI::ViewManagement::ApplicationView app_view = winrt::
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
winrt::Windows::Foundation::Rect bounds = app_view.VisibleBounds();
// The offset /2 represents how much off-screan the CoreWindow is
// positioned.
render_target_x_offset_ = bounds.X / 2;
render_target_y_offset_ = bounds.Y / 2;
}
}
float DisplayHelperWinUWP::GetDpiScale() {
double raw_per_view = current_display_info_.RawPixelsPerViewPixel();
// TODO(clarkezone): ensure DPI handling is correct:
// because XBOX has display scaling off, logicalDpi returns 96 which is
// incorrect check if raw_per_view is more acurate.
// Also confirm if it is necessary to use this workaround on 10X
// https://github.com/flutter/flutter/issues/70198
if (large_screen_device_) {
return 1.5;
}
return static_cast<float>(raw_per_view);
}
} // namespace flutter

View File

@@ -1,80 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_DISPLAY_HELPER_WINUWP_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_DISPLAY_HELPER_WINUWP_H_
#include <DispatcherQueue.h>
#include <third_party/cppwinrt/generated/winrt/Windows.Graphics.Display.h>
#include <third_party/cppwinrt/generated/winrt/Windows.System.Profile.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Core.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.Core.h>
#include "third_party/cppwinrt/generated/winrt/Windows.System.Threading.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/game_pad_winuwp.h"
namespace flutter {
struct WindowBoundsWinUWP {
float width;
float height;
};
// Helper that enables consumers to determine window bounds, DPI and some XBOX
// specific characteristics in the case when the current application is running
// on those devices.
class DisplayHelperWinUWP {
public:
DisplayHelperWinUWP();
// physical = true
// Returns with the physical bounds of the active window.
WindowBoundsWinUWP GetPhysicalBounds();
// Returns with the logical bounds of the active window.
WindowBoundsWinUWP GetLogicalBounds();
// Returns a bounds structure containing width and height information
// for the backing CoreWindow in either view or physical pixels depending on
// |physical|.
WindowBoundsWinUWP GetBounds(
winrt::Windows::Graphics::Display::DisplayInformation const& disp,
bool physical);
// Returns a scaling factor representing the current DPI scale applied to the
// backing CoreWindow.
float GetDpiScale();
bool IsRunningOnLargeScreenDevice();
// Returns a value representing the overscan to correct for X.
float GetRenderTargetXOffset();
// Returns a value representing the overscan to correct for Y.
float GetRenderTargetYOffset();
private:
// Test is current context is running on an xbox device and perform device
// specific initialization.
void ConfigureXboxSpecific();
// Most recent display information.
winrt::Windows::Graphics::Display::DisplayInformation current_display_info_{
nullptr};
// Is current context is executing on a large screen device.
bool large_screen_device_ = false;
// Current overscan compensation factors.
//
// The default value is no offset from the window's top-left, used when
// large_screen_device_ is false (normal desktop).
float render_target_x_offset_ = 0.0f;
float render_target_y_offset_ = 0.0f;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_DISPLAY_HELPER_WINUWP_H_

View File

@@ -1,67 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <oleacc.h>
#include "flutter/shell/platform/windows/flutter_platform_node_delegate_winuwp.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
namespace flutter {
FlutterPlatformNodeDelegateWinUWP::FlutterPlatformNodeDelegateWinUWP(
FlutterWindowsEngine* engine)
: engine_(engine) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
assert(engine_);
}
FlutterPlatformNodeDelegateWinUWP::~FlutterPlatformNodeDelegateWinUWP() {
if (ax_platform_node_) {
ax_platform_node_->Destroy();
}
}
// |ui::AXPlatformNodeDelegate|
void FlutterPlatformNodeDelegateWinUWP::Init(std::weak_ptr<OwnerBridge> bridge,
ui::AXNode* node) {
FlutterPlatformNodeDelegate::Init(bridge, node);
ax_platform_node_ = ui::AXPlatformNode::Create(this);
assert(ax_platform_node_);
}
// |ui::AXPlatformNodeDelegate|
gfx::NativeViewAccessible
FlutterPlatformNodeDelegateWinUWP::GetNativeViewAccessible() {
assert(ax_platform_node_);
return ax_platform_node_->GetNativeViewAccessible();
}
// |FlutterPlatformNodeDelegate|
gfx::NativeViewAccessible FlutterPlatformNodeDelegateWinUWP::GetParent() {
gfx::NativeViewAccessible parent = FlutterPlatformNodeDelegate::GetParent();
if (parent) {
return parent;
}
assert(engine_);
FlutterWindowsView* view = engine_->view();
if (!view) {
return nullptr;
}
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
// Use FlutterWindowsView::GetPlatformView to get the root view, and return
// the associated accessibility object.
return nullptr;
}
// |FlutterPlatformNodeDelegate|
gfx::Rect FlutterPlatformNodeDelegateWinUWP::GetBoundsRect(
const ui::AXCoordinateSystem coordinate_system,
const ui::AXClippingBehavior clipping_behavior,
ui::AXOffscreenResult* offscreen_result) const {
// TODO(cbracken): https://github.com/flutter/flutter/issues/93928
return {};
}
} // namespace flutter

View File

@@ -1,47 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PLATFORM_NODE_DELEGATE_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PLATFORM_NODE_DELEGATE_H_
#include "flutter/shell/platform/common/flutter_platform_node_delegate.h"
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
#include "flutter/third_party/accessibility/ax/platform/ax_platform_node.h"
namespace flutter {
class FlutterWindowsEngine;
// The Windows UWP implementation of FlutterPlatformNodeDelegate.
//
// This class implements a wrapper around the Windows UWP accessibility objects
// that compose the accessibility tree.
class FlutterPlatformNodeDelegateWinUWP : public FlutterPlatformNodeDelegate {
public:
explicit FlutterPlatformNodeDelegateWinUWP(FlutterWindowsEngine* engine);
virtual ~FlutterPlatformNodeDelegateWinUWP();
// |ui::AXPlatformNodeDelegate|
void Init(std::weak_ptr<OwnerBridge> bridge, ui::AXNode* node) override;
// |ui::AXPlatformNodeDelegate|
gfx::NativeViewAccessible GetNativeViewAccessible() override;
// |FlutterPlatformNodeDelegate|
gfx::NativeViewAccessible GetParent() override;
// |FlutterPlatformNodeDelegate|
gfx::Rect GetBoundsRect(
const ui::AXCoordinateSystem coordinate_system,
const ui::AXClippingBehavior clipping_behavior,
ui::AXOffscreenResult* offscreen_result) const override;
private:
ui::AXPlatformNode* ax_platform_node_;
FlutterWindowsEngine* engine_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_PLATFORM_NODE_DELEGATE_H_

View File

@@ -86,11 +86,7 @@ void FlutterProjectBundle::SetSwitches(
}
const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
#if WINUWP
return engine_switches_;
#else
return GetSwitchesFromEnvironment();
#endif
}
} // namespace flutter

View File

@@ -1,390 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/flutter_window_winuwp.h"
#include <map>
namespace flutter {
// Multipler used to map controller velocity to an appropriate scroll input.
static constexpr double kControllerScrollMultiplier = 3;
// Minimum pointer ID that gets emitted by the pointer ID generator.
static constexpr uint32_t kMinPointerId = 0;
// Maximum pointer ID that gets emitted by the pointer ID generator.
static constexpr uint32_t kMaxPointerId = 128;
// Maps a Flutter cursor name to a CoreCursor.
//
// Returns the arrow cursor for unknown constants.
//
// This map must be kept in sync with Flutter framework's
// services/mouse_cursor.dart.
namespace {
using winrt::Windows::UI::Core::CoreCursorType;
std::map<std::string, const CoreCursorType> cursors{
{"allScroll", CoreCursorType::SizeAll},
{"basic", CoreCursorType::Arrow},
{"click", CoreCursorType::Hand},
{"forbidden", CoreCursorType::UniversalNo},
{"help", CoreCursorType::Help},
{"move", CoreCursorType::SizeAll},
{"noDrop", CoreCursorType::UniversalNo},
{"precise", CoreCursorType::Cross},
{"text", CoreCursorType::IBeam},
{"resizeColumn", CoreCursorType::SizeWestEast},
{"resizeDown", CoreCursorType::SizeNorthSouth},
{"resizeDownLeft", CoreCursorType::SizeNortheastSouthwest},
{"resizeDownRight", CoreCursorType::SizeNorthwestSoutheast},
{"resizeLeft", CoreCursorType::SizeWestEast},
{"resizeLeftRight", CoreCursorType::SizeWestEast},
{"resizeRight", CoreCursorType::SizeWestEast},
{"resizeRow", CoreCursorType::SizeNorthSouth},
{"resizeUp", CoreCursorType::SizeNorthSouth},
{"resizeUpDown", CoreCursorType::SizeNorthSouth},
{"resizeUpLeft", CoreCursorType::SizeNorthwestSoutheast},
{"resizeUpRight", CoreCursorType::SizeNortheastSouthwest},
{"resizeUpLeftDownRight", CoreCursorType::SizeNorthwestSoutheast},
{"resizeUpRightDownLeft", CoreCursorType::SizeNortheastSouthwest},
{"wait", CoreCursorType::Wait},
};
winrt::Windows::UI::Core::CoreCursor GetCursorByName(
const std::string& cursor_name) {
if (cursor_name == "none") {
return winrt::Windows::UI::Core::CoreCursor{nullptr};
} else {
auto cursor_type = CoreCursorType::Arrow;
auto it = cursors.find(cursor_name);
if (it != cursors.end()) {
cursor_type = it->second;
}
return winrt::Windows::UI::Core::CoreCursor(cursor_type, 0);
}
}
// UWP does not care if key events are handled, since it can not redispatch them
// anyway.
static void IgnoreKeyEventResult(bool handled) {}
} // namespace
FlutterWindowWinUWP::FlutterWindowWinUWP(
ABI::Windows::ApplicationModel::Core::CoreApplicationView* applicationview)
: pointer_id_generator_(kMinPointerId, kMaxPointerId) {
winrt::Windows::ApplicationModel::Core::CoreApplicationView cav{nullptr};
winrt::copy_from_abi(cav, applicationview);
application_view_ = cav;
window_ = application_view_.CoreWindow();
SetEventHandlers();
display_helper_ = std::make_unique<DisplayHelperWinUWP>();
}
WindowsRenderTarget FlutterWindowWinUWP::GetRenderTarget() {
#ifdef USECOREWINDOW
return WindowsRenderTarget(window_);
#else
compositor_ = winrt::Windows::UI::Composition::Compositor();
target_ = compositor_.CreateTargetForCurrentView();
visual_tree_root_ = compositor_.CreateContainerVisual();
target_.Root(visual_tree_root_);
render_target_ = compositor_.CreateSpriteVisual();
render_target_.Offset({display_helper_->GetRenderTargetXOffset(),
display_helper_->GetRenderTargetYOffset(), 1.0});
if (!display_helper_->IsRunningOnLargeScreenDevice()) {
ApplyInverseDpiScalingTransform();
}
visual_tree_root_.Children().InsertAtBottom(render_target_);
game_pad_cursor_ = std::make_unique<GamepadCursorWinUWP>(
binding_handler_delegate_, display_helper_.get(), window_, compositor_,
visual_tree_root_.Children());
WindowBoundsWinUWP bounds = display_helper_->GetPhysicalBounds();
render_target_.Size({bounds.width, bounds.height});
return WindowsRenderTarget(render_target_);
#endif
}
PlatformWindow FlutterWindowWinUWP::GetPlatformWindow() {
return application_view_;
}
void FlutterWindowWinUWP::ApplyInverseDpiScalingTransform() {
// Apply inverse transform to negate built in DPI scaling in order to render
// at native scale.
auto dpiScale = GetDpiScale();
render_target_.Scale({1 / dpiScale, 1 / dpiScale, 1 / dpiScale});
}
PhysicalWindowBounds FlutterWindowWinUWP::GetPhysicalWindowBounds() {
WindowBoundsWinUWP bounds = display_helper_->GetPhysicalBounds();
return {static_cast<size_t>(bounds.width),
static_cast<size_t>(bounds.height)};
}
void FlutterWindowWinUWP::UpdateFlutterCursor(const std::string& cursor_name) {
window_.PointerCursor(GetCursorByName(cursor_name));
}
void FlutterWindowWinUWP::OnCursorRectUpdated(const Rect& rect) {
// TODO(cbracken): Implement IMM candidate window positioning.
}
void FlutterWindowWinUWP::OnResetImeComposing() {
// TODO(cbracken): Cancel composing, close the candidates view, and clear the
// composing text.
}
void FlutterWindowWinUWP::OnWindowResized() {}
FlutterWindowWinUWP::~FlutterWindowWinUWP() {}
void FlutterWindowWinUWP::SetView(WindowBindingHandlerDelegate* view) {
binding_handler_delegate_ = view;
}
void FlutterWindowWinUWP::SetEventHandlers() {
auto app_view =
winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
app_view.SetDesiredBoundsMode(winrt::Windows::UI::ViewManagement::
ApplicationViewBoundsMode::UseCoreWindow);
app_view.VisibleBoundsChanged({this, &FlutterWindowWinUWP::OnBoundsChanged});
window_.PointerPressed({this, &FlutterWindowWinUWP::OnPointerPressed});
window_.PointerReleased({this, &FlutterWindowWinUWP::OnPointerReleased});
window_.PointerMoved({this, &FlutterWindowWinUWP::OnPointerMoved});
window_.PointerWheelChanged(
{this, &FlutterWindowWinUWP::OnPointerWheelChanged});
// TODO(clarkezone) support mouse leave handling
// https://github.com/flutter/flutter/issues/70199
// TODO(clarkezone) support system font changed
// https://github.com/flutter/flutter/issues/70198
window_.KeyUp({this, &FlutterWindowWinUWP::OnKeyUp});
window_.KeyDown({this, &FlutterWindowWinUWP::OnKeyDown});
window_.CharacterReceived({this, &FlutterWindowWinUWP::OnCharacterReceived});
auto display = winrt::Windows::Graphics::Display::DisplayInformation::
GetForCurrentView();
display.DpiChanged({this, &FlutterWindowWinUWP::OnDpiChanged});
}
float FlutterWindowWinUWP::GetDpiScale() {
return display_helper_->GetDpiScale();
}
bool FlutterWindowWinUWP::IsVisible() {
// This is called from raster thread as an optimization to not wait for vsync
// if window is invisible. However CoreWindow is not agile so we can't call
// Visible() from raster thread. For now assume window is always visible.
// Possible solution would be to register a VisibilityChanged handler and
// store the visiblity state in a variable. TODO(knopp)
// https://github.com/flutter/flutter/issues/87870
return true;
}
void FlutterWindowWinUWP::OnDpiChanged(
winrt::Windows::Graphics::Display::DisplayInformation const& args,
winrt::Windows::Foundation::IInspectable const&) {
ApplyInverseDpiScalingTransform();
WindowBoundsWinUWP bounds = display_helper_->GetPhysicalBounds();
binding_handler_delegate_->OnWindowSizeChanged(
static_cast<size_t>(bounds.width), static_cast<size_t>(bounds.height));
}
void FlutterWindowWinUWP::OnPointerPressed(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args) {
double x = GetPosX(args);
double y = GetPosY(args);
FlutterPointerDeviceKind device_kind = GetPointerDeviceKind(args);
FlutterPointerMouseButtons mouse_button = GetPointerMouseButton(args);
auto pointer_id = GetPointerId(args);
binding_handler_delegate_->OnPointerDown(x, y, device_kind, pointer_id,
mouse_button);
}
void FlutterWindowWinUWP::OnPointerReleased(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args) {
double x = GetPosX(args);
double y = GetPosY(args);
FlutterPointerDeviceKind device_kind = GetPointerDeviceKind(args);
FlutterPointerMouseButtons mouse_button = GetPointerMouseButton(args);
auto pointer_id = GetPointerId(args);
binding_handler_delegate_->OnPointerUp(x, y, device_kind, pointer_id,
mouse_button);
ReleasePointer(args);
}
void FlutterWindowWinUWP::OnPointerMoved(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args) {
double x = GetPosX(args);
double y = GetPosY(args);
FlutterPointerDeviceKind device_kind = GetPointerDeviceKind(args);
auto pointer_id = GetPointerId(args);
binding_handler_delegate_->OnPointerMove(x, y, device_kind, pointer_id);
}
void FlutterWindowWinUWP::OnPointerWheelChanged(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args) {
double x = GetPosX(args);
double y = GetPosY(args);
FlutterPointerDeviceKind device_kind = GetPointerDeviceKind(args);
auto pointer_id = GetPointerId(args);
int delta = args.CurrentPoint().Properties().MouseWheelDelta();
binding_handler_delegate_->OnScroll(x, y, 0, -delta, 1, device_kind,
pointer_id);
}
double FlutterWindowWinUWP::GetPosX(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
const double inverse_dpi_scale = GetDpiScale();
return (args.CurrentPoint().Position().X -
display_helper_->GetRenderTargetXOffset()) *
inverse_dpi_scale;
}
double FlutterWindowWinUWP::GetPosY(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
const double inverse_dpi_scale = GetDpiScale();
return static_cast<double>((args.CurrentPoint().Position().Y -
display_helper_->GetRenderTargetYOffset()) *
inverse_dpi_scale);
}
FlutterPointerDeviceKind FlutterWindowWinUWP::GetPointerDeviceKind(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
switch (args.CurrentPoint().PointerDevice().PointerDeviceType()) {
case winrt::Windows::Devices::Input::PointerDeviceType::Mouse:
return kFlutterPointerDeviceKindMouse;
case winrt::Windows::Devices::Input::PointerDeviceType::Pen:
return kFlutterPointerDeviceKindStylus;
case winrt::Windows::Devices::Input::PointerDeviceType::Touch:
return kFlutterPointerDeviceKindTouch;
}
return kFlutterPointerDeviceKindMouse;
}
FlutterPointerMouseButtons FlutterWindowWinUWP::GetPointerMouseButton(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
switch (args.CurrentPoint().Properties().PointerUpdateKind()) {
case winrt::Windows::UI::Input::PointerUpdateKind::LeftButtonPressed:
case winrt::Windows::UI::Input::PointerUpdateKind::LeftButtonReleased:
return kFlutterPointerButtonMousePrimary;
case winrt::Windows::UI::Input::PointerUpdateKind::RightButtonPressed:
case winrt::Windows::UI::Input::PointerUpdateKind::RightButtonReleased:
return kFlutterPointerButtonMouseSecondary;
case winrt::Windows::UI::Input::PointerUpdateKind::MiddleButtonPressed:
case winrt::Windows::UI::Input::PointerUpdateKind::MiddleButtonReleased:
return kFlutterPointerButtonMouseMiddle;
case winrt::Windows::UI::Input::PointerUpdateKind::XButton1Pressed:
case winrt::Windows::UI::Input::PointerUpdateKind::XButton1Released:
return kFlutterPointerButtonMouseBack;
case winrt::Windows::UI::Input::PointerUpdateKind::XButton2Pressed:
case winrt::Windows::UI::Input::PointerUpdateKind::XButton2Released:
return kFlutterPointerButtonMouseForward;
case winrt::Windows::UI::Input::PointerUpdateKind::Other:
return kFlutterPointerButtonMousePrimary;
}
return kFlutterPointerButtonMousePrimary;
}
void FlutterWindowWinUWP::ReleasePointer(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
pointer_id_generator_.ReleaseNumber(args.CurrentPoint().PointerId());
}
uint32_t FlutterWindowWinUWP::GetPointerId(
winrt::Windows::UI::Core::PointerEventArgs const& args) {
// Generate a mapped ID in the interval [kMinPointerId, kMaxPointerId].
return pointer_id_generator_.GetGeneratedId(args.CurrentPoint().PointerId());
}
void FlutterWindowWinUWP::OnBoundsChanged(
winrt::Windows::UI::ViewManagement::ApplicationView const& app_view,
winrt::Windows::Foundation::IInspectable const&) {
if (binding_handler_delegate_) {
auto bounds = display_helper_->GetPhysicalBounds();
binding_handler_delegate_->OnWindowSizeChanged(
static_cast<size_t>(bounds.width), static_cast<size_t>(bounds.height));
#ifndef USECOREWINDOW
render_target_.Size({bounds.width, bounds.height});
#endif
}
}
void FlutterWindowWinUWP::OnKeyUp(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::KeyEventArgs const& args) {
// TODO(clarkezone) complete keyboard handling including
// system key (back), unicode handling, shortcut support,
// handling defered delivery, remove the need for action value.
// https://github.com/flutter/flutter/issues/70202
auto status = args.KeyStatus();
unsigned int scancode = status.ScanCode;
int key = static_cast<int>(args.VirtualKey());
int action = 0x0101;
binding_handler_delegate_->OnKey(
key, scancode, action, 0, status.IsExtendedKey /* extended */,
status.WasKeyDown /* was_down */, IgnoreKeyEventResult);
}
void FlutterWindowWinUWP::OnKeyDown(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::KeyEventArgs const& args) {
// TODO(clarkezone) complete keyboard handling including
// system key (back), unicode handling, shortcut support
// handling defered delivery, remove the need for action value.
// https://github.com/flutter/flutter/issues/70202
auto status = args.KeyStatus();
unsigned int scancode = status.ScanCode;
int key = static_cast<int>(args.VirtualKey());
int action = 0x0100;
binding_handler_delegate_->OnKey(
key, scancode, action, 0, status.IsExtendedKey /* extended */,
status.WasKeyDown /* was_down */, IgnoreKeyEventResult);
}
void FlutterWindowWinUWP::OnCharacterReceived(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::CharacterReceivedEventArgs const& args) {
auto key = args.KeyCode();
wchar_t keycode = static_cast<wchar_t>(key);
if (keycode >= u' ') {
std::u16string text({keycode});
binding_handler_delegate_->OnText(text);
}
}
bool FlutterWindowWinUWP::OnBitmapSurfaceUpdated(const void* allocation,
size_t row_bytes,
size_t height) {
// TODO(gw280): Support software rendering fallback on UWP
return false;
}
} // namespace flutter

View File

@@ -1,179 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_
#include <third_party/cppwinrt/generated/winrt/Windows.ApplicationModel.Core.h>
#include <third_party/cppwinrt/generated/winrt/Windows.Devices.Input.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Input.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Text.Core.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.Core.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.h>
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/windows/display_helper_winuwp.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/game_pad_cursor_winuwp.h"
#include "flutter/shell/platform/windows/sequential_id_generator.h"
namespace flutter {
// Implements a UWP CoreWindow. Underlying window has been created and provided
// by the runner.
//
// Specifically handles window events within windows.
class FlutterWindowWinUWP : public WindowBindingHandler {
public:
explicit FlutterWindowWinUWP(
ABI::Windows::ApplicationModel::Core::CoreApplicationView* window);
virtual ~FlutterWindowWinUWP();
// |WindowBindingHandler|
void SetView(WindowBindingHandlerDelegate* view) override;
// |WindowBindingHandler|
WindowsRenderTarget GetRenderTarget() override;
// |FlutterWindowBindingHandler|
PlatformWindow GetPlatformWindow() override;
// |WindowBindingHandler|
float GetDpiScale() override;
// |FlutterWindowBindingHandler|
bool IsVisible() override;
// |WindowBindingHandler|
PhysicalWindowBounds GetPhysicalWindowBounds() override;
// |WindowBindingHandler|
void UpdateFlutterCursor(const std::string& cursor_name) override;
// |WindowBindingHandler|
void OnCursorRectUpdated(const Rect& rect) override;
// |FlutterWindowBindingHandler|
void OnResetImeComposing() override;
// |WindowBindingHandler|
void OnWindowResized() override;
// |WindowBindingHandler|
bool OnBitmapSurfaceUpdated(const void* allocation,
size_t row_bytes,
size_t height) override;
private:
// Undoes the scale transform applied by the Windows compositor in order to
// render at native scale and produce smooth results on high DPI screens.
void ApplyInverseDpiScalingTransform();
// Hooks up event handers for keyboard, mouse, size, DPI changed events on the
// underlying CoreWindow.
void SetEventHandlers();
// Notifies current |WindowBindingHandlerDelegate| of DPI Changed events.
void OnDpiChanged(
winrt::Windows::Graphics::Display::DisplayInformation const& args,
winrt::Windows::Foundation::IInspectable const&);
// Notifies current |WindowBindingHandlerDelegate| of pointer pressed events.
void OnPointerPressed(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of pointer released events.
void OnPointerReleased(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of pointer pressed events.
void OnBoundsChanged(
winrt::Windows::UI::ViewManagement::ApplicationView const& appView,
winrt::Windows::Foundation::IInspectable const&);
// Notifies current |WindowBindingHandlerDelegate| of pointer moved events.
void OnPointerMoved(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of mouse wheel events.
void OnPointerWheelChanged(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of key up events.
void OnKeyUp(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::KeyEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of key down events.
void OnKeyDown(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::KeyEventArgs const& args);
// Notifies current |WindowBindingHandlerDelegate| of character received
// events.
void OnCharacterReceived(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::CharacterReceivedEventArgs const& args);
// Converts from logical point to physical X value.
double GetPosX(winrt::Windows::UI::Core::PointerEventArgs const& args);
// Converts from logical point to physical Y value.
double GetPosY(winrt::Windows::UI::Core::PointerEventArgs const& args);
// Gets the pointer kind.
FlutterPointerDeviceKind GetPointerDeviceKind(
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Gets the pointer ID.
uint32_t GetPointerId(winrt::Windows::UI::Core::PointerEventArgs const& args);
// Releases the pointer from the ID generator.
void ReleasePointer(winrt::Windows::UI::Core::PointerEventArgs const& args);
// Gets the mouse button.
FlutterPointerMouseButtons GetPointerMouseButton(
winrt::Windows::UI::Core::PointerEventArgs const& args);
// Backing CoreWindow. nullptr if not set.
winrt::Windows::UI::Core::CoreWindow window_{nullptr};
// CoreApplicationView that owns window_. nullptr if not set.
winrt::Windows::ApplicationModel::Core::CoreApplicationView application_view_{
nullptr};
// Pointer to a FlutterWindowsView that can be
// used to update engine windowing and input state.
WindowBindingHandlerDelegate* binding_handler_delegate_;
// Current active compositor. nullptr if not set.
winrt::Windows::UI::Composition::Compositor compositor_{nullptr};
// Current CompositionTarget for binding the
// rendering context to the CoreWindow. nullptr if not set.
winrt::Windows::UI::Composition::CompositionTarget target_{nullptr};
// Composition tree root object.
winrt::Windows::UI::Composition::ContainerVisual visual_tree_root_{nullptr};
// Compositor object that represents the render target binding the backing
// SwapChain to the CoreWindow.
winrt::Windows::UI::Composition::SpriteVisual render_target_{nullptr};
// GamepadCursorWinUWP object used to manage an emulated cursor visual driven
// by gamepad.
std::unique_ptr<GamepadCursorWinUWP> game_pad_cursor_{nullptr};
// DisplayHelper object used to determine window bounds, DPI etc.
std::unique_ptr<DisplayHelperWinUWP> display_helper_ = {nullptr};
// Generates pointer IDs for pointer events.
SequentialIdGenerator pointer_id_generator_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_UWP_FLUTTER_WINDOW_H_

View File

@@ -128,20 +128,9 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopEngineGetTextureRegistrar(
EngineFromHandle(engine)->texture_registrar());
}
#ifdef WINUWP
ABI::Windows::ApplicationModel::Core::CoreApplicationView*
FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view) {
return static_cast<
ABI::Windows::ApplicationModel::Core::CoreApplicationView*>(
winrt::get_abi(ViewFromHandle(view)->GetPlatformWindow()));
}
#endif
#ifndef WINUWP
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
return ViewFromHandle(view)->GetPlatformWindow();
}
#endif
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
FlutterDesktopPluginRegistrarRef registrar) {

View File

@@ -15,12 +15,8 @@
#include "flutter/shell/platform/windows/system_utils.h"
#include "flutter/shell/platform/windows/task_runner.h"
#if defined(WINUWP)
#include "flutter/shell/platform/windows/accessibility_bridge_delegate_winuwp.h"
#else
#include <dwmapi.h>
#include "flutter/shell/platform/windows/accessibility_bridge_delegate_win32.h"
#endif // defined(WINUWP)
// winbase.h defines GetCurrentTime as a macro.
#undef GetCurrentTime
@@ -186,10 +182,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project)
texture_registrar_ =
std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
surface_manager_ = AngleSurfaceManager::Create();
#ifndef WINUWP
window_proc_delegate_manager_ =
std::make_unique<WindowProcDelegateManagerWin32>();
#endif
// Set up internal channels.
// TODO: Replace this with an embedder.h API. See
@@ -376,7 +370,6 @@ std::chrono::nanoseconds FlutterWindowsEngine::FrameInterval() {
}
uint64_t interval = 16600000;
#ifndef WINUWP
DWM_TIMING_INFO timing_info = {};
timing_info.cbSize = sizeof(timing_info);
HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info);
@@ -386,7 +379,6 @@ std::chrono::nanoseconds FlutterWindowsEngine::FrameInterval() {
1000000000.0) /
static_cast<double>(timing_info.rateRefresh.uiNumerator);
}
#endif
return std::chrono::nanoseconds(interval);
}
@@ -527,11 +519,7 @@ bool FlutterWindowsEngine::DispatchSemanticsAction(
}
void FlutterWindowsEngine::UpdateSemanticsEnabled(bool enabled) {
#if defined(WINUWP)
using AccessibilityBridgeDelegateWindows = AccessibilityBridgeDelegateWinUWP;
#else
using AccessibilityBridgeDelegateWindows = AccessibilityBridgeDelegateWin32;
#endif // defined(WINUWP)
if (engine_ && semantics_enabled_ != enabled) {
semantics_enabled_ = enabled;

View File

@@ -22,13 +22,10 @@
#include "flutter/shell/platform/windows/public/flutter_windows.h"
#include "flutter/shell/platform/windows/settings_plugin.h"
#include "flutter/shell/platform/windows/task_runner.h"
#include "flutter/shell/platform/windows/window_proc_delegate_manager_win32.h"
#include "flutter/shell/platform/windows/window_state.h"
#include "third_party/rapidjson/include/rapidjson/document.h"
#ifndef WINUWP
#include "flutter/shell/platform/windows/window_proc_delegate_manager_win32.h" // nogncheck
#endif
namespace flutter {
class FlutterWindowsView;
@@ -127,11 +124,9 @@ class FlutterWindowsEngine {
return accessibility_bridge_;
}
#ifndef WINUWP
WindowProcDelegateManagerWin32* window_proc_delegate_manager() {
return window_proc_delegate_manager_.get();
}
#endif
// Informs the engine that the window metrics have changed.
void SendWindowMetricsEvent(const FlutterWindowMetricsEvent& event);
@@ -264,10 +259,8 @@ class FlutterWindowsEngine {
std::shared_ptr<AccessibilityBridge> accessibility_bridge_;
#ifndef WINUWP
// The manager for WindowProc delegate registration and callbacks.
std::unique_ptr<WindowProcDelegateManagerWin32> window_proc_delegate_manager_;
#endif
};
} // namespace flutter

View File

@@ -254,17 +254,14 @@ void FlutterWindowsView::OnResetImeComposing() {
void FlutterWindowsView::InitializeKeyboard() {
auto internal_plugin_messenger = internal_plugin_registrar_->messenger();
#ifdef WINUWP
KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = nullptr;
KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan = nullptr;
#else
// TODO(cbracken): This can be inlined into KeyboardKeyEmedderHandler once
// UWP code is removed. https://github.com/flutter/flutter/issues/102172.
KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = GetKeyState;
KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan =
[](UINT virtual_key, bool extended) {
return MapVirtualKey(virtual_key,
extended ? MAPVK_VK_TO_VSC_EX : MAPVK_VK_TO_VSC);
};
#endif
keyboard_key_handler_ = std::move(CreateKeyboardKeyHandler(
internal_plugin_messenger, get_key_state, map_vk_to_scan));
text_input_plugin_ =

View File

@@ -1,89 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/public/flutter_windows.h"
#include <io.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <memory>
#include <sstream>
#include <vector>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include "winrt/Windows.ApplicationModel.Core.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
#include "flutter/shell/platform/windows/flutter_window_winuwp.h" // nogncheck
// Returns the engine corresponding to the given opaque API handle.
static flutter::FlutterWindowsEngine* EngineFromHandle(
FlutterDesktopEngineRef ref) {
return reinterpret_cast<flutter::FlutterWindowsEngine*>(ref);
}
// Returns a list of discrete arguments splitting the input using a ",".
std::vector<std::string> SplitCommaSeparatedString(const std::string& s) {
std::vector<std::string> components;
std::istringstream stream(s);
std::string component;
while (getline(stream, component, ',')) {
components.push_back(component);
}
return (components);
}
FlutterDesktopViewControllerRef
FlutterDesktopViewControllerCreateFromCoreApplicationView(
ABI::Windows::ApplicationModel::Core::CoreApplicationView* application_view,
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
FlutterDesktopEngineRef engine) {
std::unique_ptr<flutter::WindowBindingHandler> window_wrapper =
std::make_unique<flutter::FlutterWindowWinUWP>(application_view);
auto state = std::make_unique<FlutterDesktopViewControllerState>();
state->view =
std::make_unique<flutter::FlutterWindowsView>(std::move(window_wrapper));
// Take ownership of the engine, starting it if necessary.
state->view->SetEngine(
std::unique_ptr<flutter::FlutterWindowsEngine>(EngineFromHandle(engine)));
state->view->CreateRenderSurface();
winrt::Windows::ApplicationModel::Activation::IActivatedEventArgs
arg_interface{nullptr};
winrt::copy_from_abi(arg_interface, args);
std::vector<std::string> engine_switches;
winrt::Windows::ApplicationModel::Activation::LaunchActivatedEventArgs launch{
nullptr};
if (arg_interface.Kind() ==
winrt::Windows::ApplicationModel::Activation::ActivationKind::Launch) {
launch = arg_interface.as<winrt::Windows::ApplicationModel::Activation::
LaunchActivatedEventArgs>();
if (launch != nullptr) {
std::string launchargs = winrt::to_string(launch.Arguments());
if (!launchargs.empty()) {
engine_switches = SplitCommaSeparatedString(launchargs);
}
}
}
state->view->GetEngine()->SetSwitches(engine_switches);
if (!state->view->GetEngine()->running()) {
if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) {
return nullptr;
}
}
// Must happen after engine is running.
state->view->SendInitialBounds();
return state.release();
}

View File

@@ -1,330 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/game_pad_cursor_winuwp.h"
#include "game_pad_cursor_winuwp.h"
namespace flutter {
static constexpr int32_t kDefaultPointerDeviceId = 0;
// UWP does not care if key events are handled, since it can not redispatch them
// anyway.
static void IgnoreKeyEventResult(bool handled) {}
GamepadCursorWinUWP::GamepadCursorWinUWP(
WindowBindingHandlerDelegate* view,
DisplayHelperWinUWP* displayhelper,
winrt::Windows::UI::Core::CoreWindow const& window,
winrt::Windows::UI::Composition::Compositor const& compositor,
winrt::Windows::UI::Composition::VisualCollection const& rootcollection) {
window_ = window;
root_collection_ = rootcollection;
binding_handler_delegate_ = view;
display_helper_ = displayhelper;
compositor_ = compositor;
cursor_visual_ = CreateCursorVisual();
ConfigureGamepad();
}
void GamepadCursorWinUWP::StartGamepadTimer() {
winrt::Windows::UI::Core::CoreDispatcher dispatcher = window_.Dispatcher();
dispatcher.RunAsync(
winrt::Windows::UI::Core::CoreDispatcherPriority::Normal,
[this, dispatcher]() {
auto queue =
winrt::Windows::System::DispatcherQueue::GetForCurrentThread();
if (cursor_move_timer_ == nullptr) {
cursor_move_timer_ = queue.CreateTimer();
cursor_move_timer_.Interval(
std::chrono::milliseconds(kNormalPollingFrequency));
cursor_move_timer_.Tick(
[=](winrt::Windows::System::DispatcherQueueTimer timer,
winrt::Windows::Foundation::IInspectable const&) {
game_pad_->Process();
});
cursor_move_timer_.Start();
}
});
}
void GamepadCursorWinUWP::StopGamepadTimer() {
winrt::Windows::UI::Core::CoreDispatcher dispatcher = window_.Dispatcher();
dispatcher.RunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Normal,
[this, dispatcher]() {
if (cursor_move_timer_ != nullptr) {
cursor_move_timer_.Stop();
cursor_move_timer_ = nullptr;
}
});
}
void GamepadCursorWinUWP::ConfigureGamepad() {
GamepadDualAxisCallback leftStick = [=](double x, double y) {
OnGamepadLeftStickMoved(x, y);
};
GamepadDualAxisCallback rightStick = [=](double x, double y) {
OnGamepadRightStickMoved(x, y);
};
GamepadButtonCallback pressedcallback =
[=](winrt::Windows::Gaming::Input::GamepadButtons buttons) {
OnGamepadButtonPressed(buttons);
};
GamepadButtonCallback releasedcallback =
[=](winrt::Windows::Gaming::Input::GamepadButtons buttons) {
OnGamepadButtonReleased(buttons);
};
GamepadAddedRemovedCallback changed = [=]() {
OnGamepadControllersChanged();
};
game_pad_ = std::make_unique<GamepadWinUWP>(leftStick, rightStick, nullptr,
nullptr, pressedcallback,
releasedcallback, changed);
game_pad_->Initialize();
SetCursorTimeout();
}
void GamepadCursorWinUWP::SetCursorTimeout() {
if (cursor_visual_ == nullptr) {
return;
}
auto queue = winrt::Windows::System::DispatcherQueue::GetForCurrentThread();
// Lazily create timer.
if (emulated_cursor_hide_timer_ == nullptr) {
emulated_cursor_hide_timer_ = queue.CreateTimer();
emulated_cursor_hide_timer_.Interval(std::chrono::seconds(kInactivePeriod));
emulated_cursor_hide_timer_.Tick(
[=](winrt::Windows::System::DispatcherQueueTimer timer,
winrt::Windows::Foundation::IInspectable const&) {
// Timer fires when user has been inactive. At this point stop the
// timer. It will be restarted next time controller interaction
// happens triggering SetCursorTimeout
timer.Stop();
// If the timer fires, the user hasn't move the cursor for more than
// the interval hence hide the cursor
cursor_visual_.IsVisible(false);
// Reduce mouse move polling frequency while user not interacting with
// controller
SetMouseMovePollingFrequency(kReducedPollingFrequency);
});
}
// Ensure the cursor is visible and restart the timer as the user is
// interacting.
cursor_visual_.IsVisible(true);
emulated_cursor_hide_timer_.Start();
SetMouseMovePollingFrequency(kNormalPollingFrequency);
}
void GamepadCursorWinUWP::SetMouseMovePollingFrequency(int ms) {
if (cursor_move_timer_ != nullptr) {
cursor_move_timer_.Interval(std::chrono::milliseconds(ms));
}
}
winrt::Windows::Foundation::Numerics::float3
GamepadCursorWinUWP::GetScaledInput(
const winrt::Windows::Foundation::Numerics::float3 input) {
if (!display_helper_->IsRunningOnLargeScreenDevice()) {
const float inverse_dpi_scale = display_helper_->GetDpiScale();
return {cursor_visual_.Offset().x * inverse_dpi_scale,
cursor_visual_.Offset().y * inverse_dpi_scale, 1.0f};
} else {
return std::move(input);
}
}
void GamepadCursorWinUWP::OnGamepadLeftStickMoved(double x, double y) {
SetCursorTimeout();
float new_x =
cursor_visual_.Offset().x + (kCursorScale * static_cast<float>(x));
float new_y =
cursor_visual_.Offset().y + (kCursorScale * -static_cast<float>(y));
WindowBoundsWinUWP logical_bounds = display_helper_->GetLogicalBounds();
if (new_x > 0 && new_y > 0 && new_x < logical_bounds.width &&
new_y < logical_bounds.height) {
cursor_visual_.Offset({new_x, new_y, 0});
winrt::Windows::Foundation::Numerics::float3 scaled =
GetScaledInput(cursor_visual_.Offset());
// TODO(dnfield): Support for gamepad as a distinct device type?
// https://github.com/flutter/flutter/issues/80472
binding_handler_delegate_->OnPointerMove(scaled.x, scaled.y,
kFlutterPointerDeviceKindMouse,
kDefaultPointerDeviceId);
}
}
void GamepadCursorWinUWP::OnGamepadRightStickMoved(double x, double y) {
winrt::Windows::Foundation::Numerics::float3 scaled =
GetScaledInput(cursor_visual_.Offset());
binding_handler_delegate_->OnScroll(
scaled.x, scaled.y, x * kControllerScrollMultiplier,
y * kControllerScrollMultiplier, 1, kFlutterPointerDeviceKindMouse,
kDefaultPointerDeviceId);
}
void GamepadCursorWinUWP::OnGamepadButtonPressed(
winrt::Windows::Gaming::Input::GamepadButtons buttons) {
if ((buttons & winrt::Windows::Gaming::Input::GamepadButtons::A) ==
winrt::Windows::Gaming::Input::GamepadButtons::A) {
winrt::Windows::Foundation::Numerics::float3 scaled =
GetScaledInput(cursor_visual_.Offset());
// TODO(clarkezone) complete keyboard handling including
// system key (back), unicode handling, shortcut support,
// handling defered delivery, remove the need for action value.
// https://github.com/flutter/flutter/issues/70202
// TODO(dnfield): Support for gamepad as a distinct device type?
// https://github.com/flutter/flutter/issues/80472
binding_handler_delegate_->OnPointerDown(
scaled.x, scaled.y, kFlutterPointerDeviceKindMouse,
kDefaultPointerDeviceId,
FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadLeft) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadLeft) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Left), kScanLeft,
0x0100, 0, true, true, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadRight) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadRight) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Right), kScanRight,
0x0100, 0, true, true, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadUp) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadUp) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Up), kScanUp,
0x0100, 0, true, true, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadDown) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadDown) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Down), kScanDown,
0x0100, 0, true, true, IgnoreKeyEventResult);
}
}
void GamepadCursorWinUWP::OnGamepadButtonReleased(
winrt::Windows::Gaming::Input::GamepadButtons buttons) {
if ((buttons & winrt::Windows::Gaming::Input::GamepadButtons::A) ==
winrt::Windows::Gaming::Input::GamepadButtons::A) {
winrt::Windows::Foundation::Numerics::float3 scaled =
GetScaledInput(cursor_visual_.Offset());
// TODO(clarkezone) complete keyboard handling including
// system key (back), unicode handling, shortcut support,
// handling defered delivery, remove the need for action value.
// https://github.com/flutter/flutter/issues/70202
// TODO(dnfield): Support for gamepad as a distinct device type?
// https://github.com/flutter/flutter/issues/80472
binding_handler_delegate_->OnPointerUp(
scaled.x, scaled.y, kFlutterPointerDeviceKindMouse,
kDefaultPointerDeviceId,
FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadLeft) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadLeft) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Left), kScanLeft,
0x0100, 0, true, false, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadRight) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadRight) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Right), kScanRight,
0x0100, 0, true, false, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadUp) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadUp) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Up), kScanUp,
0x0100, 0, true, false, IgnoreKeyEventResult);
} else if ((buttons &
winrt::Windows::Gaming::Input::GamepadButtons::DPadDown) ==
winrt::Windows::Gaming::Input::GamepadButtons::DPadDown) {
binding_handler_delegate_->OnKey(
static_cast<int>(winrt::Windows::System::VirtualKey::Down), kScanDown,
0x0100, 0, true, false, IgnoreKeyEventResult);
}
}
void GamepadCursorWinUWP::OnGamepadControllersChanged() {
if (game_pad_->HasController()) {
if (!cursor_move_timer_) {
if (cursor_visual_ != nullptr) {
root_collection_.InsertAtTop(cursor_visual_);
}
StartGamepadTimer();
} else {
if (cursor_visual_ != nullptr) {
root_collection_.Remove(cursor_visual_);
}
StopGamepadTimer();
}
}
}
winrt::Windows::UI::Composition::Visual
GamepadCursorWinUWP::CreateCursorVisual() {
auto container = compositor_.CreateContainerVisual();
container.Offset(
{window_.Bounds().Width / 2, window_.Bounds().Height / 2, 1.0});
// size of the simulated mouse cursor
constexpr float size = 20;
constexpr float container_size = size + 10;
auto cursor_visual = compositor_.CreateShapeVisual();
cursor_visual.Size({container_size, container_size});
// compensate for overscan in cursor visual
cursor_visual.Offset({display_helper_->GetRenderTargetXOffset(),
display_helper_->GetRenderTargetYOffset(), 1.0});
winrt::Windows::UI::Composition::CompositionEllipseGeometry circle =
compositor_.CreateEllipseGeometry();
circle.Radius({size / 2, size / 2});
auto circleshape = compositor_.CreateSpriteShape(circle);
circleshape.FillBrush(
compositor_.CreateColorBrush(winrt::Windows::UI::Colors::Black()));
circleshape.StrokeBrush(
compositor_.CreateColorBrush(winrt::Windows::UI::Colors::White()));
circleshape.StrokeThickness(5.0);
circleshape.Offset({container_size / 2, container_size / 2});
cursor_visual.Shapes().Append(circleshape);
winrt::Windows::UI::Composition::Visual visual =
cursor_visual.as<winrt::Windows::UI::Composition::Visual>();
visual.AnchorPoint({0.5, 0.5});
container.Children().InsertAtTop(visual);
return container;
}
} // namespace flutter

View File

@@ -1,141 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_CURSOR_WINUWP_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_CURSOR_WINUWP_H_
#include <DispatcherQueue.h>
#include <third_party/cppwinrt/generated/winrt/Windows.Foundation.Collections.h>
#include <third_party/cppwinrt/generated/winrt/Windows.Graphics.Display.h>
#include <third_party/cppwinrt/generated/winrt/Windows.System.Profile.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Core.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.Core.h>
#include "third_party/cppwinrt/generated/winrt/Windows.System.Threading.h"
#include "flutter/shell/platform/windows/display_helper_winuwp.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/game_pad_winuwp.h"
namespace flutter {
// A class abstraction for a mouse cursor driven by a gamepad. This abstraction
// is primarily intended for devices like XBOX that do not have traditional
// mouse input.
class GamepadCursorWinUWP {
public:
GamepadCursorWinUWP(
WindowBindingHandlerDelegate* view,
DisplayHelperWinUWP* displayhelper,
winrt::Windows::UI::Core::CoreWindow const& window,
winrt::Windows::UI::Composition::Compositor const& compositor,
winrt::Windows::UI::Composition::VisualCollection const& rootcollection);
private:
// Pointer to a DisplayHelperWinUWP object used to get window bounds, DPI and
// other display-related aspects.
DisplayHelperWinUWP* display_helper_;
// Current active compositor. nullptr if not set.
winrt::Windows::UI::Composition::Compositor compositor_{nullptr};
// Window that is hosting this emulated cursor.
winrt::Windows::UI::Core::CoreWindow window_{nullptr};
// The root of the composition tree that this class will add a cursor visual
// to.
winrt::Windows::UI::Composition::VisualCollection root_collection_{nullptr};
// Called when the user is interacting with the GamePad and moving the mouse
// cursor. Prevents the mouse cursor from being hidden by resetting the
// inactivity timer.
void SetCursorTimeout();
// Sets the frequency, in milliseconds, that the gamepad is polled for
// movement updates.
void SetMouseMovePollingFrequency(int ms);
// Notifies current |WindowBindingHandlerDelegate| of gamepad right stick
// events as emulated mouse move events.
void OnGamepadLeftStickMoved(double x, double y);
// Notifies current |WindowBindingHandlerDelegate| of gamepad right stick
// events delivered as scroll events.
void OnGamepadRightStickMoved(double x, double y);
// Notifies current |WindowBindingHandlerDelegate| of left gamepad move events
// delivered as emulated mouse button events.
void OnGamepadButtonPressed(
winrt::Windows::Gaming::Input::GamepadButtons buttons);
// Notifies current |WindowBindingHandlerDelegate| of left gamepad move events
// delivered as emulated mouse button events.
void OnGamepadButtonReleased(
winrt::Windows::Gaming::Input::GamepadButtons buttons);
// Show and hide the emulated mouse cursor when a gamepad arrives / departs
void OnGamepadControllersChanged();
// Creates a visual representing the emulated cursor and add to the visual
// tree.
winrt::Windows::UI::Composition::Visual CreateCursorVisual();
// Starts a timer used to update the position of the cursor visual as the
// gamepad updates the position.
void StartGamepadTimer();
// Stops time used to move the cursor.
void StopGamepadTimer();
// Configure callbacks to notify when Gamepad hardware events are received.
void ConfigureGamepad();
winrt::Windows::Foundation::Numerics::float3 GetScaledInput(
const winrt::Windows::Foundation::Numerics::float3 input);
// Object responsible for handling the low level interactions with the
// gamepad.
std::unique_ptr<GamepadWinUWP> game_pad_{nullptr};
// Pointer to a FlutterWindowsView that can be
// used to update engine windowing and input state.
WindowBindingHandlerDelegate* binding_handler_delegate_;
// Multiplier used to map controller velocity to an appropriate scroll input.
static constexpr double kControllerScrollMultiplier = 3;
// Multiplier used to scale gamepad input to mouse equivalent response.
static constexpr int kCursorScale = 7;
// Number of inactive seconds after which emulated cursor is hidden (ms).
static constexpr int kInactivePeriod = 5;
// Frequency to poll for input when no active interaction (ms).
static constexpr int kReducedPollingFrequency = 250;
// Frequency to poll for input when user is interacting (ms).
static constexpr int kNormalPollingFrequency = 10;
// Scancode definitions for dpad to cursor mapping.
static constexpr int kScanLeft = 75;
static constexpr int kScanRight = 77;
static constexpr int kScanUp = 72;
static constexpr int kScanDown = 80;
// Timer object used to update the cursor visual.
winrt::Windows::System::DispatcherQueueTimer cursor_move_timer_{nullptr};
// Timer object used to hide the mouse cursor when the user isn't interacting
// with the Gamepad.
winrt::Windows::System::DispatcherQueueTimer emulated_cursor_hide_timer_{
nullptr};
// Composition visual representing the emulated
// cursor visual.
winrt::Windows::UI::Composition::Visual cursor_visual_{nullptr};
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_CURSOR_WINUWP_H_

View File

@@ -1,218 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/game_pad_winuwp.h"
namespace flutter {
GamepadWinUWP::GamepadWinUWP(GamepadDualAxisCallback leftstick,
GamepadDualAxisCallback rightstick,
GamepadSingleAxisCallback lefttrigger,
GamepadSingleAxisCallback righttrigger,
GamepadButtonCallback pressedcb,
GamepadButtonCallback releasedcb,
GamepadAddedRemovedCallback changedcb)
: pressed_buttons_(winrt::Windows::Gaming::Input::GamepadButtons::None),
left_stick_x_value_(0),
left_stick_y_value_(0),
right_stick_x_value_(0),
right_stick_y_value_(0),
left_trigger_value_(0),
right_trigger_value_(0) {
left_stick_callback_ = leftstick;
right_stick_callback_ = rightstick;
left_trigger_callback_ = lefttrigger;
right_trigger_callback_ = righttrigger;
button_pressed_callback_ = pressedcb;
button_released_callback_ = releasedcb;
arrival_departure_callback_ = changedcb;
}
void GamepadWinUWP::Initialize() {
RefreshCachedGamepads();
winrt::Windows::Gaming::Input::Gamepad::GamepadAdded(
{this, &GamepadWinUWP::OnGamepadAdded});
winrt::Windows::Gaming::Input::Gamepad::GamepadRemoved(
{this, &GamepadWinUWP::OnGamepadRemoved});
const std::lock_guard<std::mutex> lock(gamepad_mutex_);
current_game_pad_ = GetLastGamepad();
}
bool GamepadWinUWP::HasController() const {
const std::lock_guard<std::mutex> lock(gamepad_mutex_);
return current_game_pad_ != nullptr;
}
void GamepadWinUWP::OnGamepadAdded(
winrt::Windows::Foundation::IInspectable const& th,
winrt::Windows::Gaming::Input::Gamepad const& args) {
enumerated_game_pads_.push_back(args);
{
const std::lock_guard<std::mutex> lock(gamepad_mutex_);
auto most_recent = GetLastGamepad();
if (current_game_pad_ != most_recent) {
current_game_pad_ = most_recent;
}
}
if (this->arrival_departure_callback_ != nullptr) {
arrival_departure_callback_();
}
}
void GamepadWinUWP::OnGamepadRemoved(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::Gaming::Input::Gamepad const& /*args*/) {
RefreshCachedGamepads();
}
void GamepadWinUWP::RefreshCachedGamepads() {
enumerated_game_pads_.clear();
auto gamepads = winrt::Windows::Gaming::Input::Gamepad::Gamepads();
for (auto gamepad : gamepads) {
enumerated_game_pads_.push_back(gamepad);
}
}
const winrt::Windows::Gaming::Input::Gamepad* GamepadWinUWP::GetLastGamepad()
const {
const winrt::Windows::Gaming::Input::Gamepad* gamepad = nullptr;
if (!enumerated_game_pads_.empty()) {
gamepad = &enumerated_game_pads_.back();
}
return gamepad;
}
static bool IsValid(double value) {
return value > 0.1 || value < -0.1;
}
void GamepadWinUWP::Process() {
{
const std::lock_guard<std::mutex> lock(gamepad_mutex_);
if (current_game_pad_ == nullptr) {
return;
}
last_reading_ = current_game_pad_->GetCurrentReading();
}
namespace gi = winrt::Windows::Gaming::Input;
GamepadButtonPressedInternal(last_reading_.Buttons);
// work out which values have changed since the last reading.
if (last_reading_.LeftThumbstickX != left_stick_x_value_) {
left_stick_x_value_ = last_reading_.LeftThumbstickX;
}
if (last_reading_.LeftThumbstickY != left_stick_y_value_) {
left_stick_y_value_ = last_reading_.LeftThumbstickY;
}
if (IsValid(left_stick_x_value_) || IsValid(left_stick_y_value_)) {
RaiseLeftStickMoved(left_stick_x_value_, left_stick_y_value_);
}
if (last_reading_.RightThumbstickX != right_stick_x_value_) {
right_stick_x_value_ = last_reading_.RightThumbstickX;
}
if (last_reading_.RightThumbstickY != right_stick_y_value_) {
right_stick_y_value_ = last_reading_.RightThumbstickY;
}
if (IsValid(right_stick_x_value_) || IsValid(right_stick_y_value_)) {
RaiseRightStickMoved(right_stick_x_value_, right_stick_y_value_);
}
// Raise the requisit events based on what's changed since the last reading
// was taken.
if (last_reading_.LeftTrigger != 0 &&
last_reading_.LeftTrigger != left_trigger_value_) {
left_trigger_value_ = last_reading_.LeftTrigger;
RaiseLeftTriggerMoved(left_trigger_value_);
}
if (last_reading_.RightTrigger != 0 &&
last_reading_.RightTrigger != right_trigger_value_) {
right_trigger_value_ = last_reading_.RightTrigger;
RaiseRightTriggerMoved(right_trigger_value_);
}
}
void GamepadWinUWP::GamepadButtonPressedInternal(
winrt::Windows::Gaming::Input::GamepadButtons state) {
namespace wgi = winrt::Windows::Gaming::Input;
static const wgi::GamepadButtons AllButtons[] = {
wgi::GamepadButtons::A, wgi::GamepadButtons::B,
wgi::GamepadButtons::DPadDown, wgi::GamepadButtons::DPadLeft,
wgi::GamepadButtons::DPadRight, wgi::GamepadButtons::DPadUp};
for (const auto e : AllButtons) {
// if button is pressed we have not sent a pressed already
if (((e & state) == e) && ((pressed_buttons_ & e) != e)) {
// send pressed callback
if (button_pressed_callback_ != nullptr) {
button_pressed_callback_(e);
}
// set the bit
pressed_buttons_ |= e;
}
// if button is not pressed and we have sent a pressed already
if (((e & state) != e) && ((pressed_buttons_ & e) == e)) {
// send callback
if (button_released_callback_ != nullptr) {
button_released_callback_(e);
}
// set the pressed bit
pressed_buttons_ &= ~e;
}
}
}
void GamepadWinUWP::RaiseGameGamepadButtonPressed(
winrt::Windows::Gaming::Input::GamepadButtons b) {}
void GamepadWinUWP::RaiseGameGamepadButtonReleased(
winrt::Windows::Gaming::Input::GamepadButtons b) {}
void GamepadWinUWP::RaiseLeftStickMoved(double x, double y) {
if (left_stick_callback_ != nullptr) {
left_stick_callback_(x, y);
}
}
void GamepadWinUWP::RaiseRightStickMoved(double x, double y) {
if (right_stick_callback_ != nullptr) {
right_stick_callback_(x, y);
}
}
void GamepadWinUWP::RaiseLeftTriggerMoved(double value) {
if (left_trigger_callback_ != nullptr) {
left_trigger_callback_(value);
}
}
void GamepadWinUWP::RaiseRightTriggerMoved(double value) {
if (right_trigger_callback_ != nullptr) {
right_trigger_callback_(value);
}
}
} // namespace flutter

View File

@@ -1,112 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_H_
#include <third_party/cppwinrt/generated/winrt/Windows.Foundation.Collections.h>
#include <third_party/cppwinrt/generated/winrt/Windows.Gaming.Input.h>
#include <functional>
#include <mutex>
#include <vector>
namespace flutter {
// Type definitions for callback funtions.
using GamepadSingleAxisCallback = std::function<void(double)>;
using GamepadDualAxisCallback = std::function<void(double, double)>;
using GamepadButtonCallback =
std::function<void(winrt::Windows::Gaming::Input::GamepadButtons)>;
using GamepadAddedRemovedCallback = std::function<void()>;
// A class abstraction for a Gamepad input device. Used to detect when devices
// come and go and provide event hooks for receiving scalar and discrete inputs
// from buttons and analog control surfaces.
class GamepadWinUWP {
public:
GamepadWinUWP(GamepadDualAxisCallback,
GamepadDualAxisCallback,
GamepadSingleAxisCallback,
GamepadSingleAxisCallback,
GamepadButtonCallback,
GamepadButtonCallback,
GamepadAddedRemovedCallback);
// Enumerate and cache any gamepads that are already connected and hook up
// handlers to detect arrival and departure of new devices.
void Initialize();
// Update state of the currently selected gamepad buttons and controllers if
// one exists. Raise resulting events with any attached event consumers. Must
// be called regularly in order to keep state updated.
void Process();
// There is a controller currently attached.
bool HasController() const;
private:
// Returns the last item in the collection of currently attached Gamepads.
const winrt::Windows::Gaming::Input::Gamepad* GetLastGamepad() const;
// Handers fired when a Gamepad is attached or removed from the system
// respectively.
void OnGamepadAdded(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::Gaming::Input::Gamepad const& args);
void OnGamepadRemoved(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::Gaming::Input::Gamepad const& args);
// Scan for attached Gamepad devices.
void RefreshCachedGamepads();
// Internal handler used to intercept raw device button presses.
void GamepadButtonPressedInternal(
winrt::Windows::Gaming::Input::GamepadButtons b);
// Functions to propagate controller events to external consumers.
void RaiseLeftStickMoved(double x, double y);
void RaiseRightStickMoved(double x, double y);
void RaiseLeftTriggerMoved(double value);
void RaiseRightTriggerMoved(double value);
void RaiseGameGamepadButtonPressed(
winrt::Windows::Gaming::Input::GamepadButtons);
void RaiseGameGamepadButtonReleased(
winrt::Windows::Gaming::Input::GamepadButtons);
// Storage for attached Gampads.
std::vector<winrt::Windows::Gaming::Input::Gamepad> enumerated_game_pads_;
// Storage for the last hardware state returned from the current controller.
winrt::Windows::Gaming::Input::GamepadReading last_reading_;
// Pointer to the current GamePad instance if there is one.
const winrt::Windows::Gaming::Input::Gamepad* current_game_pad_;
// Mutex to protect access to current gamepad.
mutable std::mutex gamepad_mutex_;
// Storage for most recently communicated trigger and stick values.
double left_trigger_value_;
double right_trigger_value_;
double left_stick_x_value_;
double left_stick_y_value_;
double right_stick_x_value_;
double right_stick_y_value_;
// Storage for most recently pressed buttons.
winrt::Windows::Gaming::Input::GamepadButtons pressed_buttons_;
// Storage for callbacks.
GamepadDualAxisCallback left_stick_callback_;
GamepadDualAxisCallback right_stick_callback_;
GamepadSingleAxisCallback left_trigger_callback_;
GamepadSingleAxisCallback right_trigger_callback_;
GamepadButtonCallback button_pressed_callback_;
GamepadButtonCallback button_released_callback_;
GamepadAddedRemovedCallback arrival_departure_callback_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_GAME_PAD_H_

View File

@@ -6,11 +6,6 @@
#include <windows.h>
#ifdef WINUWP
#include "third_party/cppwinrt/generated/winrt/Windows.System.h"
#include "third_party/cppwinrt/generated/winrt/Windows.UI.Core.h"
#endif
#include <iostream>
#include "flutter/shell/platform/common/json_message_codec.h"
@@ -70,49 +65,6 @@ static constexpr int kScrollLock = 1 << 13;
/// with the re-defined values declared above for compatibility with the Flutter
/// framework.
int GetModsForKeyState() {
#ifdef WINUWP
using namespace winrt::Windows::System;
using namespace winrt::Windows::UI::Core;
auto window = CoreWindow::GetForCurrentThread();
auto key_is_down = [&window](VirtualKey key) {
auto state = window.GetKeyState(key);
return (state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down;
};
int mods = 0;
if (key_is_down(VirtualKey::Shift))
mods |= kShift;
if (key_is_down(VirtualKey::LeftShift))
mods |= kShiftLeft;
if (key_is_down(VirtualKey::RightShift))
mods |= kShiftRight;
if (key_is_down(VirtualKey::Control))
mods |= kControl;
if (key_is_down(VirtualKey::LeftControl))
mods |= kControlLeft;
if (key_is_down(VirtualKey::RightControl))
mods |= kControlRight;
if (key_is_down(VirtualKey::Menu))
mods |= kAlt;
if (key_is_down(VirtualKey::LeftMenu))
mods |= kAltLeft;
if (key_is_down(VirtualKey::RightMenu))
mods |= kAltRight;
if (key_is_down(VirtualKey::LeftWindows))
mods |= kWinLeft;
if (key_is_down(VirtualKey::RightWindows))
mods |= kWinRight;
if (key_is_down(VirtualKey::CapitalLock))
mods |= kCapsLock;
if (key_is_down(VirtualKey::NumberKeyLock))
mods |= kNumLock;
if (key_is_down(VirtualKey::Scroll))
mods |= kScrollLock;
return mods;
#else
int mods = 0;
if (GetKeyState(VK_SHIFT) < 0)
@@ -144,7 +96,6 @@ int GetModsForKeyState() {
if (GetKeyState(VK_SCROLL) < 0)
mods |= kScrollLock;
return mods;
#endif
}
} // namespace

View File

@@ -335,11 +335,6 @@ void KeyboardKeyEmbedderHandler::UpdateLastSeenCritialKey(
void KeyboardKeyEmbedderHandler::SynchronizeCritialToggledStates(
int this_virtual_key,
bool is_down_event) {
// TODO(dkwingsmt) consider adding support for synchronizing key state for UWP
// https://github.com/flutter/flutter/issues/70202
#ifdef WINUWP
return;
#else
for (auto& kv : critical_keys_) {
UINT virtual_key = kv.first;
CriticalKey& key_info = kv.second;
@@ -381,17 +376,11 @@ void KeyboardKeyEmbedderHandler::SynchronizeCritialToggledStates(
key_info.toggled_on = should_toggled;
}
}
#endif
}
void KeyboardKeyEmbedderHandler::SynchronizeCritialPressedStates(
int this_virtual_key,
bool pressed_state_will_change) {
// TODO(dkwingsmt) consider adding support for synchronizing key state for UWP
// https://github.com/flutter/flutter/issues/70202
#ifdef WINUWP
return;
#else
for (auto& kv : critical_keys_) {
UINT virtual_key = kv.first;
CriticalKey& key_info = kv.second;
@@ -424,7 +413,6 @@ void KeyboardKeyEmbedderHandler::SynchronizeCritialPressedStates(
}
}
}
#endif
}
void KeyboardKeyEmbedderHandler::HandleResponse(bool handled, void* user_data) {
@@ -435,11 +423,6 @@ void KeyboardKeyEmbedderHandler::HandleResponse(bool handled, void* user_data) {
void KeyboardKeyEmbedderHandler::InitCriticalKeys(
MapVirtualKeyToScanCode map_virtual_key_to_scan_code) {
// TODO(dkwingsmt) consider adding support for synchronizing key state for UWP
// https://github.com/flutter/flutter/issues/70202
#ifdef WINUWP
return;
#else
auto createCheckedKey = [this, &map_virtual_key_to_scan_code](
UINT virtual_key, bool extended,
bool check_pressed,
@@ -479,7 +462,6 @@ void KeyboardKeyEmbedderHandler::InitCriticalKeys(
createCheckedKey(VK_SCROLL, false, true, true));
critical_keys_.emplace(VK_NUMLOCK,
createCheckedKey(VK_NUMLOCK, true, true, true));
#endif
}
void KeyboardKeyEmbedderHandler::ConvertUtf32ToUtf8_(char* out, char32_t ch) {

View File

@@ -43,36 +43,24 @@ static constexpr int kMaxPendingEvents = 1000;
// where the CtrlLeft is released early; the later, real, CtrlLeft up event will
// be ignored.
static bool IsKeyDownAltRight(int action, int virtual_key, bool extended) {
#ifdef WINUWP
return false;
#else
return virtual_key == VK_RMENU && extended &&
(action == WM_KEYDOWN || action == WM_SYSKEYDOWN);
#endif
}
// Returns true if this key is a key up event of AltRight.
//
// This is used to assist a corner case described in |IsKeyDownAltRight|.
static bool IsKeyUpAltRight(int action, int virtual_key, bool extended) {
#ifdef WINUWP
return false;
#else
return virtual_key == VK_RMENU && extended &&
(action == WM_KEYUP || action == WM_SYSKEYUP);
#endif
}
// Returns true if this key is a key down event of CtrlLeft.
//
// This is used to assist a corner case described in |IsKeyDownAltRight|.
static bool IsKeyDownCtrlLeft(int action, int virtual_key) {
#ifdef WINUWP
return false;
#else
return virtual_key == VK_LCONTROL &&
(action == WM_KEYDOWN || action == WM_SYSKEYDOWN);
#endif
}
// Returns if a character sent by Win32 is a dead key.

View File

@@ -1,117 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/platform_handler_winuwp.h"
#include "third_party/cppwinrt/generated/winrt/Windows.ApplicationModel.DataTransfer.h"
#include "third_party/cppwinrt/generated/winrt/Windows.Foundation.h"
#include "third_party/cppwinrt/generated/winrt/Windows.UI.Core.h"
#include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
static constexpr char kValueKey[] = "value";
namespace flutter {
// static
std::unique_ptr<PlatformHandler> PlatformHandler::Create(
BinaryMessenger* messenger,
FlutterWindowsView* view) {
return std::make_unique<PlatformHandlerWinUwp>(messenger, view);
}
PlatformHandlerWinUwp::PlatformHandlerWinUwp(BinaryMessenger* messenger,
FlutterWindowsView* view)
: PlatformHandler(messenger), view_(view) {}
PlatformHandlerWinUwp::~PlatformHandlerWinUwp() = default;
bool isWindowInForeground() {
auto activation_mode =
winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread()
.ActivationMode();
return activation_mode == winrt::Windows::UI::Core::CoreWindowActivationMode::
ActivatedInForeground;
}
void PlatformHandlerWinUwp::GetPlainText(
std::unique_ptr<MethodResult<rapidjson::Document>> result,
std::string_view key) {
// We call `Clipboard::GetContent()` when the application window is in
// focus, otherwise calling this will throw an error.
if (!isWindowInForeground()) {
result->Error(kClipboardError,
"Unable to read clipboard. The window is not focused.");
return;
}
auto content =
winrt::Windows::ApplicationModel::DataTransfer::Clipboard::GetContent();
// Calling `DataPackageView::GetTextAsync()` when the clipboard has no text
// content will throw an error.
if (!content.Contains(winrt::Windows::ApplicationModel::DataTransfer::
StandardDataFormats::Text())) {
result->Success(rapidjson::Document());
return;
}
// Waiting `DataPackageView::GetTextAsync()` using `TResult.get()` on the
// platform thread will causes the application stop, so we continue
// response on this callback.
content.GetTextAsync().Completed([result = std::move(result), key](
auto async_info, auto _async_status) {
auto clipboard_string = async_info.GetResults();
rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
document.AddMember(
rapidjson::Value(key.data(), allocator),
rapidjson::Value(fml::WideStringToUtf8(clipboard_string), allocator),
allocator);
result->Success(document);
});
}
void PlatformHandlerWinUwp::GetHasStrings(
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
bool has_string = false;
// We call `Clipboard::GetContent()` when the application window is in
// focus, otherwise calling this will throw an error.
if (isWindowInForeground()) {
has_string =
winrt::Windows::ApplicationModel::DataTransfer::Clipboard::GetContent()
.Contains(winrt::Windows::ApplicationModel::DataTransfer::
StandardDataFormats::Text());
}
rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
document.AddMember(rapidjson::Value(kValueKey, allocator),
rapidjson::Value(has_string), allocator);
result->Success(document);
}
void PlatformHandlerWinUwp::SetPlainText(
const std::string& text,
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
winrt::Windows::ApplicationModel::DataTransfer::DataPackage content;
content.SetText(fml::Utf8ToWideString(text));
winrt::Windows::ApplicationModel::DataTransfer::Clipboard::SetContent(
content);
result->Success();
}
void PlatformHandlerWinUwp::SystemSoundPlay(
const std::string& sound_type,
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
result->NotImplemented();
}
} // namespace flutter

View File

@@ -1,52 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WINUWP_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WINUWP_H_
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/platform_handler.h"
#include "rapidjson/document.h"
namespace flutter {
class FlutterWindowsView;
// UWP implementation of PlatformHandler.
class PlatformHandlerWinUwp : public PlatformHandler {
public:
explicit PlatformHandlerWinUwp(BinaryMessenger* messenger,
FlutterWindowsView* view);
virtual ~PlatformHandlerWinUwp();
protected:
// |PlatformHandler|
void GetPlainText(std::unique_ptr<MethodResult<rapidjson::Document>> result,
std::string_view key) override;
// |PlatformHandler|
void GetHasStrings(
std::unique_ptr<MethodResult<rapidjson::Document>> result) override;
// |PlatformHandler|
void SetPlainText(
const std::string& text,
std::unique_ptr<MethodResult<rapidjson::Document>> result) override;
// |PlatformHandler|
void SystemSoundPlay(
const std::string& sound_type,
std::unique_ptr<MethodResult<rapidjson::Document>> result) override;
private:
// A reference to the Flutter view.
FlutterWindowsView* view_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_HANDLER_WINUWP_H_

View File

@@ -13,11 +13,6 @@
#include "flutter_messenger.h"
#include "flutter_plugin_registrar.h"
#ifdef WINUWP
#include <windows.applicationmodel.activation.h>
#include <windows.ui.core.h>
#endif
#if defined(__cplusplus)
extern "C" {
#endif
@@ -76,22 +71,13 @@ typedef struct {
// The caller owns the returned reference, and is responsible for calling
// FlutterDesktopViewControllerDestroy. Returns a null pointer in the event of
// an error.
#ifdef WINUWP
// The CoreApplicationView implementation accepts a pointer to the host
// CoreApplicationView and view hookup is performed in the construction path.
FLUTTER_EXPORT FlutterDesktopViewControllerRef
FlutterDesktopViewControllerCreateFromCoreApplicationView(
ABI::Windows::ApplicationModel::Core::CoreApplicationView* window,
ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs* args,
FlutterDesktopEngineRef engine);
#else //! WINUWP
// The Win32 implementation accepts width, height
// with view hookup explicitly performed using the caller using HWND parenting.
//
// The Win32 implementation accepts width, height with view hookup explicitly
// performed using the caller using HWND parenting.
FLUTTER_EXPORT FlutterDesktopViewControllerRef
FlutterDesktopViewControllerCreate(int width,
int height,
FlutterDesktopEngineRef engine);
#endif
// Shuts down the engine instance associated with |controller|, and cleans up
// associated state.
@@ -114,7 +100,6 @@ FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller);
FLUTTER_EXPORT void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller);
#ifndef WINUWP
// Allows the Flutter engine and any interested plugins an opportunity to
// handle the given message.
//
@@ -127,7 +112,6 @@ FLUTTER_EXPORT bool FlutterDesktopViewControllerHandleTopLevelWindowProc(
WPARAM wparam,
LPARAM lparam,
LRESULT* result);
#endif
// ========== Engine ==========
@@ -157,7 +141,6 @@ FLUTTER_EXPORT bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine);
FLUTTER_EXPORT bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine,
const char* entry_point);
#ifndef WINUWP
// DEPRECATED: This is no longer necessary to call, Flutter will take care of
// processing engine messages transparently through DispatchMessage.
//
@@ -169,7 +152,6 @@ FLUTTER_EXPORT bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine,
// last return value from this function.
FLUTTER_EXPORT uint64_t
FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine);
#endif
FLUTTER_EXPORT void FlutterDesktopEngineReloadSystemFonts(
FlutterDesktopEngineRef engine);
@@ -192,15 +174,8 @@ FlutterDesktopEngineGetTextureRegistrar(
// ========== View ==========
#ifdef WINUWP
// Return backing CoreApplicationView for manipulation of CoreWindow and
// CoreTitleBar in host application.
FLUTTER_EXPORT ABI::Windows::ApplicationModel::Core::CoreApplicationView*
FlutterDesktopViewGetCoreApplicationView(FlutterDesktopViewRef view);
#else
// Return backing HWND for manipulation in host application.
FLUTTER_EXPORT HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view);
#endif
// ========== Plugin Registrar (extensions) ==========
// These are Windows-specific extensions to flutter_plugin_registrar.h
@@ -224,7 +199,6 @@ typedef bool (*FlutterDesktopWindowProcCallback)(HWND /* hwnd */,
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(
FlutterDesktopPluginRegistrarRef registrar);
#ifndef WINUWP
FLUTTER_EXPORT void
FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(
FlutterDesktopPluginRegistrarRef registrar,
@@ -235,7 +209,6 @@ FLUTTER_EXPORT void
FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate(
FlutterDesktopPluginRegistrarRef registrar,
FlutterDesktopWindowProcCallback delegate);
#endif
// ========== Freestanding Utilities ==========

View File

@@ -1,67 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/settings_plugin_winuwp.h"
#include "flutter/shell/platform/windows/system_utils.h"
#include "third_party/cppwinrt/generated/winrt/base.h"
namespace flutter {
// static
std::unique_ptr<SettingsPlugin> SettingsPlugin::Create(
BinaryMessenger* messenger,
TaskRunner* task_runner) {
return std::make_unique<SettingsPluginWinUwp>(messenger, task_runner);
}
SettingsPluginWinUwp::SettingsPluginWinUwp(BinaryMessenger* messenger,
TaskRunner* task_runner)
: SettingsPlugin(messenger, task_runner) {}
SettingsPluginWinUwp::~SettingsPluginWinUwp() {
StopWatching();
}
void SettingsPluginWinUwp::StartWatching() {
color_values_changed_ = ui_settings_.ColorValuesChanged(
{this, &SettingsPluginWinUwp::OnColorValuesChanged});
}
void SettingsPluginWinUwp::StopWatching() {
if (color_values_changed_.has_value()) {
ui_settings_.ColorValuesChanged(color_values_changed_.value());
color_values_changed_ = std::nullopt;
}
}
bool SettingsPluginWinUwp::GetAlwaysUse24HourFormat() {
return Prefer24HourTime(GetUserTimeFormat());
}
float SettingsPluginWinUwp::GetTextScaleFactor() {
return 1.0;
}
SettingsPlugin::PlatformBrightness
SettingsPluginWinUwp::GetPreferredBrightness() {
winrt::Windows::UI::ViewManagement::UISettings ui_settings;
auto background_color = ui_settings_.GetColorValue(
winrt::Windows::UI::ViewManagement::UIColorType::Background);
// Assuming that Windows return `Colors::Black` when being dark theme.
if (background_color == winrt::Windows::UI::Colors::Black()) {
return SettingsPlugin::PlatformBrightness::kDark;
} else {
return SettingsPlugin::PlatformBrightness::kLight;
}
}
void SettingsPluginWinUwp::OnColorValuesChanged(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::Foundation::IInspectable const&) {
task_runner_->RunNowOrPostTask([this]() { SendSettings(); });
}
} // namespace flutter

View File

@@ -1,56 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_WINUWP_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_WINUWP_H_
#include "flutter/shell/platform/windows/settings_plugin.h"
#include <memory>
#include <optional>
#include "third_party/cppwinrt/generated/winrt/Windows.Foundation.h"
#include "third_party/cppwinrt/generated/winrt/Windows.UI.ViewManagement.h"
namespace flutter {
// A settings plugin implementation for UWP.
class SettingsPluginWinUwp : public SettingsPlugin {
public:
explicit SettingsPluginWinUwp(BinaryMessenger* messenger,
TaskRunner* task_runner);
virtual ~SettingsPluginWinUwp();
// |SettingsPlugin|
void StartWatching() override;
// |SettingsPlugin|
void StopWatching() override;
protected:
// |SettingsPlugin|
bool GetAlwaysUse24HourFormat() override;
// |SettingsPlugin|
float GetTextScaleFactor() override;
// |SettingsPlugin|
PlatformBrightness GetPreferredBrightness() override;
private:
void OnColorValuesChanged(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::Foundation::IInspectable const&);
winrt::Windows::UI::ViewManagement::UISettings ui_settings_;
std::optional<winrt::event_token> color_values_changed_ = std::nullopt;
SettingsPluginWinUwp(const SettingsPluginWinUwp&) = delete;
SettingsPluginWinUwp& operator=(const SettingsPluginWinUwp&) = delete;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_WINUWP_H_

View File

@@ -1,83 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/system_utils.h"
#include <Windows.h>
#include <sstream>
#include "third_party/cppwinrt/generated/winrt/Windows.Foundation.Collections.h"
#include "third_party/cppwinrt/generated/winrt/Windows.System.UserProfile.h"
#include "flutter/fml/platform/win/wstring_conversion.h"
namespace flutter {
std::vector<LanguageInfo> GetPreferredLanguageInfo() {
std::vector<std::wstring> languages = GetPreferredLanguages();
std::vector<LanguageInfo> language_info;
for (auto language : languages) {
language_info.push_back(ParseLanguageName(language));
}
return language_info;
}
std::vector<std::wstring> GetPreferredLanguages() {
std::vector<std::wstring> languages;
auto platform_languages = winrt::Windows::System::UserProfile::
GlobalizationPreferences::Languages();
for (const auto& platform_language : platform_languages) {
languages.push_back(std::wstring{platform_language});
}
return languages;
}
LanguageInfo ParseLanguageName(std::wstring language_name) {
LanguageInfo info;
// Split by '-', discarding any suplemental language info (-x-foo).
std::vector<std::string> components;
std::istringstream stream(fml::WideStringToUtf8(language_name));
std::string component;
while (getline(stream, component, '-')) {
if (component == "x") {
break;
}
components.push_back(component);
}
// Determine which components are which.
info.language = components[0];
if (components.size() == 3) {
info.script = components[1];
info.region = components[2];
} else if (components.size() == 2) {
// A script code will always be four characters long.
if (components[1].size() == 4) {
info.script = components[1];
} else {
info.region = components[1];
}
}
return info;
}
std::wstring GetUserTimeFormat() {
// Rather than do the call-allocate-call-free dance, just use a sufficiently
// large buffer to handle any reasonable time format string.
const int kBufferSize = 100;
wchar_t buffer[kBufferSize];
if (::GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_STIMEFORMAT, buffer,
kBufferSize) == 0) {
return std::wstring();
}
return std::wstring(buffer, kBufferSize);
}
bool Prefer24HourTime(std::wstring time_format) {
return time_format.find(L"H") != std::wstring::npos;
}
} // namespace flutter

View File

@@ -1,53 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/task_runner_winuwp.h"
namespace flutter {
// static
std::unique_ptr<TaskRunner> TaskRunner::Create(
CurrentTimeProc get_current_time,
const TaskExpiredCallback& on_task_expired) {
return std::make_unique<TaskRunnerWinUwp>(get_current_time, on_task_expired);
}
TaskRunnerWinUwp::TaskRunnerWinUwp(CurrentTimeProc get_current_time,
const TaskExpiredCallback& on_task_expired)
: TaskRunner(get_current_time, on_task_expired) {
dispatcher_queue_ =
winrt::Windows::System::DispatcherQueue::GetForCurrentThread();
dispatcher_queue_timer_ = dispatcher_queue_.CreateTimer();
dispatcher_queue_timer_.Tick({this, &TaskRunnerWinUwp::OnTick});
}
TaskRunnerWinUwp::~TaskRunnerWinUwp() = default;
bool TaskRunnerWinUwp::RunsTasksOnCurrentThread() const {
return dispatcher_queue_.HasThreadAccess();
}
void TaskRunnerWinUwp::WakeUp() {
dispatcher_queue_.TryEnqueue([this]() { ProcessTasksAndScheduleNext(); });
}
void TaskRunnerWinUwp::OnTick(
winrt::Windows::System::DispatcherQueueTimer const&,
winrt::Windows::Foundation::IInspectable const&) {
ProcessTasks();
}
void TaskRunnerWinUwp::ProcessTasksAndScheduleNext() {
auto next = ProcessTasks();
if (next == std::chrono::nanoseconds::max()) {
dispatcher_queue_timer_.Stop();
} else {
dispatcher_queue_timer_.Interval(
std::chrono::duration_cast<winrt::Windows::Foundation::TimeSpan>(next));
dispatcher_queue_timer_.Start();
}
}
} // namespace flutter

View File

@@ -1,45 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WINUWP_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WINUWP_H_
#include <third_party/cppwinrt/generated/winrt/Windows.Foundation.h>
#include <third_party/cppwinrt/generated/winrt/Windows.System.h>
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/windows/task_runner.h"
namespace flutter {
// A custom task runner that uses a DispatcherQueue.
class TaskRunnerWinUwp : public TaskRunner {
public:
TaskRunnerWinUwp(CurrentTimeProc get_current_time,
const TaskExpiredCallback& on_task_expired);
virtual ~TaskRunnerWinUwp();
// |TaskRunner|
bool RunsTasksOnCurrentThread() const override;
protected:
// |TaskRunner|
void WakeUp() override;
private:
void OnTick(winrt::Windows::System::DispatcherQueueTimer const&,
winrt::Windows::Foundation::IInspectable const&);
void ProcessTasksAndScheduleNext();
winrt::Windows::System::DispatcherQueue dispatcher_queue_{nullptr};
winrt::Windows::System::DispatcherQueueTimer dispatcher_queue_timer_{nullptr};
TaskRunnerWinUwp(const TaskRunnerWinUwp&) = delete;
TaskRunnerWinUwp& operator=(const TaskRunnerWinUwp&) = delete;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TASK_RUNNER_WINUWP_H_

View File

@@ -1,86 +0,0 @@
#include "flutter/shell/platform/windows/uwptool_commands.h"
#include <iostream>
#include <sstream>
#include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/windows/uwptool_utils.h"
namespace flutter {
bool ListAppsCommand::ValidateArgs(const std::vector<std::string>& args) const {
return true;
}
int ListAppsCommand::Run(const std::vector<std::string>& args) const {
flutter::ApplicationStore app_store;
for (const flutter::Application& app : app_store.GetApps()) {
std::wcout << app.GetPackageFamily() << std::endl;
}
return 0;
}
bool InstallCommand::ValidateArgs(const std::vector<std::string>& args) const {
return args.size() >= 1;
}
int InstallCommand::Run(const std::vector<std::string>& args) const {
std::wstring package_uri = fml::Utf8ToWideString(args[0]);
std::vector<std::wstring> dependency_uris;
for (int i = 1; i < args.size(); ++i) {
dependency_uris.push_back(fml::Utf8ToWideString(args[i]));
}
flutter::ApplicationStore app_store;
if (app_store.Install(package_uri, dependency_uris)) {
std::wcerr << L"Installed application " << package_uri << std::endl;
return 0;
}
return 1;
}
bool UninstallCommand::ValidateArgs(
const std::vector<std::string>& args) const {
return args.size() >= 1;
}
int UninstallCommand::Run(const std::vector<std::string>& args) const {
flutter::ApplicationStore app_store;
std::wstring package_family = fml::Utf8ToWideString(args[0]);
return app_store.Uninstall(package_family) ? 0 : 1;
}
bool LaunchCommand::ValidateArgs(const std::vector<std::string>& args) const {
return args.size() >= 1;
}
int LaunchCommand::Run(const std::vector<std::string>& args) const {
// Get the package family name.
std::string package_family = args[0];
// Concatenate the remaining args, comma-separated.
std::ostringstream app_args;
for (int i = 1; i < args.size(); ++i) {
app_args << args[i];
if (i < args.size() - 1) {
app_args << ",";
}
}
flutter::ApplicationStore app_store;
int process_id = app_store.Launch(fml::Utf8ToWideString(package_family),
fml::Utf8ToWideString(app_args.str()));
if (process_id == -1) {
std::cerr << "error: Failed to launch app with package family "
<< package_family << " arguments [" << app_args.str() << "]"
<< std::endl;
return 1;
}
// Write an informative message for the user to stderr.
std::cerr << "Launched app with package family " << package_family
<< ". PID: " << std::endl;
// Write the PID to stdout. The flutter tool reads this value in.
std::cout << process_id << std::endl;
return 0;
}
} // namespace flutter

View File

@@ -1,98 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_COMMANDS_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_COMMANDS_H_
#include <string>
#include <vector>
namespace flutter {
// A uwptool command that can be invoked as the first argument of the uwptool
// arguments list.
class Command {
public:
Command(const std::string_view name,
const std::string_view usage,
const std::string_view description)
: name_(name), usage_(usage), description_(description) {}
virtual ~Command() {}
std::string GetCommandName() const { return name_; }
std::string GetUsage() const { return usage_; }
std::string GetDescription() const { return description_; }
// Returns true if the arguments list constitute valid arguments for this
// command.
virtual bool ValidateArgs(const std::vector<std::string>& args) const = 0;
// Invokes the command with the specified arguments list.
virtual int Run(const std::vector<std::string>& args) const = 0;
private:
std::string name_;
std::string usage_;
std::string description_;
};
// Command that prints a list of all installed applications on the system.
class ListAppsCommand : public Command {
public:
ListAppsCommand()
: Command("listapps",
"listapps",
"List installed apps by package family name") {}
bool ValidateArgs(const std::vector<std::string>& args) const override;
int Run(const std::vector<std::string>& args) const override;
};
// Command that installs the specified package and dependencies.
class InstallCommand : public Command {
public:
InstallCommand()
: Command("install",
"install PACKAGE_URI DEPENDENCY_URI...",
"Install the specified package with all listed dependencies") {}
bool ValidateArgs(const std::vector<std::string>& args) const override;
int Run(const std::vector<std::string>& args) const override;
};
// Command that uninstalls the specified package.
class UninstallCommand : public Command {
public:
UninstallCommand()
: Command("uninstall",
"uninstall PACKAGE_FAMILY_NAME",
"Uninstall the specified package") {}
bool ValidateArgs(const std::vector<std::string>& args) const override;
int Run(const std::vector<std::string>& args) const override;
};
// Launches the app installed on the system with the specified package.
//
// Returns -1 if no matching app, or multiple matching apps are found, or if
// the app fails to launch. Otherwise, the process ID of the launched app is
// returned.
class LaunchCommand : public Command {
public:
LaunchCommand()
: Command("launch",
"launch PACKAGE_FAMILY_NAME",
"Launch the specified package") {}
bool ValidateArgs(const std::vector<std::string>& args) const override;
int Run(const std::vector<std::string>& args) const override;
private:
int LaunchApp(const std::wstring_view package_family,
const std::wstring_view args) const;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_COMMANDS_H_

View File

@@ -1,75 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <Windows.h>
#include <winrt/base.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "flutter/fml/command_line.h"
#include "flutter/shell/platform/windows/uwptool_commands.h"
namespace {
using CommandMap = std::map<std::string, std::unique_ptr<flutter::Command>>;
// Prints the command usage to stderr.
void PrintUsage(const CommandMap& commands) {
std::cerr << "usage: uwptool COMMAND [ARGUMENTS]" << std::endl;
std::cerr << std::endl;
std::cerr << "Available commands:" << std::endl;
for (const auto& [command_name, command] : commands) {
std::cerr << " " << std::left << std::setw(15) << command_name
<< command->GetDescription() << std::endl;
}
}
void PrintCommandUsage(const flutter::Command& command) {
std::cerr << "usage: uwptool " << command.GetUsage() << std::endl;
}
} // namespace
int main(int argc, char** argv) {
winrt::init_apartment();
// Register commands alphabetically, to make usage string clearer.
CommandMap commands;
commands.emplace("install", std::make_unique<flutter::InstallCommand>());
commands.emplace("launch", std::make_unique<flutter::LaunchCommand>());
commands.emplace("listapps", std::make_unique<flutter::ListAppsCommand>());
commands.emplace("uninstall", std::make_unique<flutter::UninstallCommand>());
// Parse command line arguments.
auto command_line = fml::CommandLineFromArgcArgv(argc, argv);
if (command_line.positional_args().size() < 1) {
PrintUsage(commands);
return 1;
}
std::vector<std::string> command_args(
command_line.positional_args().begin() + 1,
command_line.positional_args().end());
// Determine the command.
const std::string& command_name = command_line.positional_args()[0];
const auto& it = commands.find(command_name);
if (it == commands.end()) {
std::cerr << "Unknown command: " << command_name << std::endl;
PrintUsage(commands);
return 1;
}
// Run the command.
auto& command = it->second;
if (!command->ValidateArgs(command_args)) {
PrintCommandUsage(*command);
return 1;
}
return command->Run(command_args);
}

View File

@@ -1,158 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/uwptool_utils.h"
#include <Windows.h>
#include <Winreg.h>
#include <shobjidl_core.h>
#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Management.Deployment.h>
#include <winrt/base.h>
#include <iostream>
#include <optional>
#include <string>
#include <unordered_set>
#include <vector>
namespace flutter {
std::vector<Application> ApplicationStore::GetApps() const {
using winrt::Windows::ApplicationModel::Package;
using winrt::Windows::Management::Deployment::PackageManager;
// Find packages for the current user (default for empty string).
std::vector<Application> apps;
try {
PackageManager package_manager;
for (const Package& package : package_manager.FindPackagesForUser(L"")) {
apps.emplace_back(package.Id().Name().c_str(),
package.Id().FamilyName().c_str(),
package.Id().FullName().c_str());
}
} catch (winrt::hresult_error error) {
return {};
}
return apps;
}
std::vector<Application> ApplicationStore::GetApps(
const std::wstring_view package_family) const {
using winrt::Windows::ApplicationModel::Package;
using winrt::Windows::Management::Deployment::PackageManager;
// Find packages for the current user (default for empty string).
std::vector<Application> apps;
try {
PackageManager package_manager;
for (const Package& package :
package_manager.FindPackagesForUser(L"", package_family)) {
apps.emplace_back(package.Id().Name().c_str(),
package.Id().FamilyName().c_str(),
package.Id().FullName().c_str());
}
} catch (winrt::hresult_error error) {
return {};
}
return apps;
}
bool ApplicationStore::Install(
const std::wstring_view package_uri,
const std::vector<std::wstring>& dependency_uris) {
using winrt::Windows::Foundation::AsyncStatus;
using winrt::Windows::Foundation::Uri;
using winrt::Windows::Foundation::Collections::IVector;
using winrt::Windows::Management::Deployment::DeploymentOptions;
using winrt::Windows::Management::Deployment::PackageManager;
Uri package(package_uri);
IVector<Uri> dependencies = winrt::single_threaded_vector<Uri>();
for (const auto& dependency_uri : dependency_uris) {
dependencies.Append(Uri(dependency_uri));
}
PackageManager package_manager;
auto operation = package_manager.AddPackageAsync(package, dependencies,
DeploymentOptions::None);
operation.get();
if (operation.Status() == AsyncStatus::Completed) {
return true;
} else if (operation.Status() == AsyncStatus::Canceled) {
return false;
} else if (operation.Status() == AsyncStatus::Error) {
auto result = operation.GetResults();
std::wcerr << L"error: install failed for package " << package_uri
<< L" with error: " << result.ErrorText().c_str() << std::endl;
return false;
}
return false;
}
bool ApplicationStore::Uninstall(const std::wstring_view package_family) {
bool success = true;
for (const Application& app : GetApps(package_family)) {
if (UninstallPackage(app.GetPackageFullName())) {
std::wcerr << L"Uninstalled application " << app.GetPackageFullName()
<< std::endl;
} else {
std::wcerr << L"error: Failed to uninstall application "
<< app.GetPackageFullName() << std::endl;
success = false;
}
}
return success;
}
bool ApplicationStore::UninstallPackage(
const std::wstring_view package_full_name) {
using winrt::Windows::Foundation::AsyncStatus;
using winrt::Windows::Management::Deployment::PackageManager;
using winrt::Windows::Management::Deployment::RemovalOptions;
PackageManager package_manager;
auto operation = package_manager.RemovePackageAsync(
package_full_name, RemovalOptions::RemoveForAllUsers);
operation.get();
if (operation.Status() == AsyncStatus::Completed) {
return true;
} else if (operation.Status() == AsyncStatus::Canceled) {
return false;
} else if (operation.Status() == AsyncStatus::Error) {
auto result = operation.GetResults();
std::wcerr << L"error: uninstall failed for package " << package_full_name
<< L" with error: " << result.ErrorText().c_str() << std::endl;
return false;
}
return false;
}
int ApplicationStore::Launch(const std::wstring_view package_family,
const std::wstring_view args) {
// Create the ApplicationActivationManager.
winrt::com_ptr<IApplicationActivationManager> activation_manager;
HRESULT hresult = ::CoCreateInstance(
CLSID_ApplicationActivationManager, nullptr, CLSCTX_INPROC_SERVER,
IID_IApplicationActivationManager, activation_manager.put_void());
if (FAILED(hresult)) {
return -1;
}
// Launch the application.
DWORD process_id;
ACTIVATEOPTIONS options = AO_NONE;
std::wstring app_user_model_id = std::wstring(package_family) + L"!App";
hresult = activation_manager->ActivateApplication(
app_user_model_id.data(), args.data(), options, &process_id);
if (FAILED(hresult)) {
return -1;
}
return process_id;
}
} // namespace flutter

View File

@@ -1,95 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_UTILS_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_UTILS_H_
#include <optional>
#include <string>
#include <vector>
namespace flutter {
// A UWP application.
class Application {
public:
Application(const std::wstring_view package_name,
const std::wstring_view package_family,
const std::wstring_view package_full_name)
: package_name_(package_name),
package_family_(package_family),
package_full_name_(package_full_name) {}
Application(const Application& other) = default;
Application& operator=(const Application& other) = default;
// Returns the package name.
//
// The package name is a globally unique name that represents the 'friendly'
// name of a package.
std::wstring GetPackageName() const { return package_name_; }
// Returns the package family.
//
// The package family is a serialized form of the package identifiers that
// includes the package name and publisher.
std::wstring GetPackageFamily() const { return package_family_; }
// Returns the package full name.
//
// The package full name is a serialized form of the package identifiers that
// includes a particular version of the package on the computer. It encodes
// package name, publisher, architecture and version information.
std::wstring GetPackageFullName() const { return package_full_name_; }
private:
std::wstring package_name_;
std::wstring package_family_;
std::wstring package_full_name_;
};
// The machine-local store of installed applications.
class ApplicationStore {
public:
ApplicationStore() = default;
// Prevent copying.
ApplicationStore(const ApplicationStore& other) = delete;
ApplicationStore& operator=(const ApplicationStore& other) = delete;
// Returns all installed applications.
std::vector<Application> GetApps() const;
// Returns all installed applications with the specified family name.
std::vector<Application> GetApps(
const std::wstring_view package_family) const;
// Installs the specified application.
//
// Installs the application located at package_uri with the specified
// dependencies.
bool Install(const std::wstring_view package_uri,
const std::vector<std::wstring>& dependency_uris);
// Uninstalls all application packages in the specified package family.
//
// Returns true on success.
bool Uninstall(const std::wstring_view package_family);
// Launches the application with the specified list of launch arguments.
//
// Returns the process ID on success, or -1 on failure.
int Launch(const std::wstring_view package_family,
const std::wstring_view args);
private:
// Uninstalls the specified application package.
//
// Returns true on success.
bool UninstallPackage(const std::wstring_view package_full_name);
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_UWPTOOL_UTILS_H_

View File

@@ -1,50 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/uwptool_utils.h"
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
// TODO(cbracken): write registry values to be tested, then cleanup, refactor
// to support a mock registry.
// https://github.com/flutter/flutter/issues/82095
// Verify that at least one Microsoft app (e.g. Microsoft.WindowsCalculator) is
// installed and can be found.
TEST(ApplicationStore, GetApps) {
ApplicationStore store;
std::vector<Application> apps = store.GetApps();
EXPECT_FALSE(apps.empty());
auto ms_pos = std::find_if(apps.begin(), apps.end(), [](const auto& app) {
return app.GetPackageFamily().rfind(L"Microsoft.", 0);
});
EXPECT_TRUE(ms_pos != apps.end());
}
// Verify that we can look up an app by family name.
TEST(ApplicationStore, GetAppsByPackageFamily) {
ApplicationStore store;
std::vector<Application> all_apps = store.GetApps();
EXPECT_FALSE(all_apps.empty());
Application app = all_apps[0];
std::vector<Application> found_apps = store.GetApps(app.GetPackageFamily());
ASSERT_FALSE(found_apps.empty());
for (const Application& found_app : found_apps) {
EXPECT_EQ(found_app.GetPackageName(), app.GetPackageName());
EXPECT_EQ(found_app.GetPackageFamily(), app.GetPackageFamily());
}
}
} // namespace testing
} // namespace flutter

View File

@@ -14,11 +14,6 @@
#include "flutter/shell/platform/windows/public/flutter_windows.h"
#include "flutter/shell/platform/windows/window_binding_handler_delegate.h"
#ifdef WINUWP
#include <third_party/cppwinrt/generated/winrt/Windows.ApplicationModel.Activation.h>
#include <third_party/cppwinrt/generated/winrt/Windows.UI.Composition.h>
#endif
namespace flutter {
class FlutterWindowsView;
@@ -30,23 +25,11 @@ struct PhysicalWindowBounds {
};
// Type representing an underlying platform window.
#ifdef WINUWP
using PlatformWindow =
winrt::Windows::ApplicationModel::Core::CoreApplicationView;
#else
using PlatformWindow = HWND;
#endif
// Type representing a platform object that can be accepted by the Angle
// rendering layer to bind to and render pixels into.
#ifdef WINUWP
using WindowsRenderTarget =
std::variant<winrt::Windows::UI::Composition::SpriteVisual,
winrt::Windows::UI::Core::CoreWindow,
HWND>;
#else
using WindowsRenderTarget = std::variant<HWND>;
#endif
// Abstract class for binding Windows platform windows to Flutter views.
class WindowBindingHandler {

View File

@@ -54,11 +54,9 @@ class WindowBindingHandlerDelegate {
// Typically called by currently configured WindowBindingHandler
virtual void OnText(const std::u16string&) = 0;
// TODO(clarkezone) refactor delegate to avoid needing win32 magic values in
// UWP implementation https://github.com/flutter/flutter/issues/70202 Notifies
// delegate that backing window size has received key press. Should return
// true if the event was handled and should not be propagated. Typically
// called by currently configured WindowBindingHandler.
// Notifies delegate that backing window size has received key press. Should
// return true if the event was handled and should not be propagated.
// Typically called by currently configured WindowBindingHandler.
virtual void OnKey(int key,
int scancode,
int action,

View File

@@ -217,12 +217,13 @@ std::string GetAbsoluteFilePath(const std::string& path) {
if (ret == 0 || ret > MAX_PATH) {
std::string result;
if (GetLastError() == ERROR_ACCESS_DENIED) {
// In UWP, GetFinalPathNameByHandle requires the app to declare
// appropriate capabilities in the app's package manifest. Some of these
// capabilities are not permitted in shipping apps on the app store, but
// may be fine for development/debugging scenarios. If we can't resolve
// the full path due to insufficient access, but have verified the handle
// is valid, return AbsolutePath of the original path.
// In sandboxed apps, GetFinalPathNameByHandle requires the app to
// declare appropriate capabilities in the app's package manifest. Some
// of these capabilities are not permitted in shipping apps on the app
// store, but may be fine for development/debugging scenarios. If we
// can't resolve the full path due to insufficient access, but have
// verified the handle is valid, return AbsolutePath of the original
// path.
//
// https://github.com/flutter/flutter/issues/79609
result = AbsolutePath(path);

View File

@@ -1,5 +1,5 @@
package: flutter/cppwinrt/win-amd64
description: C++/WinRT tool used for building WinRT headers for Windows UWP builds
description: C++/WinRT tool used for building WinRT headers for Windows UWP/App SDK builds
install_mode: copy
# The temp directory into which the nupkg archive is extracted.
root: tmp