diff --git a/Base/home/anon/www/br.html b/Base/home/anon/www/br.html new file mode 100644 index 0000000000..0af2d1eb56 --- /dev/null +++ b/Base/home/anon/www/br.html @@ -0,0 +1,14 @@ + + BR element test + + Hello world
+ This is

+ a test page
+ for
+ the
+
+ BR element! +



+ Does it work? + + diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index 8a1524bc29..24602f109e 100644 --- a/Base/home/anon/www/welcome.html +++ b/Base/home/anon/www/welcome.html @@ -24,6 +24,7 @@ h1 {
  • selectors
  • link element
  • blink element
  • +
  • br element
  • www.serenityos.org
  • diff --git a/Libraries/LibHTML/DOM/ElementFactory.cpp b/Libraries/LibHTML/DOM/ElementFactory.cpp index 1124e5fdc9..922f25283d 100644 --- a/Libraries/LibHTML/DOM/ElementFactory.cpp +++ b/Libraries/LibHTML/DOM/ElementFactory.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -37,6 +38,8 @@ NonnullRefPtr create_element(Document& document, const String& tag_name return adopt(*new HTMLImageElement(document, lowercase_tag_name)); if (lowercase_tag_name == "blink") return adopt(*new HTMLBlinkElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "br") + return adopt(*new HTMLBRElement(document, lowercase_tag_name)); if (lowercase_tag_name == "h1" || lowercase_tag_name == "h2" || lowercase_tag_name == "h3" diff --git a/Libraries/LibHTML/DOM/HTMLBRElement.cpp b/Libraries/LibHTML/DOM/HTMLBRElement.cpp new file mode 100644 index 0000000000..c2e6d85325 --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLBRElement.cpp @@ -0,0 +1,16 @@ +#include +#include + +HTMLBRElement::HTMLBRElement(Document& document, const String& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLBRElement::~HTMLBRElement() +{ +} + +RefPtr HTMLBRElement::create_layout_node(const StyleResolver&, const StyleProperties*) const +{ + return adopt(*new LayoutBreak(*this)); +} diff --git a/Libraries/LibHTML/DOM/HTMLBRElement.h b/Libraries/LibHTML/DOM/HTMLBRElement.h new file mode 100644 index 0000000000..086b2b960d --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLBRElement.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +class HTMLBRElement final : public HTMLElement { +public: + HTMLBRElement(Document&, const String& tag_name); + virtual ~HTMLBRElement() override; + + virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override; +}; + +template<> +inline bool is(const Node& node) +{ + return is(node) && to(node).tag_name().to_lowercase() == "br"; +} diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp index fc66448692..4373624c76 100644 --- a/Libraries/LibHTML/Layout/LayoutBlock.cpp +++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp @@ -54,10 +54,12 @@ void LayoutBlock::layout_inline_children() child.split_into_lines(*this); }); + int min_line_height = style().line_height(); + int content_height = 0; for (auto& line_box : m_line_boxes) { - int max_height = 0; + int max_height = min_line_height; for (auto& fragment : line_box.fragments()) { max_height = max(max_height, fragment.rect().height()); } diff --git a/Libraries/LibHTML/Layout/LayoutBreak.cpp b/Libraries/LibHTML/Layout/LayoutBreak.cpp new file mode 100644 index 0000000000..24c2e581d8 --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutBreak.cpp @@ -0,0 +1,17 @@ +#include +#include + +LayoutBreak::LayoutBreak(const HTMLBRElement& element) + : LayoutNode(&element) +{ + set_inline(true); +} + +LayoutBreak::~LayoutBreak() +{ +} + +void LayoutBreak::split_into_lines(LayoutBlock& block) +{ + block.line_boxes().append(LineBox()); +} diff --git a/Libraries/LibHTML/Layout/LayoutBreak.h b/Libraries/LibHTML/Layout/LayoutBreak.h new file mode 100644 index 0000000000..af803e7ae3 --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutBreak.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +class LayoutBreak final : public LayoutNode { +public: + explicit LayoutBreak(const HTMLBRElement&); + virtual ~LayoutBreak() override; + + const HTMLBRElement& node() const { return to(*LayoutNode::node()); } + +private: + virtual const char* class_name() const override { return "LayoutBreak"; } + virtual void split_into_lines(LayoutBlock&) override; +}; diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared index 3252e010e3..08fc3d5500 100644 --- a/Libraries/LibHTML/Makefile.shared +++ b/Libraries/LibHTML/Makefile.shared @@ -15,6 +15,7 @@ LIBHTML_OBJS = \ DOM/HTMLImageElement.o \ DOM/HTMLLinkElement.o \ DOM/HTMLBlinkElement.o \ + DOM/HTMLBRElement.o \ DOM/Document.o \ DOM/Text.o \ DOM/DocumentType.o \ @@ -39,6 +40,7 @@ LIBHTML_OBJS = \ Layout/LayoutImage.o \ Layout/LayoutListItem.o \ Layout/LayoutListItemMarker.o \ + Layout/LayoutBreak.o \ Layout/BoxModelMetrics.o \ Layout/LineBox.o \ Layout/LineBoxFragment.o \