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

LibWeb: Move border width and color into LayoutStyle

To make this possible, I also had to give each LayoutNode a Document&
so it can resolve document-specific colors correctly. There's probably
ways to avoid having this extra member by resolving colors later, but
this works for now.
This commit is contained in:
Andreas Kling 2020-06-24 19:41:12 +02:00
parent 4b2ac34725
commit 440b4ece22
57 changed files with 173 additions and 190 deletions

View file

@ -267,7 +267,7 @@ void Document::update_layout()
layout();
}
RefPtr<LayoutNode> Document::create_layout_node(const StyleProperties*) const
RefPtr<LayoutNode> Document::create_layout_node(const StyleProperties*)
{
return adopt(*new LayoutDocument(*this, StyleProperties::create()));
}

View file

@ -145,7 +145,7 @@ public:
void set_quirks_mode(bool mode) { m_quirks_mode = mode; }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
OwnPtr<StyleResolver> m_style_resolver;
RefPtr<CSS::StyleSheetList> m_style_sheets;

View file

@ -107,7 +107,7 @@ bool Element::has_class(const FlyString& class_name) const
return false;
}
RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
const_cast<Element&>(*this).m_resolved_style = style;
@ -120,21 +120,21 @@ RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_sty
return nullptr;
if (display == CSS::Display::Block)
return adopt(*new LayoutBlock(this, move(style)));
return adopt(*new LayoutBlock(document(), this, move(style)));
if (display == CSS::Display::Inline)
return adopt(*new LayoutInline(*this, move(style)));
return adopt(*new LayoutInline(document(), *this, move(style)));
if (display == CSS::Display::ListItem)
return adopt(*new LayoutListItem(*this, move(style)));
return adopt(*new LayoutListItem(document(), *this, move(style)));
if (display == CSS::Display::Table)
return adopt(*new LayoutTable(*this, move(style)));
return adopt(*new LayoutTable(document(), *this, move(style)));
if (display == CSS::Display::TableRow)
return adopt(*new LayoutTableRow(*this, move(style)));
return adopt(*new LayoutTableRow(document(), *this, move(style)));
if (display == CSS::Display::TableCell)
return adopt(*new LayoutTableCell(*this, move(style)));
return adopt(*new LayoutTableCell(document(), *this, move(style)));
if (display == CSS::Display::TableRowGroup)
return adopt(*new LayoutTableRowGroup(*this, move(style)));
return adopt(*new LayoutTableRowGroup(document(), *this, move(style)));
if (display == CSS::Display::InlineBlock) {
auto inline_block = adopt(*new LayoutBlock(this, move(style)));
auto inline_block = adopt(*new LayoutBlock(document(), this, move(style)));
inline_block->set_inline(true);
return inline_block;
}

View file

@ -88,7 +88,7 @@ public:
void set_class_name(const String& value) { set_attribute(HTML::AttributeNames::class_, value); }
protected:
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
private:
Attribute* find_attribute(const FlyString& name);

View file

@ -38,9 +38,9 @@ HTMLBRElement::~HTMLBRElement()
{
}
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleProperties*) const
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleProperties*)
{
return adopt(*new LayoutBreak(*this));
return adopt(*new LayoutBreak(document(), *this));
}
}

View file

@ -35,7 +35,7 @@ public:
HTMLBRElement(Document&, const FlyString& tag_name);
virtual ~HTMLBRElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
};
template<>

View file

@ -55,12 +55,12 @@ unsigned HTMLCanvasElement::height() const
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
}
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
if (style->display() == CSS::Display::None)
return nullptr;
return adopt(*new LayoutCanvas(*this, move(style)));
return adopt(*new LayoutCanvas(document(), *this, move(style)));
}
CanvasRenderingContext2D* HTMLCanvasElement::get_context(String type)

View file

@ -51,7 +51,7 @@ public:
unsigned height() const;
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
RefPtr<Gfx::Bitmap> m_bitmap;
RefPtr<CanvasRenderingContext2D> m_context;

View file

@ -50,10 +50,10 @@ HTMLIFrameElement::~HTMLIFrameElement()
{
}
RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
return adopt(*new LayoutFrame(*this, move(style)));
return adopt(*new LayoutFrame(document(), *this, move(style)));
}
void HTMLIFrameElement::document_did_attach_to_frame(Frame& frame)

View file

@ -35,7 +35,7 @@ public:
HTMLIFrameElement(Document&, const FlyString& tag_name);
virtual ~HTMLIFrameElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
Frame* hosted_frame() { return m_hosted_frame; }
const Frame* hosted_frame() const { return m_hosted_frame; }

View file

@ -68,12 +68,12 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu
m_image_loader.load(document().complete_url(value));
}
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
if (style->display() == CSS::Display::None)
return nullptr;
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader));
}
const Gfx::Bitmap* HTMLImageElement::bitmap() const

View file

@ -53,7 +53,7 @@ public:
private:
void animate();
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
ImageLoader m_image_loader;
};

View file

@ -46,7 +46,7 @@ HTMLInputElement::~HTMLInputElement()
{
}
RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* parent_style)
{
ASSERT(document().frame());
auto& frame = *document().frame();
@ -97,7 +97,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* p
widget = text_box;
}
return adopt(*new LayoutWidget(*this, *widget));
return adopt(*new LayoutWidget(document(), *this, *widget));
}
}

View file

@ -35,7 +35,7 @@ public:
HTMLInputElement(Document&, const FlyString& tag_name);
virtual ~HTMLInputElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
String type() const { return attribute(HTML::AttributeNames::type); }
String value() const { return attribute(HTML::AttributeNames::value); }

View file

@ -61,7 +61,7 @@ void HTMLObjectElement::parse_attribute(const FlyString& name, const String& val
m_image_loader.load(document().complete_url(value));
}
RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const StyleProperties* parent_style) const
RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const StyleProperties* parent_style)
{
if (m_should_show_fallback_content)
return HTMLElement::create_layout_node(parent_style);
@ -70,7 +70,7 @@ RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const StyleProperties*
if (style->display() == CSS::Display::None)
return nullptr;
if (m_image_loader.has_image())
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader));
return nullptr;
}

View file

@ -46,7 +46,7 @@ public:
String type() const { return attribute(HTML::AttributeNames::type); }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
ImageLoader m_image_loader;
bool m_should_show_fallback_content { false };

View file

@ -110,7 +110,7 @@ const Element* Node::previous_element_sibling() const
return nullptr;
}
RefPtr<LayoutNode> Node::create_layout_node(const StyleProperties*) const
RefPtr<LayoutNode> Node::create_layout_node(const StyleProperties*)
{
return nullptr;
}

View file

@ -85,7 +85,7 @@ public:
RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true);
RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true);
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style);
virtual FlyString node_name() const = 0;

View file

@ -38,9 +38,9 @@ Text::~Text()
{
}
RefPtr<LayoutNode> Text::create_layout_node(const StyleProperties*) const
RefPtr<LayoutNode> Text::create_layout_node(const StyleProperties*)
{
return adopt(*new LayoutText(*this));
return adopt(*new LayoutText(document(), *this));
}
}

View file

@ -40,7 +40,7 @@ public:
virtual FlyString node_name() const override { return "#text"; }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
};
template<>