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 2f12763143..fc3478c43b 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_window_winuwp.cc @@ -268,10 +268,10 @@ void FlutterWindowWinUWP::OnKeyUp( auto status = args.KeyStatus(); unsigned int scancode = status.ScanCode; int key = static_cast(args.VirtualKey()); - char32_t chararacter = static_cast(key | 32); int action = 0x0101; - binding_handler_delegate_->OnKey(key, scancode, action, chararacter, - false /* extended */, true /* was_down */); + binding_handler_delegate_->OnKey(key, scancode, action, 0, + status.IsExtendedKey /* extended */, + status.WasKeyDown /* was_down */); } void FlutterWindowWinUWP::OnKeyDown( @@ -284,10 +284,10 @@ void FlutterWindowWinUWP::OnKeyDown( auto status = args.KeyStatus(); unsigned int scancode = status.ScanCode; int key = static_cast(args.VirtualKey()); - char32_t chararacter = static_cast(key | 32); int action = 0x0100; - binding_handler_delegate_->OnKey(key, scancode, action, chararacter, - false /* extended */, false /* was_down */); + binding_handler_delegate_->OnKey(key, scancode, action, 0, + status.IsExtendedKey /* extended */, + status.WasKeyDown /* was_down */); } void FlutterWindowWinUWP::OnCharacterReceived( diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc index 93d2aae634..a8916053f9 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_view.cc @@ -78,7 +78,17 @@ void FlutterWindowsView::RegisterKeyboardHandlers( // of the event. In order to allow the same real event in the future, the // handler is "toggled" when events pass through, therefore the redispatching // algorithm does not allow more than 1 handler that takes |SendInput|. - auto key_handler = std::make_unique(SendInput); +#ifdef WINUWP + flutter::KeyboardKeyHandler::EventRedispatcher redispatch_event = nullptr; + flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = + nullptr; +#else + flutter::KeyboardKeyHandler::EventRedispatcher redispatch_event = SendInput; + flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = + GetKeyState; +#endif + auto key_handler = + std::make_unique(redispatch_event); key_handler->AddDelegate( std::make_unique(messenger)); key_handler->AddDelegate(std::make_unique( @@ -86,7 +96,7 @@ void FlutterWindowsView::RegisterKeyboardHandlers( void* user_data) { return engine_->SendKeyEvent(event, callback, user_data); }, - GetKeyState)); + get_key_state)); AddKeyboardHandler(std::move(key_handler)); AddKeyboardHandler( std::make_unique(messenger, this)); diff --git a/engine/src/flutter/shell/platform/windows/keyboard_key_channel_handler.cc b/engine/src/flutter/shell/platform/windows/keyboard_key_channel_handler.cc index a5b0790b98..c2601e3c71 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_key_channel_handler.cc +++ b/engine/src/flutter/shell/platform/windows/keyboard_key_channel_handler.cc @@ -55,6 +55,11 @@ static constexpr int kScrollLock = 1 << 13; /// with the re-defined values declared above for compatibility with the Flutter /// framework. int GetModsForKeyState() { + // TODO(clarkezone) need to add support for get modifier state for UWP + // https://github.com/flutter/flutter/issues/70202 +#ifdef WINUWP + return 0; +#else int mods = 0; if (GetKeyState(VK_SHIFT) < 0) @@ -86,6 +91,7 @@ int GetModsForKeyState() { if (GetKeyState(VK_SCROLL) < 0) mods |= kScrollLock; return mods; +#endif } } // namespace diff --git a/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.cc b/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.cc index ad34793ca2..cacc64a233 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.cc +++ b/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.cc @@ -56,9 +56,7 @@ constexpr SHORT kStateMaskPressed = 0x80; } // namespace KeyboardKeyEmbedderHandler::KeyboardKeyEmbedderHandler( - std::function send_event, + SendEvent send_event, GetKeyStateHandler get_key_state) : sendEvent_(send_event), get_key_state_(get_key_state), response_id_(1) { InitCriticalKeys(); @@ -264,6 +262,11 @@ void KeyboardKeyEmbedderHandler::UpdateLastSeenCritialKey( void KeyboardKeyEmbedderHandler::SynchronizeCritialToggledStates( int toggle_virtual_key) { + // 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; @@ -301,9 +304,15 @@ void KeyboardKeyEmbedderHandler::SynchronizeCritialToggledStates( key_info.toggled_on = should_toggled; } } +#endif } void KeyboardKeyEmbedderHandler::SynchronizeCritialPressedStates() { + // 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; @@ -333,6 +342,7 @@ void KeyboardKeyEmbedderHandler::SynchronizeCritialPressedStates() { } } } +#endif } void KeyboardKeyEmbedderHandler::HandleResponse(bool handled, void* user_data) { @@ -342,6 +352,11 @@ void KeyboardKeyEmbedderHandler::HandleResponse(bool handled, void* user_data) { } void KeyboardKeyEmbedderHandler::InitCriticalKeys() { + // 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](UINT virtual_key, bool extended, bool check_pressed, bool check_toggled) -> CriticalKey { @@ -374,6 +389,7 @@ 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) { diff --git a/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.h b/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.h index 3dc8753498..edc90f207b 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.h +++ b/engine/src/flutter/shell/platform/windows/keyboard_key_embedder_handler.h @@ -37,7 +37,8 @@ class KeyboardKeyEmbedderHandler // of the SendEvent call might be nullptr. // // Use `get_key_state` to define how the class should get a reliable result of - // the state for a virtual key. It's typically Win32's GetKeyState. + // the state for a virtual key. It's typically Win32's GetKeyState, but can + // also be nullptr (for UWP). explicit KeyboardKeyEmbedderHandler(SendEvent send_event, GetKeyStateHandler get_key_state); diff --git a/engine/src/flutter/shell/platform/windows/keyboard_key_handler.cc b/engine/src/flutter/shell/platform/windows/keyboard_key_handler.cc index d21a9f9577..a1137644d7 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_key_handler.cc +++ b/engine/src/flutter/shell/platform/windows/keyboard_key_handler.cc @@ -38,9 +38,7 @@ KeyboardKeyHandler::KeyboardKeyHandlerDelegate::~KeyboardKeyHandlerDelegate() = default; KeyboardKeyHandler::KeyboardKeyHandler(EventRedispatcher redispatch_event) - : redispatch_event_(redispatch_event), last_sequence_id_(1) { - assert(redispatch_event_ != nullptr); -} + : redispatch_event_(redispatch_event), last_sequence_id_(1) {} KeyboardKeyHandler::~KeyboardKeyHandler() = default; @@ -57,6 +55,12 @@ size_t KeyboardKeyHandler::RedispatchedCount() { } void KeyboardKeyHandler::RedispatchEvent(std::unique_ptr event) { + // TODO(dkwingsmt) consider adding support for redispatching events for UWP + // in order to support add-to-app. + // https://github.com/flutter/flutter/issues/70202 +#ifdef WINUWP + return; +#else uint8_t scancode = event->scancode; char32_t character = event->character; @@ -81,6 +85,7 @@ void KeyboardKeyHandler::RedispatchEvent(std::unique_ptr event) { "with scancode " << scancode << " (character " << character << ")" << std::endl; } +#endif } bool KeyboardKeyHandler::KeyboardHook(FlutterWindowsView* view, diff --git a/engine/src/flutter/shell/platform/windows/keyboard_key_handler.h b/engine/src/flutter/shell/platform/windows/keyboard_key_handler.h index b7856b55e0..811ee30b04 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_key_handler.h +++ b/engine/src/flutter/shell/platform/windows/keyboard_key_handler.h @@ -58,7 +58,8 @@ class KeyboardKeyHandler : public KeyboardHandlerBase { // Create a KeyboardKeyHandler and specify where to redispatch events. // - // The |redispatch_event| is typically |SendInput|. + // The |redispatch_event| is typically |SendInput|, but can also be nullptr + // (for UWP). explicit KeyboardKeyHandler(EventRedispatcher redispatch_event); ~KeyboardKeyHandler();