LibWeb: Copy some properties from specified style into layout node

Another step towards not having to carry the full specified style with
us everywhere. This isn't the ideal final layout, since we're mixing
computed and used values a bit randomly here, but one step at a time.
This commit is contained in:
Andreas Kling 2021-01-06 11:31:19 +01:00
parent e5490ae1d1
commit 2cc39cfb0e
Notes: sideshowbarker 2024-07-19 00:04:48 +09:00
4 changed files with 30 additions and 18 deletions

View File

@ -343,15 +343,10 @@ RefPtr<Gfx::Bitmap> Document::background_image() const
if (!body_layout_node)
return {};
auto background_image = body_layout_node->specified_style().property(CSS::PropertyID::BackgroundImage);
if (!background_image.has_value() || !background_image.value()->is_image())
auto background_image = body_layout_node->background_image();
if (!background_image)
return {};
auto& image_value = static_cast<const CSS::ImageStyleValue&>(*background_image.value());
if (!image_value.bitmap())
return {};
return *image_value.bitmap();
return background_image->bitmap();
}
URL Document::complete_url(const String& string) const

View File

@ -55,7 +55,7 @@ static AvailableSpaceForLineInfo available_space_for_line(const InlineFormatting
AvailableSpaceForLineInfo info;
// FIXME: This is a total hack guess since we don't actually know the final y position of lines here!
float line_height = context.containing_block().specified_style().line_height(context.containing_block());
float line_height = context.containing_block().line_height();
float y = (line_index * line_height);
auto& bfc = static_cast<const BlockFormattingContext&>(*context.parent());
@ -110,7 +110,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
containing_block().line_boxes().take_last();
auto text_align = containing_block().computed_values().text_align();
float min_line_height = containing_block().specified_style().line_height(containing_block());
float min_line_height = containing_block().line_height();
float content_height = 0;
float max_linebox_width = 0;

View File

@ -157,13 +157,6 @@ void Node::set_needs_display()
}
}
float Node::font_size() const
{
// FIXME: This doesn't work right for relative font-sizes
auto length = specified_style().length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(10, CSS::Length::Type::Px));
return length.raw_value();
}
Gfx::FloatPoint Node::box_type_agnostic_position() const
{
if (is<Box>(*this))
@ -223,6 +216,18 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
auto& computed_values = static_cast<CSS::MutableComputedValues&>(m_computed_values);
m_font = specified_style.font();
m_line_height = specified_style.line_height(*this);
{
// FIXME: This doesn't work right for relative font-sizes
auto length = specified_style.length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(10, CSS::Length::Type::Px));
m_font_size = length.raw_value();
}
auto bgimage = specified_style.property(CSS::PropertyID::BackgroundImage);
if (bgimage.has_value() && bgimage.value()->is_image()) {
m_background_image = static_ptr_cast<CSS::ImageStyleValue>(bgimage.value());
}
auto position = specified_style.position();
if (position.has_value())
@ -310,5 +315,4 @@ bool Node::is_inline_block() const
{
return is_inline() && is<BlockBox>(*this);
}
}

View File

@ -206,6 +206,9 @@ public:
void apply_style(const CSS::StyleProperties&);
const Gfx::Font& font() const { return *m_font; }
float line_height() const { return m_line_height; }
float font_size() const { return m_font_size; }
const CSS::ImageStyleValue* background_image() const { return m_background_image; }
protected:
NodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
@ -213,6 +216,9 @@ protected:
private:
CSS::ComputedValues m_computed_values;
RefPtr<Gfx::Font> m_font;
float m_line_height { 0 };
float m_font_size { 0 };
RefPtr<CSS::ImageStyleValue> m_background_image;
NonnullRefPtr<CSS::StyleProperties> m_specified_style;
CSS::Position m_position;
@ -240,6 +246,13 @@ inline const Gfx::Font& Node::font() const
return parent()->font();
}
inline float Node::font_size() const
{
if (m_has_style)
return static_cast<const NodeWithStyle*>(this)->font_size();
return parent()->font_size();
}
inline const CSS::StyleProperties& Node::specified_style() const
{
if (m_has_style)