[UWP] Implement setting cursor icon. (flutter/engine#28098)

This commit is contained in:
moko256 2021-08-27 09:15:46 +09:00 committed by GitHub
parent ab8ca80751
commit 4836ff6b3c
2 changed files with 56 additions and 3 deletions

View File

@ -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<std::string, const wchar_t*>{
{"allScroll", IDC_SIZEALL},

View File

@ -4,6 +4,8 @@
#include "flutter/shell/platform/windows/flutter_window_winuwp.h"
#include <map>
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<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);
}
}
} // 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) {