mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
Ladybird: Add a location bar and allow navigating to new pages :^)
This commit is contained in:
parent
88d256c109
commit
8b7000e151
7 changed files with 60 additions and 18 deletions
7
Ladybird/.gitignore
vendored
7
Ladybird/.gitignore
vendored
|
@ -1,8 +1,5 @@
|
||||||
.qmake.stash
|
.qmake.stash
|
||||||
Makefile
|
Makefile
|
||||||
WebView.o
|
|
||||||
ladybird
|
ladybird
|
||||||
main.o
|
*.o
|
||||||
moc_WebView.cpp
|
moc_*
|
||||||
moc_WebView.o
|
|
||||||
moc_predefs.h
|
|
||||||
|
|
27
Ladybird/BrowserWindow.cpp
Normal file
27
Ladybird/BrowserWindow.cpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#include "BrowserWindow.h"
|
||||||
|
#include "WebView.h"
|
||||||
|
#include <QStatusBar>
|
||||||
|
|
||||||
|
BrowserWindow::BrowserWindow()
|
||||||
|
{
|
||||||
|
m_toolbar = new QToolBar;
|
||||||
|
m_toolbar->setFixedHeight(28);
|
||||||
|
m_location_edit = new QLineEdit;
|
||||||
|
m_toolbar->addWidget(m_location_edit);
|
||||||
|
|
||||||
|
addToolBar(m_toolbar);
|
||||||
|
|
||||||
|
m_view = new WebView;
|
||||||
|
setCentralWidget(m_view);
|
||||||
|
|
||||||
|
QObject::connect(m_view, &WebView::linkHovered, statusBar(), &QStatusBar::showMessage);
|
||||||
|
QObject::connect(m_view, &WebView::linkUnhovered, statusBar(), &QStatusBar::clearMessage);
|
||||||
|
|
||||||
|
QObject::connect(m_view, &WebView::loadStarted, m_location_edit, &QLineEdit::setText);
|
||||||
|
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &BrowserWindow::location_edit_return_pressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::location_edit_return_pressed()
|
||||||
|
{
|
||||||
|
view().load(m_location_edit->text().toUtf8().data());
|
||||||
|
}
|
23
Ladybird/BrowserWindow.h
Normal file
23
Ladybird/BrowserWindow.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QToolBar>
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class WebView;
|
||||||
|
|
||||||
|
class BrowserWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
BrowserWindow();
|
||||||
|
|
||||||
|
WebView& view() { return *m_view; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void location_edit_return_pressed();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QToolBar* m_toolbar { nullptr };
|
||||||
|
QLineEdit* m_location_edit { nullptr };
|
||||||
|
WebView* m_view { nullptr };
|
||||||
|
};
|
|
@ -138,8 +138,9 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void page_did_start_loading(AK::URL const&) override
|
virtual void page_did_start_loading(AK::URL const& url) override
|
||||||
{
|
{
|
||||||
|
emit m_view.loadStarted(url.to_string().characters());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void page_did_finish_loading(AK::URL const&) override
|
virtual void page_did_finish_loading(AK::URL const&) override
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void linkHovered(QString, int timeout = 0);
|
void linkHovered(QString, int timeout = 0);
|
||||||
void linkUnhovered();
|
void linkUnhovered();
|
||||||
|
void loadStarted(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OwnPtr<HeadlessBrowserPageClient> m_page_client;
|
OwnPtr<HeadlessBrowserPageClient> m_page_client;
|
||||||
|
|
|
@ -20,8 +20,8 @@ INCLUDEPATH += \
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += WebView.h
|
HEADERS += WebView.h BrowserWindow.h
|
||||||
SOURCES += main.cpp WebView.cpp
|
SOURCES += main.cpp WebView.cpp BrowserWindow.cpp
|
||||||
|
|
||||||
QMAKE_LIBDIR += /home/kling/src/serenity/Build/lagom/
|
QMAKE_LIBDIR += /home/kling/src/serenity/Build/lagom/
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "BrowserWindow.h"
|
||||||
#include "WebView.h"
|
#include "WebView.h"
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QStatusBar>
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
extern void initialize_web_engine();
|
extern void initialize_web_engine();
|
||||||
|
@ -29,24 +28,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
Core::EventLoop event_loop;
|
Core::EventLoop event_loop;
|
||||||
|
|
||||||
QApplication app(arguments.argc, arguments.argv);
|
QApplication app(arguments.argc, arguments.argv);
|
||||||
QMainWindow window;
|
BrowserWindow window;
|
||||||
window.setWindowTitle("Ladybird");
|
window.setWindowTitle("Ladybird");
|
||||||
window.resize(800, 600);
|
window.resize(800, 600);
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
WebView view;
|
|
||||||
window.setCentralWidget(&view);
|
|
||||||
|
|
||||||
QObject::connect(&view, &WebView::linkHovered, window.statusBar(), &QStatusBar::showMessage);
|
|
||||||
QObject::connect(&view, &WebView::linkUnhovered, window.statusBar(), &QStatusBar::clearMessage);
|
|
||||||
|
|
||||||
auto qt_event_loop_driver = Core::Timer::create_repeating(50, [&] {
|
auto qt_event_loop_driver = Core::Timer::create_repeating(50, [&] {
|
||||||
app.processEvents();
|
app.processEvents();
|
||||||
});
|
});
|
||||||
qt_event_loop_driver->start();
|
qt_event_loop_driver->start();
|
||||||
|
|
||||||
if (!url.is_empty()) {
|
if (!url.is_empty()) {
|
||||||
view.load(url);
|
window.view().load(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return event_loop.exec();
|
return event_loop.exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue