Jelajahi Sumber

Userland+LibHTML: Add the html command

This is a simple command that can be used to display HTML from a given
file, or from the standard input, in an HtmlView. It replaces the `tho`
(test HTML output) command.
Sergey Bugaev 5 tahun lalu
induk
melakukan
6ec625d6f3

+ 0 - 1
Kernel/build-root-filesystem.sh

@@ -104,7 +104,6 @@ cp ../Servers/AudioServer/AudioServer mnt/bin/AudioServer
 cp ../Servers/TTYServer/TTYServer mnt/bin/TTYServer
 cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer
 cp ../Shell/Shell mnt/bin/Shell
-cp ../Libraries/LibHTML/tho mnt/bin/tho
 echo "done"
 
 echo -n "installing shortcuts... "

+ 1 - 4
Libraries/LibHTML/Makefile

@@ -2,12 +2,9 @@ include ../../Makefile.common
 
 LIBRARY = libhtml.a
 
-all: $(LIBRARY) tho
+all: $(LIBRARY)
 
 include Makefile.shared
 
-tho: $(TEST_OBJS) $(LIBRARY)
-	$(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -ldraw -lcore -lc
-
 $(LIBRARY): $(LIBHTML_OBJS)
 	@echo "LIB $@"; $(AR) rcs $@ $(LIBHTML_OBJS)

+ 2 - 5
Libraries/LibHTML/Makefile.shared

@@ -26,10 +26,7 @@ LIBHTML_OBJS = \
 GENERATED_SOURCES = \
     CSS/DefaultStyleSheetSource.cpp
 
-TEST_OBJS = test.o
-TEST_PROGRAM = tho
-
-OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS) $(TEST_OBJS)
+OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS)
 
 LIBRARY = libhtml.a
 DEFINES += -DUSERLAND
@@ -43,5 +40,5 @@ CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSourc
 -include $(OBJS:%.o=%.d)
 
 clean:
-	@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
+	@echo "CLEAN"; rm -f $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
 

+ 1 - 1
Userland/Makefile

@@ -19,7 +19,7 @@ clean:
 
 $(APPS) : % : %.o $(OBJS)
 	@echo "LD $@"
-	@$(LD) -o $@ $(LDFLAGS) $< -lc -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown
+	@$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown
 
 %.o: %.cpp
 	@echo "CXX $<"

+ 12 - 5
Libraries/LibHTML/test.cpp → Userland/html.cpp

@@ -7,6 +7,7 @@
 #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>
@@ -15,26 +16,32 @@ int main(int argc, char** argv)
 {
     GApplication app(argc, argv);
 
-    auto f = CFile::construct(argc == 1 ? "/home/anon/small.html" : argv[1]);
-    if (!f->open(CIODevice::ReadOnly)) {
+    auto f = CFile::construct();
+    bool success;
+    if (argc < 2) {
+        success = f->open(STDIN_FILENO, CIODevice::OpenMode::ReadOnly, CFile::ShouldCloseFileDescription::No);
+    } else {
+        f->set_filename(argv[1]);
+        success = f->open(CIODevice::OpenMode::ReadOnly);
+    }
+    if (!success) {
         fprintf(stderr, "Error: %s\n", f->error_string());
         return 1;
     }
 
     extern const char default_stylesheet_source[];
     String css = default_stylesheet_source;
-
     auto sheet = parse_css(css);
-    dump_sheet(sheet);
 
     String html = String::copy(f->read_all());
     auto document = parse_html(html);
-    dump_tree(document);
+    document->normalize();
     document->add_sheet(*sheet);
 
     auto window = GWindow::construct();
     auto widget = HtmlView::construct();
     widget->set_document(document);
+    window->set_title("HTML");
     window->set_main_widget(widget);
     window->show();