mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05:00
Ladybird: Accept file drops
This commit is contained in:
parent
731fec525e
commit
f3c6510b83
3 changed files with 26 additions and 0 deletions
|
@ -349,6 +349,14 @@ void BrowserWindow::new_tab(QString const& url, Activate activate)
|
|||
QObject::connect(tab_ptr, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
|
||||
QObject::connect(tab_ptr, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
|
||||
|
||||
QObject::connect(&tab_ptr->view(), &WebContentView::urls_dropped, this, [this](auto& urls) {
|
||||
VERIFY(urls.size());
|
||||
m_current_tab->navigate(urls[0].toString());
|
||||
|
||||
for (qsizetype i = 1; i < urls.size(); ++i)
|
||||
new_tab(urls[i].toString(), Activate::No);
|
||||
});
|
||||
|
||||
tab_ptr->view().on_get_all_cookies = [this](auto const& url) {
|
||||
return m_cookie_jar.get_all_cookies(url);
|
||||
};
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
|
@ -58,6 +59,7 @@ WebContentView::WebContentView(StringView webdriver_content_ipc_path)
|
|||
: m_webdriver_content_ipc_path(webdriver_content_ipc_path)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
|
||||
|
||||
|
@ -312,6 +314,19 @@ void WebContentView::mouseReleaseEvent(QMouseEvent* event)
|
|||
client().async_mouse_up(to_content(position), button, buttons, modifiers);
|
||||
}
|
||||
|
||||
void WebContentView::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void WebContentView::dropEvent(QDropEvent* event)
|
||||
{
|
||||
VERIFY(event->mimeData()->hasUrls());
|
||||
emit urls_dropped(event->mimeData()->urls());
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void WebContentView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
switch (event->key()) {
|
||||
|
|
|
@ -78,6 +78,8 @@ public:
|
|||
virtual void mouseMoveEvent(QMouseEvent*) override;
|
||||
virtual void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent*) override;
|
||||
virtual void dragEnterEvent(QDragEnterEvent*) override;
|
||||
virtual void dropEvent(QDropEvent*) override;
|
||||
virtual void keyPressEvent(QKeyEvent* event) override;
|
||||
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
||||
virtual void showEvent(QShowEvent*) override;
|
||||
|
@ -159,6 +161,7 @@ signals:
|
|||
void navigate_forward();
|
||||
void refresh();
|
||||
void restore_window();
|
||||
void urls_dropped(QList<QUrl> const&);
|
||||
Gfx::IntPoint reposition_window(Gfx::IntPoint);
|
||||
Gfx::IntSize resize_window(Gfx::IntSize);
|
||||
Gfx::IntRect maximize_window();
|
||||
|
|
Loading…
Reference in a new issue