Serenity Operating System
at portability 95 lines 3.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <AK/ByteBuffer.h> 28#include <LibCore/File.h> 29#include <LibGUI/AboutDialog.h> 30#include <LibGUI/Action.h> 31#include <LibGUI/Application.h> 32#include <LibGUI/Menu.h> 33#include <LibGUI/MenuBar.h> 34#include <LibGUI/Window.h> 35#include <LibHTML/CSS/StyleResolver.h> 36#include <LibHTML/DOM/Element.h> 37#include <LibHTML/Dump.h> 38#include <LibHTML/HtmlView.h> 39#include <LibHTML/Layout/LayoutBlock.h> 40#include <LibHTML/Layout/LayoutInline.h> 41#include <LibHTML/Layout/LayoutNode.h> 42#include <LibHTML/Parser/CSSParser.h> 43#include <LibHTML/Parser/HTMLParser.h> 44#include <stdio.h> 45 46int main(int argc, char** argv) 47{ 48 GUI::Application app(argc, argv); 49 50 auto f = Core::File::construct(); 51 bool success; 52 if (argc < 2) { 53 success = f->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescription::No); 54 } else { 55 f->set_filename(argv[1]); 56 success = f->open(Core::IODevice::OpenMode::ReadOnly); 57 } 58 if (!success) { 59 fprintf(stderr, "Error: %s\n", f->error_string()); 60 return 1; 61 } 62 63 String html = String::copy(f->read_all()); 64 auto document = parse_html_document(html); 65 66 auto window = GUI::Window::construct(); 67 auto widget = HtmlView::construct(); 68 widget->set_document(document); 69 if (!widget->document()->title().is_null()) 70 window->set_title(String::format("%s - HTML", widget->document()->title().characters())); 71 else 72 window->set_title("HTML"); 73 window->set_main_widget(widget); 74 window->show(); 75 76 auto menubar = make<GUI::MenuBar>(); 77 78 auto app_menu = GUI::Menu::construct("HTML"); 79 app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { 80 app.quit(); 81 })); 82 menubar->add_menu(move(app_menu)); 83 84 auto help_menu = GUI::Menu::construct("Help"); 85 help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) { 86 GUI::AboutDialog::show("HTML", Gfx::Bitmap::load_from_file("/res/icons/32x32/filetype-html.png"), window); 87 })); 88 menubar->add_menu(move(help_menu)); 89 90 app.set_menubar(move(menubar)); 91 92 window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png")); 93 94 return app.exec(); 95}