diff options
Diffstat (limited to 'platform/web')
| -rw-r--r-- | platform/web/display_server_web.cpp | 19 | ||||
| -rw-r--r-- | platform/web/dom_keys.inc | 56 | ||||
| -rw-r--r-- | platform/web/export/editor_http_server.h | 3 | ||||
| -rw-r--r-- | platform/web/http_client_web.cpp | 10 | ||||
| -rw-r--r-- | platform/web/http_client_web.h | 2 |
5 files changed, 41 insertions, 49 deletions
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index fdb9d107a7..d71fd60543 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -121,18 +121,25 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers // Resume audio context after input in case autoplay was denied. OS_Web::get_singleton()->resume_audio(); + char32_t c = 0x00; + String unicode = String::utf8(key_event.key); + if (unicode.length() == 1) { + c = unicode[0]; + } + + Key keycode = dom_code2godot_scancode(key_event.code, key_event.key, false); + Key scancode = dom_code2godot_scancode(key_event.code, key_event.key, true); + Ref<InputEventKey> ev; ev.instantiate(); ev->set_echo(p_repeat); - ev->set_keycode(dom_code2godot_scancode(key_event.code, key_event.key, false)); - ev->set_physical_keycode(dom_code2godot_scancode(key_event.code, key_event.key, true)); + ev->set_keycode(fix_keycode(c, keycode)); + ev->set_physical_keycode(scancode); + ev->set_key_label(fix_key_label(c, keycode)); + ev->set_unicode(fix_unicode(c)); ev->set_pressed(p_pressed); dom2godot_mod(ev, p_modifiers); - String unicode = String::utf8(key_event.key); - if (unicode.length() == 1) { - ev->set_unicode(unicode[0]); - } Input::get_singleton()->parse_input_event(ev); // Make sure to flush all events so we can call restricted APIs inside the event. diff --git a/platform/web/dom_keys.inc b/platform/web/dom_keys.inc index 5f8d921bfb..e63bd7c69f 100644 --- a/platform/web/dom_keys.inc +++ b/platform/web/dom_keys.inc @@ -32,9 +32,9 @@ // See https://w3c.github.io/uievents-code/#code-value-tables Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], bool p_physical) { -#define DOM2GODOT(p_str, p_godot_code) \ - if (memcmp((const void *)p_str, (void *)p_code, strlen(p_str) + 1) == 0) { \ - return Key::p_godot_code; \ +#define DOM2GODOT(p_str, p_godot_code) \ + if (memcmp((const void *)p_str, (void *)(p_physical ? p_key : p_code), strlen(p_str) + 1) == 0) { \ + return Key::p_godot_code; \ } // Numpad section. @@ -70,35 +70,6 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b DOM2GODOT("NumpadStar", KP_MULTIPLY); // or ASTERISK ? DOM2GODOT("NumpadSubtract", KP_SUBTRACT); - // Printable ASCII. - if (!p_physical) { - uint8_t b0 = (uint8_t)p_key[0]; - uint8_t b1 = (uint8_t)p_key[1]; - uint8_t b2 = (uint8_t)p_key[2]; - if (b1 == 0 && b0 > 0x1F && b0 < 0x7F) { // ASCII. - if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII. - b0 -= 32; - } - return (Key)b0; - } - -#define _U_2BYTES_MASK 0xE0 -#define _U_2BYTES 0xC0 - // Latin-1 codes. - if (b2 == 0 && (b0 & _U_2BYTES_MASK) == _U_2BYTES) { // 2-bytes utf8, only known latin. - uint32_t key = ((b0 & ~_U_2BYTES_MASK) << 6) | (b1 & 0x3F); - if (key >= 0xA0 && key <= 0xDF) { - return (Key)key; - } - if (key >= 0xE0 && key <= 0xFF) { // Lowercase known latin. - key -= 0x20; - return (Key)key; - } - } -#undef _U_2BYTES_MASK -#undef _U_2BYTES - } - // Alphanumeric section. DOM2GODOT("Backquote", QUOTELEFT); DOM2GODOT("Backslash", BACKSLASH); @@ -162,8 +133,8 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b DOM2GODOT("ControlLeft", CTRL); DOM2GODOT("ControlRight", CTRL); DOM2GODOT("Enter", ENTER); - DOM2GODOT("MetaLeft", SUPER_L); - DOM2GODOT("MetaRight", SUPER_R); + DOM2GODOT("MetaLeft", META); + DOM2GODOT("MetaRight", META); DOM2GODOT("ShiftLeft", SHIFT); DOM2GODOT("ShiftRight", SHIFT); DOM2GODOT("Space", SPACE); @@ -227,6 +198,21 @@ Key dom_code2godot_scancode(EM_UTF8 const p_code[32], EM_UTF8 const p_key[32], b DOM2GODOT("AudioVolumeMute", VOLUMEMUTE); DOM2GODOT("AudioVolumeUp", VOLUMEUP); //DOM2GODOT("WakeUp", UNKNOWN); - return Key::UNKNOWN; + + // Printable ASCII. + uint8_t b0 = (uint8_t)p_key[0]; + uint8_t b1 = (uint8_t)p_key[1]; + if (b0 >= 0x20 && b0 < 0x7F) { // ASCII. + if (b0 > 0x60 && b0 < 0x7B) { // Lowercase ASCII. + b0 -= 32; + } + return (Key)b0; + } else if (b0 == 0xC2 && b1 == 0xA5) { + return Key::YEN; + } else if (b0 == 0xC2 && b1 == 0xA7) { + return Key::SECTION; + } + + return Key::NONE; #undef DOM2GODOT } diff --git a/platform/web/export/editor_http_server.h b/platform/web/export/editor_http_server.h index ce6b0be713..3f87288537 100644 --- a/platform/web/export/editor_http_server.h +++ b/platform/web/export/editor_http_server.h @@ -205,8 +205,7 @@ public: if (tls.is_null()) { tls = Ref<StreamPeerTLS>(StreamPeerTLS::create()); peer = tls; - tls->set_blocking_handshake_enabled(false); - if (tls->accept_stream(tcp, key, cert) != OK) { + if (tls->accept_stream(tcp, TLSOptions::server(key, cert)) != OK) { _clear_client(); return; } diff --git a/platform/web/http_client_web.cpp b/platform/web/http_client_web.cpp index 31f54dad9f..3e4ba5a2ae 100644 --- a/platform/web/http_client_web.cpp +++ b/platform/web/http_client_web.cpp @@ -37,20 +37,20 @@ void HTTPClientWeb::_parse_headers(int p_len, const char **p_headers, void *p_re } } -Error HTTPClientWeb::connect_to_host(const String &p_host, int p_port, bool p_tls, bool p_verify_host) { +Error HTTPClientWeb::connect_to_host(const String &p_host, int p_port, Ref<TLSOptions> p_tls_options) { + ERR_FAIL_COND_V(p_tls_options.is_valid() && p_tls_options->is_server(), ERR_INVALID_PARAMETER); + close(); - if (p_tls && !p_verify_host) { - WARN_PRINT("Disabling HTTPClientWeb's host verification is not supported for the Web platform, host will be verified"); - } port = p_port; - use_tls = p_tls; + use_tls = p_tls_options.is_valid(); host = p_host; String host_lower = host.to_lower(); if (host_lower.begins_with("http://")) { host = host.substr(7, host.length() - 7); + use_tls = false; } else if (host_lower.begins_with("https://")) { use_tls = true; host = host.substr(8, host.length() - 8); diff --git a/platform/web/http_client_web.h b/platform/web/http_client_web.h index 993ec6c0e2..def7837a27 100644 --- a/platform/web/http_client_web.h +++ b/platform/web/http_client_web.h @@ -86,7 +86,7 @@ public: Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override; - Error connect_to_host(const String &p_host, int p_port = -1, bool p_tls = false, bool p_verify_host = true) override; + Error connect_to_host(const String &p_host, int p_port = -1, Ref<TLSOptions> p_tls_options = Ref<TLSOptions>()) override; void set_connection(const Ref<StreamPeer> &p_connection) override; Ref<StreamPeer> get_connection() const override; void close() override; |