mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
LibWeb: Allow doing .to_color() on a StyleValue without a layout node
This will be needed to access the color of a stop from a SVG gradient <stop> element (which does not participate in layout, so does not have a layout node).
This commit is contained in:
parent
2013761feb
commit
f099ee3d47
4 changed files with 12 additions and 7 deletions
|
@ -285,7 +285,7 @@ public:
|
||||||
|
|
||||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
||||||
|
|
||||||
virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; }
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
||||||
ValueID to_identifier() const;
|
ValueID to_identifier() const;
|
||||||
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
||||||
virtual float to_number() const { return 0; }
|
virtual float to_number() const { return 0; }
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
Color color() const { return m_color; }
|
Color color() const { return m_color; }
|
||||||
virtual ErrorOr<String> to_string() const override;
|
virtual ErrorOr<String> to_string() const override;
|
||||||
virtual bool has_color() const override { return true; }
|
virtual bool has_color() const override { return true; }
|
||||||
virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override { return m_color; }
|
||||||
|
|
||||||
bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; };
|
bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; };
|
||||||
|
|
||||||
|
|
|
@ -84,15 +84,20 @@ bool IdentifierStyleValue::has_color() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Color IdentifierStyleValue::to_color(Layout::NodeWithStyle const& node) const
|
Color IdentifierStyleValue::to_color(Optional<Layout::NodeWithStyle const&> node) const
|
||||||
{
|
{
|
||||||
if (id() == CSS::ValueID::Currentcolor) {
|
if (id() == CSS::ValueID::Currentcolor) {
|
||||||
if (!node.has_style())
|
if (!node.has_value() || !node->has_style())
|
||||||
return Color::Black;
|
return Color::Black;
|
||||||
return node.computed_values().color();
|
return node->computed_values().color();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& document = node.document();
|
if (!node.has_value()) {
|
||||||
|
// FIXME: Can't resolve palette colors without layout node.
|
||||||
|
return Color::Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& document = node->document();
|
||||||
if (id() == CSS::ValueID::LibwebLink)
|
if (id() == CSS::ValueID::LibwebLink)
|
||||||
return document.link_color();
|
return document.link_color();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
ValueID id() const { return m_id; }
|
ValueID id() const { return m_id; }
|
||||||
|
|
||||||
virtual bool has_color() const override;
|
virtual bool has_color() const override;
|
||||||
virtual Color to_color(Layout::NodeWithStyle const& node) const override;
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&> node) const override;
|
||||||
virtual ErrorOr<String> to_string() const override;
|
virtual ErrorOr<String> to_string() const override;
|
||||||
|
|
||||||
bool properties_equal(IdentifierStyleValue const& other) const { return m_id == other.m_id; }
|
bool properties_equal(IdentifierStyleValue const& other) const { return m_id == other.m_id; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue