2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-15 00:29:06 +03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/File.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
#include <LibGUI/Application.h>
|
2021-01-05 01:51:49 +03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
#include <LibGUI/MenuBar.h>
|
|
|
|
#include <LibGUI/Window.h>
|
2020-10-08 23:32:22 +03:00
|
|
|
#include <LibGfx/Bitmap.h>
|
|
|
|
#include <LibWeb/OutOfProcessWebView.h>
|
2019-06-15 21:20:55 +03:00
|
|
|
#include <stdio.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
|
2019-06-15 21:20:55 +03:00
|
|
|
int main(int argc, char** argv)
|
2019-06-15 19:55:47 +03:00
|
|
|
{
|
2020-07-04 15:05:19 +03:00
|
|
|
auto app = GUI::Application::construct(argc, argv);
|
2019-09-25 12:44:22 +03:00
|
|
|
|
2020-02-02 14:34:39 +03:00
|
|
|
auto f = Core::File::construct();
|
2020-10-08 23:23:04 +03:00
|
|
|
URL url;
|
2019-09-25 12:45:47 +03:00
|
|
|
bool success;
|
|
|
|
if (argc < 2) {
|
2020-10-25 14:31:27 +03:00
|
|
|
success = f->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
2019-09-25 12:45:47 +03:00
|
|
|
} else {
|
2020-10-08 23:23:04 +03:00
|
|
|
url = URL::create_with_file_protocol(argv[1]);
|
2019-09-25 12:45:47 +03:00
|
|
|
f->set_filename(argv[1]);
|
2020-02-02 14:34:39 +03:00
|
|
|
success = f->open(Core::IODevice::OpenMode::ReadOnly);
|
2019-09-25 12:45:47 +03:00
|
|
|
}
|
|
|
|
if (!success) {
|
2019-09-21 21:50:06 +03:00
|
|
|
fprintf(stderr, "Error: %s\n", f->error_string());
|
2019-06-15 21:20:55 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2019-06-21 21:54:13 +03:00
|
|
|
|
2020-06-21 23:04:26 +03:00
|
|
|
auto html = f->read_all();
|
2019-06-16 22:35:03 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
auto window = GUI::Window::construct();
|
2020-10-08 23:32:22 +03:00
|
|
|
window->set_title("HTML");
|
|
|
|
auto& widget = window->set_main_widget<Web::OutOfProcessWebView>();
|
|
|
|
widget.on_title_change = [&](auto& title) {
|
|
|
|
window->set_title(String::formatted("{} - HTML", title));
|
|
|
|
};
|
2020-10-08 23:23:04 +03:00
|
|
|
widget.load_html(html, url);
|
2019-09-25 12:44:22 +03:00
|
|
|
window->show();
|
|
|
|
|
2020-04-21 17:01:00 +03:00
|
|
|
auto menubar = GUI::MenuBar::construct();
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2020-04-04 13:18:40 +03:00
|
|
|
auto& app_menu = menubar->add_menu("HTML");
|
|
|
|
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
2020-07-04 15:05:19 +03:00
|
|
|
app->quit();
|
2019-09-29 22:00:41 +03:00
|
|
|
}));
|
|
|
|
|
2020-04-04 13:18:40 +03:00
|
|
|
auto& help_menu = menubar->add_menu("Help");
|
2021-01-05 01:51:49 +03:00
|
|
|
help_menu.add_action(GUI::CommonActions::make_about_action("HTML", GUI::Icon::default_icon("filetype-html"), window));
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2020-07-04 15:05:19 +03:00
|
|
|
app->set_menubar(move(menubar));
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2020-02-06 13:56:38 +03:00
|
|
|
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
|
2019-09-29 22:00:41 +03:00
|
|
|
|
2020-07-04 15:05:19 +03:00
|
|
|
return app->exec();
|
2019-06-15 19:55:47 +03:00
|
|
|
}
|