From 0a38e0028f6787160a1b464195380743b2a1adbd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 5 Oct 2019 10:19:12 +0200 Subject: [PATCH] Browser: Start working on a simple browser using LibHTML This was inevitable. :^) --- Applications/Browser/Makefile | 8 +++ Applications/Browser/main.cpp | 96 +++++++++++++++++++++++++++++++++ Kernel/build-root-filesystem.sh | 2 + Kernel/makeall.sh | 1 + 4 files changed, 107 insertions(+) create mode 100755 Applications/Browser/Makefile create mode 100644 Applications/Browser/main.cpp diff --git a/Applications/Browser/Makefile b/Applications/Browser/Makefile new file mode 100755 index 0000000000..1905214418 --- /dev/null +++ b/Applications/Browser/Makefile @@ -0,0 +1,8 @@ +include ../../Makefile.common + +OBJS = \ + main.o + +APP = Browser + +include ../Makefile.common diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp new file mode 100644 index 0000000000..78d017eab9 --- /dev/null +++ b/Applications/Browser/main.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + GApplication app(argc, argv); + + auto window = GWindow::construct(); + window->set_rect(100, 100, 640, 480); + + auto widget = GWidget::construct(); + widget->set_fill_with_background_color(true); + widget->set_layout(make(Orientation::Vertical)); + widget->layout()->set_spacing(0); + + auto toolbar = GToolBar::construct(widget); + auto html_widget = HtmlView::construct(widget); + + toolbar->add_action(GCommonActions::make_go_back_action([&](auto&) { + // FIXME: Implement back action + })); + + toolbar->add_action(GCommonActions::make_go_forward_action([&](auto&) { + // FIXME: Implement forward action + })); + + toolbar->add_action(GAction::create("Reload", { Mod_Ctrl, Key_R }, GraphicsBitmap::load_from_file("/res/icons/16x16/reload.png"), [&](auto&) { + html_widget->reload(); + })); + + auto location_box = GTextBox::construct(toolbar); + + location_box->on_return_pressed = [&] { + html_widget->load(location_box->text()); + }; + + html_widget->on_load_start = [&](auto& url) { + location_box->set_text(url.to_string()); + }; + + html_widget->on_link_click = [&](auto& url) { + html_widget->load(html_widget->document()->complete_url(url)); + }; + + auto focus_location_box_action = GAction::create("Focus location box", { Mod_Ctrl, Key_L }, [&](auto&) { + location_box->select_all(); + location_box->set_focus(true); + }); + + auto statusbar = GStatusBar::construct(widget); + + auto menubar = make(); + + auto app_menu = make("Browser"); + app_menu->add_action(GCommonActions::make_quit_action([&](auto&) { + app.quit(); + })); + menubar->add_menu(move(app_menu)); + + auto help_menu = make("Help"); + help_menu->add_action(GAction::create("About", [&](const GAction&) { + GAboutDialog::show("Browser", GraphicsBitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window); + })); + menubar->add_menu(move(help_menu)); + + app.set_menubar(move(menubar)); + + window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-html.png")); + + window->set_title("Browser"); + window->set_main_widget(widget); + window->show(); + + html_widget->load("file:///home/anon/www/phint.html"); + + return app.exec(); +} diff --git a/Kernel/build-root-filesystem.sh b/Kernel/build-root-filesystem.sh index 62a0c1b772..b9c51f73d9 100755 --- a/Kernel/build-root-filesystem.sh +++ b/Kernel/build-root-filesystem.sh @@ -89,6 +89,7 @@ cp ../Applications/SoundPlayer/SoundPlayer mnt/bin/SoundPlayer cp ../Applications/DisplayProperties/DisplayProperties mnt/bin/DisplayProperties cp ../Applications/Welcome/Welcome mnt/bin/Welcome cp ../Applications/Help/Help mnt/bin/Help +cp ../Applications/Browser/Browser mnt/bin/Browser cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld cp ../Demos/HelloWorld2/HelloWorld2 mnt/bin/HelloWorld2 cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch @@ -129,6 +130,7 @@ ln -s Calculator mnt/bin/calc ln -s Inspector mnt/bin/ins ln -s SoundPlayer mnt/bin/sp ln -s Help mnt/bin/help +ln -s Browser mnt/bin/br echo "done" mkdir -p mnt/boot/ diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index 2e9e2b5996..27fdb4d80e 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -60,6 +60,7 @@ build_targets="$build_targets ../Applications/TextEditor" build_targets="$build_targets ../Applications/SoundPlayer" build_targets="$build_targets ../Applications/Welcome" build_targets="$build_targets ../Applications/Help" +build_targets="$build_targets ../Applications/Browser" build_targets="$build_targets ../Demos/Fire" build_targets="$build_targets ../Demos/HelloWorld"