mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb+WebContent+UI: Port text pasting to UTF-16
This commit is contained in:
parent
ca082d6d73
commit
efa9311527
Notes:
github-actions[bot]
2025-09-19 10:39:52 +00:00
Author: https://github.com/trflynn89
Commit: efa9311527
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6228
15 changed files with 19 additions and 20 deletions
|
|
@ -2576,7 +2576,7 @@ void Navigable::select_all()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Navigable::paste(String const& text)
|
void Navigable::paste(Utf16String const& text)
|
||||||
{
|
{
|
||||||
auto document = active_document();
|
auto document = active_document();
|
||||||
if (!document)
|
if (!document)
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ public:
|
||||||
|
|
||||||
String selected_text() const;
|
String selected_text() const;
|
||||||
void select_all();
|
void select_all();
|
||||||
void paste(String const&);
|
void paste(Utf16String const&);
|
||||||
|
|
||||||
Web::EventHandler& event_handler() { return m_event_handler; }
|
Web::EventHandler& event_handler() { return m_event_handler; }
|
||||||
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ void Internals::send_key(HTML::HTMLElement& target, String const& key_name, WebI
|
||||||
page().handle_keydown(key_code, modifiers, 0, false);
|
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();
|
auto& page = this->page();
|
||||||
target.focus();
|
target.focus();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
void send_text(HTML::HTMLElement&, String const&, WebIDL::UnsignedShort modifiers);
|
void send_text(HTML::HTMLElement&, String const&, WebIDL::UnsignedShort modifiers);
|
||||||
void send_key(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 commit_text();
|
||||||
|
|
||||||
void click(double x, double y);
|
void click(double x, double y);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ interface Internals {
|
||||||
|
|
||||||
undefined sendText(HTMLElement target, DOMString text, optional unsigned short modifiers = 0);
|
undefined sendText(HTMLElement target, DOMString text, optional unsigned short modifiers = 0);
|
||||||
undefined sendKey(HTMLElement target, DOMString keyName, 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 commitText();
|
||||||
|
|
||||||
undefined click(double x, double y);
|
undefined click(double x, double y);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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();
|
auto active_document = m_navigable->active_document();
|
||||||
if (!active_document)
|
if (!active_document)
|
||||||
|
|
@ -1457,10 +1457,9 @@ EventResult EventHandler::handle_paste(String const& text)
|
||||||
if (!target)
|
if (!target)
|
||||||
return EventResult::Dropped;
|
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;
|
return EventResult::Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public:
|
||||||
|
|
||||||
void set_mouse_event_tracking_paintable(GC::Ptr<Painting::Paintable>);
|
void set_mouse_event_tracking_paintable(GC::Ptr<Painting::Paintable>);
|
||||||
|
|
||||||
EventResult handle_paste(String const& text);
|
EventResult handle_paste(Utf16String const& text);
|
||||||
|
|
||||||
void handle_sdl_input_events();
|
void handle_sdl_input_events();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ public:
|
||||||
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const;
|
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const;
|
||||||
virtual void display_error_dialog(StringView error_message) const;
|
virtual void display_error_dialog(StringView error_message) const;
|
||||||
|
|
||||||
virtual String clipboard_text() const { return {}; }
|
virtual Utf16String clipboard_text() const { return {}; }
|
||||||
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const { return {}; }
|
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const { return {}; }
|
||||||
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) { }
|
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) { }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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())
|
if (auto page = this->page(page_id); page.has_value())
|
||||||
page->page().focused_navigable().paste(text);
|
page->page().focused_navigable().paste(text);
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ private:
|
||||||
virtual void find_in_page_next_match(u64 page_id) override;
|
virtual void find_in_page_next_match(u64 page_id) override;
|
||||||
virtual void find_in_page_previous_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 system_time_zone_changed() override;
|
||||||
virtual void cookies_changed(Vector<Web::Cookie::Cookie>) override;
|
virtual void cookies_changed(Vector<Web::Cookie::Cookie>) override;
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ endpoint WebContentServer
|
||||||
|
|
||||||
get_selected_text(u64 page_id) => (ByteString selection)
|
get_selected_text(u64 page_id) => (ByteString selection)
|
||||||
select_all(u64 page_id) =|
|
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(u64 page_id, String query, AK::CaseSensitivity case_sensitivity) =|
|
||||||
find_in_page_next_match(u64 page_id) =|
|
find_in_page_next_match(u64 page_id) =|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ private:
|
||||||
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const override;
|
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 void display_error_dialog(StringView error_message) const override;
|
||||||
|
|
||||||
virtual String clipboard_text() const override;
|
virtual Utf16String clipboard_text() const override;
|
||||||
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const override;
|
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const override;
|
||||||
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override;
|
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,12 @@ void Application::display_error_dialog(StringView error_message) const
|
||||||
completionHandler:nil];
|
completionHandler:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
String Application::clipboard_text() const
|
Utf16String Application::clipboard_text() const
|
||||||
{
|
{
|
||||||
auto* paste_board = [NSPasteboard generalPasteboard];
|
auto* paste_board = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
if (auto* contents = [paste_board stringForType:NSPasteboardTypeString])
|
if (auto* contents = [paste_board stringForType:NSPasteboardTypeString])
|
||||||
return Ladybird::ns_string_to_string(contents);
|
return Ladybird::ns_string_to_utf16_string(contents);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,10 @@ void Application::display_error_dialog(StringView error_message) const
|
||||||
QMessageBox::warning(active_tab(), "Ladybird", qstring_from_ak_string(error_message));
|
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();
|
auto const* clipboard = QGuiApplication::clipboard();
|
||||||
return ak_string_from_qstring(clipboard->text());
|
return utf16_string_from_qstring(clipboard->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Web::Clipboard::SystemClipboardRepresentation> Application::clipboard_entries() const
|
Vector<Web::Clipboard::SystemClipboardRepresentation> Application::clipboard_entries() const
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ private:
|
||||||
virtual void display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const override;
|
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 void display_error_dialog(StringView error_message) const override;
|
||||||
|
|
||||||
virtual String clipboard_text() const override;
|
virtual Utf16String clipboard_text() const override;
|
||||||
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const override;
|
virtual Vector<Web::Clipboard::SystemClipboardRepresentation> clipboard_entries() const override;
|
||||||
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override;
|
virtual void insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation) override;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue