From dc0a27764fe37c56935d80fb26bab3931fdc8e02 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Fri, 6 Sep 2019 01:25:37 +0800 Subject: [PATCH 1/9] Improve input method and Unicode character display(#30661) --- shell/platform/common/cpp/text_input_model.cc | 16 ++++++++++++---- shell/platform/common/cpp/text_input_model.h | 10 ++++++---- shell/platform/glfw/text_input_plugin.cc | 2 +- shell/platform/windows/text_input_plugin.cc | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index 41231a6d611d4..79d602dbe8274 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -26,10 +26,16 @@ static constexpr char kTextInputAction[] = "inputAction"; static constexpr char kTextInputType[] = "inputType"; static constexpr char kTextInputTypeName[] = "name"; +#if defined(_MSC_VER) +// TODO(naifu): This temporary code is to solve link error.(VS2015/2017) +// https://social.msdn.microsoft.com/Forums/vstudio/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error +std::locale::id std::codecvt::id; +#endif // defined(_MSC_VER) + namespace flutter { TextInputModel::TextInputModel(int client_id, const rapidjson::Value& config) - : text_(""), + : text_(std::u16string()), client_id_(client_id), selection_base_(text_.begin()), selection_extent_(text_.begin()) { @@ -64,7 +70,8 @@ bool TextInputModel::SetEditingState(size_t selection_base, if (selection_extent > text.size()) { return false; } - text_ = std::string(text); + std::wstring_convert, char16_t> utf16conv; + text_ = utf16conv.from_bytes(text); selection_base_ = text_.begin() + selection_base; selection_extent_ = text_.begin() + selection_extent; return true; @@ -76,7 +83,7 @@ void TextInputModel::DeleteSelected() { selection_extent_ = selection_base_; } -void TextInputModel::AddCharacter(char c) { +void TextInputModel::AddCharacter(unsigned int c) { if (selection_base_ != selection_extent_) { DeleteSelected(); } @@ -172,7 +179,8 @@ std::unique_ptr TextInputModel::GetState() const { static_cast(selection_extent_ - text_.begin()), allocator); editing_state.AddMember(kSelectionIsDirectionalKey, false, allocator); - editing_state.AddMember(kTextKey, rapidjson::Value(text_, allocator).Move(), + std::wstring_convert, char16_t> utf8conv; + editing_state.AddMember(kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), allocator); args->PushBack(editing_state, allocator); return args; diff --git a/shell/platform/common/cpp/text_input_model.h b/shell/platform/common/cpp/text_input_model.h index e3ea19bae9010..03dfc089b305e 100644 --- a/shell/platform/common/cpp/text_input_model.h +++ b/shell/platform/common/cpp/text_input_model.h @@ -7,6 +7,8 @@ #include #include +#include +#include #include "rapidjson/document.h" @@ -32,7 +34,7 @@ class TextInputModel { // Either appends after the cursor (when selection base and extent are the // same), or deletes the selected characters, replacing the text with the // character specified. - void AddCharacter(char c); + void AddCharacter(unsigned int c); // Deletes either the selection, or one character ahead of the cursor. // @@ -89,12 +91,12 @@ class TextInputModel { private: void DeleteSelected(); - std::string text_; + std::u16string text_; int client_id_; std::string input_type_; std::string input_action_; - std::string::iterator selection_base_; - std::string::iterator selection_extent_; + std::u16string::iterator selection_base_; + std::u16string::iterator selection_extent_; }; } // namespace flutter diff --git a/shell/platform/glfw/text_input_plugin.cc b/shell/platform/glfw/text_input_plugin.cc index 3779510e301ac..66112a3a51661 100644 --- a/shell/platform/glfw/text_input_plugin.cc +++ b/shell/platform/glfw/text_input_plugin.cc @@ -42,7 +42,7 @@ void TextInputPlugin::CharHook(GLFWwindow* window, unsigned int code_point) { } // TODO(awdavies): Actually handle potential unicode characters. Probably // requires some ICU data or something. - active_model_->AddCharacter(static_cast(code_point)); + active_model_->AddCharacter(code_point); SendStateUpdate(*active_model_); } diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index 3324e8ee0f685..2105c8a3979cc 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -44,7 +44,7 @@ void TextInputPlugin::CharHook(Win32FlutterWindow* window, return; } // TODO bug 30661 - active_model_->AddCharacter(static_cast(code_point)); + active_model_->AddCharacter(code_point); SendStateUpdate(*active_model_); } From 79f4a570db157f61d538f0094eabf60301b3b357 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Fri, 6 Sep 2019 01:56:50 +0800 Subject: [PATCH 2/9] clang-format --- shell/platform/common/cpp/text_input_model.cc | 5 +++-- shell/platform/common/cpp/text_input_model.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index 79d602dbe8274..abe00417684cb 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -180,8 +180,9 @@ std::unique_ptr TextInputModel::GetState() const { allocator); editing_state.AddMember(kSelectionIsDirectionalKey, false, allocator); std::wstring_convert, char16_t> utf8conv; - editing_state.AddMember(kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), - allocator); + editing_state.AddMember( + kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), + allocator); args->PushBack(editing_state, allocator); return args; } diff --git a/shell/platform/common/cpp/text_input_model.h b/shell/platform/common/cpp/text_input_model.h index 03dfc089b305e..f52aec204a689 100644 --- a/shell/platform/common/cpp/text_input_model.h +++ b/shell/platform/common/cpp/text_input_model.h @@ -5,10 +5,10 @@ #ifndef FLUTTER_SHELL_PLATFORM_CPP_TEXT_INPUT_MODEL_H_ #define FLUTTER_SHELL_PLATFORM_CPP_TEXT_INPUT_MODEL_H_ -#include -#include #include #include +#include +#include #include "rapidjson/document.h" From 60ba55c13188b4319e962c2d32335f8dfd6a846b Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Fri, 6 Sep 2019 08:42:47 +0800 Subject: [PATCH 3/9] patch set-1 --- shell/platform/common/cpp/text_input_model.cc | 20 +++++++++---------- shell/platform/common/cpp/text_input_model.h | 10 ++++------ shell/platform/glfw/text_input_plugin.cc | 4 +--- shell/platform/glfw/text_input_plugin.h | 2 +- shell/platform/windows/text_input_plugin.cc | 3 +-- shell/platform/windows/text_input_plugin.h | 2 +- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index abe00417684cb..01d25b8123e06 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -4,7 +4,9 @@ #include "flutter/shell/platform/common/cpp/text_input_model.h" +#include #include +#include // TODO(awdavies): Need to fix this regarding issue #47. static constexpr char kComposingBaseKey[] = "composingBase"; @@ -29,14 +31,13 @@ static constexpr char kTextInputTypeName[] = "name"; #if defined(_MSC_VER) // TODO(naifu): This temporary code is to solve link error.(VS2015/2017) // https://social.msdn.microsoft.com/Forums/vstudio/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error -std::locale::id std::codecvt::id; +std::locale::id std::codecvt::id; #endif // defined(_MSC_VER) namespace flutter { TextInputModel::TextInputModel(int client_id, const rapidjson::Value& config) - : text_(std::u16string()), - client_id_(client_id), + : client_id_(client_id), selection_base_(text_.begin()), selection_extent_(text_.begin()) { // TODO: Improve error handling during refactoring; this is just minimal @@ -70,8 +71,8 @@ bool TextInputModel::SetEditingState(size_t selection_base, if (selection_extent > text.size()) { return false; } - std::wstring_convert, char16_t> utf16conv; - text_ = utf16conv.from_bytes(text); + std::wstring_convert, char32_t> utf32conv; + text_ = utf32conv.from_bytes(text); selection_base_ = text_.begin() + selection_base; selection_extent_ = text_.begin() + selection_extent; return true; @@ -83,7 +84,7 @@ void TextInputModel::DeleteSelected() { selection_extent_ = selection_base_; } -void TextInputModel::AddCharacter(unsigned int c) { +void TextInputModel::AddCharacter(uint32_t c) { if (selection_base_ != selection_extent_) { DeleteSelected(); } @@ -179,10 +180,9 @@ std::unique_ptr TextInputModel::GetState() const { static_cast(selection_extent_ - text_.begin()), allocator); editing_state.AddMember(kSelectionIsDirectionalKey, false, allocator); - std::wstring_convert, char16_t> utf8conv; - editing_state.AddMember( - kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), - allocator); + std::wstring_convert, char32_t> utf8conv; + editing_state.AddMember(kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), + allocator); args->PushBack(editing_state, allocator); return args; } diff --git a/shell/platform/common/cpp/text_input_model.h b/shell/platform/common/cpp/text_input_model.h index f52aec204a689..f32b58a97ec49 100644 --- a/shell/platform/common/cpp/text_input_model.h +++ b/shell/platform/common/cpp/text_input_model.h @@ -5,8 +5,6 @@ #ifndef FLUTTER_SHELL_PLATFORM_CPP_TEXT_INPUT_MODEL_H_ #define FLUTTER_SHELL_PLATFORM_CPP_TEXT_INPUT_MODEL_H_ -#include -#include #include #include @@ -34,7 +32,7 @@ class TextInputModel { // Either appends after the cursor (when selection base and extent are the // same), or deletes the selected characters, replacing the text with the // character specified. - void AddCharacter(unsigned int c); + void AddCharacter(uint32_t c); // Deletes either the selection, or one character ahead of the cursor. // @@ -91,12 +89,12 @@ class TextInputModel { private: void DeleteSelected(); - std::u16string text_; + std::u32string text_; int client_id_; std::string input_type_; std::string input_action_; - std::u16string::iterator selection_base_; - std::u16string::iterator selection_extent_; + std::u32string::iterator selection_base_; + std::u32string::iterator selection_extent_; }; } // namespace flutter diff --git a/shell/platform/glfw/text_input_plugin.cc b/shell/platform/glfw/text_input_plugin.cc index 66112a3a51661..756b037dfcb82 100644 --- a/shell/platform/glfw/text_input_plugin.cc +++ b/shell/platform/glfw/text_input_plugin.cc @@ -36,12 +36,10 @@ static constexpr uint32_t kInputModelLimit = 256; namespace flutter { -void TextInputPlugin::CharHook(GLFWwindow* window, unsigned int code_point) { +void TextInputPlugin::CharHook(GLFWwindow* window, uint32_t code_point) { if (active_model_ == nullptr) { return; } - // TODO(awdavies): Actually handle potential unicode characters. Probably - // requires some ICU data or something. active_model_->AddCharacter(code_point); SendStateUpdate(*active_model_); } diff --git a/shell/platform/glfw/text_input_plugin.h b/shell/platform/glfw/text_input_plugin.h index daf2fa7d22f05..8d31a8bbbdbf8 100644 --- a/shell/platform/glfw/text_input_plugin.h +++ b/shell/platform/glfw/text_input_plugin.h @@ -33,7 +33,7 @@ class TextInputPlugin : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(GLFWwindow* window, unsigned int code_point) override; + void CharHook(GLFWwindow* window, uint32_t code_point) override; private: // Sends the current state of the given model to the Flutter engine. diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index 2105c8a3979cc..266ae49e9e059 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -39,11 +39,10 @@ static constexpr uint32_t kInputModelLimit = 256; namespace flutter { void TextInputPlugin::CharHook(Win32FlutterWindow* window, - unsigned int code_point) { + uint32_t code_point) { if (active_model_ == nullptr) { return; } - // TODO bug 30661 active_model_->AddCharacter(code_point); SendStateUpdate(*active_model_); } diff --git a/shell/platform/windows/text_input_plugin.h b/shell/platform/windows/text_input_plugin.h index 1cc57642e8af0..722d0e7dc58d2 100644 --- a/shell/platform/windows/text_input_plugin.h +++ b/shell/platform/windows/text_input_plugin.h @@ -35,7 +35,7 @@ class TextInputPlugin : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(Win32FlutterWindow* window, unsigned int code_point) override; + void CharHook(Win32FlutterWindow* window, uint32_t code_point) override; private: // Sends the current state of the given model to the Flutter engine. From 1a6cbcc7023615c3cf142ebad849c072cc95c6c9 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Fri, 6 Sep 2019 09:09:51 +0800 Subject: [PATCH 4/9] clang-format --- shell/platform/common/cpp/text_input_model.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index 01d25b8123e06..206e1d7c2bd39 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -181,8 +181,9 @@ std::unique_ptr TextInputModel::GetState() const { allocator); editing_state.AddMember(kSelectionIsDirectionalKey, false, allocator); std::wstring_convert, char32_t> utf8conv; - editing_state.AddMember(kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), - allocator); + editing_state.AddMember( + kTextKey, rapidjson::Value(utf8conv.to_bytes(text_), allocator).Move(), + allocator); args->PushBack(editing_state, allocator); return args; } From 9b080e15caf4a23243330d74436c5c9873de3677 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Sat, 7 Sep 2019 12:17:39 +0800 Subject: [PATCH 5/9] utf-16 convert logic --- shell/platform/common/cpp/text_input_model.cc | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index 206e1d7c2bd39..82044adf4c55e 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -88,7 +88,30 @@ void TextInputModel::AddCharacter(uint32_t c) { if (selection_base_ != selection_extent_) { DeleteSelected(); } - selection_extent_ = text_.insert(selection_extent_, c); + char32_t ch = c; + { + // I put this code (compatible processing logic for UTF-16) here for + // several reasons: + // 1. If I put it in win32/glfw 's message processing logic, there would + // be two sets of duplicate code. + // 2. Putting it here can still be guaranteed to be platform-independent + // and can handle more scenarios. + // Specific logic: + // What we expect to pass in is a Unicode, if it's UTF-32, it doesn't need + // any processing, and if it's UTF-16, it's converted to Unicode. + static char32_t lead_ch = 0; + // If ch is Lead Surrogate. + if ((ch & 0xFFFFFC00) == 0xD800) { + lead_ch = ch; + return; + } + // If ch is Trail Surrogate and pre-ch is Lead Surrogate. + if (lead_ch != 0 && (ch & 0xFFFFFC00) == 0xDC00) { + ch = 0x10000 + ((lead_ch & 0x000003FF) << 10) + (ch & 0x3FF); + } + lead_ch = 0; + } + selection_extent_ = text_.insert(selection_extent_, ch); selection_extent_++; selection_base_ = selection_extent_; } From ad7984b4e0b21aea8330e398b12838a9e1d2c6a3 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Sat, 7 Sep 2019 22:51:36 +0800 Subject: [PATCH 6/9] move logic to MessageHandler --- shell/platform/common/cpp/text_input_model.cc | 27 ++--------------- shell/platform/common/cpp/text_input_model.h | 2 +- shell/platform/windows/text_input_plugin.cc | 2 +- shell/platform/windows/text_input_plugin.h | 2 +- shell/platform/windows/win32_window.cc | 29 +++++++++++++++++-- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/shell/platform/common/cpp/text_input_model.cc b/shell/platform/common/cpp/text_input_model.cc index 82044adf4c55e..35bc07592f0a2 100644 --- a/shell/platform/common/cpp/text_input_model.cc +++ b/shell/platform/common/cpp/text_input_model.cc @@ -84,34 +84,11 @@ void TextInputModel::DeleteSelected() { selection_extent_ = selection_base_; } -void TextInputModel::AddCharacter(uint32_t c) { +void TextInputModel::AddCharacter(char32_t c) { if (selection_base_ != selection_extent_) { DeleteSelected(); } - char32_t ch = c; - { - // I put this code (compatible processing logic for UTF-16) here for - // several reasons: - // 1. If I put it in win32/glfw 's message processing logic, there would - // be two sets of duplicate code. - // 2. Putting it here can still be guaranteed to be platform-independent - // and can handle more scenarios. - // Specific logic: - // What we expect to pass in is a Unicode, if it's UTF-32, it doesn't need - // any processing, and if it's UTF-16, it's converted to Unicode. - static char32_t lead_ch = 0; - // If ch is Lead Surrogate. - if ((ch & 0xFFFFFC00) == 0xD800) { - lead_ch = ch; - return; - } - // If ch is Trail Surrogate and pre-ch is Lead Surrogate. - if (lead_ch != 0 && (ch & 0xFFFFFC00) == 0xDC00) { - ch = 0x10000 + ((lead_ch & 0x000003FF) << 10) + (ch & 0x3FF); - } - lead_ch = 0; - } - selection_extent_ = text_.insert(selection_extent_, ch); + selection_extent_ = text_.insert(selection_extent_, c); selection_extent_++; selection_base_ = selection_extent_; } diff --git a/shell/platform/common/cpp/text_input_model.h b/shell/platform/common/cpp/text_input_model.h index f32b58a97ec49..0688512aedbd8 100644 --- a/shell/platform/common/cpp/text_input_model.h +++ b/shell/platform/common/cpp/text_input_model.h @@ -32,7 +32,7 @@ class TextInputModel { // Either appends after the cursor (when selection base and extent are the // same), or deletes the selected characters, replacing the text with the // character specified. - void AddCharacter(uint32_t c); + void AddCharacter(char32_t c); // Deletes either the selection, or one character ahead of the cursor. // diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index 266ae49e9e059..d1a35e3a071ce 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -39,7 +39,7 @@ static constexpr uint32_t kInputModelLimit = 256; namespace flutter { void TextInputPlugin::CharHook(Win32FlutterWindow* window, - uint32_t code_point) { + unsigned int code_point) { if (active_model_ == nullptr) { return; } diff --git a/shell/platform/windows/text_input_plugin.h b/shell/platform/windows/text_input_plugin.h index 722d0e7dc58d2..1cc57642e8af0 100644 --- a/shell/platform/windows/text_input_plugin.h +++ b/shell/platform/windows/text_input_plugin.h @@ -35,7 +35,7 @@ class TextInputPlugin : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(Win32FlutterWindow* window, uint32_t code_point) override; + void CharHook(Win32FlutterWindow* window, unsigned int code_point) override; private: // Sends the current state of the given model to the Flutter engine. diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index fce8ae73e1450..d929a9ffe70de 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -153,13 +153,36 @@ Win32Window::MessageHandler(HWND hwnd, window->OnScroll( 0.0, -(static_cast(HIWORD(wparam)) / (double)WHEEL_DELTA)); break; + case WM_UNICHAR: + { + // Tell thiary-pary app, we can support Unicode. + if (wparam == UNICODE_NOCHAR) + return TRUE; + // DefWindowProc will send WM_CHAR for this WM_UNICHAR. + break; + } case WM_CHAR: case WM_SYSCHAR: - case WM_UNICHAR: - if (wparam != VK_BACK) { - window->OnChar(static_cast(wparam)); + { + if (wparam == VK_BACK) + break; + char32_t ch = static_cast(wparam); + // What we expect to pass in is a Unicode, if it's UTF-32, it doesn't + // need any processing, and if it's UTF-16, it's converted to Unicode. + static char32_t lead_ch = 0; + // If ch is Lead Surrogate. + if ((ch & 0xFFFFFC00) == 0xD800) { + lead_ch = ch; + return TRUE; + } + // If ch is Trail Surrogate and pre-ch is Lead Surrogate. + if (lead_ch != 0 && (ch & 0xFFFFFC00) == 0xDC00) { + ch = 0x10000 + ((lead_ch & 0x000003FF) << 10) + (ch & 0x3FF); } + lead_ch = 0; + window->OnChar(ch); break; + } case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_KEYUP: From 59ce05affd94e5578631cd2a8b21eeaa7e59a0db Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Sat, 7 Sep 2019 23:00:39 +0800 Subject: [PATCH 7/9] format --- shell/platform/glfw/text_input_plugin.cc | 2 +- shell/platform/glfw/text_input_plugin.h | 2 +- shell/platform/windows/win32_window.cc | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/shell/platform/glfw/text_input_plugin.cc b/shell/platform/glfw/text_input_plugin.cc index 756b037dfcb82..ebf7cc62bb121 100644 --- a/shell/platform/glfw/text_input_plugin.cc +++ b/shell/platform/glfw/text_input_plugin.cc @@ -36,7 +36,7 @@ static constexpr uint32_t kInputModelLimit = 256; namespace flutter { -void TextInputPlugin::CharHook(GLFWwindow* window, uint32_t code_point) { +void TextInputPlugin::CharHook(GLFWwindow* window, unsigned int code_point) { if (active_model_ == nullptr) { return; } diff --git a/shell/platform/glfw/text_input_plugin.h b/shell/platform/glfw/text_input_plugin.h index 8d31a8bbbdbf8..daf2fa7d22f05 100644 --- a/shell/platform/glfw/text_input_plugin.h +++ b/shell/platform/glfw/text_input_plugin.h @@ -33,7 +33,7 @@ class TextInputPlugin : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(GLFWwindow* window, uint32_t code_point) override; + void CharHook(GLFWwindow* window, unsigned int code_point) override; private: // Sends the current state of the given model to the Flutter engine. diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index d929a9ffe70de..450d1ca933545 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -153,17 +153,15 @@ Win32Window::MessageHandler(HWND hwnd, window->OnScroll( 0.0, -(static_cast(HIWORD(wparam)) / (double)WHEEL_DELTA)); break; - case WM_UNICHAR: - { - // Tell thiary-pary app, we can support Unicode. + case WM_UNICHAR: { + // Tell third-pary app, we can support Unicode. if (wparam == UNICODE_NOCHAR) return TRUE; // DefWindowProc will send WM_CHAR for this WM_UNICHAR. break; } case WM_CHAR: - case WM_SYSCHAR: - { + case WM_SYSCHAR: { if (wparam == VK_BACK) break; char32_t ch = static_cast(wparam); From c65c5a78fb37226ee26999186dc359c47458f23a Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Sun, 8 Sep 2019 05:40:54 +0800 Subject: [PATCH 8/9] style changes --- shell/platform/windows/key_event_handler.cc | 2 +- shell/platform/windows/key_event_handler.h | 2 +- .../platform/windows/keyboard_hook_handler.h | 2 +- shell/platform/windows/text_input_plugin.cc | 2 +- shell/platform/windows/text_input_plugin.h | 2 +- .../platform/windows/win32_flutter_window.cc | 4 +-- shell/platform/windows/win32_flutter_window.h | 4 +-- shell/platform/windows/win32_window.cc | 25 ++++++++++--------- shell/platform/windows/win32_window.h | 2 +- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/shell/platform/windows/key_event_handler.cc b/shell/platform/windows/key_event_handler.cc index e2e94d6398748..63af2446b889b 100644 --- a/shell/platform/windows/key_event_handler.cc +++ b/shell/platform/windows/key_event_handler.cc @@ -32,7 +32,7 @@ KeyEventHandler::KeyEventHandler(flutter::BinaryMessenger* messenger) KeyEventHandler::~KeyEventHandler() = default; void KeyEventHandler::CharHook(Win32FlutterWindow* window, - unsigned int code_point) {} + char32_t code_point) {} void KeyEventHandler::KeyboardHook(Win32FlutterWindow* window, int key, diff --git a/shell/platform/windows/key_event_handler.h b/shell/platform/windows/key_event_handler.h index 4fc569ffce9f4..47ec63f6d1755 100644 --- a/shell/platform/windows/key_event_handler.h +++ b/shell/platform/windows/key_event_handler.h @@ -34,7 +34,7 @@ class KeyEventHandler : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(Win32FlutterWindow* window, unsigned int code_point) override; + void CharHook(Win32FlutterWindow* window, char32_t code_point) override; private: // The Flutter system channel for key event messages. diff --git a/shell/platform/windows/keyboard_hook_handler.h b/shell/platform/windows/keyboard_hook_handler.h index 761dbd655d222..2c3f6f21768b4 100644 --- a/shell/platform/windows/keyboard_hook_handler.h +++ b/shell/platform/windows/keyboard_hook_handler.h @@ -25,7 +25,7 @@ class KeyboardHookHandler { // A function for hooking into unicode code point input. virtual void CharHook(Win32FlutterWindow* window, - unsigned int code_point) = 0; + char32_t code_point) = 0; }; } // namespace flutter diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index d1a35e3a071ce..128f1f8d5b9a3 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -39,7 +39,7 @@ static constexpr uint32_t kInputModelLimit = 256; namespace flutter { void TextInputPlugin::CharHook(Win32FlutterWindow* window, - unsigned int code_point) { + char32_t code_point) { if (active_model_ == nullptr) { return; } diff --git a/shell/platform/windows/text_input_plugin.h b/shell/platform/windows/text_input_plugin.h index 1cc57642e8af0..c367dbcc427b6 100644 --- a/shell/platform/windows/text_input_plugin.h +++ b/shell/platform/windows/text_input_plugin.h @@ -35,7 +35,7 @@ class TextInputPlugin : public KeyboardHookHandler { int mods) override; // |KeyboardHookHandler| - void CharHook(Win32FlutterWindow* window, unsigned int code_point) override; + void CharHook(Win32FlutterWindow* window, char32_t code_point) override; private: // Sends the current state of the given model to the Flutter engine. diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index edd40d989309c..5b2f20c153576 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -125,7 +125,7 @@ void Win32FlutterWindow::OnPointerUp(double x, double y) { } } -void Win32FlutterWindow::OnChar(unsigned int code_point) { +void Win32FlutterWindow::OnChar(char32_t code_point) { if (process_events_) { SendChar(code_point); } @@ -207,7 +207,7 @@ void Win32FlutterWindow::SendPointerUp(double x, double y) { SendPointerEventWithData(event); } -void Win32FlutterWindow::SendChar(unsigned int code_point) { +void Win32FlutterWindow::SendChar(char32_t code_point) { for (const auto& handler : keyboard_hook_handlers_) { handler->CharHook(this, code_point); } diff --git a/shell/platform/windows/win32_flutter_window.h b/shell/platform/windows/win32_flutter_window.h index bd5f40c9b94ad..c2316a88e0add 100644 --- a/shell/platform/windows/win32_flutter_window.h +++ b/shell/platform/windows/win32_flutter_window.h @@ -54,7 +54,7 @@ class Win32FlutterWindow : public Win32Window { void OnPointerUp(double x, double y) override; // |Win32Window| - void OnChar(unsigned int code_point) override; + void OnChar(char32_t code_point) override; // |Win32Window| void OnKey(int key, int scancode, int action, int mods) override; @@ -103,7 +103,7 @@ class Win32FlutterWindow : public Win32Window { void SendPointerUp(double x, double y); // Reports a keyboard character to Flutter engine. - void SendChar(unsigned int code_point); + void SendChar(char32_t code_point); // Reports a raw keyboard message to Flutter engine. void SendKey(int key, int scancode, int action, int mods); diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index 450d1ca933545..aa0e623ef09ed 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -164,21 +164,22 @@ Win32Window::MessageHandler(HWND hwnd, case WM_SYSCHAR: { if (wparam == VK_BACK) break; - char32_t ch = static_cast(wparam); - // What we expect to pass in is a Unicode, if it's UTF-32, it doesn't - // need any processing, and if it's UTF-16, it's converted to Unicode. - static char32_t lead_ch = 0; - // If ch is Lead Surrogate. - if ((ch & 0xFFFFFC00) == 0xD800) { - lead_ch = ch; + char32_t code_point = static_cast(wparam); + static char32_t lead_surrogate = 0; + // If code_point is LeadSurrogate, save and return. + if ((code_point & 0xFFFFFC00) == 0xD800) { + lead_surrogate = code_point; return TRUE; } - // If ch is Trail Surrogate and pre-ch is Lead Surrogate. - if (lead_ch != 0 && (ch & 0xFFFFFC00) == 0xDC00) { - ch = 0x10000 + ((lead_ch & 0x000003FF) << 10) + (ch & 0x3FF); + // Merge TrailSurrogate and LeadSurrogate. + if (lead_surrogate != 0 && (code_point & 0xFFFFFC00) == 0xDC00) { + code_point = + 0x10000 + + ((lead_surrogate & 0x000003FF) << 10) + + (code_point & 0x3FF); } - lead_ch = 0; - window->OnChar(ch); + lead_surrogate = 0; + window->OnChar(code_point); break; } case WM_KEYDOWN: diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index 99036802f01a4..45819b589ea61 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -89,7 +89,7 @@ class Win32Window { virtual void OnPointerUp(double x, double y) = 0; // Called when character input occurs. - virtual void OnChar(unsigned int code_point) = 0; + virtual void OnChar(char32_t code_point) = 0; // Called when raw keyboard input occurs. virtual void OnKey(int key, int scancode, int action, int mods) = 0; From 80aabe982d967f9d0daf2f46e9a02b8b276e82b4 Mon Sep 17 00:00:00 2001 From: shoryukenn Date: Sun, 8 Sep 2019 05:54:15 +0800 Subject: [PATCH 9/9] clang-format --- shell/platform/windows/keyboard_hook_handler.h | 3 +-- shell/platform/windows/win32_window.cc | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/shell/platform/windows/keyboard_hook_handler.h b/shell/platform/windows/keyboard_hook_handler.h index 2c3f6f21768b4..1b3304ddd50b0 100644 --- a/shell/platform/windows/keyboard_hook_handler.h +++ b/shell/platform/windows/keyboard_hook_handler.h @@ -24,8 +24,7 @@ class KeyboardHookHandler { int mods) = 0; // A function for hooking into unicode code point input. - virtual void CharHook(Win32FlutterWindow* window, - char32_t code_point) = 0; + virtual void CharHook(Win32FlutterWindow* window, char32_t code_point) = 0; }; } // namespace flutter diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index aa0e623ef09ed..ad6265109d805 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -173,10 +173,8 @@ Win32Window::MessageHandler(HWND hwnd, } // Merge TrailSurrogate and LeadSurrogate. if (lead_surrogate != 0 && (code_point & 0xFFFFFC00) == 0xDC00) { - code_point = - 0x10000 - + ((lead_surrogate & 0x000003FF) << 10) - + (code_point & 0x3FF); + code_point = 0x10000 + ((lead_surrogate & 0x000003FF) << 10) + + (code_point & 0x3FF); } lead_surrogate = 0; window->OnChar(code_point);