diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp index d9cb76abe93..e02622d08be 100644 --- a/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Libraries/LibWeb/HTML/Navigable.cpp @@ -2576,7 +2576,7 @@ void Navigable::select_all() } } -void Navigable::paste(String const& text) +void Navigable::paste(Utf16String const& text) { auto document = active_document(); if (!document) diff --git a/Libraries/LibWeb/HTML/Navigable.h b/Libraries/LibWeb/HTML/Navigable.h index 1277a603dfa..6e95d1954cd 100644 --- a/Libraries/LibWeb/HTML/Navigable.h +++ b/Libraries/LibWeb/HTML/Navigable.h @@ -196,7 +196,7 @@ public: String selected_text() const; void select_all(); - void paste(String const&); + void paste(Utf16String const&); Web::EventHandler& event_handler() { return m_event_handler; } Web::EventHandler const& event_handler() const { return m_event_handler; } diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index aa659e38d8a..91f17b78882 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -156,7 +156,7 @@ void Internals::send_key(HTML::HTMLElement& target, String const& key_name, WebI page().handle_keydown(key_code, modifiers, 0, false); } -void Internals::paste(HTML::HTMLElement& target, String const& text) +void Internals::paste(HTML::HTMLElement& target, Utf16String const& text) { auto& page = this->page(); target.focus(); diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h index e5769a8a001..c26b55f7b9d 100644 --- a/Libraries/LibWeb/Internals/Internals.h +++ b/Libraries/LibWeb/Internals/Internals.h @@ -32,7 +32,7 @@ public: void send_text(HTML::HTMLElement&, String const&, WebIDL::UnsignedShort modifiers); void send_key(HTML::HTMLElement&, String const&, WebIDL::UnsignedShort modifiers); - void paste(HTML::HTMLElement& target, String const& text); + void paste(HTML::HTMLElement& target, Utf16String const& text); void commit_text(); void click(double x, double y); diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl index 8134dcfa60d..c4cb1017741 100644 --- a/Libraries/LibWeb/Internals/Internals.idl +++ b/Libraries/LibWeb/Internals/Internals.idl @@ -24,7 +24,7 @@ interface Internals { undefined sendText(HTMLElement target, DOMString text, optional unsigned short modifiers = 0); undefined sendKey(HTMLElement target, DOMString keyName, optional unsigned short modifiers = 0); - undefined paste(HTMLElement target, DOMString text); + undefined paste(HTMLElement target, Utf16DOMString text); undefined commitText(); undefined click(double x, double y); diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 6331b10078d..ccbaeb88122 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -1445,7 +1445,7 @@ EventResult EventHandler::handle_keyup(UIEvents::KeyCode key, u32 modifiers, u32 return fire_keyboard_event(UIEvents::EventNames::keyup, m_navigable, key, modifiers, code_point, false); } -EventResult EventHandler::handle_paste(String const& text) +EventResult EventHandler::handle_paste(Utf16String const& text) { auto active_document = m_navigable->active_document(); if (!active_document) @@ -1457,10 +1457,9 @@ EventResult EventHandler::handle_paste(String const& text) if (!target) return EventResult::Dropped; - auto utf16_string = Utf16String::from_utf8(text); + FIRE(input_event(UIEvents::EventNames::beforeinput, UIEvents::InputTypes::insertFromPaste, m_navigable, text)); + target->handle_insert(text); - FIRE(input_event(UIEvents::EventNames::beforeinput, UIEvents::InputTypes::insertFromPaste, m_navigable, utf16_string)); - target->handle_insert(utf16_string); return EventResult::Handled; } diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h index 508b3aab12e..0fe3d9bf83c 100644 --- a/Libraries/LibWeb/Page/EventHandler.h +++ b/Libraries/LibWeb/Page/EventHandler.h @@ -42,7 +42,7 @@ public: void set_mouse_event_tracking_paintable(GC::Ptr); - EventResult handle_paste(String const& text); + EventResult handle_paste(Utf16String const& text); void handle_sdl_input_events(); diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h index a2f4809b805..34185cbb11f 100644 --- a/Libraries/LibWebView/Application.h +++ b/Libraries/LibWebView/Application.h @@ -76,7 +76,7 @@ public: virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const; virtual void display_error_dialog(StringView error_message) const; - virtual String clipboard_text() const { return {}; } + virtual Utf16String clipboard_text() const { return {}; } virtual Vector clipboard_entries() const { return {}; } virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) { } diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index 3b5c4e0a114..6c6f4591cd8 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -1076,7 +1076,7 @@ void ConnectionFromClient::find_in_page_previous_match(u64 page_id) async_did_find_in_page(page_id, result.current_match_index, result.total_match_count); } -void ConnectionFromClient::paste(u64 page_id, String text) +void ConnectionFromClient::paste(u64 page_id, Utf16String text) { if (auto page = this->page(page_id); page.has_value()) page->page().focused_navigable().paste(text); diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h index 91f524a173d..dd8357ddeb6 100644 --- a/Services/WebContent/ConnectionFromClient.h +++ b/Services/WebContent/ConnectionFromClient.h @@ -155,7 +155,7 @@ private: virtual void find_in_page_next_match(u64 page_id) override; virtual void find_in_page_previous_match(u64 page_id) override; - virtual void paste(u64 page_id, String text) override; + virtual void paste(u64 page_id, Utf16String text) override; virtual void system_time_zone_changed() override; virtual void cookies_changed(Vector) override; diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc index a1404b609dd..f5cf45e7efe 100644 --- a/Services/WebContent/WebContentServer.ipc +++ b/Services/WebContent/WebContentServer.ipc @@ -82,7 +82,7 @@ endpoint WebContentServer get_selected_text(u64 page_id) => (ByteString selection) select_all(u64 page_id) =| - paste(u64 page_id, String text) =| + paste(u64 page_id, Utf16String text) =| find_in_page(u64 page_id, String query, AK::CaseSensitivity case_sensitivity) =| find_in_page_next_match(u64 page_id) =| diff --git a/UI/AppKit/Application/Application.h b/UI/AppKit/Application/Application.h index 94fcaee878a..7d42b6c8747 100644 --- a/UI/AppKit/Application/Application.h +++ b/UI/AppKit/Application/Application.h @@ -27,7 +27,7 @@ private: virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const override; virtual void display_error_dialog(StringView error_message) const override; - virtual String clipboard_text() const override; + virtual Utf16String clipboard_text() const override; virtual Vector clipboard_entries() const override; virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override; diff --git a/UI/AppKit/Application/Application.mm b/UI/AppKit/Application/Application.mm index 7935155d0be..353e8d95f2b 100644 --- a/UI/AppKit/Application/Application.mm +++ b/UI/AppKit/Application/Application.mm @@ -98,12 +98,12 @@ void Application::display_error_dialog(StringView error_message) const completionHandler:nil]; } -String Application::clipboard_text() const +Utf16String Application::clipboard_text() const { auto* paste_board = [NSPasteboard generalPasteboard]; if (auto* contents = [paste_board stringForType:NSPasteboardTypeString]) - return Ladybird::ns_string_to_string(contents); + return Ladybird::ns_string_to_utf16_string(contents); return {}; } diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp index 74e137c5570..0cf39f4fb36 100644 --- a/UI/Qt/Application.cpp +++ b/UI/Qt/Application.cpp @@ -136,10 +136,10 @@ void Application::display_error_dialog(StringView error_message) const QMessageBox::warning(active_tab(), "Ladybird", qstring_from_ak_string(error_message)); } -String Application::clipboard_text() const +Utf16String Application::clipboard_text() const { auto const* clipboard = QGuiApplication::clipboard(); - return ak_string_from_qstring(clipboard->text()); + return utf16_string_from_qstring(clipboard->text()); } Vector Application::clipboard_entries() const diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h index 895bad0b7e5..6ccd150b9f6 100644 --- a/UI/Qt/Application.h +++ b/UI/Qt/Application.h @@ -43,7 +43,7 @@ private: virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const override; virtual void display_error_dialog(StringView error_message) const override; - virtual String clipboard_text() const override; + virtual Utf16String clipboard_text() const override; virtual Vector clipboard_entries() const override; virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override;