LibWeb: Add a hook for when an URL is dropped on an HtmlView
Embedders of HtmlView can now react to this by hooking on_url_drop.
This commit is contained in:
parent
f1708b3832
commit
fc26aefe81
Notes:
sideshowbarker
2024-07-19 06:44:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fc26aefe812
2 changed files with 14 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
|
@ -590,4 +591,15 @@ void HtmlView::run_javascript_url(const String& url)
|
|||
document()->run_javascript(source);
|
||||
}
|
||||
|
||||
void HtmlView::drop_event(GUI::DropEvent& event)
|
||||
{
|
||||
if (event.mime_data().has_urls()) {
|
||||
if (on_url_drop) {
|
||||
on_url_drop(event.mime_data().urls().first());
|
||||
return;
|
||||
}
|
||||
}
|
||||
ScrollableWidget::drop_event(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
Function<void(const String&)> on_title_change;
|
||||
Function<void(const URL&)> on_load_start;
|
||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||
Function<void(const URL&)> on_url_drop;
|
||||
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
|
||||
|
@ -76,6 +77,7 @@ protected:
|
|||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||
virtual void mouseup_event(GUI::MouseEvent&) override;
|
||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
|
||||
private:
|
||||
virtual void did_scroll() override;
|
||||
|
|
Loading…
Add table
Reference in a new issue