mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
LibWeb: Make StyleValue::to_color() take a Node instead of the Document
This is in preparation for the `currentcolor` value, which needs to know what Node it's on so it can check the `color`.
This commit is contained in:
parent
8657148194
commit
86f78bff2a
6 changed files with 18 additions and 17 deletions
|
@ -105,12 +105,12 @@ LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID t
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color StyleProperties::color_or_fallback(CSS::PropertyID id, const DOM::Document& document, Color fallback) const
|
Color StyleProperties::color_or_fallback(CSS::PropertyID id, Layout::NodeWithStyle const& node, Color fallback) const
|
||||||
{
|
{
|
||||||
auto value = property(id);
|
auto value = property(id);
|
||||||
if (!value.has_value())
|
if (!value.has_value())
|
||||||
return fallback;
|
return fallback;
|
||||||
return value.value()->to_color(document);
|
return value.value()->to_color(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleProperties::load_font(Layout::Node const& node) const
|
void StyleProperties::load_font(Layout::Node const& node) const
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
|
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
|
||||||
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
|
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
|
||||||
Color color_or_fallback(CSS::PropertyID, const DOM::Document&, Color fallback) const;
|
Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
|
||||||
Optional<CSS::TextAlign> text_align() const;
|
Optional<CSS::TextAlign> text_align() const;
|
||||||
CSS::Display display() const;
|
CSS::Display display() const;
|
||||||
Optional<CSS::Float> float_() const;
|
Optional<CSS::Float> float_() const;
|
||||||
|
|
|
@ -31,8 +31,9 @@ String IdentifierStyleValue::to_string() const
|
||||||
return CSS::string_from_value_id(m_id);
|
return CSS::string_from_value_id(m_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color IdentifierStyleValue::to_color(const DOM::Document& document) const
|
Color IdentifierStyleValue::to_color(Layout::NodeWithStyle const& node) const
|
||||||
{
|
{
|
||||||
|
auto& document = node.document();
|
||||||
if (id() == CSS::ValueID::LibwebLink)
|
if (id() == CSS::ValueID::LibwebLink)
|
||||||
return document.link_color();
|
return document.link_color();
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ public:
|
||||||
|
|
||||||
virtual String to_string() const = 0;
|
virtual String to_string() const = 0;
|
||||||
virtual Length to_length() const { return {}; }
|
virtual Length to_length() const { return {}; }
|
||||||
virtual Color to_color(const DOM::Document&) const { return {}; }
|
virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; }
|
||||||
|
|
||||||
CSS::ValueID to_identifier() const;
|
CSS::ValueID to_identifier() const;
|
||||||
|
|
||||||
|
@ -607,7 +607,7 @@ public:
|
||||||
|
|
||||||
Color color() const { return m_color; }
|
Color color() const { return m_color; }
|
||||||
String to_string() const override { return m_color.to_string(); }
|
String to_string() const override { return m_color.to_string(); }
|
||||||
Color to_color(const DOM::Document&) const override { return m_color; }
|
Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }
|
||||||
|
|
||||||
virtual bool equals(const StyleValue& other) const override
|
virtual bool equals(const StyleValue& other) const override
|
||||||
{
|
{
|
||||||
|
@ -637,7 +637,7 @@ public:
|
||||||
CSS::ValueID id() const { return m_id; }
|
CSS::ValueID id() const { return m_id; }
|
||||||
|
|
||||||
virtual String to_string() const override;
|
virtual String to_string() const override;
|
||||||
virtual Color to_color(const DOM::Document&) const override;
|
virtual Color to_color(Layout::NodeWithStyle const& node) const override;
|
||||||
|
|
||||||
virtual bool equals(const StyleValue& other) const override
|
virtual bool equals(const StyleValue& other) const override
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,7 +175,7 @@ enum class StyleDifference {
|
||||||
NeedsRelayout,
|
NeedsRelayout,
|
||||||
};
|
};
|
||||||
|
|
||||||
static StyleDifference compute_style_difference(const CSS::StyleProperties& old_style, const CSS::StyleProperties& new_style, const Document& document)
|
static StyleDifference compute_style_difference(CSS::StyleProperties const& old_style, CSS::StyleProperties const& new_style, Layout::NodeWithStyle const& node)
|
||||||
{
|
{
|
||||||
if (old_style == new_style)
|
if (old_style == new_style)
|
||||||
return StyleDifference::None;
|
return StyleDifference::None;
|
||||||
|
@ -186,9 +186,9 @@ static StyleDifference compute_style_difference(const CSS::StyleProperties& old_
|
||||||
if (new_style.display() != old_style.display())
|
if (new_style.display() != old_style.display())
|
||||||
needs_relayout = true;
|
needs_relayout = true;
|
||||||
|
|
||||||
if (new_style.color_or_fallback(CSS::PropertyID::Color, document, Color::Black) != old_style.color_or_fallback(CSS::PropertyID::Color, document, Color::Black))
|
if (new_style.color_or_fallback(CSS::PropertyID::Color, node, Color::Black) != old_style.color_or_fallback(CSS::PropertyID::Color, node, Color::Black))
|
||||||
needs_repaint = true;
|
needs_repaint = true;
|
||||||
else if (new_style.color_or_fallback(CSS::PropertyID::BackgroundColor, document, Color::Black) != old_style.color_or_fallback(CSS::PropertyID::BackgroundColor, document, Color::Black))
|
else if (new_style.color_or_fallback(CSS::PropertyID::BackgroundColor, node, Color::Black) != old_style.color_or_fallback(CSS::PropertyID::BackgroundColor, node, Color::Black))
|
||||||
needs_repaint = true;
|
needs_repaint = true;
|
||||||
|
|
||||||
if (needs_relayout)
|
if (needs_relayout)
|
||||||
|
@ -215,8 +215,8 @@ void Element::recompute_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto diff = StyleDifference::NeedsRelayout;
|
auto diff = StyleDifference::NeedsRelayout;
|
||||||
if (old_specified_css_values)
|
if (old_specified_css_values && layout_node())
|
||||||
diff = compute_style_difference(*old_specified_css_values, *new_specified_css_values, document());
|
diff = compute_style_difference(*old_specified_css_values, *new_specified_css_values, *layout_node());
|
||||||
if (diff == StyleDifference::None)
|
if (diff == StyleDifference::None)
|
||||||
return;
|
return;
|
||||||
layout_node()->apply_style(*new_specified_css_values);
|
layout_node()->apply_style(*new_specified_css_values);
|
||||||
|
|
|
@ -321,8 +321,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
||||||
if (auto list_style_type = specified_style.list_style_type(); list_style_type.has_value())
|
if (auto list_style_type = specified_style.list_style_type(); list_style_type.has_value())
|
||||||
computed_values.set_list_style_type(list_style_type.value());
|
computed_values.set_list_style_type(list_style_type.value());
|
||||||
|
|
||||||
computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, document(), Color::Black));
|
computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, Color::Black));
|
||||||
computed_values.set_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, document(), Color::Transparent));
|
computed_values.set_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, Color::Transparent));
|
||||||
|
|
||||||
computed_values.set_z_index(specified_style.z_index());
|
computed_values.set_z_index(specified_style.z_index());
|
||||||
computed_values.set_opacity(specified_style.opacity());
|
computed_values.set_opacity(specified_style.opacity());
|
||||||
|
@ -348,7 +348,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
||||||
computed_values.set_box_shadow(specified_style.box_shadow());
|
computed_values.set_box_shadow(specified_style.box_shadow());
|
||||||
|
|
||||||
auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
|
auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
|
||||||
border.color = specified_style.color_or_fallback(color_property, document(), Color::Transparent);
|
border.color = specified_style.color_or_fallback(color_property, *this, Color::Transparent);
|
||||||
border.line_style = specified_style.line_style(style_property).value_or(CSS::LineStyle::None);
|
border.line_style = specified_style.line_style(style_property).value_or(CSS::LineStyle::None);
|
||||||
if (border.line_style == CSS::LineStyle::None)
|
if (border.line_style == CSS::LineStyle::None)
|
||||||
border.width = 0;
|
border.width = 0;
|
||||||
|
@ -362,9 +362,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
||||||
do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
|
do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
|
||||||
|
|
||||||
if (auto fill = specified_style.property(CSS::PropertyID::Fill); fill.has_value())
|
if (auto fill = specified_style.property(CSS::PropertyID::Fill); fill.has_value())
|
||||||
computed_values.set_fill(fill.value()->to_color(document()));
|
computed_values.set_fill(fill.value()->to_color(*this));
|
||||||
if (auto stroke = specified_style.property(CSS::PropertyID::Stroke); stroke.has_value())
|
if (auto stroke = specified_style.property(CSS::PropertyID::Stroke); stroke.has_value())
|
||||||
computed_values.set_stroke(stroke.value()->to_color(document()));
|
computed_values.set_stroke(stroke.value()->to_color(*this));
|
||||||
if (auto stroke_width = specified_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
|
if (auto stroke_width = specified_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
|
||||||
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
|
||||||
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue