From 4836ff6b3cfccfc606ce5228867d7b08dc03ed2b Mon Sep 17 00:00:00 2001 From: moko256 Date: Fri, 27 Aug 2021 09:15:46 +0900 Subject: [PATCH] [UWP] Implement setting cursor icon. (flutter/engine#28098) --- .../platform/windows/flutter_window_win32.cc | 2 +- .../platform/windows/flutter_window_winuwp.cc | 57 ++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc b/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc index 9983de587e4..064eb711b2a 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_win32.cc @@ -25,7 +25,7 @@ constexpr int kScrollOffsetMultiplier = 20; // Returns the arrow cursor for unknown constants. // // This map must be kept in sync with Flutter framework's -// rendering/mouse_cursor.dart. +// services/mouse_cursor.dart. static HCURSOR GetCursorByName(const std::string& cursor_name) { static auto* cursors = new std::map{ {"allScroll", IDC_SIZEALL}, diff --git a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc index c64310da8fd..634a2c71a01 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc @@ -4,6 +4,8 @@ #include "flutter/shell/platform/windows/flutter_window_winuwp.h" +#include + namespace flutter { // Multipler used to map controller velocity to an appropriate scroll input. @@ -14,6 +16,58 @@ static constexpr double kControllerScrollMultiplier = 3; // touch. See https://github.com/flutter/flutter/issues/70201 static constexpr int32_t kDefaultPointerDeviceId = 0; +// Maps a Flutter cursor name to an 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 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); + } +} + +} // namespace + FlutterWindowWinUWP::FlutterWindowWinUWP( ABI::Windows::ApplicationModel::Core::CoreApplicationView* applicationview) { @@ -72,8 +126,7 @@ PhysicalWindowBounds FlutterWindowWinUWP::GetPhysicalWindowBounds() { } void FlutterWindowWinUWP::UpdateFlutterCursor(const std::string& cursor_name) { - // TODO(clarkezone): add support for Flutter cursors: - // https://github.com/flutter/flutter/issues/70199 + window_.PointerCursor(GetCursorByName(cursor_name)); } void FlutterWindowWinUWP::OnCursorRectUpdated(const Rect& rect) {