mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Significantly improves the behavior of non-ASCII text input on Windows. Correctly processes incoming character events as UTF-16, and for now uses UTF-32 for the text model so that the existing index-based logic will work much more often. Future work is still needed, but this will handle far more cases correctly.
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
// 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/key_event_handler.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/json_message_codec.h"
|
|
|
|
static constexpr char kChannelName[] = "flutter/keyevent";
|
|
|
|
static constexpr char kKeyCodeKey[] = "keyCode";
|
|
static constexpr char kKeyMapKey[] = "keymap";
|
|
static constexpr char kTypeKey[] = "type";
|
|
|
|
static constexpr char kAndroidKeyMap[] = "android";
|
|
static constexpr char kKeyUp[] = "keyup";
|
|
static constexpr char kKeyDown[] = "keydown";
|
|
|
|
namespace flutter {
|
|
|
|
KeyEventHandler::KeyEventHandler(flutter::BinaryMessenger* messenger)
|
|
: channel_(
|
|
std::make_unique<flutter::BasicMessageChannel<rapidjson::Document>>(
|
|
messenger,
|
|
kChannelName,
|
|
&flutter::JsonMessageCodec::GetInstance())) {}
|
|
|
|
KeyEventHandler::~KeyEventHandler() = default;
|
|
|
|
void KeyEventHandler::CharHook(Win32FlutterWindow* window,
|
|
char32_t code_point) {}
|
|
|
|
void KeyEventHandler::KeyboardHook(Win32FlutterWindow* window,
|
|
int key,
|
|
int scancode,
|
|
int action,
|
|
int mods) {
|
|
// TODO: Translate to a cross-platform key code system rather than passing
|
|
// the native key code.
|
|
rapidjson::Document event(rapidjson::kObjectType);
|
|
auto& allocator = event.GetAllocator();
|
|
event.AddMember(kKeyCodeKey, key, allocator);
|
|
event.AddMember(kKeyMapKey, kAndroidKeyMap, allocator);
|
|
|
|
switch (action) {
|
|
case WM_KEYDOWN:
|
|
event.AddMember(kTypeKey, kKeyDown, allocator);
|
|
break;
|
|
case WM_KEYUP:
|
|
event.AddMember(kTypeKey, kKeyUp, allocator);
|
|
break;
|
|
default:
|
|
std::cerr << "Unknown key event action: " << action << std::endl;
|
|
return;
|
|
}
|
|
channel_->Send(event);
|
|
}
|
|
|
|
} // namespace flutter
|