LibWeb: Move everything into the Web namespace

This commit is contained in:
Andreas Kling 2020-03-07 10:27:02 +01:00
parent 6a3b12664a
commit 7a6c4a72d5
Notes: sideshowbarker 2024-07-19 08:51:28 +09:00
143 changed files with 593 additions and 45 deletions

View file

@ -41,13 +41,13 @@ InspectorWidget::InspectorWidget()
auto& splitter = add<GUI::VerticalSplitter>();
m_dom_tree_view = splitter.add<GUI::TreeView>();
m_dom_tree_view->on_selection = [this](auto& index) {
auto* node = static_cast<Node*>(index.internal_data());
auto* node = static_cast<Web::Node*>(index.internal_data());
node->document().set_inspected_node(node);
if (node->is_element()) {
auto element = to<Element>(*node);
auto element = Web::to<Web::Element>(*node);
if (element.resolved_style()) {
m_style_table_view->set_model(StylePropertiesModel::create(*element.resolved_style()));
m_computed_style_table_view->set_model(StylePropertiesModel::create(*element.computed_style()));
m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.resolved_style()));
m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style()));
}
} else {
m_style_table_view->set_model(nullptr);
@ -68,10 +68,10 @@ InspectorWidget::~InspectorWidget()
{
}
void InspectorWidget::set_document(Document* document)
void InspectorWidget::set_document(Web::Document* document)
{
if (m_document == document)
return;
m_document = document;
m_dom_tree_view->set_model(DOMTreeModel::create(*document));
m_dom_tree_view->set_model(Web::DOMTreeModel::create(*document));
}

View file

@ -25,15 +25,14 @@
*/
#include <LibGUI/Widget.h>
class Document;
#include <LibHTML/Forward.h>
class InspectorWidget final : public GUI::Widget {
C_OBJECT(InspectorWidget)
public:
virtual ~InspectorWidget();
void set_document(Document*);
void set_document(Web::Document*);
private:
InspectorWidget();
@ -41,5 +40,5 @@ private:
RefPtr<GUI::TreeView> m_dom_tree_view;
RefPtr<GUI::TableView> m_style_table_view;
RefPtr<GUI::TableView> m_computed_style_table_view;
RefPtr<Document> m_document;
RefPtr<Web::Document> m_document;
};

View file

@ -64,7 +64,7 @@ int main(int argc, char** argv)
GUI::Application app(argc, argv);
// Connect to the ProtocolServer immediately so we can drop the "unix" pledge.
ResourceLoader::the();
Web::ResourceLoader::the();
if (pledge("stdio shared_buffer accept rpath", nullptr) < 0) {
perror("pledge");
@ -81,7 +81,7 @@ int main(int argc, char** argv)
widget.layout()->set_spacing(0);
auto& toolbar = widget.add<GUI::ToolBar>();
auto& html_widget = widget.add<HtmlView>();
auto& html_widget = widget.add<Web::HtmlView>();
History<URL> history;
@ -157,12 +157,12 @@ int main(int argc, char** argv)
statusbar.set_text(href);
};
ResourceLoader::the().on_load_counter_change = [&] {
if (ResourceLoader::the().pending_loads() == 0) {
Web::ResourceLoader::the().on_load_counter_change = [&] {
if (Web::ResourceLoader::the().pending_loads() == 0) {
statusbar.set_text("");
return;
}
statusbar.set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
statusbar.set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads()));
};
auto menubar = make<GUI::MenuBar>();

View file

@ -93,7 +93,7 @@ int main(int argc, char* argv[])
tree_view.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
tree_view.set_preferred_size(200, 500);
auto& html_view = splitter.add<HtmlView>();
auto& html_view = splitter.add<Web::HtmlView>();
History history;
@ -129,7 +129,7 @@ int main(int argc, char* argv[])
ASSERT(success);
String html = md_document.render_to_html();
auto html_document = parse_html_document(html);
auto html_document = Web::parse_html_document(html);
html_view.set_document(html_document);
String page_and_section = model->page_and_section(tree_view.selection().first());

View file

@ -43,14 +43,14 @@ NonnullRefPtr<IRCLogBuffer> IRCLogBuffer::create()
IRCLogBuffer::IRCLogBuffer()
{
m_document = adopt(*new Document);
m_document->append_child(adopt(*new DocumentType(document())));
m_document = adopt(*new Web::Document);
m_document->append_child(adopt(*new Web::DocumentType(document())));
auto html_element = create_element(document(), "html");
m_document->append_child(html_element);
auto head_element = create_element(document(), "head");
html_element->append_child(head_element);
auto style_element = create_element(document(), "style");
style_element->append_child(adopt(*new Text(document(), "div { font-family: Csilla; font-weight: lighter; }")));
style_element->append_child(adopt(*new Web::Text(document(), "div { font-family: Csilla; font-weight: lighter; }")));
head_element->append_child(style_element);
auto body_element = create_element(document(), "body");
html_element->append_child(body_element);

View file

@ -49,11 +49,11 @@ public:
void add_message(const String& text, Color = Color::Black);
void dump() const;
const Document& document() const { return *m_document; }
Document& document() { return *m_document; }
const Web::Document& document() const { return *m_document; }
Web::Document& document() { return *m_document; }
private:
IRCLogBuffer();
RefPtr<Document> m_document;
RefPtr<Element> m_container_element;
RefPtr<Web::Document> m_document;
RefPtr<Web::Element> m_container_element;
};

View file

@ -46,7 +46,7 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
// Make a container for the log buffer view + (optional) member list.
auto& container = add<GUI::HorizontalSplitter>();
m_html_view = container.add<HtmlView>();
m_html_view = container.add<Web::HtmlView>();
if (m_type == Channel) {
auto& member_view = container.add<GUI::TableView>();
@ -82,7 +82,7 @@ IRCWindow::~IRCWindow()
void IRCWindow::set_log_buffer(const IRCLogBuffer& log_buffer)
{
m_log_buffer = &log_buffer;
m_html_view->set_document(const_cast<Document*>(&log_buffer.document()));
m_html_view->set_document(const_cast<Web::Document*>(&log_buffer.document()));
}
bool IRCWindow::is_active() const

View file

@ -27,12 +27,12 @@
#pragma once
#include <LibGUI/Widget.h>
#include <LibHTML/Forward.h>
class IRCChannel;
class IRCClient;
class IRCQuery;
class IRCLogBuffer;
class HtmlView;
class IRCWindow : public GUI::Widget {
C_OBJECT(IRCWindow)
@ -72,7 +72,7 @@ private:
void* m_owner { nullptr };
Type m_type;
String m_name;
RefPtr<HtmlView> m_html_view;
RefPtr<Web::HtmlView> m_html_view;
RefPtr<GUI::TextEditor> m_text_editor;
RefPtr<IRCLogBuffer> m_log_buffer;
int m_unread_count { 0 };

View file

@ -48,7 +48,7 @@ Editor::Editor()
m_documentation_tooltip_window = GUI::Window::construct();
m_documentation_tooltip_window->set_rect(0, 0, 500, 400);
m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
m_documentation_html_view = m_documentation_tooltip_window->set_main_widget<HtmlView>();
m_documentation_html_view = m_documentation_tooltip_window->set_main_widget<Web::HtmlView>();
}
Editor::~Editor()
@ -145,7 +145,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
auto html_text = man_document.render_to_html();
auto html_document = parse_html_document(html_text);
auto html_document = Web::parse_html_document(html_text);
if (!html_document) {
dbg() << "failed to parse HTML";
return;
@ -153,10 +153,10 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
// FIXME: LibHTML needs a friendlier DOM manipulation API. Something like innerHTML :^)
auto style_element = create_element(*html_document, "style");
style_element->append_child(adopt(*new Text(*html_document, "body { background-color: #dac7b5; }")));
style_element->append_child(adopt(*new Web::Text(*html_document, "body { background-color: #dac7b5; }")));
// FIXME: This const_cast should not be necessary.
auto* head_element = const_cast<HTMLHeadElement*>(html_document->head());
auto* head_element = const_cast<Web::HTMLHeadElement*>(html_document->head());
ASSERT(head_element);
head_element->append_child(style_element);

View file

@ -27,9 +27,9 @@
#pragma once
#include <LibGUI/TextEditor.h>
#include <LibHTML/Forward.h>
class EditorWrapper;
class HtmlView;
class Editor final : public GUI::TextEditor {
C_OBJECT(Editor)
@ -52,6 +52,6 @@ private:
explicit Editor();
RefPtr<GUI::Window> m_documentation_tooltip_window;
RefPtr<HtmlView> m_documentation_html_view;
RefPtr<Web::HtmlView> m_documentation_html_view;
String m_last_parsed_token;
};

View file

@ -309,7 +309,8 @@ PageFaultResponse Region::handle_fault(const PageFault& fault)
}
return handle_zero_fault(page_index_in_region);
#else
ASSERT_NOT_REACHED();
dbg() << "BUG! Unexpected NP fault at " << fault.vaddr();
return PageFaultResponse::ShouldCrash;
#endif
}
ASSERT(fault.type() == PageFault::Type::ProtectionViolation);

View file

@ -50,7 +50,7 @@ void __libc_init()
}
extern u32 __stack_chk_guard;
u32 __stack_chk_guard = (u32)0xc0000c13;
u32 __stack_chk_guard = (u32)0xc6c7c8c9;
[[noreturn]] void __stack_chk_fail()
{

View file

@ -28,6 +28,8 @@
#include <AK/String.h>
namespace Web {
class Length {
public:
enum class Type {
@ -76,3 +78,5 @@ inline const LogStream& operator<<(const LogStream& stream, const Length& value)
{
return stream << value.to_string();
}
}

View file

@ -28,9 +28,13 @@
#include <LibHTML/CSS/Length.h>
namespace Web {
struct LengthBox {
Length top;
Length right;
Length bottom;
Length left;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/CSS/Selector.h>
namespace Web {
Selector::Selector(Vector<ComplexSelector>&& component_lists)
: m_complex_selectors(move(component_lists))
{
@ -61,3 +63,5 @@ Specificity Selector::specificity() const
return { ids, classes, tag_names };
}
}

View file

@ -30,6 +30,8 @@
#include <AK/Vector.h>
#include <LibHTML/CSS/Specificity.h>
namespace Web {
class Selector {
public:
struct SimpleSelector {
@ -90,3 +92,5 @@ public:
private:
Vector<ComplexSelector> m_complex_selectors;
};
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/DOM/Element.h>
#include <LibHTML/DOM/Text.h>
namespace Web {
namespace SelectorEngine {
static bool matches_hover_pseudo_class(const Element& element)
@ -146,3 +148,5 @@ bool matches(const Selector& selector, const Element& element)
}
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/CSS/Selector.h>
namespace Web {
class Element;
namespace SelectorEngine {
@ -35,3 +37,5 @@ namespace SelectorEngine {
bool matches(const Selector&, const Element&);
}
}

View file

@ -26,6 +26,8 @@
#pragma once
namespace Web {
class Specificity {
public:
Specificity(unsigned ids, unsigned classes, unsigned tag_names)
@ -58,3 +60,5 @@ private:
unsigned m_classes { 0 };
unsigned m_tag_names { 0 };
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/CSS/StyleDeclaration.h>
namespace Web {
StyleDeclaration::StyleDeclaration(Vector<StyleProperty>&& properties)
: m_properties(move(properties))
{
@ -34,3 +36,5 @@ StyleDeclaration::StyleDeclaration(Vector<StyleProperty>&& properties)
StyleDeclaration::~StyleDeclaration()
{
}
}

View file

@ -30,6 +30,8 @@
#include <AK/Vector.h>
#include <LibHTML/CSS/StyleValue.h>
namespace Web {
struct StyleProperty {
CSS::PropertyID property_id;
NonnullRefPtr<StyleValue> value;
@ -52,3 +54,5 @@ public:
Vector<StyleProperty> m_properties;
};
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/FontCache.h>
#include <ctype.h>
namespace Web {
StyleProperties::StyleProperties()
{
}
@ -177,3 +179,5 @@ bool StyleProperties::operator==(const StyleProperties& other) const
return true;
}
}

View file

@ -32,6 +32,8 @@
#include <LibGfx/Forward.h>
#include <LibHTML/CSS/StyleValue.h>
namespace Web {
class StyleProperties : public RefCounted<StyleProperties> {
public:
StyleProperties();
@ -75,3 +77,5 @@ private:
mutable RefPtr<Gfx::Font> m_font;
};
}

View file

@ -34,6 +34,8 @@
#include <ctype.h>
#include <stdio.h>
namespace Web {
StyleResolver::StyleResolver(Document& document)
: m_document(document)
{
@ -294,3 +296,5 @@ NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& eleme
return style;
}
}

View file

@ -30,6 +30,8 @@
#include <AK/OwnPtr.h>
#include <LibHTML/CSS/StyleProperties.h>
namespace Web {
class Document;
class Element;
class ParentNode;
@ -56,3 +58,5 @@ private:
Document& m_document;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/CSS/StyleRule.h>
namespace Web {
StyleRule::StyleRule(Vector<Selector>&& selectors, NonnullRefPtr<StyleDeclaration>&& declaration)
: m_selectors(move(selectors))
, m_declaration(move(declaration))
@ -35,3 +37,5 @@ StyleRule::StyleRule(Vector<Selector>&& selectors, NonnullRefPtr<StyleDeclaratio
StyleRule::~StyleRule()
{
}
}

View file

@ -30,6 +30,8 @@
#include <LibHTML/CSS/Selector.h>
#include <LibHTML/CSS/StyleDeclaration.h>
namespace Web {
class StyleRule : public RefCounted<StyleRule> {
public:
static NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, NonnullRefPtr<StyleDeclaration>&& declaration)
@ -48,3 +50,5 @@ private:
Vector<Selector> m_selectors;
NonnullRefPtr<StyleDeclaration> m_declaration;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/CSS/StyleSheet.h>
namespace Web {
StyleSheet::StyleSheet(NonnullRefPtrVector<StyleRule>&& rules)
: m_rules(move(rules))
{
@ -34,3 +36,5 @@ StyleSheet::StyleSheet(NonnullRefPtrVector<StyleRule>&& rules)
StyleSheet::~StyleSheet()
{
}
}

View file

@ -29,6 +29,8 @@
#include <AK/NonnullRefPtrVector.h>
#include <LibHTML/CSS/StyleRule.h>
namespace Web {
class StyleSheet : public RefCounted<StyleSheet> {
public:
static NonnullRefPtr<StyleSheet> create(NonnullRefPtrVector<StyleRule>&& rules)
@ -45,3 +47,5 @@ private:
NonnullRefPtrVector<StyleRule> m_rules;
};
}

View file

@ -32,6 +32,8 @@
#include <LibHTML/Frame.h>
#include <LibHTML/ResourceLoader.h>
namespace Web {
StyleValue::StyleValue(Type type)
: m_type(type)
{
@ -76,3 +78,5 @@ ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
m_document->frame()->set_needs_display({});
});
}
}

View file

@ -37,6 +37,8 @@
#include <LibHTML/CSS/Length.h>
#include <LibHTML/CSS/PropertyID.h>
namespace Web {
class Document;
namespace CSS {
@ -222,3 +224,5 @@ private:
WeakPtr<Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;
};
}

View file

@ -60,6 +60,7 @@ int main(int argc, char** argv)
dbg() << "#include <AK/Assertions.h>";
dbg() << "#include <LibHTML/CSS/PropertyID.h>";
dbg() << "namespace Web {";
dbg() << "namespace CSS {";
dbg() << "PropertyID property_id_from_string(const StringView& string) {";
@ -86,6 +87,7 @@ int main(int argc, char** argv)
dbg() << " }";
dbg() << "}";
dbg() << "}";
dbg() << "}";
return 0;
}

View file

@ -62,6 +62,7 @@ int main(int argc, char** argv)
dbg() << "#include <AK/StringView.h>";
dbg() << "#include <AK/Traits.h>";
dbg() << "namespace Web {";
dbg() << "namespace CSS {";
dbg() << "enum class PropertyID {";
dbg() << " Invalid,";
@ -75,11 +76,12 @@ int main(int argc, char** argv)
PropertyID property_id_from_string(const StringView&);\n\
const char* string_from_property_id(PropertyID);\n\
}\n\
}\n\
\n\
namespace AK {\n\
template<>\n\
struct Traits<CSS::PropertyID> : public GenericTraits<CSS::PropertyID> {\n\
static unsigned hash(CSS::PropertyID property_id) { return int_hash((unsigned)property_id); }\n\
struct Traits<Web::CSS::PropertyID> : public GenericTraits<Web::CSS::PropertyID> {\n\
static unsigned hash(Web::CSS::PropertyID property_id) { return int_hash((unsigned)property_id); }\n\
};\n\
}\n";

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/CharacterData.h>
namespace Web {
CharacterData::CharacterData(Document& document, NodeType type, const String& data)
: Node(document, type)
, m_data(data)
@ -35,3 +37,5 @@ CharacterData::CharacterData(Document& document, NodeType type, const String& da
CharacterData::~CharacterData()
{
}
}

View file

@ -29,6 +29,8 @@
#include <AK/String.h>
#include <LibHTML/DOM/Node.h>
namespace Web {
class CharacterData : public Node {
public:
virtual ~CharacterData() override;
@ -49,3 +51,5 @@ inline bool is<CharacterData>(const Node& node)
{
return node.is_character_data();
}
}

View file

@ -27,6 +27,8 @@
#include <LibHTML/DOM/Comment.h>
#include <LibHTML/Layout/LayoutText.h>
namespace Web {
Comment::Comment(Document& document, const String& data)
: CharacterData(document, NodeType::COMMENT_NODE, data)
{
@ -35,3 +37,5 @@ Comment::Comment(Document& document, const String& data)
Comment::~Comment()
{
}
}

View file

@ -29,6 +29,8 @@
#include <AK/String.h>
#include <LibHTML/DOM/CharacterData.h>
namespace Web {
class Comment final : public CharacterData {
public:
explicit Comment(Document&, const String&);
@ -42,3 +44,5 @@ inline bool is<Comment>(const Node& node)
{
return node.is_comment();
}
}

View file

@ -43,6 +43,8 @@
#include <LibHTML/Layout/LayoutTreeBuilder.h>
#include <stdio.h>
namespace Web {
Document::Document()
: ParentNode(*this, NodeType::DOCUMENT_NODE)
, m_style_resolver(make<StyleResolver>(*this))
@ -329,3 +331,5 @@ Color Document::visited_link_color() const
return Color::Magenta;
return frame()->html_view()->palette().visited_link();
}
}

View file

@ -37,6 +37,8 @@
#include <LibHTML/CSS/StyleSheet.h>
#include <LibHTML/DOM/ParentNode.h>
namespace Web {
class Frame;
class HTMLBodyElement;
class HTMLHtmlElement;
@ -144,3 +146,5 @@ inline bool is<Document>(const Node& node)
{
return node.is_document();
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/ParentNode.h>
namespace Web {
class DocumentFragment : public ParentNode {
public:
DocumentFragment(Document& document)
@ -43,3 +45,5 @@ inline bool is<DocumentFragment>(const Node& node)
{
return node.is_document_fragment();
}
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/DocumentType.h>
namespace Web {
DocumentType::DocumentType(Document& document)
: Node(document, NodeType::DOCUMENT_TYPE_NODE)
{
@ -34,3 +36,5 @@ DocumentType::DocumentType(Document& document)
DocumentType::~DocumentType()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/Node.h>
namespace Web {
class DocumentType final : public Node {
public:
explicit DocumentType(Document&);
@ -41,3 +43,5 @@ inline bool is<DocumentType>(const Node& node)
{
return node.type() == NodeType::DOCUMENT_TYPE_NODE;
}
}

View file

@ -37,6 +37,8 @@
#include <LibHTML/Layout/LayoutTableRow.h>
#include <LibHTML/Layout/LayoutTreeBuilder.h>
namespace Web {
Element::Element(Document& document, const String& tag_name)
: ParentNode(document, NodeType::ELEMENT_NODE)
, m_tag_name(tag_name)
@ -215,3 +217,5 @@ NonnullRefPtr<StyleProperties> Element::computed_style()
}
return properties;
}
}

View file

@ -30,6 +30,8 @@
#include <LibHTML/DOM/ParentNode.h>
#include <LibHTML/Layout/LayoutNode.h>
namespace Web {
class LayoutNodeWithStyle;
class Attribute {
@ -102,3 +104,5 @@ inline bool is<Element>(const Node& node)
{
return node.is_element();
}
}

View file

@ -41,6 +41,8 @@
#include <LibHTML/DOM/HTMLStyleElement.h>
#include <LibHTML/DOM/HTMLTitleElement.h>
namespace Web {
NonnullRefPtr<Element> create_element(Document& document, const String& tag_name)
{
auto lowercase_tag_name = tag_name.to_lowercase();
@ -82,3 +84,5 @@ NonnullRefPtr<Element> create_element(Document& document, const String& tag_name
}
return adopt(*new Element(document, lowercase_tag_name));
}
}

View file

@ -28,4 +28,8 @@
#include <LibHTML/DOM/Element.h>
namespace Web {
NonnullRefPtr<Element> create_element(Document&, const String& tag_name);
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLAnchorElement.h>
namespace Web {
HTMLAnchorElement::HTMLAnchorElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLAnchorElement::HTMLAnchorElement(Document& document, const String& tag_name)
HTMLAnchorElement::~HTMLAnchorElement()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLAnchorElement : public HTMLElement {
public:
HTMLAnchorElement(Document&, const String& tag_name);
@ -41,3 +43,5 @@ inline bool is<HTMLAnchorElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "a";
}
}

View file

@ -27,6 +27,8 @@
#include <LibHTML/DOM/HTMLBRElement.h>
#include <LibHTML/Layout/LayoutBreak.h>
namespace Web {
HTMLBRElement::HTMLBRElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -40,3 +42,5 @@ RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleProperties*) con
{
return adopt(*new LayoutBreak(*this));
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLBRElement final : public HTMLElement {
public:
HTMLBRElement(Document&, const String& tag_name);
@ -41,3 +43,5 @@ inline bool is<HTMLBRElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "br";
}
}

View file

@ -30,6 +30,8 @@
#include <LibHTML/DOM/HTMLBlinkElement.h>
#include <LibHTML/Layout/LayoutNode.h>
namespace Web {
HTMLBlinkElement::HTMLBlinkElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
, m_timer(Core::Timer::construct())
@ -51,3 +53,5 @@ void HTMLBlinkElement::blink()
layout_node()->set_visible(!layout_node()->is_visible());
layout_node()->set_needs_display();
}
}

View file

@ -29,6 +29,8 @@
#include <LibCore/Forward.h>
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLBlinkElement : public HTMLElement {
public:
HTMLBlinkElement(Document&, const String& tag_name);
@ -39,3 +41,5 @@ private:
NonnullRefPtr<Core::Timer> m_timer;
};
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/HTMLBodyElement.h>
namespace Web {
HTMLBodyElement::HTMLBodyElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -71,3 +73,5 @@ void HTMLBodyElement::parse_attribute(const String& name, const String& value)
document().set_visited_link_color(color.value());
}
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLBodyElement : public HTMLElement {
public:
HTMLBodyElement(Document&, const String& tag_name);
@ -42,3 +44,5 @@ inline bool is<HTMLBodyElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "body";
}
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
HTMLElement::HTMLElement(Document& document, const String& tag_name)
: Element(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLElement::HTMLElement(Document& document, const String& tag_name)
HTMLElement::~HTMLElement()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/Element.h>
namespace Web {
class HTMLElement : public Element {
public:
HTMLElement(Document&, const String& tag_name);
@ -44,3 +46,5 @@ inline bool is<HTMLElement>(const Node& node)
{
return node.is_html_element();
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/CSS/StyleValue.h>
#include <LibHTML/DOM/HTMLFontElement.h>
namespace Web {
HTMLFontElement::HTMLFontElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -47,3 +49,5 @@ void HTMLFontElement::apply_presentational_hints(StyleProperties& style) const
}
});
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLFontElement : public HTMLElement {
public:
HTMLFontElement(Document&, const String& tag_name);
@ -35,3 +37,5 @@ public:
virtual void apply_presentational_hints(StyleProperties&) const override;
};
}

View file

@ -30,6 +30,8 @@
#include <LibHTML/Frame.h>
#include <LibHTML/HtmlView.h>
namespace Web {
HTMLFormElement::HTMLFormElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -80,3 +82,5 @@ void HTMLFormElement::submit()
// FIXME: We shouldn't let the form just do this willy-nilly.
document().frame()->html_view()->load(url);
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLFormElement : public HTMLElement {
public:
HTMLFormElement(Document&, const String& tag_name);
@ -44,3 +46,5 @@ inline bool is<HTMLFormElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "form";
}
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLHRElement.h>
namespace Web {
HTMLHRElement::HTMLHRElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLHRElement::HTMLHRElement(Document& document, const String& tag_name)
HTMLHRElement::~HTMLHRElement()
{
}
}

View file

@ -28,8 +28,12 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLHRElement : public HTMLElement {
public:
HTMLHRElement(Document&, const String& tag_name);
virtual ~HTMLHRElement() override;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLHeadElement.h>
namespace Web {
HTMLHeadElement::HTMLHeadElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLHeadElement::HTMLHeadElement(Document& document, const String& tag_name)
HTMLHeadElement::~HTMLHeadElement()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLHeadElement : public HTMLElement {
public:
HTMLHeadElement(Document&, const String& tag_name);
@ -39,3 +41,5 @@ inline bool is<HTMLHeadElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "head";
}
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLHeadingElement.h>
namespace Web {
HTMLHeadingElement::HTMLHeadingElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLHeadingElement::HTMLHeadingElement(Document& document, const String& tag_nam
HTMLHeadingElement::~HTMLHeadingElement()
{
}
}

View file

@ -28,8 +28,12 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLHeadingElement : public HTMLElement {
public:
HTMLHeadingElement(Document&, const String& tag_name);
virtual ~HTMLHeadingElement() override;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLHtmlElement.h>
namespace Web {
HTMLHtmlElement::HTMLHtmlElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLHtmlElement::HTMLHtmlElement(Document& document, const String& tag_name)
HTMLHtmlElement::~HTMLHtmlElement()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLHtmlElement : public HTMLElement {
public:
HTMLHtmlElement(Document&, const String& tag_name);
@ -39,3 +41,5 @@ inline bool is<HTMLHtmlElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "html";
}
}

View file

@ -32,6 +32,8 @@
#include <LibHTML/Layout/LayoutImage.h>
#include <LibHTML/ResourceLoader.h>
namespace Web {
HTMLImageElement::HTMLImageElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -121,3 +123,5 @@ void HTMLImageElement::set_volatile(Badge<LayoutDocument>, bool v)
return;
m_image_decoder = Gfx::ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size());
}
}

View file

@ -30,6 +30,8 @@
#include <LibGfx/Forward.h>
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class LayoutDocument;
class HTMLImageElement : public HTMLElement {
@ -57,3 +59,5 @@ private:
RefPtr<Gfx::ImageDecoder> m_image_decoder;
ByteBuffer m_encoded_data;
};
}

View file

@ -34,6 +34,8 @@
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutWidget.h>
namespace Web {
HTMLInputElement::HTMLInputElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -76,3 +78,5 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
return adopt(*new LayoutWidget(*this, *widget));
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLInputElement : public HTMLElement {
public:
HTMLInputElement(Document&, const String& tag_name);
@ -45,3 +47,5 @@ inline bool is<HTMLInputElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "input";
}
}

View file

@ -32,6 +32,8 @@
#include <LibHTML/Parser/CSSParser.h>
#include <LibHTML/ResourceLoader.h>
namespace Web {
HTMLLinkElement::HTMLLinkElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -60,3 +62,5 @@ void HTMLLinkElement::inserted_into(Node&)
});
}
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLLinkElement final : public HTMLElement {
public:
HTMLLinkElement(Document&, const String& tag_name);
@ -45,3 +47,5 @@ inline bool is<HTMLLinkElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "link";
}
}

View file

@ -30,6 +30,8 @@
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Parser/CSSParser.h>
namespace Web {
HTMLStyleElement::HTMLStyleElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -59,3 +61,5 @@ void HTMLStyleElement::removed_from(Node& old_parent)
}
return HTMLElement::removed_from(old_parent);
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class StyleSheet;
class HTMLStyleElement : public HTMLElement {
@ -41,3 +43,5 @@ public:
private:
RefPtr<StyleSheet> m_stylesheet;
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/DOM/HTMLTitleElement.h>
namespace Web {
HTMLTitleElement::HTMLTitleElement(Document& document, const String& tag_name)
: HTMLElement(document, tag_name)
{
@ -34,3 +36,5 @@ HTMLTitleElement::HTMLTitleElement(Document& document, const String& tag_name)
HTMLTitleElement::~HTMLTitleElement()
{
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/HTMLElement.h>
namespace Web {
class HTMLTitleElement : public HTMLElement {
public:
HTMLTitleElement(Document&, const String& tag_name);
@ -39,3 +41,5 @@ inline bool is<HTMLTitleElement>(const Node& node)
{
return is<Element>(node) && to<Element>(node).tag_name().to_lowercase() == "title";
}
}

View file

@ -35,6 +35,8 @@
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/Layout/LayoutText.h>
namespace Web {
Node::Node(Document& document, NodeType type)
: m_document(document)
, m_type(type)
@ -114,3 +116,5 @@ bool Node::is_link() const
return false;
return enclosing_link->has_attribute("href");
}
}

View file

@ -32,6 +32,8 @@
#include <AK/Vector.h>
#include <LibHTML/TreeNode.h>
namespace Web {
enum class NodeType : unsigned {
INVALID = 0,
ELEMENT_NODE = 1,
@ -185,3 +187,5 @@ inline const T* Node::first_ancestor_of_type() const
}
return nullptr;
}
}

View file

@ -28,6 +28,8 @@
#include <LibHTML/DOM/Node.h>
namespace Web {
class ParentNode : public Node {
public:
template<typename F> void for_each_child(F) const;
@ -53,3 +55,5 @@ inline void ParentNode::for_each_child(Callback callback)
for (auto* node = first_child(); node; node = node->next_sibling())
callback(*node);
}
}

View file

@ -27,6 +27,8 @@
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Layout/LayoutText.h>
namespace Web {
Text::Text(Document& document, const String& data)
: CharacterData(document, NodeType::TEXT_NODE, data)
{
@ -40,3 +42,5 @@ RefPtr<LayoutNode> Text::create_layout_node(const StyleProperties*) const
{
return adopt(*new LayoutText(*this));
}
}

View file

@ -29,6 +29,8 @@
#include <AK/String.h>
#include <LibHTML/DOM/CharacterData.h>
namespace Web {
class Text final : public CharacterData {
public:
explicit Text(Document&, const String&);
@ -45,3 +47,5 @@ inline bool is<Text>(const Node& node)
{
return node.is_text();
}
}

View file

@ -32,6 +32,8 @@
#include <ctype.h>
#include <stdio.h>
namespace Web {
DOMTreeModel::DOMTreeModel(Document& document)
: m_document(document)
{
@ -151,3 +153,5 @@ void DOMTreeModel::update()
{
did_update();
}
}

View file

@ -28,6 +28,8 @@
#include <LibGUI/Model.h>
namespace Web {
class Document;
class DOMTreeModel final : public GUI::Model {
@ -55,3 +57,5 @@ private:
GUI::Icon m_element_icon;
GUI::Icon m_text_icon;
};
}

View file

@ -38,6 +38,8 @@
#include <LibHTML/Layout/LayoutText.h>
#include <stdio.h>
namespace Web {
void dump_tree(const Node& node)
{
static int indent = 0;
@ -252,3 +254,5 @@ void dump_sheet(const StyleSheet& sheet)
dump_rule(rule);
}
}
}

View file

@ -26,6 +26,8 @@
#pragma once
namespace Web {
class Node;
class LayoutNode;
class StyleRule;
@ -37,3 +39,5 @@ void dump_sheet(const StyleSheet&);
void dump_rule(const StyleRule&);
#undef HTML_DEBUG
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 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.
*/
#pragma once
namespace Web {
class Document;
class Element;
class Frame;
class HtmlView;
class Node;
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutDocument.h>
namespace Web {
Frame::Frame(HtmlView& html_view)
: m_html_view(html_view.make_weak_ptr())
{
@ -78,3 +80,5 @@ void Frame::set_needs_display(const Gfx::Rect& rect)
return;
on_set_needs_display(rect);
}
}

View file

@ -34,6 +34,8 @@
#include <LibGfx/Size.h>
#include <LibHTML/TreeNode.h>
namespace Web {
class Document;
class HtmlView;
@ -67,3 +69,5 @@ private:
Gfx::Size m_size;
Gfx::Rect m_viewport_rect;
};
}

View file

@ -25,6 +25,7 @@
*/
#include <AK/FileSystemPath.h>
#include <AK/URL.h>
#include <LibCore/File.h>
#include <LibGUI/Application.h>
#include <LibGUI/Painter.h>
@ -46,8 +47,10 @@
#include <LibHTML/ResourceLoader.h>
#include <stdio.h>
namespace Web {
HtmlView::HtmlView()
: m_main_frame(::Frame::create(*this))
: m_main_frame(Web::Frame::create(*this))
{
main_frame().on_set_needs_display = [this](auto& content_rect) {
if (content_rect.is_empty()) {
@ -320,7 +323,7 @@ static RefPtr<Document> create_image_document(const ByteBuffer& data, const URL&
void HtmlView::load(const URL& url)
{
dbg() << "HtmlView::load: " << url;
dbg() << "HtmlView::load: " << url.to_string();
if (window())
window()->set_override_cursor(GUI::StandardCursor::None);
@ -410,3 +413,5 @@ void HtmlView::did_scroll()
{
main_frame().set_viewport_rect(visible_content_rect());
}
}

View file

@ -29,6 +29,8 @@
#include <LibGUI/ScrollableWidget.h>
#include <LibHTML/DOM/Document.h>
namespace Web {
class Frame;
class HtmlView : public GUI::ScrollableWidget {
@ -43,8 +45,8 @@ public:
const LayoutDocument* layout_root() const;
LayoutDocument* layout_root();
::Frame& main_frame() { return *m_main_frame; }
const ::Frame& main_frame() const { return *m_main_frame; }
Web::Frame& main_frame() { return *m_main_frame; }
const Web::Frame& main_frame() const { return *m_main_frame; }
void reload();
void load(const URL&);
@ -77,8 +79,10 @@ private:
void layout_and_sync_size();
void dump_selection(const char* event_name);
RefPtr<::Frame> m_main_frame;
RefPtr<Web::Frame> m_main_frame;
bool m_should_show_line_box_borders { false };
bool m_in_mouse_selection { false };
};
}

View file

@ -26,6 +26,8 @@
#include <LibHTML/Layout/BoxModelMetrics.h>
namespace Web {
BoxModelMetrics::BoxModelMetrics()
{
}
@ -43,3 +45,5 @@ BoxModelMetrics::PixelBox BoxModelMetrics::full_margin() const
m_margin.left.to_px() + m_border.left.to_px() + m_padding.left.to_px(),
};
}
}

View file

@ -29,6 +29,8 @@
#include <LibGfx/Size.h>
#include <LibHTML/CSS/LengthBox.h>
namespace Web {
class BoxModelMetrics {
public:
BoxModelMetrics();
@ -56,3 +58,5 @@ private:
LengthBox m_padding;
LengthBox m_border;
};
}

View file

@ -33,6 +33,8 @@
#include <LibHTML/Layout/LayoutText.h>
#include <math.h>
namespace Web {
LayoutBlock::LayoutBlock(const Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutBox(node, move(style))
{
@ -384,3 +386,5 @@ LineBox& LayoutBlock::add_line_box()
m_line_boxes.append(LineBox());
return m_line_boxes.last();
}
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/Layout/LayoutBox.h>
#include <LibHTML/Layout/LineBox.h>
namespace Web {
class Element;
class LayoutBlock : public LayoutBox {
@ -103,3 +105,5 @@ inline bool is<LayoutBlock>(const LayoutNode& node)
{
return node.is_block();
}
}

View file

@ -34,6 +34,8 @@
//#define DRAW_BOXES_AROUND_LAYOUT_NODES
//#define DRAW_BOXES_AROUND_HOVERED_NODES
namespace Web {
void LayoutBox::paint_border(RenderingContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id)
{
auto border_width = style().property(width_property_id);
@ -238,3 +240,5 @@ bool LayoutBox::is_body() const
{
return node() && node() == document().body();
}
}

View file

@ -29,6 +29,8 @@
#include <LibGfx/FloatRect.h>
#include <LibHTML/Layout/LayoutNode.h>
namespace Web {
class LayoutBox : public LayoutNodeWithStyleAndBoxModelMetrics {
public:
const Gfx::FloatRect& rect() const { return m_rect; }
@ -74,3 +76,5 @@ inline bool is<LayoutBox>(const LayoutNode& node)
{
return node.is_box();
}
}

View file

@ -27,6 +27,8 @@
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutBreak.h>
namespace Web {
LayoutBreak::LayoutBreak(const HTMLBRElement& element)
: LayoutNodeWithStyleAndBoxModelMetrics(&element, StyleProperties::create())
{
@ -41,3 +43,5 @@ void LayoutBreak::split_into_lines(LayoutBlock& block)
{
block.add_line_box();
}
}

View file

@ -29,6 +29,8 @@
#include <LibHTML/DOM/HTMLBRElement.h>
#include <LibHTML/Layout/LayoutNode.h>
namespace Web {
class LayoutBreak final : public LayoutNodeWithStyleAndBoxModelMetrics {
public:
explicit LayoutBreak(const HTMLBRElement&);
@ -40,3 +42,5 @@ private:
virtual const char* class_name() const override { return "LayoutBreak"; }
virtual void split_into_lines(LayoutBlock&) override;
};
}

Some files were not shown because too many files have changed in this diff Show more