mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 06:03:09 +00:00
Merge pull request #91695 from bruvzg/web_ime_pos
[Web IME] Fix suggestion window position in Chromium based browsers.
This commit is contained in:
commit
ac6f5780b1
@ -866,6 +866,9 @@ void DisplayServerWeb::_ime_callback(int p_type, const String &p_text) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ds->process_keys();
|
||||
Input::get_singleton()->flush_buffered_events();
|
||||
}
|
||||
|
||||
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() {
|
||||
process_keys();
|
||||
Input::get_singleton()->flush_buffered_events();
|
||||
if (godot_js_input_gamepad_sample() == OK) {
|
||||
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 {
|
||||
return 1;
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ private:
|
||||
static void _drop_files_js_callback(const Vector<String> &p_files);
|
||||
|
||||
void process_joypads();
|
||||
void process_keys();
|
||||
|
||||
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);
|
||||
|
@ -63,8 +63,15 @@ const GodotIME = {
|
||||
|
||||
ime_position: function (x, y) {
|
||||
if (GodotIME.ime) {
|
||||
GodotIME.ime.style.left = `${x}px`;
|
||||
GodotIME.ime.style.top = `${y}px`;
|
||||
const canvas = GodotConfig.canvas;
|
||||
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.opacity = 0.0;
|
||||
ime.style.position = 'fixed';
|
||||
ime.style.textAlign = 'left';
|
||||
ime.style.fontSize = '1px';
|
||||
ime.style.left = '0px';
|
||||
ime.style.top = '0px';
|
||||
ime.style.width = '2px';
|
||||
ime.style.height = '2px';
|
||||
ime.style.width = '100%';
|
||||
ime.style.height = '40px';
|
||||
ime.style.display = 'none';
|
||||
ime.contentEditable = 'true';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user