summaryrefslogtreecommitdiff
path: root/Applications/Browser/main.cpp
blob: aef4e98e2073f3420f14cbc7b87f5ee230585bb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <LibCore/CFile.h>
#include <LibGUI/GAboutDialog.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GStatusBar.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GToolBar.h>
#include <LibGUI/GWindow.h>
#include <LibHTML/CSS/StyleResolver.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Dump.h>
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutInline.h>
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/Parser/CSSParser.h>
#include <LibHTML/Parser/HTMLParser.h>
#include <stdio.h>

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<GBoxLayout>(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));
    };

    html_widget->on_title_change = [&](auto& title) {
        window->set_title(String::format("%s - Browser", title.characters()));
    };

    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<GMenuBar>();

    auto app_menu = make<GMenu>("Browser");
    app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
        app.quit();
    }));
    menubar->add_menu(move(app_menu));

    auto help_menu = make<GMenu>("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();

    String url_to_load = "file:///home/anon/www/welcome.html";

    if (app.args().size() >= 1)
        url_to_load = app.args()[0];

    html_widget->load(url_to_load);

    return app.exec();
}