瀏覽代碼

LibWeb: Define a helper constant for the platform ctrl-ish key

For all intents and purposes, the cmd (super) key on macOS should be
treated as the ctrl key.
Timothy Flynn 11 月之前
父節點
當前提交
71b25e3e5a
共有 2 個文件被更改,包括 16 次插入0 次删除
  1. 7 0
      Userland/Libraries/LibWeb/UIEvents/KeyCode.h
  2. 9 0
      Userland/Libraries/LibWeb/UIEvents/MouseEvent.h

+ 7 - 0
Userland/Libraries/LibWeb/UIEvents/KeyCode.h

@@ -8,6 +8,7 @@
 #pragma once
 
 #include <AK/EnumBits.h>
+#include <AK/Platform.h>
 #include <AK/Types.h>
 
 namespace Web::UIEvents {
@@ -169,6 +170,12 @@ enum KeyModifier {
     Mod_Mask = Mod_Alt | Mod_Ctrl | Mod_Shift | Mod_Super | Mod_AltGr | Mod_Keypad,
 
     Is_Press = 0x80,
+
+#if defined(AK_OS_MACOS)
+    Mod_PlatformCtrl = Mod_Super,
+#else
+    Mod_PlatformCtrl = Mod_Ctrl,
+#endif
 };
 
 AK_ENUM_BITWISE_OPERATORS(KeyModifier);

+ 9 - 0
Userland/Libraries/LibWeb/UIEvents/MouseEvent.h

@@ -56,6 +56,15 @@ public:
     bool alt_key() const { return m_alt_key; }
     bool meta_key() const { return m_meta_key; }
 
+    bool platform_ctrl_key() const
+    {
+#if defined(AK_OS_MACOS)
+        return meta_key();
+#else
+        return ctrl_key();
+#endif
+    }
+
     double movement_x() const { return m_movement_x; }
     double movement_y() const { return m_movement_y; }