summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-16 19:20:20 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-17 23:06:45 +0200
commit86f78bff2a8d88ce5aa92f4146542cb482e8c1a5 (patch)
treed6cab6f90708a720278dfc69cf602d9ba135340a /Userland/Libraries
parent86571481946ce3a60a354d0072a204ed958651cd (diff)
downloadserenity-86f78bff2a8d88ce5aa92f4146542cb482e8c1a5.zip
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`.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.h2
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp3
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h6
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp10
6 files changed, 18 insertions, 17 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index 189c48ae10..e51111fd85 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -105,12 +105,12 @@ LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID t
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);
if (!value.has_value())
return fallback;
- return value.value()->to_color(document);
+ return value.value()->to_color(node);
}
void StyleProperties::load_font(Layout::Node const& node) const
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
index e4296851f3..2f0a0fa48f 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
@@ -39,7 +39,7 @@ public:
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;
- 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;
CSS::Display display() const;
Optional<CSS::Float> float_() const;
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 481de75603..412b6bc440 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -31,8 +31,9 @@ String IdentifierStyleValue::to_string() const
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)
return document.link_color();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 9d17b400d1..ac02a17d94 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -286,7 +286,7 @@ public:
virtual String to_string() const = 0;
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;
@@ -607,7 +607,7 @@ public:
Color color() const { return m_color; }
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
{
@@ -637,7 +637,7 @@ public:
CSS::ValueID id() const { return m_id; }
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
{
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 583689cfbc..e706dac660 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -175,7 +175,7 @@ enum class StyleDifference {
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)
return StyleDifference::None;
@@ -186,9 +186,9 @@ static StyleDifference compute_style_difference(const CSS::StyleProperties& old_
if (new_style.display() != old_style.display())
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;
- 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;
if (needs_relayout)
@@ -215,8 +215,8 @@ void Element::recompute_style()
}
auto diff = StyleDifference::NeedsRelayout;
- if (old_specified_css_values)
- diff = compute_style_difference(*old_specified_css_values, *new_specified_css_values, document());
+ if (old_specified_css_values && layout_node())
+ diff = compute_style_difference(*old_specified_css_values, *new_specified_css_values, *layout_node());
if (diff == StyleDifference::None)
return;
layout_node()->apply_style(*new_specified_css_values);
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index b1ee4196f7..2537755389 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -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())
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_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, document(), Color::Transparent));
+ 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, *this, Color::Transparent));
computed_values.set_z_index(specified_style.z_index());
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());
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);
if (border.line_style == CSS::LineStyle::None)
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);
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())
- 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()) {
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits