From e38b6f14f6010f05d4158cebc6756693a0063a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:31:33 -0800 Subject: [PATCH] [Windows] Remove unnecessary statics in keyboard (flutter/engine#49834) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows's `KeyboardManager` has several top-level helper functions. These are already wrapped in an anonymous C++ namespace, which is the C++ equivalent of the C `static` keyword. No tests are updated as this PR is a refactoring with no semantic changes.   [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../platform/windows/keyboard_manager.cc | 20 +++++++++---------- .../shell/platform/windows/keyboard_manager.h | 10 +++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/keyboard_manager.cc b/engine/src/flutter/shell/platform/windows/keyboard_manager.cc index 21433aa0e5..20faa1e124 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_manager.cc +++ b/engine/src/flutter/shell/platform/windows/keyboard_manager.cc @@ -15,7 +15,7 @@ namespace { // The maximum number of pending events to keep before // emitting a warning on the console about unhandled events. -static constexpr int kMaxPendingEvents = 1000; +constexpr int kMaxPendingEvents = 1000; // Returns true if this key is an AltRight key down event. // @@ -40,7 +40,7 @@ static constexpr int kMaxPendingEvents = 1000; // would be rare, and a misrecognition would only cause a minor consequence // where the CtrlLeft is released early; the later, real, CtrlLeft up event will // be ignored. -static bool IsKeyDownAltRight(int action, int virtual_key, bool extended) { +bool IsKeyDownAltRight(int action, int virtual_key, bool extended) { return virtual_key == VK_RMENU && extended && (action == WM_KEYDOWN || action == WM_SYSKEYDOWN); } @@ -48,7 +48,7 @@ static bool IsKeyDownAltRight(int action, int virtual_key, bool extended) { // Returns true if this key is a key up event of AltRight. // // This is used to assist a corner case described in |IsKeyDownAltRight|. -static bool IsKeyUpAltRight(int action, int virtual_key, bool extended) { +bool IsKeyUpAltRight(int action, int virtual_key, bool extended) { return virtual_key == VK_RMENU && extended && (action == WM_KEYUP || action == WM_SYSKEYUP); } @@ -56,24 +56,22 @@ static bool IsKeyUpAltRight(int action, int virtual_key, bool extended) { // Returns true if this key is a key down event of CtrlLeft. // // This is used to assist a corner case described in |IsKeyDownAltRight|. -static bool IsKeyDownCtrlLeft(int action, int virtual_key) { +bool IsKeyDownCtrlLeft(int action, int virtual_key) { return virtual_key == VK_LCONTROL && (action == WM_KEYDOWN || action == WM_SYSKEYDOWN); } // Returns if a character sent by Win32 is a dead key. -static bool IsDeadKey(uint32_t ch) { +bool IsDeadKey(uint32_t ch) { return (ch & kDeadKeyCharMask) != 0; } -static char32_t CodePointFromSurrogatePair(wchar_t high, wchar_t low) { +char32_t CodePointFromSurrogatePair(wchar_t high, wchar_t low) { return 0x10000 + ((static_cast(high) & 0x000003FF) << 10) + (low & 0x3FF); } -static uint16_t ResolveKeyCode(uint16_t original, - bool extended, - uint8_t scancode) { +uint16_t ResolveKeyCode(uint16_t original, bool extended, uint8_t scancode) { switch (original) { case VK_SHIFT: case VK_LSHIFT: @@ -89,13 +87,13 @@ static uint16_t ResolveKeyCode(uint16_t original, } } -static bool IsPrintable(uint32_t c) { +bool IsPrintable(uint32_t c) { constexpr char32_t kMinPrintable = ' '; constexpr char32_t kDelete = 0x7F; return c >= kMinPrintable && c != kDelete; } -static bool IsSysAction(UINT action) { +bool IsSysAction(UINT action) { return action == WM_SYSKEYDOWN || action == WM_SYSKEYUP || action == WM_SYSCHAR || action == WM_SYSDEADCHAR; } diff --git a/engine/src/flutter/shell/platform/windows/keyboard_manager.h b/engine/src/flutter/shell/platform/windows/keyboard_manager.h index 9988fec4c4..b88983e44b 100644 --- a/engine/src/flutter/shell/platform/windows/keyboard_manager.h +++ b/engine/src/flutter/shell/platform/windows/keyboard_manager.h @@ -26,14 +26,14 @@ namespace flutter { // system calls (to allow mocking) and where to send the results of key calls // and text calls to. // -// Typically, |KeyboardManager| is owned by a |Window|, which also implements -// the window delegate. The key calls and text calls are forwarded to those of -// |Window|'s, and consequently, those of |FlutterWindowsView|'s. +// Typically, |KeyboardManager| is owned by a |FlutterWindow|, which also +// implements the window delegate. The key calls and text calls are forwarded to +// the |FlutterWindow|, and consequently, to the |FlutterWindowsView|. // // ## Terminology // -// The keyboard system follows the following terminology instead of the -// inconsistent/incomplete one used by Win32: +// The keyboard system uses the following terminology (which is different +// than Win32's terminology): // // * Message: An invocation of |WndProc|, which consists of an // action, an lparam, and a wparam.