1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 13:17:36 +00:00

LibWeb: Never blockify HTML <br> elements

This is a bit iffy, but since <br> elements can't be implemented in
"just CSS" today, we should also exclude them from the blockification
algorithm. This is important, since <br> is expected to always have
inline-like behavior.
This commit is contained in:
Andreas Kling 2023-09-01 09:55:56 +02:00
parent a7c770268f
commit d54cd23615
3 changed files with 15 additions and 0 deletions

View file

@ -68,6 +68,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/FontCache.h>
#include <LibWeb/HTML/HTMLBRElement.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Loader/ResourceLoader.h>
@ -2427,6 +2428,12 @@ enum class BoxTypeTransformation {
static BoxTypeTransformation required_box_type_transformation(StyleProperties const& style, DOM::Element const& element, Optional<CSS::Selector::PseudoElement> const& pseudo_element)
{
// NOTE: We never blockify <br> elements. They are always inline.
// There is currently no way to express in CSS how a <br> element really behaves.
// Spec issue: https://github.com/whatwg/html/issues/2291
if (is<HTML::HTMLBRElement>(element))
return BoxTypeTransformation::None;
// Absolute positioning or floating an element blockifies the boxs display type. [CSS2]
if (style.position() == CSS::Position::Absolute || style.position() == CSS::Position::Fixed || style.float_() != CSS::Float::None)
return BoxTypeTransformation::Blockify;

View file

@ -99,6 +99,7 @@ public:
virtual bool is_html_table_section_element() const { return false; }
virtual bool is_html_table_row_element() const { return false; }
virtual bool is_html_table_cell_element() const { return false; }
virtual bool is_html_br_element() const { return false; }
virtual bool is_navigable_container() const { return false; }
WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> pre_insert(JS::NonnullGCPtr<Node>, JS::GCPtr<Node>);

View file

@ -19,9 +19,16 @@ public:
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
private:
virtual bool is_html_br_element() const override { return true; }
HTMLBRElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLBRElement>() const { return is_html_br_element(); }
}