Merge pull request #91695 from bruvzg/web_ime_pos

[Web IME] Fix suggestion window position in Chromium based browsers.
This commit is contained in:
Rémi Verschelde 2024-05-28 15:48:42 +02:00
commit ac6f5780b1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 40 additions and 23 deletions

View File

@ -866,6 +866,9 @@ void DisplayServerWeb::_ime_callback(int p_type, const String &p_text) {
default: default:
break; break;
} }
ds->process_keys();
Input::get_singleton()->flush_buffered_events();
} }
void DisplayServerWeb::window_set_ime_active(const bool p_active, WindowID p_window) { void DisplayServerWeb::window_set_ime_active(const bool p_active, WindowID p_window) {
@ -1353,31 +1356,35 @@ DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsyn
} }
void DisplayServerWeb::process_events() { void DisplayServerWeb::process_events() {
process_keys();
Input::get_singleton()->flush_buffered_events(); Input::get_singleton()->flush_buffered_events();
if (godot_js_input_gamepad_sample() == OK) { if (godot_js_input_gamepad_sample() == OK) {
process_joypads(); process_joypads();
for (int i = 0; i < key_event_pos; i++) {
const DisplayServerWeb::KeyEvent &ke = key_event_buffer[i];
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_pressed(ke.pressed);
ev->set_echo(ke.echo);
ev->set_keycode(ke.keycode);
ev->set_physical_keycode(ke.physical_keycode);
ev->set_key_label(ke.key_label);
ev->set_unicode(ke.unicode);
ev->set_location(ke.location);
if (ke.raw) {
dom2godot_mod(ev, ke.mod, ke.keycode);
}
Input::get_singleton()->parse_input_event(ev);
}
key_event_pos = 0;
} }
} }
void DisplayServerWeb::process_keys() {
for (int i = 0; i < key_event_pos; i++) {
const DisplayServerWeb::KeyEvent &ke = key_event_buffer[i];
Ref<InputEventKey> ev;
ev.instantiate();
ev->set_pressed(ke.pressed);
ev->set_echo(ke.echo);
ev->set_keycode(ke.keycode);
ev->set_physical_keycode(ke.physical_keycode);
ev->set_key_label(ke.key_label);
ev->set_unicode(ke.unicode);
ev->set_location(ke.location);
if (ke.raw) {
dom2godot_mod(ev, ke.mod, ke.keycode);
}
Input::get_singleton()->parse_input_event(ev);
}
key_event_pos = 0;
}
int DisplayServerWeb::get_current_video_driver() const { int DisplayServerWeb::get_current_video_driver() const {
return 1; return 1;
} }

View File

@ -145,6 +145,7 @@ private:
static void _drop_files_js_callback(const Vector<String> &p_files); static void _drop_files_js_callback(const Vector<String> &p_files);
void process_joypads(); void process_joypads();
void process_keys();
static Vector<String> get_rendering_drivers_func(); static Vector<String> get_rendering_drivers_func();
static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error); static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);

View File

@ -63,8 +63,15 @@ const GodotIME = {
ime_position: function (x, y) { ime_position: function (x, y) {
if (GodotIME.ime) { if (GodotIME.ime) {
GodotIME.ime.style.left = `${x}px`; const canvas = GodotConfig.canvas;
GodotIME.ime.style.top = `${y}px`; const rect = canvas.getBoundingClientRect();
const rw = canvas.width / rect.width;
const rh = canvas.height / rect.height;
const clx = (x / rw) + rect.x;
const cly = (y / rh) + rect.y;
GodotIME.ime.style.left = `${clx}px`;
GodotIME.ime.style.top = `${cly}px`;
} }
}, },
@ -99,10 +106,12 @@ const GodotIME = {
ime.style.background = 'none'; ime.style.background = 'none';
ime.style.opacity = 0.0; ime.style.opacity = 0.0;
ime.style.position = 'fixed'; ime.style.position = 'fixed';
ime.style.textAlign = 'left';
ime.style.fontSize = '1px';
ime.style.left = '0px'; ime.style.left = '0px';
ime.style.top = '0px'; ime.style.top = '0px';
ime.style.width = '2px'; ime.style.width = '100%';
ime.style.height = '2px'; ime.style.height = '40px';
ime.style.display = 'none'; ime.style.display = 'none';
ime.contentEditable = 'true'; ime.contentEditable = 'true';