mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibWeb: Add equals() for LengthStyleValue and ColorStyleValue
The default equals() does to_string() on both sides which is pretty silly when they are of the same type.
This commit is contained in:
parent
58bade25dd
commit
30685a7714
2 changed files with 24 additions and 0 deletions
|
@ -154,6 +154,16 @@ public:
|
||||||
return String::format("[%g %s]", m_value, unit_name());
|
return String::format("[%g %s]", m_value, unit_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const Length& other) const
|
||||||
|
{
|
||||||
|
return m_type == other.m_type && m_value == other.m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Length& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float relative_length_to_px(const Layout::Node&) const;
|
float relative_length_to_px(const Layout::Node&) const;
|
||||||
|
|
||||||
|
|
|
@ -338,6 +338,13 @@ public:
|
||||||
|
|
||||||
virtual bool is_auto() const override { return m_length.is_auto(); }
|
virtual bool is_auto() const override { return m_length.is_auto(); }
|
||||||
|
|
||||||
|
virtual bool equals(const StyleValue& other) const override
|
||||||
|
{
|
||||||
|
if (type() != other.type())
|
||||||
|
return false;
|
||||||
|
return m_length == static_cast<const LengthStyleValue&>(other).m_length;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit LengthStyleValue(const Length& length)
|
explicit LengthStyleValue(const Length& length)
|
||||||
: StyleValue(Type::Length)
|
: StyleValue(Type::Length)
|
||||||
|
@ -388,6 +395,13 @@ public:
|
||||||
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(const DOM::Document&) const override { return m_color; }
|
||||||
|
|
||||||
|
virtual bool equals(const StyleValue& other) const override
|
||||||
|
{
|
||||||
|
if (type() != other.type())
|
||||||
|
return false;
|
||||||
|
return m_color == static_cast<const ColorStyleValue&>(other).m_color;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ColorStyleValue(Color color)
|
explicit ColorStyleValue(Color color)
|
||||||
: StyleValue(Type::Color)
|
: StyleValue(Type::Color)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue